mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-10 16:16:47 +00:00

* [NOD-1147] Implement address exchange * [NOD-1147] Put placeholder for source address * [NOD-1147] Fix tests * [NOD-1147] Add comment * [NOD-1147] Remove needAddresses from MsgGetAddr * [NOD-1147] Use rand.Shuffle * [NOD-1147] Remove redundant const * [NOD-1147] Move defer to its correct place * [NOD-1147] Fix typo * [NOD-1147] Use EnqueueWithTimeout for outgoingRoute * [NOD-1147] Rename MsgGetAddr->MsgGetAddresses * [NOD-1147] Rename MsgGetAddr->MsgGetAddresses * [NOD-1147] Rename MsgAddr->MsgAddresses * [NOD-1147] Rename fakeSrcAddr->fakeSourceAddress * [NOD-1147] Remove redundant files * [NOD-1147] CmdAddr -> CmdAddress * [NOD-1147] Rename addr to address in protocol package
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package p2p
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/config"
|
|
"github.com/kaspanet/kaspad/peer"
|
|
"github.com/kaspanet/kaspad/wire"
|
|
)
|
|
|
|
// OnGetAddr is invoked when a peer receives a getaddr kaspa message
|
|
// and is used to provide the peer with known addresses from the address
|
|
// manager.
|
|
func (sp *Peer) OnGetAddr(_ *peer.Peer, msg *wire.MsgGetAddresses) {
|
|
// Don't return any addresses when running on the simulation test
|
|
// network. This helps prevent the network from becoming another
|
|
// public test network since it will not be able to learn about other
|
|
// peers that have not specifically been provided.
|
|
if config.ActiveConfig().Simnet {
|
|
return
|
|
}
|
|
|
|
// Do not accept getaddr requests from outbound peers. This reduces
|
|
// fingerprinting attacks.
|
|
if !sp.Inbound() {
|
|
peerLog.Debugf("Ignoring getaddr request from outbound peer %s", sp)
|
|
return
|
|
}
|
|
|
|
// Only allow one getaddr request per connection to discourage
|
|
// address stamping of inv announcements.
|
|
if sp.sentAddrs {
|
|
peerLog.Debugf("Ignoring repeated getaddr request from peer %s", sp)
|
|
return
|
|
}
|
|
sp.sentAddrs = true
|
|
|
|
// Get the current known addresses from the address manager.
|
|
addrCache := sp.server.AddrManager.AddressCache(msg.IncludeAllSubnetworks, msg.SubnetworkID)
|
|
|
|
// Push the addresses.
|
|
sp.pushAddrMsg(addrCache, sp.SubnetworkID())
|
|
}
|