1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 23:53:19 +08:00

handshake: log whether new addr observed

This commit is contained in:
Juan Batiz-Benet
2014-11-05 04:05:30 -08:00
parent 4989dcafed
commit 40aea2a934
2 changed files with 9 additions and 4 deletions

View File

@ -48,7 +48,9 @@ func Handshake3Update(lpeer, rpeer peer.Peer, msg *pb.Handshake3) (*Handshake3Re
if err != nil {
return res, err
}
lpeer.AddAddress(observedAddr)
if lpeer.AddAddress(observedAddr) {
log.Infof("(nat) added new local, remote-observed address: %s", observedAddr)
}
res.LocalObservedAddress = observedAddr
// remote's reported addresses

View File

@ -66,7 +66,8 @@ type Peer interface {
Addresses() []ma.Multiaddr
// AddAddress adds the given Multiaddr address to Peer's addresses.
AddAddress(a ma.Multiaddr)
// returns whether this was a newly added address.
AddAddress(a ma.Multiaddr) bool
// NetAddress returns the first Multiaddr found for a given network.
NetAddress(n string) ma.Multiaddr
@ -141,16 +142,18 @@ func (p *peer) Addresses() []ma.Multiaddr {
}
// AddAddress adds the given Multiaddr address to Peer's addresses.
func (p *peer) AddAddress(a ma.Multiaddr) {
// Returns whether this address was a newly added address
func (p *peer) AddAddress(a ma.Multiaddr) bool {
p.Lock()
defer p.Unlock()
for _, addr := range p.addresses {
if addr.Equal(a) {
return
return false
}
}
p.addresses = append(p.addresses, a)
return true
}
// NetAddress returns the first Multiaddr found for a given network.