mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm: port to p2p/enode
This commit is contained in:
parent
8b3a50ab13
commit
92edb4dfe3
3 changed files with 18 additions and 24 deletions
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/contracts/ens"
|
"github.com/ethereum/go-ethereum/contracts/ens"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"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/log"
|
||||||
"github.com/ethereum/go-ethereum/swarm/network"
|
"github.com/ethereum/go-ethereum/swarm/network"
|
||||||
"github.com/ethereum/go-ethereum/swarm/pss"
|
"github.com/ethereum/go-ethereum/swarm/pss"
|
||||||
|
|
@ -117,7 +117,7 @@ func (c *Config) Init(prvKey *ecdsa.PrivateKey) {
|
||||||
|
|
||||||
c.PublicKey = pubkeyhex
|
c.PublicKey = pubkeyhex
|
||||||
c.BzzKey = keyhex
|
c.BzzKey = keyhex
|
||||||
c.NodeID = discover.PubkeyID(&prvKey.PublicKey).String()
|
c.NodeID = enode.PubkeyToIDV4(&prvKey.PublicKey).String()
|
||||||
|
|
||||||
if c.SwapEnabled {
|
if c.SwapEnabled {
|
||||||
c.Swap.Init(c.Contract, prvKey)
|
c.Swap.Init(c.Contract, prvKey)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"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/p2p/simulations/adapters"
|
||||||
"github.com/ethereum/go-ethereum/swarm/api"
|
"github.com/ethereum/go-ethereum/swarm/api"
|
||||||
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
||||||
|
|
@ -234,14 +234,14 @@ type testSwarmNetworkStep struct {
|
||||||
type file struct {
|
type file struct {
|
||||||
addr storage.Address
|
addr storage.Address
|
||||||
data string
|
data string
|
||||||
nodeID discover.NodeID
|
nodeID enode.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// check represents a reference to a file that is retrieved
|
// check represents a reference to a file that is retrieved
|
||||||
// from a particular node.
|
// from a particular node.
|
||||||
type check struct {
|
type check struct {
|
||||||
key string
|
key string
|
||||||
nodeID discover.NodeID
|
nodeID enode.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// testSwarmNetworkOptions contains optional parameters for running
|
// testSwarmNetworkOptions contains optional parameters for running
|
||||||
|
|
@ -440,7 +440,7 @@ func retrieve(
|
||||||
|
|
||||||
checkCount++
|
checkCount++
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(f file, id discover.NodeID) {
|
go func(f file, id enode.ID) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
log.Debug("api get: check file", "node", id.String(), "key", f.addr.String(), "total files found", atomic.LoadUint64(totalFoundCount))
|
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)
|
}(f, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func(id discover.NodeID) {
|
go func(id enode.ID) {
|
||||||
defer totalWg.Done()
|
defer totalWg.Done()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"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/p2p/protocols"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"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
|
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{
|
bzzconfig := &network.BzzConfig{
|
||||||
NetworkID: config.NetworkID,
|
NetworkID: config.NetworkID,
|
||||||
OverlayAddr: addr.OAddr,
|
OverlayAddr: common.FromHex(config.BzzKey),
|
||||||
UnderlayAddr: addr.UAddr,
|
HiveParams: config.HiveParams,
|
||||||
HiveParams: config.HiveParams,
|
LightNode: config.LightNodeEnabled,
|
||||||
LightNode: config.LightNodeEnabled,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stateStore, err := state.NewDBStore(filepath.Join(config.Path, "state-store.db"))
|
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)
|
delivery := stream.NewDelivery(to, self.netStore)
|
||||||
self.netStore.NewNetFetcherFunc = network.NewFetcherFactory(delivery.RequestFromPeers, config.DeliverySkipCheck).New
|
self.netStore.NewNetFetcherFunc = network.NewFetcherFactory(delivery.RequestFromPeers, config.DeliverySkipCheck).New
|
||||||
|
|
||||||
self.streamer = stream.NewRegistry(addr, delivery, self.netStore, stateStore, &stream.RegistryOptions{
|
var nodeID enode.ID
|
||||||
SkipCheck: config.SyncingSkipCheck,
|
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,
|
DoSync: config.SyncEnabled,
|
||||||
DoRetrieve: true,
|
DoRetrieve: true,
|
||||||
SyncUpdateDelay: config.SyncUpdateDelay,
|
SyncUpdateDelay: config.SyncUpdateDelay,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue