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

Bitswap Refactor #3: Extract sessions to package #30

Merged
merged 2 commits into from
Dec 13, 2018

Conversation

hannahhoward
Copy link
Contributor

Goals

Modularize Bitswap in preparation for attempts to optimize bitswap further
child of #26

Implementation

  • moved sessions out of main bitswap package
  • modified session manager to manage all sessions
  • did a bit of cleanup on sessions
  • moved get functions to their own package so sessions can directly

BREAKING CHANGE: SessionsForBlock, while not used outside of Bitswap, has been removed, and was an exported function

@ghost ghost assigned hannahhoward Dec 4, 2018
@ghost ghost added the status/in-progress In progress label Dec 4, 2018
@hannahhoward hannahhoward changed the title Bitswap Refactor #3 Bitswap Refactor #3: Extract sessions to package Dec 4, 2018
@hannahhoward hannahhoward changed the base branch from feat/extract-managers to master December 11, 2018 19:43
- moved sessions out of main bitswap package
- modified session manager to manage all sessions
- moved get functions to their own package so sessions can directly

BREAKING CHANGE: SessionsForBlock, while not used outside of Bitswap, has been removed, and was an
exported function
@hannahhoward
Copy link
Contributor Author

@Stebalien @whyrusleeping @michaelavila @eingenito @lanzafame @schomatis @parkan This is now the next part to review, if/when you have time.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct and is a nice improvement. I think there's some room to further decouple things but we can do that later without much difficulty.

LGTM modulo the odd loop in NewSession.

logging "github.com/ipfs/go-log"
loggables "github.com/libp2p/go-libp2p-loggables"
peer "github.com/libp2p/go-libp2p-peer"
)

const activeWantsLimit = 16

// SessionWantmanager is an interface that can be used to request blocks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: SessionWantManager.

type SessionWantManager interface {
WantBlocks(ctx context.Context, ks []cid.Cid, peers []peer.ID, ses uint64)
CancelWants(ctx context.Context, ks []cid.Cid, peers []peer.ID, ses uint64)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought for a future direction (we can leave this as-is for now, I really like the architecture):

type WantManager interface {
  AddWants(ctx context.Context, ks []cid.Cid, peers []peer.ID)
  CancelWants(ctx context.Context, ks []cid.Cid, peers []peer.ID)
}

That is, we're currently:

  1. Constructing a session, passing in a session ID and a SessionWantManager.
  2. Expecting that SessionWantManager to pass the ID back for each request.

Instead, we could construct a thin helper type implementing the WantManager interface that remembers the session ID.


But we can leave this for later, if ever.

sm.sessLk.Lock()
sm.sessions = append(sm.sessions, session)
sm.sessLk.Unlock()
go func() {
for {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, you're right. good catch. :)

remove for loop not needed, cleanup spelling
defer cancel()
select {
case <-sm.ctx.Done():
sm.removeSession(session)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: duplicate code. We can replace this with:

defer cancel()
select {
case <-sm.ctx.Done():
case <-ctx.Done():
}
sm.removeSession(session)

@Stebalien
Copy link
Member

(this has been up for long enough, feel free to merge when you're ready)

@hannahhoward hannahhoward merged commit 1e9b2c4 into master Dec 13, 2018
@ghost ghost removed the status/in-progress In progress label Dec 13, 2018
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
Bitswap Refactor ipfs#3: Extract sessions to package

This commit was moved from ipfs/go-bitswap@1e9b2c4
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants