diff --git a/api/config.go b/api/config.go index d343c1c5be..34e64bfb78 100644 --- a/api/config.go +++ b/api/config.go @@ -72,6 +72,7 @@ type Config struct { MaxStreamPeerServers int LightNodeEnabled bool BootnodeMode bool + DisableAutoConnect bool SyncUpdateDelay time.Duration SwapAPI string Cors string diff --git a/cmd/swarm/config.go b/cmd/swarm/config.go index 09cacf2427..e11a90b330 100644 --- a/cmd/swarm/config.go +++ b/cmd/swarm/config.go @@ -266,6 +266,10 @@ func flagsOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Confi currentConfig.BootnodeMode = ctx.GlobalBool(SwarmBootnodeModeFlag.Name) } + if ctx.GlobalIsSet(SwarmDisableAutoConnectFlag.Name) { + currentConfig.DisableAutoConnect = ctx.GlobalBool(SwarmDisableAutoConnectFlag.Name) + } + if ctx.GlobalIsSet(SwarmGlobalStoreAPIFlag.Name) { currentConfig.GlobalStoreAPI = ctx.GlobalString(SwarmGlobalStoreAPIFlag.Name) } diff --git a/cmd/swarm/flags.go b/cmd/swarm/flags.go index 0bb0fe2543..5005529d15 100644 --- a/cmd/swarm/flags.go +++ b/cmd/swarm/flags.go @@ -166,6 +166,10 @@ var ( Name: "bootnode-mode", Usage: "Run Swarm in Bootnode mode", } + SwarmDisableAutoConnectFlag = cli.BoolFlag{ + Name: "disable-auto-connect", + Usage: "Disables the peer discovery mechanism in the hive protocol as well as the auto connect loop (manual peer addition)", + } SwarmFeedNameFlag = cli.StringFlag{ Name: "name", Usage: "User-defined name for the new feed, limited to 32 characters. If combined with topic, it will refer to a subtopic with this name", diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index b57b02847c..bd321cbbb3 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -196,6 +196,7 @@ func init() { SwarmUploadMimeType, // bootnode mode SwarmBootnodeModeFlag, + SwarmDisableAutoConnectFlag, // storage flags SwarmStorePath, SwarmStoreCapacity, diff --git a/network/hive.go b/network/hive.go index d290c98af3..900d9720a1 100644 --- a/network/hive.go +++ b/network/hive.go @@ -39,6 +39,7 @@ to suggest peers to bootstrap connectivity // HiveParams holds the config options to hive type HiveParams struct { Discovery bool // if want discovery of not + DisableAutoConnect bool // this flag disables the auto connect loop PeersBroadcastSetSize uint8 // how many peers to use when relaying MaxPeersPerRequest uint8 // max size for peer address batches KeepAliveInterval time.Duration @@ -97,7 +98,9 @@ func (h *Hive) Start(server *p2p.Server) error { // ticker to keep the hive alive h.ticker = time.NewTicker(h.KeepAliveInterval) // this loop is doing bootstrapping and maintains a healthy table - go h.connect() + if !h.DisableAutoConnect { + go h.connect() + } return nil } diff --git a/swarm.go b/swarm.go index c8052d3bed..11c695d281 100644 --- a/swarm.go +++ b/swarm.go @@ -120,6 +120,10 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e config.HiveParams.Discovery = true + if config.DisableAutoConnect { + config.HiveParams.DisableAutoConnect = true + } + bzzconfig := &network.BzzConfig{ NetworkID: config.NetworkID, OverlayAddr: common.FromHex(config.BzzKey),