mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Record BlockchainHeight and BlockchainVersion for each peer. New function IsPortForward.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user