diff --git a/Config.go b/Config.go index 6599ebe..74bc000 100644 --- a/Config.go +++ b/Config.go @@ -16,7 +16,7 @@ import ( ) // Version is the current core library version -const Version = "Alpha 2/20.05.2021" +const Version = "Alpha 2/09.06.2021" var config struct { LogFile string `yaml:"LogFile"` // Log file diff --git a/Connection.go b/Connection.go index 50778bf..e97b27d 100644 --- a/Connection.go +++ b/Connection.go @@ -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 diff --git a/Network.go b/Network.go index 9ee19d7..92fffc6 100644 --- a/Network.go +++ b/Network.go @@ -185,6 +185,8 @@ func packetWorker(packets <-chan networkWire) { peer.UserAgent = announce.UserAgent } peer.Features = announce.Features + peer.BlockchainHeight = announce.BlockchainHeight + peer.BlockchainVersion = announce.BlockchainVersion peer.cmdAnouncement(announce) } @@ -206,6 +208,8 @@ func packetWorker(packets <-chan networkWire) { peer.UserAgent = response.UserAgent } peer.Features = response.Features + peer.BlockchainHeight = response.BlockchainHeight + peer.BlockchainVersion = response.BlockchainVersion peer.cmdResponse(response) } @@ -216,6 +220,8 @@ func packetWorker(packets <-chan networkWire) { peer.UserAgent = announce.UserAgent } peer.Features = announce.Features + peer.BlockchainHeight = announce.BlockchainHeight + peer.BlockchainVersion = announce.BlockchainVersion peer.cmdLocalDiscovery(announce) } diff --git a/Peer ID.go b/Peer ID.go index ab818dd..4ea3cf4 100644 --- a/Peer ID.go +++ b/Peer ID.go @@ -94,6 +94,8 @@ type PeerInfo struct { isVirtual bool // Whether it is a virtual peer for establishing a connection. targetAddresses []*peerAddress // Virtual peer: Addresses to send any replies. traversePeer *PeerInfo // Virtual peer: Same field as in connection. + BlockchainHeight uint32 // Blockchain height + BlockchainVersion uint64 // Blockchain version // statistics StatsPacketSent uint64 // Count of packets sent