in pkg/profiling/task/network/analyze/base/traffic.go [255:310]
func (t *TrafficAnalyzer) buildCache(connections []*ConnectionContext) {
for _, con := range connections {
if t.ipNotEmpty(con.LocalIP, con.LocalPort) && t.ipNotEmpty(con.RemoteIP, con.RemotePort) {
t.localWithPeerCache[LocalWithPeerAddress{
LocalIP: con.LocalIP,
LocalPort: con.LocalPort,
RemoteIP: con.RemoteIP,
RemotePort: con.RemotePort,
}] = &PidWithRole{
Pid: con.LocalPid,
Role: con.Role,
}
}
if t.ipNotEmpty(con.LocalIP, con.LocalPort) {
peerAddress := PeerAddress{
RemoteIP: con.LocalIP,
RemotePort: con.LocalPort,
}
t.peerAddressCache[peerAddress] = append(t.peerAddressCache[peerAddress], con.LocalPid)
if len(con.LocalProcesses) > 0 {
localAddressProcesses := t.localAddresses[con.LocalIP]
if len(localAddressProcesses) == 0 {
localAddressProcesses = make(map[string]api.ProcessInterface)
t.localAddresses[con.LocalIP] = localAddressProcesses
}
for _, p := range con.LocalProcesses {
localAddressProcesses[p.Entity().Layer] = p
}
}
} else if t.ipNotEmpty(con.RemoteIP, con.RemotePort) {
// if server side is envoy
if con.Role == enums.ConnectionRoleServer && len(con.LocalProcesses) > 0 {
name, err := con.LocalProcesses[0].ExeName()
if err != nil {
log.Warnf("get process exe name failure, pid: %d, error: %v", con.LocalPid, err)
}
if name == processEnvoy {
t.envoyAcceptClientAddressCache[PeerAddress{
RemoteIP: con.RemoteIP,
RemotePort: con.RemotePort,
}] = &AddressWithPid{
RemoteIP: con.LocalIP,
RemotePort: con.LocalPort,
Pid: con.LocalPid,
}
}
}
}
if len(t.processData[con.LocalPid]) == 0 {
t.processData[con.LocalPid] = con.LocalProcesses
}
t.processExportPortAnalyze(con)
}
}