Simplify and streamline send code. Close #21

This commit is contained in:
Kleissner
2021-05-19 03:40:26 +02:00
parent 8e2043728c
commit d148fddd1e
5 changed files with 83 additions and 103 deletions

View File

@@ -799,6 +799,19 @@ createPacketLoop:
}
}
// setSelfReportedPorts sets the fields Internal Port and External Port according to the connection details.
// This is important for the remote peer to make smart decisions whether this peer is behind a NAT/firewall and supports port forwarding/UPnP.
func (packet *PacketRaw) setSelfReportedPorts(n *Network) {
if packet.Command != CommandAnnouncement && packet.Command != CommandResponse { // only for Announcement and Response messages
return
}
portI, portE := n.SelfReportedPorts()
binary.LittleEndian.PutUint16(packet.Payload[15:17], portI)
binary.LittleEndian.PutUint16(packet.Payload[17:19], portE)
}
// ---- Traverse ----
const traversePayloadHeaderSize = 76 + 65 + 28