Record BlockchainHeight and BlockchainVersion for each peer. New function IsPortForward.

This commit is contained in:
Kleissner
2021-06-09 22:35:55 +02:00
parent 594c06e276
commit 94c8e16724
4 changed files with 34 additions and 1 deletions

View File

@@ -64,6 +64,11 @@ func (c *Connection) IsBehindNAT() bool {
return c.PortInternal > 0 && c.Address.Port != int(c.PortInternal)
}
// IsPortForward checks if the remote peer uses port forwarding on the connection
func (c *Connection) IsPortForward() bool {
return c.PortExternal > 0
}
// GetConnections returns the list of connections
func (peer *PeerInfo) GetConnections(active bool) (connections []*Connection) {
peer.RLock()
@@ -284,6 +289,26 @@ func (peer *PeerInfo) IsBehindNAT() (result bool) {
return false
}
// IsPortForward checks if the peer uses port forwarding
func (peer *PeerInfo) IsPortForward() (result bool) {
peer.Lock()
defer peer.Unlock()
for _, connection := range peer.connectionActive {
if connection.IsPortForward() {
return true
}
}
for _, connection := range peer.connectionInactive {
if connection.IsPortForward() {
return true
}
}
return false
}
// ---- sending code ----
// send sends the packet to the peer on the connection