swarm: enable both bzz and hive

This commit is contained in:
Anton Evangelatov 2019-01-18 14:22:54 +01:00
parent 314a180116
commit 2131b622ad
2 changed files with 15 additions and 15 deletions

View file

@ -67,6 +67,7 @@ type BzzConfig struct {
HiveParams *HiveParams
NetworkID uint64
LightNode bool
BootnodeMode bool
}
// Bzz is the swarm protocol bundle
@ -87,7 +88,7 @@ type Bzz struct {
// * overlay driver
// * peer store
func NewBzz(config *BzzConfig, kad *Kademlia, store state.Store, streamerSpec *protocols.Spec, streamerRun func(*BzzPeer) error) *Bzz {
return &Bzz{
bzz := &Bzz{
Hive: NewHive(config.HiveParams, kad, store),
NetworkID: config.NetworkID,
LightNode: config.LightNode,
@ -96,6 +97,13 @@ func NewBzz(config *BzzConfig, kad *Kademlia, store state.Store, streamerSpec *p
streamerRun: streamerRun,
streamerSpec: streamerSpec,
}
if config.BootnodeMode {
bzz.streamerRun = nil
bzz.streamerSpec = nil
}
return bzz
}
// UpdateLocalAddr updates underlayaddress of the running node

View file

@ -119,6 +119,7 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
OverlayAddr: common.FromHex(config.BzzKey),
HiveParams: config.HiveParams,
LightNode: config.LightNodeEnabled,
BootnodeMode: config.BootnodeMode,
}
self.stateStore, err = state.NewDBStore(filepath.Join(config.Path, "state-store.db"))
@ -457,16 +458,7 @@ func (self *Swarm) Stop() error {
// Protocols implements the node.Service interface
func (s *Swarm) Protocols() (protos []p2p.Protocol) {
if s.config.BootnodeMode {
protos = []p2p.Protocol{
{
Name: network.DiscoverySpec.Name,
Version: network.DiscoverySpec.Version,
Length: network.DiscoverySpec.Length(),
Run: s.bzz.RunProtocol(network.DiscoverySpec, s.bzz.Hive.Run),
NodeInfo: s.bzz.Hive.NodeInfo,
PeerInfo: s.bzz.Hive.PeerInfo,
},
}
protos = append(protos, s.bzz.Protocols()...)
} else {
protos = append(protos, s.bzz.Protocols()...)