diff options
author | Anton Evangelatov <anton.evangelatov@gmail.com> | 2019-03-01 19:20:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-01 19:20:37 +0800 |
commit | 4e9230ea7a846013777a9d7227f2ac0dec8678ec (patch) | |
tree | 7918d2d382f2c058e33ab5d6dff2acde87c55f80 /swarm | |
parent | 94eca08ad8bf8d101a29334afe69498cde2aa584 (diff) | |
download | go-tangerine-4e9230ea7a846013777a9d7227f2ac0dec8678ec.tar go-tangerine-4e9230ea7a846013777a9d7227f2ac0dec8678ec.tar.gz go-tangerine-4e9230ea7a846013777a9d7227f2ac0dec8678ec.tar.bz2 go-tangerine-4e9230ea7a846013777a9d7227f2ac0dec8678ec.tar.lz go-tangerine-4e9230ea7a846013777a9d7227f2ac0dec8678ec.tar.xz go-tangerine-4e9230ea7a846013777a9d7227f2ac0dec8678ec.tar.zst go-tangerine-4e9230ea7a846013777a9d7227f2ac0dec8678ec.zip |
swarm: enable p2p/discovery and disable dynamic dialling (#19189)
Diffstat (limited to 'swarm')
-rw-r--r-- | swarm/api/inspector.go | 9 | ||||
-rw-r--r-- | swarm/network/kademlia.go | 27 |
2 files changed, 35 insertions, 1 deletions
diff --git a/swarm/api/inspector.go b/swarm/api/inspector.go index 6706b32e6..ea3c4c049 100644 --- a/swarm/api/inspector.go +++ b/swarm/api/inspector.go @@ -18,6 +18,7 @@ package api import ( "context" + "fmt" "github.com/ethereum/go-ethereum/swarm/network" "github.com/ethereum/go-ethereum/swarm/storage" @@ -38,6 +39,14 @@ func (inspector *Inspector) Hive() string { return inspector.hive.String() } +func (inspector *Inspector) ListKnown() []string { + res := []string{} + for _, v := range inspector.hive.Kademlia.ListKnown() { + res = append(res, fmt.Sprintf("%v", v)) + } + return res +} + type HasInfo struct { Addr string `json:"address"` Has bool `json:"has"` diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go index 723f17f1c..304f9cd77 100644 --- a/swarm/network/kademlia.go +++ b/swarm/network/kademlia.go @@ -140,6 +140,7 @@ func (k *Kademlia) Register(peers ...*BzzAddr) error { defer k.lock.Unlock() var known, size int for _, p := range peers { + log.Trace("kademlia trying to register", "addr", p) // error if self received, peer should know better // and should be punished for this if bytes.Equal(p.Address(), k.base) { @@ -149,10 +150,22 @@ func (k *Kademlia) Register(peers ...*BzzAddr) error { k.addrs, _, found, _ = pot.Swap(k.addrs, p, Pof, func(v pot.Val) pot.Val { // if not found if v == nil { + log.Trace("registering new peer", "addr", p) // insert new offline peer into conns return newEntry(p) } - // found among known peers, do nothing + + e := v.(*entry) + + // if underlay address is different, still add + if !bytes.Equal(e.BzzAddr.UAddr, p.UAddr) { + log.Trace("underlay addr is different, so add again", "new", p, "old", e.BzzAddr) + // insert new offline peer into conns + return newEntry(p) + } + + log.Trace("found among known peers, underlay addr is same, do nothing", "new", p, "old", e.BzzAddr) + return v }) if found { @@ -417,6 +430,18 @@ func (k *Kademlia) Off(p *Peer) { } } +func (k *Kademlia) ListKnown() []*BzzAddr { + res := []*BzzAddr{} + + k.addrs.Each(func(val pot.Val) bool { + e := val.(*entry) + res = append(res, e.BzzAddr) + return true + }) + + return res +} + // EachConn is an iterator with args (base, po, f) applies f to each live peer // that has proximity order po or less as measured from the base // if base is nil, kademlia base address is used |