swarm/network: Fix for local node address not being set correctly

This was causing nodes to share bad addresses during peer discovery.
The Update(OverlayAddr) interface method returns an updated copy
rather than mutating the existing object.
This commit is contained in:
Shane Howley 2018-02-14 11:41:13 +00:00
parent a375d95143
commit c60d47882b
2 changed files with 3 additions and 3 deletions

View file

@ -124,10 +124,10 @@ func NewBzz(config *BzzConfig, kad Overlay, store StateStore) *Bzz {
// UpdateLocalAddr updates underlayaddress of the running node
func (b *Bzz) UpdateLocalAddr(byteaddr []byte) *BzzAddr {
b.localAddr.Update(&BzzAddr{
b.localAddr = b.localAddr.Update(&BzzAddr{
UAddr: byteaddr,
OAddr: b.localAddr.OAddr,
})
}).(*BzzAddr)
return b.localAddr
}

View file

@ -209,7 +209,7 @@ func (self *Swarm) Start(srv *p2p.Server) error {
// update uaddr to correct enode
newaddr := self.bzz.UpdateLocalAddr([]byte(srv.Self().String()))
log.Warn("Updated bzz local addr", "oaddr", fmt.Sprintf("%x", newaddr.OAddr), "uaddr", fmt.Sprintf("%x", newaddr.UAddr))
log.Warn("Updated bzz local addr", "oaddr", fmt.Sprintf("%x", newaddr.OAddr), "uaddr", fmt.Sprintf("%s", newaddr.UAddr))
// set chequebook
if self.config.SwapEnabled {