Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions addrmgr/netaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,18 @@ func (netAddr *NetAddress) Key() string {
return net.JoinHostPort(netAddr.ipString(), portString)
}

// Network returns the name of the network. It is always tcp.
//
// This is part of the [net.Addr] implementation.
func (netAddr *NetAddress) Network() string {
return "tcp"
}

// String returns a human-readable string for the network address. This is
// equivalent to calling Key, but is provided so the type can be used as a
// fmt.Stringer.
//
// This is part of the [net.Addr] implementation.
func (netAddr *NetAddress) String() string {
return netAddr.Key()
}
Expand Down
71 changes: 35 additions & 36 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,42 +1036,6 @@ func (sp *serverPeer) OnVersion(msg *wire.MsgVersion) error {
"providing desired services %v", msg.Services, missingServices)
}

// Update the address manager and request known addresses from the
// remote peer for outbound connections. This is skipped when running
// on the simulation and regression test networks since they are only
// intended to connect to specified peers and actively avoid advertising
// and connecting to discovered peers.
if !cfg.SimNet && !cfg.RegNet && !isInbound {
// Advertise the local address when the server accepts incoming
// connections and it believes itself to be close to the best
// known tip.
if !cfg.DisableListen && sp.server.syncManager.IsCurrent() {
// Get address that best matches.
pver := uint32(msg.ProtocolVersion)
addrTypeFilter := natfSupported(pver)
lna := addrManager.GetBestLocalAddress(sp.remoteAddr, addrTypeFilter)
if lna.IsRoutable() {
addresses := []*addrmgr.NetAddress{lna}
sp.pushAddrMsg(pver, addresses)
} else {
srvrLog.Debugf("Local address %s is not routable and will not "+
"be broadcast to outbound peer %v", lna.Key(), sp.Addr())
}
}

// Request known addresses if the server address manager needs
// more.
if addrManager.NeedMoreAddresses() {
sp.QueueMessage(wire.NewMsgGetAddr(), nil)
}

// Mark the address as a known good address.
err := addrManager.Good(sp.remoteAddr)
if err != nil {
srvrLog.Errorf("Marking address as good failed: %v", err)
}
}

sp.reportedLocalAddr.Store(&msg.AddrYou)

// Choose whether or not to relay transactions.
Expand Down Expand Up @@ -2737,6 +2701,41 @@ func (s *server) handleAddPeer(sp *serverPeer) bool {
return false
}

// Update the address manager and request known addresses from the remote
// peer for outbound connections. This is skipped when running on the
// simulation and regression test networks since they are only intended to
// connect to specified peers and actively avoid advertising and connecting
// to discovered peers.
addrManager := sp.server.addrManager
if !cfg.SimNet && !cfg.RegNet && !sp.Inbound() {
// Advertise the local address when the server accepts incoming
// connections and it believes itself to be close to the best known tip.
if !cfg.DisableListen && sp.server.syncManager.IsCurrent() {
// Get address that best matches.
pver := sp.ProtocolVersion()
addrTypeFilter := natfSupported(pver)
lna := addrManager.GetBestLocalAddress(sp.remoteAddr, addrTypeFilter)
if lna.IsRoutable() {
addrs := []*addrmgr.NetAddress{lna}
sp.pushAddrMsg(pver, addrs)
} else {
srvrLog.Debugf("Local address %s is not routable and will not "+
"be broadcast to outbound peer %v", lna.Key(), sp.Addr())
}
}

// Request known addresses if the server address manager needs more.
if addrManager.NeedMoreAddresses() {
sp.QueueMessage(wire.NewMsgGetAddr(), nil)
}

// Mark the address as a known good address.
err := addrManager.Good(sp.remoteAddr)
if err != nil {
srvrLog.Errorf("Marking address as good failed: %v", err)
}
}

// Consider the address the remote peer reported for the local connection as
// a potential external address candidate for the server.
s.considerReportedAddr(sp, sp.reportedLocalAddr.Load())
Expand Down