Skip to content

Commit

Permalink
feat: no-op peer ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Apr 26, 2024
1 parent 3161376 commit b2d4cd2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/felixge/httpsnoop v1.0.4
github.com/ipfs-shipyard/nopfs v0.0.12
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a
github.com/ipfs/boxo v0.19.1-0.20240425141508-cf4721157323
github.com/ipfs/boxo v0.19.1-0.20240426063719-8d74823b30b2
github.com/ipfs/go-block-format v0.2.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-datastore v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a h1:MKG
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.19.1-0.20240425141508-cf4721157323 h1:5mK+3r703mtstolx6fIkujm22hLrze5x4NZti+UGjyE=
github.com/ipfs/boxo v0.19.1-0.20240425141508-cf4721157323/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0=
github.com/ipfs/boxo v0.19.1-0.20240426063719-8d74823b30b2 h1:Se2CmDXD/e8+3zRMbmPNQzw42MiyD6s4VbEDV0iHu1U=
github.com/ipfs/boxo v0.19.1-0.20240426063719-8d74823b30b2/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=
Expand Down
39 changes: 34 additions & 5 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
nopfs "github.com/ipfs-shipyard/nopfs"
nopfsipfs "github.com/ipfs-shipyard/nopfs/ipfs"
"github.com/ipfs/boxo/bitswap"
wl "github.com/ipfs/boxo/bitswap/client/wantlist"
bsmspb "github.com/ipfs/boxo/bitswap/message/pb"
bsnet "github.com/ipfs/boxo/bitswap/network"
bsserver "github.com/ipfs/boxo/bitswap/server"
"github.com/ipfs/boxo/blockservice"
Expand Down Expand Up @@ -433,15 +435,42 @@ func setupBitswap(ctx context.Context, cfg Config, h host.Host, cr routing.Conte
bitswap.ProvideEnabled(false),
// Do not keep track of other peer's wantlists, we only want to reply if we
// have a block. If we get it later, it's no longer relevant.
bitswap.WithNoPeerLedger(),
// Do not notify peers once we get blocks they've asked for, reduces processing.
// This should already be a no-op considering we're not keeping track of other
// peer's wantlists.
bitswap.WithNotifyNewBlocks(false),
bitswap.WithPeerLedger(&noopPeerLedger{}),
// When we don't have a block, don't reply. This reduces processment.
bitswap.SetSendDontHaves(false),
)
bn.Start(bswap)

return bswap
}

type noopPeerLedger struct{}

func (*noopPeerLedger) Wants(p peer.ID, e wl.Entry) {}

func (*noopPeerLedger) CancelWant(p peer.ID, k cid.Cid) bool {
return false
}

func (*noopPeerLedger) CancelWantWithType(p peer.ID, k cid.Cid, typ bsmspb.Message_Wantlist_WantType) {
}

func (*noopPeerLedger) Peers(k cid.Cid) []bsserver.PeerEntry {
return nil
}

func (*noopPeerLedger) CollectPeerIDs() []peer.ID {
return nil

Check warning on line 463 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L462-L463

Added lines #L462 - L463 were not covered by tests
}

func (*noopPeerLedger) WantlistSizeForPeer(p peer.ID) int {
return 0
}

func (*noopPeerLedger) WantlistForPeer(p peer.ID) []wl.Entry {
return nil

Check warning on line 471 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L470-L471

Added lines #L470 - L471 were not covered by tests
}

func (*noopPeerLedger) ClearPeerWantlist(p peer.ID) {}

Check warning on line 474 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L474

Added line #L474 was not covered by tests

func (*noopPeerLedger) PeerDisconnected(p peer.ID) {}

Check warning on line 476 in setup.go

View check run for this annotation

Codecov / codecov/patch

setup.go#L476

Added line #L476 was not covered by tests

0 comments on commit b2d4cd2

Please sign in to comment.