Skip to content

Commit 9892d7d

Browse files
authored
feat(p2p): add support for configuration of edgevpn listen_maddrs, dht_announce_maddrs and bootstrap_peers (#4200)
* add support for edgevpn listen_maddrs, dht_announce_maddrs, dht_bootstrap_peers * upd docs for libp2p loglevel
1 parent 96377fe commit 9892d7d

File tree

4 files changed

+95
-179
lines changed

4 files changed

+95
-179
lines changed

core/p2p/p2p.go

+24-4
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

+5-1
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ 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) |
136-
| **LOCALAI_LIBP2P_LOGLEVEL** | Set the loglevel for the underlying libp2p stack (default: fatal) |
139+
| **LOCALAI_P2P_LIB_LOGLEVEL** | Set the loglevel for the underlying libp2p stack (default: fatal) |
140+
137141

138142
## Architecture
139143

go.mod

+22-47
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ go 1.23
55
toolchain go1.23.1
66

77
require (
8-
dario.cat/mergo v1.0.0
8+
dario.cat/mergo v1.0.1
99
github.com/M0Rf30/go-tiny-dream v0.0.0-20240425104733-c04fa463ace9
10-
github.com/Masterminds/sprig/v3 v3.2.3
10+
github.com/Masterminds/sprig/v3 v3.3.0
1111
github.com/alecthomas/kong v0.9.0
12-
github.com/census-instrumentation/opencensus-proto v0.4.1
1312
github.com/charmbracelet/glamour v0.7.0
1413
github.com/chasefleming/elem-go v0.26.0
15-
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b
1614
github.com/containerd/containerd v1.7.19
15+
github.com/dave-gray101/v2keyauth v0.0.0-20240624150259-c45d584d25e2
1716
github.com/donomii/go-rwkv.cpp v0.0.0-20240228065144-661e7ae26d44
1817
github.com/elliotchance/orderedmap/v2 v2.2.0
1918
github.com/fsnotify/fsnotify v1.7.0
@@ -25,10 +24,8 @@ require (
2524
github.com/gofiber/swagger v1.0.0
2625
github.com/gofiber/template/html/v2 v2.1.2
2726
github.com/gofrs/flock v0.12.1
28-
github.com/golang/protobuf v1.5.4
2927
github.com/google/go-containerregistry v0.19.2
3028
github.com/google/uuid v1.6.0
31-
github.com/grpc-ecosystem/grpc-gateway v1.5.0
3229
github.com/hpcloud/tail v1.0.0
3330
github.com/ipfs/go-log v1.0.5
3431
github.com/jaypipes/ghw v0.12.0
@@ -37,11 +34,11 @@ require (
3734
github.com/libp2p/go-libp2p v0.36.2
3835
github.com/mholt/archiver/v3 v3.5.1
3936
github.com/microcosm-cc/bluemonday v1.0.26
40-
github.com/mudler/edgevpn v0.28.3
37+
github.com/mudler/edgevpn v0.28.4
4138
github.com/mudler/go-processmanager v0.0.0-20240820160718-8b802d3ecf82
4239
github.com/mudler/go-stable-diffusion v0.0.0-20240429204715-4a3cd6aeae6f
43-
github.com/onsi/ginkgo/v2 v2.20.1
44-
github.com/onsi/gomega v1.34.1
40+
github.com/onsi/ginkgo/v2 v2.21.0
41+
github.com/onsi/gomega v1.35.1
4542
github.com/ory/dockertest/v3 v3.10.0
4643
github.com/otiai10/openaigo v1.7.0
4744
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
@@ -60,30 +57,16 @@ require (
6057
go.opentelemetry.io/otel/exporters/prometheus v0.50.0
6158
go.opentelemetry.io/otel/metric v1.28.0
6259
go.opentelemetry.io/otel/sdk/metric v1.28.0
63-
google.golang.org/api v0.180.0
6460
google.golang.org/grpc v1.65.0
65-
google.golang.org/protobuf v1.34.2
61+
google.golang.org/protobuf v1.35.1
6662
gopkg.in/yaml.v2 v2.4.0
6763
gopkg.in/yaml.v3 v3.0.1
6864
oras.land/oras-go/v2 v2.5.0
6965
)
7066

7167
require (
72-
cel.dev/expr v0.15.0 // indirect
73-
cloud.google.com/go/auth v0.4.1 // indirect
74-
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
75-
cloud.google.com/go/compute/metadata v0.3.0 // indirect
76-
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
77-
github.com/dave-gray101/v2keyauth v0.0.0-20240624150259-c45d584d25e2 // indirect
78-
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
79-
github.com/felixge/httpsnoop v1.0.4 // indirect
8068
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
8169
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
82-
github.com/google/s2a-go v0.1.7 // indirect
83-
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
84-
github.com/googleapis/gax-go/v2 v2.12.4 // indirect
85-
github.com/labstack/echo/v4 v4.12.0 // indirect
86-
github.com/labstack/gommon v0.4.2 // indirect
8770
github.com/moby/docker-image-spec v1.3.1 // indirect
8871
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8972
github.com/pion/datachannel v1.5.8 // indirect
@@ -102,23 +85,16 @@ require (
10285
github.com/pion/transport/v2 v2.2.10 // indirect
10386
github.com/pion/turn/v2 v2.1.6 // indirect
10487
github.com/pion/webrtc/v3 v3.3.0 // indirect
105-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
10688
github.com/shirou/gopsutil/v4 v4.24.7 // indirect
107-
github.com/urfave/cli/v2 v2.27.4 // indirect
108-
github.com/valyala/fasttemplate v1.2.2 // indirect
10989
github.com/wlynxg/anet v0.0.4 // indirect
110-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
111-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect
11290
go.uber.org/mock v0.4.0 // indirect
113-
golang.org/x/oauth2 v0.21.0 // indirect
114-
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
11591
)
11692

11793
require (
11894
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
11995
github.com/KyleBanks/depth v1.2.1 // indirect
12096
github.com/Masterminds/goutils v1.1.1 // indirect
121-
github.com/Masterminds/semver/v3 v3.2.0 // indirect
97+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
12298
github.com/Microsoft/go-winio v0.6.2 // indirect
12399
github.com/Microsoft/hcsshim v0.11.7 // indirect
124100
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
@@ -138,7 +114,7 @@ require (
138114
github.com/containerd/log v0.1.0 // indirect
139115
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
140116
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
141-
github.com/creachadair/otp v0.4.2 // indirect
117+
github.com/creachadair/otp v0.5.0 // indirect
142118
github.com/davecgh/go-spew v1.1.1 // indirect
143119
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
144120
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
@@ -173,7 +149,7 @@ require (
173149
github.com/google/btree v1.1.2 // indirect
174150
github.com/google/go-cmp v0.6.0 // indirect
175151
github.com/google/gopacket v1.1.19 // indirect
176-
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
152+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
177153
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
178154
github.com/gorilla/css v1.0.1 // indirect
179155
github.com/gorilla/websocket v1.5.3 // indirect
@@ -182,9 +158,8 @@ require (
182158
github.com/hashicorp/golang-lru v1.0.2 // indirect
183159
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
184160
github.com/henvic/httpretty v0.1.3 // indirect
185-
github.com/huandu/xstrings v1.3.3 // indirect
161+
github.com/huandu/xstrings v1.5.0 // indirect
186162
github.com/huin/goupnp v1.3.0 // indirect
187-
github.com/imdario/mergo v0.3.16 // indirect
188163
github.com/ipfs/boxo v0.21.0 // indirect
189164
github.com/ipfs/go-cid v0.4.1 // indirect
190165
github.com/ipfs/go-datastore v0.6.0 // indirect
@@ -237,8 +212,8 @@ require (
237212
github.com/muesli/termenv v0.15.2 // indirect
238213
github.com/multiformats/go-base32 v0.1.0 // indirect
239214
github.com/multiformats/go-base36 v0.2.0 // indirect
240-
github.com/multiformats/go-multiaddr v0.13.0 // indirect
241-
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
215+
github.com/multiformats/go-multiaddr v0.14.0
216+
github.com/multiformats/go-multiaddr-dns v0.4.0 // indirect
242217
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
243218
github.com/multiformats/go-multibase v0.2.0 // indirect
244219
github.com/multiformats/go-multicodec v0.9.0 // indirect
@@ -270,12 +245,12 @@ require (
270245
github.com/raulk/go-watchdog v1.3.0 // indirect
271246
github.com/rivo/uniseg v0.4.7 // indirect
272247
github.com/shoenig/go-m1cpu v0.1.6 // indirect
273-
github.com/shopspring/decimal v1.3.1 // indirect
248+
github.com/shopspring/decimal v1.4.0 // indirect
274249
github.com/sirupsen/logrus v1.9.3 // indirect
275250
github.com/smallnest/ringbuffer v0.0.0-20240423223918-bab516b2000b // indirect
276251
github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091 // indirect
277252
github.com/spaolacci/murmur3 v1.1.0 // indirect
278-
github.com/spf13/cast v1.5.0 // indirect
253+
github.com/spf13/cast v1.7.0 // indirect
279254
github.com/swaggo/files/v2 v2.0.0 // indirect
280255
github.com/tinylib/msgp v1.1.8 // indirect
281256
github.com/tklauser/go-sysconf v0.3.14 // indirect
@@ -301,15 +276,15 @@ require (
301276
go.uber.org/fx v1.22.2 // indirect
302277
go.uber.org/multierr v1.11.0 // indirect
303278
go.uber.org/zap v1.27.0 // indirect
304-
golang.org/x/crypto v0.26.0 // indirect
279+
golang.org/x/crypto v0.28.0 // indirect
305280
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
306-
golang.org/x/mod v0.20.0 // indirect
307-
golang.org/x/net v0.28.0 // indirect
281+
golang.org/x/mod v0.21.0 // indirect
282+
golang.org/x/net v0.30.0 // indirect
308283
golang.org/x/sync v0.8.0 // indirect
309-
golang.org/x/sys v0.24.0 // indirect
310-
golang.org/x/term v0.23.0 // indirect
311-
golang.org/x/text v0.17.0 // indirect
312-
golang.org/x/tools v0.24.0 // indirect
284+
golang.org/x/sys v0.27.0 // indirect
285+
golang.org/x/term v0.25.0 // indirect
286+
golang.org/x/text v0.19.0 // indirect
287+
golang.org/x/tools v0.26.0 // indirect
313288
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
314289
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478 // indirect
315290
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect

0 commit comments

Comments
 (0)