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 6, 2023
1 parent 38c47c6 commit 3117017
Show file tree
Hide file tree
Showing 2 changed files with 26 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)",
},

Check warning on line 178 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L173-L178

Added lines #L173 - L178 were not covered by tests
}

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)

Check warning on line 259 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L253-L259

Added lines #L253 - L259 were not covered by tests
}

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,

Check warning on line 276 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L276

Added line #L276 was not covered by tests
}

goLog.Debugf("Rainbow config: %+v", cfg)
Expand Down
10 changes: 10 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,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)
}

Check warning on line 280 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L274-L280

Added lines #L274 - L280 were not covered by tests

bsctx := metri.CtxScope(ctx, "ipfs_bitswap")
bn := bsnet.NewFromIpfsHost(h, cr)
bswap := bsclient.New(bsctx, bn, blkst,
Expand Down

0 comments on commit 3117017

Please sign in to comment.