func()

in pkg/profiling/task/network/analyze/base/context.go [150:197]


func (c *AnalyzerContext) handleSocketConnectEvent(data interface{}) {
	event := data.(*events.SocketConnectEvent)

	if log.Enable(logrus.DebugLevel) {
		marshal, _ := json.Marshal(event)
		log.Debugf("found connect event, json: %s", string(marshal))
	}

	processes := c.processes[int32(event.Pid)]
	if len(processes) == 0 {
		log.Warnf("get process connect event, but this process is don't need to monitor, pid: %d", event.Pid)
		return
	}

	// build active connection information
	con := c.NewConnectionContext(event.ConID, event.RandomID, event.Pid, event.FD, processes, false)
	con.Role = event.Role
	if event.NeedComplete == 0 {
		con.RemotePort = uint16(event.RemoteAddrPort)
		con.LocalPort = uint16(event.LocalAddrPort)
		if event.SocketFamily == unix.AF_INET {
			con.LocalIP = parseAddressV4(event.LocalAddrV4)
			con.RemoteIP = parseAddressV4(event.RemoteAddrV4)
		} else {
			con.LocalIP = parseAddressV6(event.LocalAddrV6)
			con.RemoteIP = parseAddressV6(event.RemoteAddrV6)
		}
	} else {
		// if the remote address exists then setting it
		if event.RemoteAddrPort != 0 {
			con.RemotePort = uint16(event.RemoteAddrPort)
			if event.SocketFamily == unix.AF_INET {
				con.RemoteIP = parseAddressV4(event.RemoteAddrV4)
			} else {
				con.RemoteIP = parseAddressV6(event.RemoteAddrV6)
			}
		}
		c.sockParseQueue <- con
	}

	// notify the listeners
	for _, l := range c.listeners {
		l.ReceiveNewConnection(con, event)
	}

	// add to the context
	c.saveActiveConnection(con)
}