Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Feat: A more robust provider finder for sessions (for now) and soon for all bitswap #60

Merged
merged 9 commits into from
Feb 5, 2019
10 changes: 9 additions & 1 deletion bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
bsnet "github.com/ipfs/go-bitswap/network"
notifications "github.com/ipfs/go-bitswap/notifications"
bspm "github.com/ipfs/go-bitswap/peermanager"
bspqm "github.com/ipfs/go-bitswap/providerquerymanager"
bssession "github.com/ipfs/go-bitswap/session"
bssm "github.com/ipfs/go-bitswap/sessionmanager"
bsspm "github.com/ipfs/go-bitswap/sessionpeermanager"
Expand Down Expand Up @@ -105,11 +106,13 @@ func New(parent context.Context, network bsnet.BitSwapNetwork,
}

wm := bswm.New(ctx)
pqm := bspqm.New(ctx, network)

sessionFactory := func(ctx context.Context, id uint64, pm bssession.PeerManager, srs bssession.RequestSplitter) bssm.Session {
return bssession.New(ctx, id, wm, pm, srs)
}
sessionPeerManagerFactory := func(ctx context.Context, id uint64) bssession.PeerManager {
return bsspm.New(ctx, id, network)
return bsspm.New(ctx, id, network.ConnectionManager(), pqm)
}
sessionRequestSplitterFactory := func(ctx context.Context) bssession.RequestSplitter {
return bssrs.New(ctx)
Expand All @@ -125,6 +128,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork,
newBlocks: make(chan cid.Cid, HasBlockBufferSize),
provideKeys: make(chan cid.Cid, provideKeysBufferSize),
wm: wm,
pqm: pqm,
pm: bspm.New(ctx, peerQueueFactory),
sm: bssm.New(ctx, sessionFactory, sessionPeerManagerFactory, sessionRequestSplitterFactory),
counters: new(counters),
Expand All @@ -136,6 +140,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork,
bs.wm.SetDelegate(bs.pm)
bs.pm.Startup()
bs.wm.Startup()
bs.pqm.Startup()
network.SetDelegate(bs)

// Start up bitswaps async worker routines
Expand All @@ -161,6 +166,9 @@ type Bitswap struct {
// the wantlist tracks global wants for bitswap
wm *bswm.WantManager

// the provider query manager manages requests to find providers
pqm *bspqm.ProviderQueryManager

// the engine is the bit of logic that decides who to send which blocks to
engine *decision.Engine

Expand Down
Loading