Skip to content

Commit

Permalink
feat: add peering
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Nov 7, 2023
1 parent 3e3972a commit 9894e81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")),
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -269,6 +271,16 @@ func Setup(ctx context.Context, cfg Config, key crypto.PrivKey, dnsCache *cached
return nil, err
}

if len(cfg.Peering) > 0 {
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,
Expand Down

0 comments on commit 9894e81

Please sign in to comment.