Skip to content

Commit

Permalink
patching with capacity limits
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Anderson <dmikey@users.noreply.github.com>
  • Loading branch information
dmikey committed Nov 13, 2024
1 parent cec3542 commit 6ea387a
Show file tree
Hide file tree
Showing 136 changed files with 4,357 additions and 752 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dist/
runtime/
*.env
__debug*

*.exe
.b7s_*
*.exe
.vscode/
202 changes: 127 additions & 75 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,77 +1,129 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Head Node",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/node",
"args": [
"--peer-db",
"/tmp/b7s/head-peer-db",
"--function-db",
"/tmp/b7s/head-fdb",
"--log-level",
"debug",
"--port",
"9527",
"--role",
"head",
"--workspace",
"/tmp/debug/head",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident1/priv.bin",
"--rest-api",
":8081"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch Worker Node",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/node",
"args": [
"--peer-db",
"/tmp/b7s/worker-peer-db",
"--function-db",
"/tmp/b7s/worker-fdb",
"--log-level",
"debug",
"--port",
"0",
"--role",
"worker",
"--runtime-path",
"/tmp/runtime",
"--runtime-cli",
"bls-runtime",
"--workspace",
"/tmp/debug/worker",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident2/priv.bin",
"--boot-nodes",
"/ip4/0.0.0.0/tcp/9527/p2p/12D3KooWH9GerdSEroL2nqjpd2GuE5dwmqNi7uHX7FoywBdKcP4q"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch Manager",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/manager",
"args": [
"-l",
"3333",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident2/priv.bin",
"--allowed-peer",
"QmSz8bJZjg9gWfvrJjYibo4UhSo8dXYtpNRb4kxn28SoHG"
],
"cwd": "${workspaceFolder}"
}
]
"version": "0.2.0",
"configurations": [
{
"name": "Launch Head Node",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/node",
"args": [
"--db",
"/tmp/b7s/head-db",
"--log-level",
"debug",
"--port",
"9527",
"--role",
"head",
"--workspace",
"/tmp/debug/head",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident1/priv.bin",
"--rest-api",
":8081"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch Worker 1",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/node",
"args": [
"--db",
"/tmp/b7s/worker1-db",
"--log-level",
"debug",
"--port",
"0",
"--role",
"worker",
"--runtime-path",
"/tmp/runtime",
"--runtime-cli",
"bls-runtime",
"--workspace",
"/tmp/debug/worker",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident2/priv.bin",
"--boot-nodes",
"/ip4/0.0.0.0/tcp/9527/p2p/12D3KooWH9GerdSEroL2nqjpd2GuE5dwmqNi7uHX7FoywBdKcP4q"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch Worker 2",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/node",
"args": [
"--db",
"/tmp/b7s/worker2-db",
"--log-level",
"debug",
"--port",
"0",
"--role",
"worker",
"--runtime-path",
"/tmp/runtime",
"--runtime-cli",
"bls-runtime",
"--workspace",
"/tmp/debug/worker",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident3/priv.bin",
"--boot-nodes",
"/ip4/0.0.0.0/tcp/9527/p2p/12D3KooWH9GerdSEroL2nqjpd2GuE5dwmqNi7uHX7FoywBdKcP4q"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch Worker 3",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/node",
"args": [
"--db",
"/tmp/b7s/worker3-db",
"--log-level",
"debug",
"--port",
"0",
"--role",
"worker",
"--runtime-path",
"/tmp/runtime",
"--runtime-cli",
"bls-runtime",
"--workspace",
"/tmp/debug/worker",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident4/priv.bin",
"--boot-nodes",
"/ip4/0.0.0.0/tcp/9527/p2p/12D3KooWH9GerdSEroL2nqjpd2GuE5dwmqNi7uHX7FoywBdKcP4q"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch Manager",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/manager",
"args": [
"-l",
"3333",
"--private-key",
"${workspaceFolder}/configs/testkeys/ident2/priv.bin",
"--allowed-peer",
"QmSz8bJZjg9gWfvrJjYibo4UhSo8dXYtpNRb4kxn28SoHG"
],
"cwd": "${workspaceFolder}"
}
]
}
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type API struct {
func New(log zerolog.Logger, node Node) *API {

api := API{
Log: log.With().Str("component", "api").Logger(),
Log: log,
Node: node,
}

Expand Down
43 changes: 43 additions & 0 deletions cmd/node/host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"

"github.com/rs/zerolog"

"github.com/blocklessnetwork/b7s/config"
"github.com/blocklessnetwork/b7s/host"
"github.com/blocklessnetwork/b7s/models/blockless"
)

func createHost(log zerolog.Logger, cfg config.Config, role blockless.NodeRole, dialbackPeers ...blockless.Peer) (*host.Host, error) {

// Get the list of boot nodes addresses.
bootNodes, err := getBootNodeAddresses(cfg.BootNodes)
if err != nil {
return nil, fmt.Errorf("could not get boot node addresses: %w", err)
}

opts := []func(*host.Config){
host.WithPrivateKey(cfg.Connectivity.PrivateKey),
host.WithBootNodes(bootNodes),
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),
host.WithDialBackPeers(dialbackPeers),
host.WithMustReachBootNodes(cfg.Connectivity.MustReachBootNodes),
host.WithDisabledResourceLimits(cfg.Connectivity.DisableConnectionLimits),
host.WithEnableP2PRelay(role == blockless.HeadNode),
host.WithConnectionLimit(cfg.Connectivity.ConnectionCount),
}

// Create libp2p host.
host, err := host.New(log, cfg.Connectivity.Address, cfg.Connectivity.Port, opts...)
if err != nil {
return nil, fmt.Errorf("could not create host (key: '%s'): %w", cfg.Connectivity.PrivateKey, err)
}

return host, nil
}
5 changes: 2 additions & 3 deletions cmd/node/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"log"
"os"

"github.com/libp2p/go-libp2p/core/crypto"
Expand All @@ -13,12 +12,12 @@ func peerIDFromKey(keyPath string) (string, error) {

key, err := readPrivateKey(keyPath)
if err != nil {
log.Fatalf("could not read key file: %s", err)
return "", fmt.Errorf("could not read key file: %w", err)
}

id, err := peer.IDFromPrivateKey(key)
if err != nil {
log.Fatalf("could not determine identity: %s", err)
return "", fmt.Errorf("could not determine identity: %w", err)
}

return id.String(), nil
Expand Down
Loading

0 comments on commit 6ea387a

Please sign in to comment.