Skip to content

Commit

Permalink
fix(p2p): couple bitswap client and server (#3641)
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Aug 14, 2024
1 parent 6a03661 commit d593e37
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions nodebuilder/p2p/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package p2p

import (
"context"
"errors"
"fmt"

"github.com/ipfs/boxo/bitswap/client"
"github.com/ipfs/boxo/bitswap"
"github.com/ipfs/boxo/bitswap/network"
"github.com/ipfs/boxo/bitswap/server"
"github.com/ipfs/boxo/blockstore"
"github.com/ipfs/boxo/exchange"
"github.com/ipfs/go-datastore"
Expand All @@ -32,36 +30,26 @@ const (
func dataExchange(params bitSwapParams) exchange.Interface {
prefix := protocolID(params.Net)
net := network.NewFromIpfsHost(params.Host, &routinghelpers.Null{}, network.Prefix(prefix))
srvr := server.New(
params.Ctx,
net,
params.Bs,
server.ProvideEnabled(false), // we don't provide blocks over DHT

opts := []bitswap.Option{
// Server options
bitswap.ProvideEnabled(false), // we don't provide blocks over DHT
// NOTE: These below are required for our protocol to work reliably.
// // See https://github.com/celestiaorg/celestia-node/issues/732
server.SetSendDontHaves(false),
)
bitswap.SetSendDontHaves(false),

clnt := client.New(
params.Ctx,
net,
params.Bs,
client.WithBlockReceivedNotifier(srvr),
client.SetSimulateDontHavesOnTimeout(false),
client.WithoutDuplicatedBlockStats(),
)
net.Start(srvr, clnt) // starting with hook does not work
// Client options
bitswap.SetSimulateDontHavesOnTimeout(false),
bitswap.WithoutDuplicatedBlockStats(),
}
bs := bitswap.New(params.Ctx, net, params.Bs, opts...)

params.Lifecycle.Append(fx.Hook{
OnStop: func(_ context.Context) (err error) {
err = errors.Join(err, clnt.Close())
err = errors.Join(err, srvr.Close())
net.Stop()
return err
return bs.Close()
},
})

return clnt
return bs
}

func blockstoreFromDatastore(ctx context.Context, ds datastore.Batching) (blockstore.Blockstore, error) {
Expand Down

0 comments on commit d593e37

Please sign in to comment.