forked from cerc-io/plugeth
swarm: enable p2p/discovery and disable dynamic dialling (#19189)
This commit is contained in:
parent
94eca08ad8
commit
4e9230ea7a
@ -287,8 +287,8 @@ func bzzd(ctx *cli.Context) error {
|
||||
//setup the ethereum node
|
||||
utils.SetNodeConfig(ctx, &cfg)
|
||||
|
||||
//always disable discovery from p2p package - swarm discovery is done with the `hive` protocol
|
||||
cfg.P2P.NoDiscovery = true
|
||||
//disable dynamic dialing from p2p/discovery
|
||||
cfg.P2P.NoDial = true
|
||||
|
||||
stack, err := node.New(&cfg)
|
||||
if err != nil {
|
||||
|
@ -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"`
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user