Skip to content

Commit 0a181d9

Browse files
committed
add support for edgevpn listen_maddrs, dht_announce_maddrs, dht_bootstrap_peers
1 parent cfb0ac3 commit 0a181d9

File tree

4 files changed

+113
-28
lines changed

4 files changed

+113
-28
lines changed

core/p2p/p2p.go

Lines changed: 25 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,18 @@ 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
}
397+
392398
c := config.Config{
399+
ListenMaddrs: []string{},
400+
DHTAnnounceMaddrs: []multiaddr.Multiaddr{},
393401
Limit: config.ResourceLimit{
394402
Enable: noLimits,
395403
MaxConns: 100,
@@ -411,9 +419,10 @@ func newNodeOpts(token string) ([]node.Option, error) {
411419
RateLimitInterval: defaultInterval,
412420
},
413421
Discovery: config.Discovery{
414-
DHT: !noDHT,
415-
MDNS: true,
416-
Interval: 10 * time.Second,
422+
DHT: !noDHT,
423+
MDNS: true,
424+
Interval: 10 * time.Second,
425+
BootstrapPeers: bootstrapPeers,
417426
},
418427
Connection: config.Connection{
419428
HolePunch: true,
@@ -432,6 +441,18 @@ func newNodeOpts(token string) ([]node.Option, error) {
432441
return nodeOpts, nil
433442
}
434443

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

docs/content/docs/features/distributed_inferencing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ 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) |

go.mod

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ 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
1212
github.com/census-instrumentation/opencensus-proto v0.4.1
1313
github.com/charmbracelet/glamour v0.7.0
1414
github.com/chasefleming/elem-go v0.26.0
1515
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b
1616
github.com/containerd/containerd v1.7.19
17+
github.com/dave-gray101/v2keyauth v0.0.0-20240624150259-c45d584d25e2
1718
github.com/donomii/go-rwkv.cpp v0.0.0-20240228065144-661e7ae26d44
1819
github.com/elliotchance/orderedmap/v2 v2.2.0
1920
github.com/fsnotify/fsnotify v1.7.0
@@ -37,11 +38,11 @@ require (
3738
github.com/libp2p/go-libp2p v0.36.2
3839
github.com/mholt/archiver/v3 v3.5.1
3940
github.com/microcosm-cc/bluemonday v1.0.26
40-
github.com/mudler/edgevpn v0.28.3
41+
github.com/mudler/edgevpn v0.28.4
4142
github.com/mudler/go-processmanager v0.0.0-20240820160718-8b802d3ecf82
4243
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
44+
github.com/onsi/ginkgo/v2 v2.21.0
45+
github.com/onsi/gomega v1.35.1
4546
github.com/ory/dockertest/v3 v3.10.0
4647
github.com/otiai10/openaigo v1.7.0
4748
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
@@ -62,7 +63,7 @@ require (
6263
go.opentelemetry.io/otel/sdk/metric v1.28.0
6364
google.golang.org/api v0.180.0
6465
google.golang.org/grpc v1.65.0
65-
google.golang.org/protobuf v1.34.2
66+
google.golang.org/protobuf v1.35.1
6667
gopkg.in/yaml.v2 v2.4.0
6768
gopkg.in/yaml.v3 v3.0.1
6869
oras.land/oras-go/v2 v2.5.0
@@ -73,8 +74,7 @@ require (
7374
cloud.google.com/go/auth v0.4.1 // indirect
7475
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
7576
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
77+
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
7878
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
7979
github.com/felixge/httpsnoop v1.0.4 // indirect
8080
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
@@ -104,7 +104,7 @@ require (
104104
github.com/pion/webrtc/v3 v3.3.0 // indirect
105105
github.com/russross/blackfriday/v2 v2.1.0 // indirect
106106
github.com/shirou/gopsutil/v4 v4.24.7 // indirect
107-
github.com/urfave/cli/v2 v2.27.4 // indirect
107+
github.com/urfave/cli/v2 v2.27.5 // indirect
108108
github.com/valyala/fasttemplate v1.2.2 // indirect
109109
github.com/wlynxg/anet v0.0.4 // indirect
110110
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
@@ -118,7 +118,7 @@ require (
118118
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
119119
github.com/KyleBanks/depth v1.2.1 // indirect
120120
github.com/Masterminds/goutils v1.1.1 // indirect
121-
github.com/Masterminds/semver/v3 v3.2.0 // indirect
121+
github.com/Masterminds/semver/v3 v3.3.0 // indirect
122122
github.com/Microsoft/go-winio v0.6.2 // indirect
123123
github.com/Microsoft/hcsshim v0.11.7 // indirect
124124
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
@@ -138,7 +138,7 @@ require (
138138
github.com/containerd/log v0.1.0 // indirect
139139
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
140140
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
141-
github.com/creachadair/otp v0.4.2 // indirect
141+
github.com/creachadair/otp v0.5.0 // indirect
142142
github.com/davecgh/go-spew v1.1.1 // indirect
143143
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
144144
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
@@ -173,7 +173,7 @@ require (
173173
github.com/google/btree v1.1.2 // indirect
174174
github.com/google/go-cmp v0.6.0 // indirect
175175
github.com/google/gopacket v1.1.19 // indirect
176-
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
176+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
177177
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
178178
github.com/gorilla/css v1.0.1 // indirect
179179
github.com/gorilla/websocket v1.5.3 // indirect
@@ -182,7 +182,7 @@ require (
182182
github.com/hashicorp/golang-lru v1.0.2 // indirect
183183
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
184184
github.com/henvic/httpretty v0.1.3 // indirect
185-
github.com/huandu/xstrings v1.3.3 // indirect
185+
github.com/huandu/xstrings v1.5.0 // indirect
186186
github.com/huin/goupnp v1.3.0 // indirect
187187
github.com/imdario/mergo v0.3.16 // indirect
188188
github.com/ipfs/boxo v0.21.0 // indirect
@@ -237,8 +237,8 @@ require (
237237
github.com/muesli/termenv v0.15.2 // indirect
238238
github.com/multiformats/go-base32 v0.1.0 // indirect
239239
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
240+
github.com/multiformats/go-multiaddr v0.14.0 // indirect
241+
github.com/multiformats/go-multiaddr-dns v0.4.0 // indirect
242242
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
243243
github.com/multiformats/go-multibase v0.2.0 // indirect
244244
github.com/multiformats/go-multicodec v0.9.0 // indirect
@@ -270,12 +270,12 @@ require (
270270
github.com/raulk/go-watchdog v1.3.0 // indirect
271271
github.com/rivo/uniseg v0.4.7 // indirect
272272
github.com/shoenig/go-m1cpu v0.1.6 // indirect
273-
github.com/shopspring/decimal v1.3.1 // indirect
273+
github.com/shopspring/decimal v1.4.0 // indirect
274274
github.com/sirupsen/logrus v1.9.3 // indirect
275275
github.com/smallnest/ringbuffer v0.0.0-20240423223918-bab516b2000b // indirect
276276
github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091 // indirect
277277
github.com/spaolacci/murmur3 v1.1.0 // indirect
278-
github.com/spf13/cast v1.5.0 // indirect
278+
github.com/spf13/cast v1.7.0 // indirect
279279
github.com/swaggo/files/v2 v2.0.0 // indirect
280280
github.com/tinylib/msgp v1.1.8 // indirect
281281
github.com/tklauser/go-sysconf v0.3.14 // indirect
@@ -301,15 +301,15 @@ require (
301301
go.uber.org/fx v1.22.2 // indirect
302302
go.uber.org/multierr v1.11.0 // indirect
303303
go.uber.org/zap v1.27.0 // indirect
304-
golang.org/x/crypto v0.26.0 // indirect
304+
golang.org/x/crypto v0.28.0 // indirect
305305
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
306+
golang.org/x/mod v0.21.0 // indirect
307+
golang.org/x/net v0.30.0 // indirect
308308
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
309+
golang.org/x/sys v0.27.0 // indirect
310+
golang.org/x/term v0.25.0 // indirect
311+
golang.org/x/text v0.19.0 // indirect
312+
golang.org/x/tools v0.26.0 // indirect
313313
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
314314
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478 // indirect
315315
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
@@ -320,3 +320,19 @@ require (
320320
howett.net/plist v1.0.0 // indirect
321321
lukechampine.com/blake3 v1.3.0 // indirect
322322
)
323+
324+
replace github.com/donomii/go-rwkv.cpp => /Users/mintyleaf/Projects/work/LocalAI/sources/go-rwkv.cpp
325+
326+
replace github.com/ggerganov/whisper.cpp => /Users/mintyleaf/Projects/work/LocalAI/sources/whisper.cpp
327+
328+
replace github.com/ggerganov/whisper.cpp/bindings/go => /Users/mintyleaf/Projects/work/LocalAI/sources/whisper.cpp/bindings/go
329+
330+
replace github.com/go-skynet/go-bert.cpp => /Users/mintyleaf/Projects/work/LocalAI/sources/go-bert.cpp
331+
332+
replace github.com/M0Rf30/go-tiny-dream => /Users/mintyleaf/Projects/work/LocalAI/sources/go-tiny-dream
333+
334+
replace github.com/mudler/go-piper => /Users/mintyleaf/Projects/work/LocalAI/sources/go-piper
335+
336+
replace github.com/mudler/go-stable-diffusion => /Users/mintyleaf/Projects/work/LocalAI/sources/go-stable-diffusion
337+
338+
replace github.com/go-skynet/go-llama.cpp => /Users/mintyleaf/Projects/work/LocalAI/sources/go-llama.cpp

0 commit comments

Comments
 (0)