Skip to content

Commit b108a1c

Browse files
committed
Add default bootstrap peers and connection fixes
Introduce default libp2p bootstrap peers and a new BootstrapPeers config field, applied in NewConfig and init to ensure gomobile-created Configs get sensible defaults. Reduce autorelay boot delay from 30s to 15s. Spawn a background goroutine to connect to bootstrap peers (with a 15s timeout per peer) to improve DHT/identify/hole-punching startup behavior, ignoring malformed addresses. When using a direct BloxAddr, also add relay /p2p-circuit addresses to the peerstore as a fallback so libp2p can try relays if direct connections fail. Also add strings import required for the new fallback logic.
1 parent 872745c commit b108a1c

File tree

5 files changed

+619
-710
lines changed

5 files changed

+619
-710
lines changed

cmd/blox/main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import (
4848
"github.com/ipld/go-ipld-prime/linking"
4949
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
5050
"github.com/ipni/index-provider/engine"
51-
goprocess "github.com/jbenet/goprocess"
5251
"github.com/libp2p/go-libp2p"
5352
"github.com/libp2p/go-libp2p/core/crypto"
5453
"github.com/libp2p/go-libp2p/core/host"
@@ -882,9 +881,9 @@ func rewriteMaddrToUseLocalhostIfItsAny(maddr ma.Multiaddr) ma.Multiaddr {
882881
first, rest := ma.SplitFirst(maddr)
883882

884883
switch {
885-
case first.Equal(manet.IP4Unspecified):
884+
case first.Equal(&manet.IP4Unspecified[0]):
886885
return manet.IP4Loopback.Encapsulate(rest)
887-
case first.Equal(manet.IP6Unspecified):
886+
case first.Equal(&manet.IP6Unspecified[0]):
888887
return manet.IP6Loopback.Encapsulate(rest)
889888
default:
890889
return maddr // not ip
@@ -1235,7 +1234,9 @@ func action(ctx *cli.Context) error {
12351234
if err != nil {
12361235
return err
12371236
}
1238-
ipfsNode.Process.AddChild(goprocess.WithTeardown(cctx.Plugins.Close))
1237+
context.AfterFunc(ipfsNode.Context(), func() {
1238+
cctx.Plugins.Close()
1239+
})
12391240

12401241
wg.Add(1)
12411242
go func() {
@@ -1264,7 +1265,9 @@ func action(ctx *cli.Context) error {
12641265
if err != nil {
12651266
logger.Errorw("Error in Plugins Start", "err", err)
12661267
}
1267-
ipfsNode.Process.AddChild(goprocess.WithTeardown(cctx.Plugins.Close))
1268+
context.AfterFunc(ipfsNode.Context(), func() {
1269+
cctx.Plugins.Close()
1270+
})
12681271
_, err := serveHTTPApi(&cctx)
12691272
if err != nil {
12701273
logger.Errorw("Error setting up HTTP API server:", "err", err)

0 commit comments

Comments
 (0)