Skip to content

Commit

Permalink
Made changes suggested by Mauro
Browse files Browse the repository at this point in the history
  • Loading branch information
JoukoVirtanen committed Oct 23, 2024
1 parent ec47f16 commit c879f86
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions integration-tests/pkg/mock_sensor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,33 +489,27 @@ func (m *MockSensor) pushEndpoint(containerID string, endpoint *sensorAPI.Networ
// translateAddress is a helper function for converting binary representations
// of network addresses (in the signals) to usable forms for testing
func (m *MockSensor) translateAddress(addr *sensorAPI.NetworkAddress) string {
address := utils.IPAddress{}
ipNetwork := utils.IPNetwork{}

peerId := utils.NetworkPeerID{Port: uint16(addr.GetPort())}
addressData := addr.GetAddressData()
if len(addressData) > 0 {
address = utils.IPFromBytes(addressData)
} else {
// If there is no address data IpNetwork should be set and represent
// a CIDR block or external IP address.
ipNetworkData := addr.GetIpNetwork()
if len(ipNetworkData) > 0 {
ipNetwork = utils.IPNetworkFromCIDRBytes(ipNetworkData)
// If the prefix length is 32 this is a regular IP address
// and not a CIDR block
if ipNetwork.PrefixLen() == byte(32) {
address = ipNetwork.IP()
ipNetwork = utils.IPNetwork{}
}
}

peerId.Address = utils.IPFromBytes(addressData)
return peerId.String()
}

ipPortPair := utils.NetworkPeerID{
Address: address,
IPNetwork: ipNetwork,
Port: uint16(addr.GetPort()),
// If there is no address data, IpNetwork should be set and represent
// a CIDR block or external IP address.
ipNetworkData := addr.GetIpNetwork()
if len(ipNetworkData) == 0 {
return peerId.String()
}

return ipPortPair.String()
// If the prefix length is 32 this is a regular IP address
// and not a CIDR block
ipNetwork := utils.IPNetworkFromCIDRBytes(ipNetworkData)
if ipNetwork.PrefixLen() == byte(32) {
peerId.Address = ipNetwork.IP()
} else {
peerId.IPNetwork = ipNetwork
}
return peerId.String()
}

0 comments on commit c879f86

Please sign in to comment.