Skip to content

Commit

Permalink
add remote multiaddr from active connection to peerstore
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Feb 17, 2016
1 parent 8c511da commit 3518749
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer())
c.Close()
return
} else {
bwc := ids.Host.GetBandwidthReporter()
s = mstream.WrapStream(s, ID, bwc)

// ok give the response to our handler.
if err := msmux.SelectProtoOrFail(ID, s); err != nil {
log.Debugf("error writing stream header for %s", ID)
log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer())
s.Close()
return
} else {
ids.ResponseHandler(s)
}
}

bwc := ids.Host.GetBandwidthReporter()
s = mstream.WrapStream(s, ID, bwc)

// ok give the response to our handler.
if err := msmux.SelectProtoOrFail(ID, s); err != nil {
log.Debugf("error writing stream header for %s", ID)
log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer())
s.Close()
return
}

ids.ResponseHandler(s)

ids.currmu.Lock()
ch, found := ids.currid[c]
delete(ids.currid, c)
Expand Down Expand Up @@ -190,6 +190,8 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
lmaddrs = append(lmaddrs, maddr)
}

lmaddrs = append(lmaddrs, c.RemoteMultiaddr())

// update our peerstore with the addresses. here, we SET the addresses, clearing old ones.
// We are receiving from the peer itself. this is current address ground truth.
ids.Host.Peerstore().SetAddrs(p, lmaddrs, peer.ConnectedAddrTTL)
Expand Down

0 comments on commit 3518749

Please sign in to comment.