@cryptotaxi247 / kubo / commits / 40aea2a93

handshake: log whether new addr observed

Juan Batiz-Benet committed Nov 5, 2014 at 04:05 UTC 40aea2a934c9f0e0000d13fcd9f7ffc3c30c6bc7
2 files changed +9 -4
net/handshake/handshake3.go
+3 -1
@@ -48,7 +48,9 @@ func Handshake3Update(lpeer, rpeer peer.Peer, msg *pb.Handshake3) (*Handshake3Re
48 if err != nil {
49 return res, err
50 }
51 - lpeer.AddAddress(observedAddr)
51 + if lpeer.AddAddress(observedAddr) {
52 + log.Infof("(nat) added new local, remote-observed address: %s", observedAddr)
53 + }
54 res.LocalObservedAddress = observedAddr
55
56 // remote's reported addresses
peer/peer.go
+6 -3
@@ -66,7 +66,8 @@ type Peer interface {
66 Addresses() []ma.Multiaddr
67
68 // AddAddress adds the given Multiaddr address to Peer's addresses.
69 - AddAddress(a ma.Multiaddr)
69 + // returns whether this was a newly added address.
70 + AddAddress(a ma.Multiaddr) bool
71
72 // NetAddress returns the first Multiaddr found for a given network.
73 NetAddress(n string) ma.Multiaddr
@@ -141,16 +142,18 @@ func (p *peer) Addresses() []ma.Multiaddr {
142 }
143
144 // AddAddress adds the given Multiaddr address to Peer's addresses.
144 -func (p *peer) AddAddress(a ma.Multiaddr) {
145 +// Returns whether this address was a newly added address
146 +func (p *peer) AddAddress(a ma.Multiaddr) bool {
147 p.Lock()
148 defer p.Unlock()
149
150 for _, addr := range p.addresses {
151 if addr.Equal(a) {
150 - return
152 + return false
153 }
154 }
155 p.addresses = append(p.addresses, a)
156 + return true
157 }
158
159 // NetAddress returns the first Multiaddr found for a given network.