mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/network: Add Healthy proxy method for api in hive
This commit is contained in:
parent
166f08403a
commit
e41cf5456b
2 changed files with 21 additions and 10 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
|
|
@ -247,7 +248,15 @@ func (h *Hive) savePeers() error {
|
|||
func (h *Hive) Healthy(addrs [][]byte) *Health {
|
||||
k := NewKademlia(h.BaseAddr(), NewKadParams())
|
||||
for _, a := range addrs {
|
||||
k.On(a)
|
||||
p := &Peer{
|
||||
BzzPeer: &BzzPeer{
|
||||
BzzAddr: &BzzAddr{
|
||||
OAddr: a,
|
||||
},
|
||||
},
|
||||
}
|
||||
k.On(p)
|
||||
}
|
||||
return pp.Healthy([]*Kademlia{k})
|
||||
pp := NewPeerPotMap([]*Kademlia{k})
|
||||
return pp[common.Bytes2Hex(h.BaseAddr())].Healthy()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
|||
for _, a := range addrs {
|
||||
kads = append(kads, network.NewKademlia(a, network.NewKadParams()))
|
||||
}
|
||||
ppmap := network.NewPeerPotMap(kads)
|
||||
//ppmap := network.NewPeerPotMap(kads)
|
||||
check := func(ctx context.Context, id enode.ID) (bool, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
|
@ -287,8 +287,9 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
|||
}
|
||||
|
||||
healthy := &network.Health{}
|
||||
pp := ppmap[id.String()]
|
||||
if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), pp); err != nil {
|
||||
//pp := ppmap[id.String()]
|
||||
//if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), pp); err != nil {
|
||||
if err := client.Call(&healthy, "hive_healthy", addrs); err != nil {
|
||||
return false, fmt.Errorf("error getting node health: %s", err)
|
||||
}
|
||||
log.Debug(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v,\n\n%v", id, healthy.GotNN, healthy.KnowNN, healthy.Hive))
|
||||
|
|
@ -389,7 +390,7 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
|||
for _, a := range addrs {
|
||||
kads = append(kads, network.NewKademlia(a, network.NewKadParams()))
|
||||
}
|
||||
ppmap := network.NewPeerPotMap(kads)
|
||||
//ppmap := network.NewPeerPotMap(kads)
|
||||
|
||||
var restartTime time.Time
|
||||
|
||||
|
|
@ -411,9 +412,9 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
|||
healthy := &network.Health{}
|
||||
addr := id.String()
|
||||
log.Error("before hive healthy call")
|
||||
pp := ppmap[addr]
|
||||
//pp := ppmap[addr]
|
||||
// if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), pp); err != nil {
|
||||
if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), addrs); err != nil {
|
||||
if err := client.Call(&healthy, "hive_healthy", addrs); err != nil {
|
||||
return fmt.Errorf("error getting node health: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -492,8 +493,9 @@ func discoveryPersistenceSimulation(nodes, conns int, adapter adapters.NodeAdapt
|
|||
return false, fmt.Errorf("error getting node client: %s", err)
|
||||
}
|
||||
healthy := &network.Health{}
|
||||
pp := ppmap[id.String()]
|
||||
if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), pp); err != nil {
|
||||
//pp := ppmap[id.String()]
|
||||
//if err := client.Call(&healthy, "hive_healthy", pp.BaseAddr(), pp); err != nil {
|
||||
if err := client.Call(&healthy, "hive_healthy", addrs); err != nil {
|
||||
return false, fmt.Errorf("error getting node health: %s", err)
|
||||
}
|
||||
log.Info(fmt.Sprintf("node %4s healthy: got nearest neighbours: %v, know nearest neighbours: %v", id, healthy.GotNN, healthy.KnowNN))
|
||||
|
|
|
|||
Loading…
Reference in a new issue