diff --git a/README.md b/README.md index 6e6cfbe6..c504ff3f 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,7 @@ For a more detailed overview of the configuration options, see the [b7s-node Rea | websocket-dialback-port | N/A | 0 | Specifies the advertised dialback port for Websocket connections. | | cpu-percentage-limit | N/A | 1.0 | Specifies the amount of CPU time allowed for Blockless Functions in the 0-1 range, 1 being unlimited. | | memory-limit | N/A | N/A | Specifies the memory limit for Blockless Functions, in kB. | -| purge-functions | N/A | false | Specifies if the node should purge installed Functions. | -| purge-dialback-peers | N/A | false | Specifies if the node should purge past known peers. | +| no-dialback-peers | N/A | false | Specifies if the node should avoid dialing back peers known from past runs | ## Dependencies diff --git a/cmd/node/README.md b/cmd/node/README.md index f8e7db2e..bed2740c 100644 --- a/cmd/node/README.md +++ b/cmd/node/README.md @@ -42,13 +42,12 @@ Usage of b7s-node: -w, --websocket should the node use websocket protocol for communication --websocket-port uint port to use for websocket connections --websocket-dialback-port uint external port that the b7s host will advertise for websocket connections - --purge-dialback-peers purge peers known from previous runs + --no-dialback-peers start without dialing back peers from previous runs --rest-api string address where the head node REST API will listen on --runtime-path string Blockless Runtime location (used by the worker node) --runtime-cli string runtime CLI name (used by the worker node) --cpu-percentage-limit float amount of CPU time allowed for Blockless Functions in the 0-1 range, 1 being unlimited --memory-limit int memory limit (kB) for Blockless Functions - --purge-functions purge installed functions --config string path to a config file ``` diff --git a/cmd/node/dialback.go b/cmd/node/dialback.go deleted file mode 100644 index 52badb9f..00000000 --- a/cmd/node/dialback.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/blocklessnetwork/b7s/models/blockless" -) - -func purgeDialbackPeers(store blockless.PeerStore) error { - - // NOTE: If the peer count grows too much in the future - we should adopt a more iterative approach. - peers, err := store.RetrievePeers() - if err != nil { - return fmt.Errorf("could not retrieve peers: %w", err) - } - - for _, peer := range peers { - err = store.RemovePeer(peer.ID) - if err != nil { - return fmt.Errorf("could not remove peer: %w", err) - } - } - - return nil -} diff --git a/cmd/node/functions.go b/cmd/node/functions.go deleted file mode 100644 index c33e510b..00000000 --- a/cmd/node/functions.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/blocklessnetwork/b7s/models/blockless" -) - -func purgeFunctions(store blockless.FunctionStore, workspace string) error { - - functions, err := store.RetrieveFunctions() - if err != nil { - return fmt.Errorf("could not retrieve functions: %w", err) - } - - for _, function := range functions { - err = store.RemoveFunction(function.CID) - if err != nil { - return fmt.Errorf("could not remove function: %w", err) - } - - fdir := filepath.Join(workspace, function.Files) - err = os.RemoveAll(fdir) - if err != nil { - return fmt.Errorf("could not remove directory: %w", err) - } - } - - return nil -} diff --git a/cmd/node/main.go b/cmd/node/main.go index 69a05c67..c1003e17 100644 --- a/cmd/node/main.go +++ b/cmd/node/main.go @@ -112,21 +112,6 @@ func run() int { // Create a new store. store := store.New(db, codec.NewJSONCodec()) - if cfg.Connectivity.PurgeDialbackPeers { - err = purgeDialbackPeers(store) - if err != nil { - log.Error().Err(err).Msg("could not purge dialback peers") - return failure - } - } - - // Get the list of dial back peers. - peers, err := store.RetrievePeers() - if err != nil { - log.Error().Err(err).Msg("could not get list of dial-back peers") - return failure - } - // Get the list of boot nodes addresses. bootNodeAddrs, err := getBootNodeAddresses(cfg.BootNodes) if err != nil { @@ -134,17 +119,29 @@ func run() int { return failure } - // Create libp2p host. - host, err := host.New(log, cfg.Connectivity.Address, cfg.Connectivity.Port, + hostOpts := []func(*host.Config){ host.WithPrivateKey(cfg.Connectivity.PrivateKey), host.WithBootNodes(bootNodeAddrs), - host.WithDialBackPeers(peers), host.WithDialBackAddress(cfg.Connectivity.DialbackAddress), host.WithDialBackPort(cfg.Connectivity.DialbackPort), host.WithDialBackWebsocketPort(cfg.Connectivity.WebsocketDialbackPort), host.WithWebsocket(cfg.Connectivity.Websocket), host.WithWebsocketPort(cfg.Connectivity.WebsocketPort), - ) + } + + if !cfg.Connectivity.NoDialbackPeers { + // Get the list of dial back peers. + peers, err := store.RetrievePeers() + if err != nil { + log.Error().Err(err).Msg("could not get list of dial-back peers") + return failure + } + + hostOpts = append(hostOpts, host.WithDialBackPeers(peers)) + } + + // Create libp2p host. + host, err := host.New(log, cfg.Connectivity.Address, cfg.Connectivity.Port, hostOpts...) if err != nil { log.Error().Err(err).Str("key", cfg.Connectivity.PrivateKey).Msg("could not create host") return failure @@ -155,7 +152,6 @@ func run() int { Str("id", host.ID().String()). Strs("addresses", host.Addresses()). Int("boot_nodes", len(bootNodeAddrs)). - Int("dial_back_peers", len(peers)). Msg("created host") // Set node options. @@ -208,14 +204,6 @@ func run() int { opts = append(opts, node.WithWorkspace(cfg.Workspace)) } - if cfg.Worker.PurgeFunctions { - err = purgeFunctions(store, cfg.Workspace) - if err != nil { - log.Error().Err(err).Msg("could not purge installed functions") - return failure - } - } - // Create function store. fstore := fstore.New(log, store, cfg.Workspace) diff --git a/config/config.go b/config/config.go index af314f99..afb9e13b 100644 --- a/config/config.go +++ b/config/config.go @@ -67,7 +67,7 @@ type Connectivity struct { Websocket bool `koanf:"websocket" flag:"websocket,w"` WebsocketPort uint `koanf:"websocket-port" flag:"websocket-port"` WebsocketDialbackPort uint `koanf:"websocket-dialback-port" flag:"websocket-dialback-port"` - PurgeDialbackPeers bool `koanf:"purge-dialback-peers" flag:"purge-dialback-peers"` + NoDialbackPeers bool `koanf:"no-dialback-peers" flag:"no-dialback-peers"` } type Head struct { @@ -79,7 +79,6 @@ type Worker struct { RuntimeCLI string `koanf:"runtime-cli" flag:"runtime-cli"` CPUPercentageLimit float64 `koanf:"cpu-percentage-limit" flag:"cpu-percentage-limit"` MemoryLimitKB int64 `koanf:"memory-limit" flag:"memory-limit"` - PurgeFunctions bool `koanf:"purge-functions" flag:"purge-functions"` } // ConfigOptionInfo describes a specific configuration option, it's location in the config file and @@ -138,10 +137,8 @@ func getFlagDescription(flag string) string { return "amount of CPU time allowed for Blockless Functions in the 0-1 range, 1 being unlimited" case "memory-limit": return "memory limit (kB) for Blockless Functions" - case "purge-dialback-peers": - return "purge peers known from previous runs" - case "purge-functions": - return "purge installed functions" + case "no-dialback-peers": + return "start without dialing back peers from previous runs" default: return "" }