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 HiveParams *HiveParams
NetworkID uint64 NetworkID uint64
LightNode bool LightNode bool
BootnodeMode bool
} }
// Bzz is the swarm protocol bundle // Bzz is the swarm protocol bundle
@ -87,7 +88,7 @@ type Bzz struct {
// * overlay driver // * overlay driver
// * peer store // * peer store
func NewBzz(config *BzzConfig, kad *Kademlia, store state.Store, streamerSpec *protocols.Spec, streamerRun func(*BzzPeer) error) *Bzz { 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), Hive: NewHive(config.HiveParams, kad, store),
NetworkID: config.NetworkID, NetworkID: config.NetworkID,
LightNode: config.LightNode, LightNode: config.LightNode,
@ -96,6 +97,13 @@ func NewBzz(config *BzzConfig, kad *Kademlia, store state.Store, streamerSpec *p
streamerRun: streamerRun, streamerRun: streamerRun,
streamerSpec: streamerSpec, streamerSpec: streamerSpec,
} }
if config.BootnodeMode {
bzz.streamerRun = nil
bzz.streamerSpec = nil
}
return bzz
} }
// UpdateLocalAddr updates underlayaddress of the running node // 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), OverlayAddr: common.FromHex(config.BzzKey),
HiveParams: config.HiveParams, HiveParams: config.HiveParams,
LightNode: config.LightNodeEnabled, LightNode: config.LightNodeEnabled,
BootnodeMode: config.BootnodeMode,
} }
self.stateStore, err = state.NewDBStore(filepath.Join(config.Path, "state-store.db")) 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 // Protocols implements the node.Service interface
func (s *Swarm) Protocols() (protos []p2p.Protocol) { func (s *Swarm) Protocols() (protos []p2p.Protocol) {
if s.config.BootnodeMode { if s.config.BootnodeMode {
protos = []p2p.Protocol{ protos = append(protos, s.bzz.Protocols()...)
{
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,
},
}
} else { } else {
protos = append(protos, s.bzz.Protocols()...) protos = append(protos, s.bzz.Protocols()...)