mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Use PortReportedExternal when available.
This commit is contained in:
14
Bootstrap.go
14
Bootstrap.go
@@ -226,12 +226,24 @@ func (peer *PeerInfo) cmdResponseBootstrapFindSelf(msg *MessageResponse, closest
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, closePeer := range closest {
|
for _, closePeer := range closest {
|
||||||
|
// Use the self-reported external port if available.
|
||||||
|
port := closePeer.Port
|
||||||
|
if closePeer.PortReportedExternal > 0 {
|
||||||
|
port = closePeer.PortReportedExternal
|
||||||
|
}
|
||||||
|
|
||||||
// Initiate contact. Once a response comes back, the peer is actually added to the list.
|
// Initiate contact. Once a response comes back, the peer is actually added to the list.
|
||||||
if contactArbitraryPeer(closePeer.PublicKey, []*net.UDPAddr{{IP: closePeer.IP, Port: int(closePeer.Port)}}) {
|
if contactArbitraryPeer(closePeer.PublicKey, []*net.UDPAddr{{IP: closePeer.IP, Port: int(port)}}) {
|
||||||
// Blacklist the target Peer ID, IP:Port for contact in the next 10 minutes.
|
// Blacklist the target Peer ID, IP:Port for contact in the next 10 minutes.
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If NAT is detected and the port is not forwarded, send a Traverse message.
|
||||||
|
// NAT detection is the same algorithm as peer.IsBehindNAT.
|
||||||
|
if closePeer.PortReportedExternal == 0 && closePeer.Port != closePeer.PortReportedInternal {
|
||||||
|
// TODO send traverse message
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -196,7 +196,14 @@ func record2Peer(record PeerRecord, network *Network) (peerN *PeerInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create temporary peer which is not added to the global list and not added to Kademlia.
|
// Create temporary peer which is not added to the global list and not added to Kademlia.
|
||||||
connection := &Connection{Network: network, Address: &net.UDPAddr{IP: record.IP, Port: int(record.Port)}, Status: ConnectionActive}
|
port := record.Port
|
||||||
|
if record.PortReportedExternal > 0 { // Use the external port if available
|
||||||
|
port = record.PortReportedExternal
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Traverse message needs to be considered here
|
||||||
|
|
||||||
|
connection := &Connection{Network: network, Address: &net.UDPAddr{IP: record.IP, Port: int(port)}, Status: ConnectionActive, PortInternal: record.PortReportedInternal, PortExternal: record.PortReportedExternal}
|
||||||
return &PeerInfo{PublicKey: record.PublicKey, connectionActive: []*Connection{connection}, connectionLatest: connection, NodeID: publicKey2NodeID(record.PublicKey), messageSequence: rand.Uint32()}
|
return &PeerInfo{PublicKey: record.PublicKey, connectionActive: []*Connection{connection}, connectionLatest: connection, NodeID: publicKey2NodeID(record.PublicKey), messageSequence: rand.Uint32()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user