diff --git a/main.go b/main.go index b832ce0..43582d3 100644 --- a/main.go +++ b/main.go @@ -170,6 +170,12 @@ Generate an identity seed and launch a gateway: EnvVars: []string{"RAINBOW_DENYLISTS"}, Usage: "Denylist HTTP subscriptions (comma-separated). Must be append-only denylists", }, + &cli.StringFlag{ + Name: "peering", + Value: "", + EnvVars: []string{"RAINBOW_PEERING"}, + Usage: "Multiaddresses of peers to stay connected to (comma-separated)", + }, } app.Commands = []*cli.Command{ @@ -244,6 +250,15 @@ share the same seed as long as the indexes are different. return err } + var peeringAddrs []peer.AddrInfo + for _, maStr := range getCommaSeparatedList(cctx.String("peering")) { + ai, err := peer.AddrInfoFromString(maStr) + if err != nil { + return err + } + peeringAddrs = append(peeringAddrs, *ai) + } + cfg := Config{ DataDir: ddir, GatewayDomains: getCommaSeparatedList(cctx.String("gateway-domains")), @@ -258,6 +273,7 @@ share the same seed as long as the indexes are different. KuboRPCURLs: getEnvs(EnvKuboRPC, DefaultKuboRPC), DHTSharedHost: cctx.Bool("dht-shared-host"), DenylistSubs: getCommaSeparatedList(cctx.String("denylists")), + Peering: peeringAddrs, } goLog.Debugf("Rainbow config: %+v", cfg) diff --git a/setup.go b/setup.go index 0b7a21d..af9e7da 100644 --- a/setup.go +++ b/setup.go @@ -24,6 +24,7 @@ import ( "github.com/ipfs/boxo/ipns" "github.com/ipfs/boxo/namesys" "github.com/ipfs/boxo/path/resolver" + "github.com/ipfs/boxo/peering" routingv1client "github.com/ipfs/boxo/routing/http/client" httpcontentrouter "github.com/ipfs/boxo/routing/http/contentrouter" "github.com/ipfs/go-cid" @@ -99,6 +100,7 @@ type Config struct { DHTSharedHost bool DenylistSubs []string + Peering []peer.AddrInfo } func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cachedDNS) (*Node, error) { @@ -269,6 +271,14 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached return nil, err } + ps := peering.NewPeeringService(h) + if err := ps.Start(); err != nil { + return nil, err + } + for _, a := range cfg.Peering { + ps.AddPeer(a) + } + bsctx := metri.CtxScope(ctx, "ipfs_bitswap") bn := bsnet.NewFromIpfsHost(h, cr) bswap := bsclient.New(bsctx, bn, blkst,