Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(p2p): add support for configuration of edgevpn listen_maddrs, dht_announce_maddrs and bootstrap_peers #4200

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 24 additions & 4 deletions core/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"io"
"net"
"os"
"strings"
"sync"
"time"

Expand All @@ -22,6 +23,7 @@
"github.com/mudler/edgevpn/pkg/services"
"github.com/mudler/edgevpn/pkg/types"
eutils "github.com/mudler/edgevpn/pkg/utils"
"github.com/multiformats/go-multiaddr"
"github.com/phayes/freeport"
zlog "github.com/rs/zerolog/log"

Expand Down Expand Up @@ -384,12 +386,17 @@
// TODO: move this up, expose more config options when creating a node
noDHT := os.Getenv("LOCALAI_P2P_DISABLE_DHT") == "true"
noLimits := os.Getenv("LOCALAI_P2P_ENABLE_LIMITS") == "true"
listenMaddrs := strings.Split(os.Getenv("LOCALAI_P2P_LISTEN_MADDRS"), ",")
bootstrapPeers := strings.Split(os.Getenv("LOCALAI_P2P_BOOTSTRAP_PEERS_MADDRS"), ",")
dhtAnnounceMaddrs := stringsToMultiAddr(strings.Split(os.Getenv("LOCALAI_P2P_DHT_ANNOUNCE_MADDRS"), ","))

libp2ploglevel := os.Getenv("LOCALAI_LIBP2P_LOGLEVEL")
libp2ploglevel := os.Getenv("LOCALAI_P2P_LIB_LOGLEVEL")
if libp2ploglevel == "" {
libp2ploglevel = "fatal"
}
c := config.Config{
ListenMaddrs: listenMaddrs,

Check failure on line 398 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-macOS-arm64

unknown field ListenMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config

Check failure on line 398 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-macOS-x86_64

unknown field ListenMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config

Check failure on line 398 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-linux-arm

unknown field ListenMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config

Check failure on line 398 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-linux

unknown field ListenMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config
DHTAnnounceMaddrs: dhtAnnounceMaddrs,

Check failure on line 399 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-macOS-arm64

unknown field DHTAnnounceMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config

Check failure on line 399 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-macOS-x86_64

unknown field DHTAnnounceMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config

Check failure on line 399 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-linux-arm

unknown field DHTAnnounceMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config

Check failure on line 399 in core/p2p/p2p.go

View workflow job for this annotation

GitHub Actions / build-linux

unknown field DHTAnnounceMaddrs in struct literal of type "github.com/mudler/edgevpn/pkg/config".Config
Limit: config.ResourceLimit{
Enable: noLimits,
MaxConns: 100,
Expand All @@ -411,9 +418,10 @@
RateLimitInterval: defaultInterval,
},
Discovery: config.Discovery{
DHT: !noDHT,
MDNS: true,
Interval: 10 * time.Second,
DHT: !noDHT,
MDNS: true,
Interval: 10 * time.Second,
BootstrapPeers: bootstrapPeers,
},
Connection: config.Connection{
HolePunch: true,
Expand All @@ -432,6 +440,18 @@
return nodeOpts, nil
}

func stringsToMultiAddr(peers []string) []multiaddr.Multiaddr {
res := []multiaddr.Multiaddr{}
for _, p := range peers {
addr, err := multiaddr.NewMultiaddr(p)
if err != nil {
continue
}
res = append(res, addr)
}
return res
}

func copyStream(closer chan struct{}, dst io.Writer, src io.Reader) {
defer func() { closer <- struct{}{} }() // connection is closed, send signal to stop proxy
io.Copy(dst, src)
Expand Down
6 changes: 5 additions & 1 deletion docs/content/docs/features/distributed_inferencing.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ There are options that can be tweaked or parameters that can be set using enviro
|----------------------|-------------|
| **LOCALAI_P2P_DISABLE_DHT** | Set to "true" to disable DHT and enable p2p layer to be local only (mDNS) |
| **LOCALAI_P2P_ENABLE_LIMITS** | Set to "true" to enable connection limits and resources management (useful when running with poor connectivity or want to limit resources consumption) |
| **LOCALAI_P2P_LISTEN_MADDRS** | Set to comma separated list of multiaddresses to override default libp2p 0.0.0.0 multiaddresses |
| **LOCALAI_P2P_DHT_ANNOUNCE_MADDRS** | Set to comma separated list of multiaddresses to override announcing of listen multiaddresses (useful when external address:port is remapped) |
| **LOCALAI_P2P_BOOTSTRAP_PEERS_MADDRS** | Set to comma separated list of multiaddresses to specify custom DHT bootstrap nodes |
| **LOCALAI_P2P_TOKEN** | Set the token for the p2p network |
| **LOCALAI_P2P_LOGLEVEL** | Set the loglevel for the LocalAI p2p stack (default: info) |
| **LOCALAI_LIBP2P_LOGLEVEL** | Set the loglevel for the underlying libp2p stack (default: fatal) |
| **LOCALAI_P2P_LIB_LOGLEVEL** | Set the loglevel for the underlying libp2p stack (default: fatal) |


## Architecture

Expand Down
Loading