Skip to content

Commit

Permalink
Remove "purge" flags - introduce non-destructive "--no-dialback-peers"
Browse files Browse the repository at this point in the history
  • Loading branch information
Maelkum committed May 10, 2024
1 parent 0ae80c9 commit 5e36e72
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 95 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions cmd/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
25 changes: 0 additions & 25 deletions cmd/node/dialback.go

This file was deleted.

32 changes: 0 additions & 32 deletions cmd/node/functions.go

This file was deleted.

44 changes: 16 additions & 28 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,36 @@ 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 {
log.Error().Err(err).Msg("could not get boot node addresses")
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
Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 3 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 ""
}
Expand Down

0 comments on commit 5e36e72

Please sign in to comment.