Skip to content

Commit 13a9fa7

Browse files
committed
add support for edgevpn listen_maddrs, dht_announce_maddrs, dht_bootstrap_peers
1 parent cfb0ac3 commit 13a9fa7

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

core/p2p/p2p.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io"
1111
"net"
1212
"os"
13+
"strings"
1314
"sync"
1415
"time"
1516

@@ -22,6 +23,7 @@ import (
2223
"github.com/mudler/edgevpn/pkg/services"
2324
"github.com/mudler/edgevpn/pkg/types"
2425
eutils "github.com/mudler/edgevpn/pkg/utils"
26+
"github.com/multiformats/go-multiaddr"
2527
"github.com/phayes/freeport"
2628
zlog "github.com/rs/zerolog/log"
2729

@@ -384,12 +386,17 @@ func newNodeOpts(token string) ([]node.Option, error) {
384386
// TODO: move this up, expose more config options when creating a node
385387
noDHT := os.Getenv("LOCALAI_P2P_DISABLE_DHT") == "true"
386388
noLimits := os.Getenv("LOCALAI_P2P_ENABLE_LIMITS") == "true"
389+
listenMaddrs := strings.Split(os.Getenv("LOCALAI_P2P_LISTEN_MADDRS"), ",")
390+
bootstrapPeers := strings.Split(os.Getenv("LOCALAI_P2P_BOOTSTRAP_PEERS_MADDRS"), ",")
391+
dhtAnnounceMaddrs := stringsToMultiAddr(strings.Split(os.Getenv("LOCALAI_P2P_DHT_ANNOUNCE_MADDRS"), ","))
387392

388-
libp2ploglevel := os.Getenv("LOCALAI_LIBP2P_LOGLEVEL")
393+
libp2ploglevel := os.Getenv("LOCALAI_P2P_LIB_LOGLEVEL")
389394
if libp2ploglevel == "" {
390395
libp2ploglevel = "fatal"
391396
}
392397
c := config.Config{
398+
ListenMaddrs: listenMaddrs,
399+
DHTAnnounceMaddrs: dhtAnnounceMaddrs,
393400
Limit: config.ResourceLimit{
394401
Enable: noLimits,
395402
MaxConns: 100,
@@ -411,9 +418,10 @@ func newNodeOpts(token string) ([]node.Option, error) {
411418
RateLimitInterval: defaultInterval,
412419
},
413420
Discovery: config.Discovery{
414-
DHT: !noDHT,
415-
MDNS: true,
416-
Interval: 10 * time.Second,
421+
DHT: !noDHT,
422+
MDNS: true,
423+
Interval: 10 * time.Second,
424+
BootstrapPeers: bootstrapPeers,
417425
},
418426
Connection: config.Connection{
419427
HolePunch: true,
@@ -432,6 +440,18 @@ func newNodeOpts(token string) ([]node.Option, error) {
432440
return nodeOpts, nil
433441
}
434442

443+
func stringsToMultiAddr(peers []string) []multiaddr.Multiaddr {
444+
res := []multiaddr.Multiaddr{}
445+
for _, p := range peers {
446+
addr, err := multiaddr.NewMultiaddr(p)
447+
if err != nil {
448+
continue
449+
}
450+
res = append(res, addr)
451+
}
452+
return res
453+
}
454+
435455
func copyStream(closer chan struct{}, dst io.Writer, src io.Reader) {
436456
defer func() { closer <- struct{}{} }() // connection is closed, send signal to stop proxy
437457
io.Copy(dst, src)

docs/content/docs/features/distributed_inferencing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,14 @@ There are options that can be tweaked or parameters that can be set using enviro
131131
|----------------------|-------------|
132132
| **LOCALAI_P2P_DISABLE_DHT** | Set to "true" to disable DHT and enable p2p layer to be local only (mDNS) |
133133
| **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) |
134+
| **LOCALAI_P2P_LISTEN_MADDRS** | Set to comma separated list of multiaddresses to override default libp2p 0.0.0.0 multiaddresses |
135+
| **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) |
136+
| **LOCALAI_P2P_BOOTSTRAP_PEERS_MADDRS** | Set to comma separated list of multiaddresses to specify custom DHT bootstrap nodes |
134137
| **LOCALAI_P2P_TOKEN** | Set the token for the p2p network |
135138
| **LOCALAI_P2P_LOGLEVEL** | Set the loglevel for the LocalAI p2p stack (default: info) |
136139
| **LOCALAI_LIBP2P_LOGLEVEL** | Set the loglevel for the underlying libp2p stack (default: fatal) |
137140

141+
138142
## Architecture
139143

140144
LocalAI uses https://github.com/libp2p/go-libp2p under the hood, the same project powering IPFS. Differently from other frameworks, LocalAI uses peer2peer without a single master server, but rather it uses sub/gossip and ledger functionalities to achieve consensus across different peers.

0 commit comments

Comments
 (0)