Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

add --disable-auto-connect flag #1576

Merged
merged 1 commit into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Config struct {
MaxStreamPeerServers int
LightNodeEnabled bool
BootnodeMode bool
DisableAutoConnect bool
SyncUpdateDelay time.Duration
SwapAPI string
Cors string
Expand Down
4 changes: 4 additions & 0 deletions cmd/swarm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/swarm/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions cmd/swarm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func init() {
SwarmUploadMimeType,
// bootnode mode
SwarmBootnodeModeFlag,
SwarmDisableAutoConnectFlag,
// storage flags
SwarmStorePath,
SwarmStoreCapacity,
Expand Down
5 changes: 4 additions & 1 deletion network/hive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down