swarm: port to p2p/enode

This commit is contained in:
Felix Lange 2018-09-11 19:01:13 +02:00
parent 8b3a50ab13
commit 92edb4dfe3
3 changed files with 18 additions and 24 deletions

View file

@ -27,7 +27,7 @@ import (
"github.com/ethereum/go-ethereum/contracts/ens"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/swarm/log"
"github.com/ethereum/go-ethereum/swarm/network"
"github.com/ethereum/go-ethereum/swarm/pss"
@ -117,7 +117,7 @@ func (c *Config) Init(prvKey *ecdsa.PrivateKey) {
c.PublicKey = pubkeyhex
c.BzzKey = keyhex
c.NodeID = discover.PubkeyID(&prvKey.PublicKey).String()
c.NodeID = enode.PubkeyToIDV4(&prvKey.PublicKey).String()
if c.SwapEnabled {
c.Swap.Init(c.Contract, prvKey)

View file

@ -31,7 +31,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
"github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/swarm/network/simulation"
@ -234,14 +234,14 @@ type testSwarmNetworkStep struct {
type file struct {
addr storage.Address
data string
nodeID discover.NodeID
nodeID enode.ID
}
// check represents a reference to a file that is retrieved
// from a particular node.
type check struct {
key string
nodeID discover.NodeID
nodeID enode.ID
}
// testSwarmNetworkOptions contains optional parameters for running
@ -440,7 +440,7 @@ func retrieve(
checkCount++
wg.Add(1)
go func(f file, id discover.NodeID) {
go func(f file, id enode.ID) {
defer wg.Done()
log.Debug("api get: check file", "node", id.String(), "key", f.addr.String(), "total files found", atomic.LoadUint64(totalFoundCount))
@ -466,7 +466,7 @@ func retrieve(
}(f, id)
}
go func(id discover.NodeID) {
go func(id enode.ID) {
defer totalWg.Done()
wg.Wait()

View file

@ -36,7 +36,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/protocols"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
@ -125,21 +125,11 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
config.HiveParams.Discovery = true
nodeID, err := discover.HexID(config.NodeID)
if err != nil {
return nil, err
}
addr := &network.BzzAddr{
OAddr: common.FromHex(config.BzzKey),
UAddr: []byte(discover.NewNode(nodeID, net.IP{127, 0, 0, 1}, 30303, 30303).String()),
}
bzzconfig := &network.BzzConfig{
NetworkID: config.NetworkID,
OverlayAddr: addr.OAddr,
UnderlayAddr: addr.UAddr,
HiveParams: config.HiveParams,
LightNode: config.LightNodeEnabled,
NetworkID: config.NetworkID,
OverlayAddr: common.FromHex(config.BzzKey),
HiveParams: config.HiveParams,
LightNode: config.LightNodeEnabled,
}
stateStore, err := state.NewDBStore(filepath.Join(config.Path, "state-store.db"))
@ -181,8 +171,12 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
delivery := stream.NewDelivery(to, self.netStore)
self.netStore.NewNetFetcherFunc = network.NewFetcherFactory(delivery.RequestFromPeers, config.DeliverySkipCheck).New
self.streamer = stream.NewRegistry(addr, delivery, self.netStore, stateStore, &stream.RegistryOptions{
SkipCheck: config.SyncingSkipCheck,
var nodeID enode.ID
if err := nodeID.UnmarshalText([]byte(config.NodeID)); err != nil {
return nil, err
}
self.streamer = stream.NewRegistry(nodeID, delivery, self.netStore, stateStore, &stream.RegistryOptions{
SkipCheck: config.DeliverySkipCheck,
DoSync: config.SyncEnabled,
DoRetrieve: true,
SyncUpdateDelay: config.SyncUpdateDelay,