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

Commit

Permalink
fix session exchange interface implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping authored and Stebalien committed Oct 8, 2018
1 parent 19df599 commit 84a7035
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

var log = logging.Logger("bitswap")

var _ exchange.SessionExchange = (*Bitswap)(nil)

const (
// maxProvidersPerRequest specifies the maximum number of providers desired
// from the network. This value is specified because the network streams
Expand Down
7 changes: 5 additions & 2 deletions dup_blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func TestDups2Nodes(t *testing.T) {
t.Run("10Nodes-OnePeerPerBlock-UnixfsFetch", func(t *testing.T) {
subtestDistributeAndFetch(t, 10, 100, onePeerPerBlock, unixfsFileFetch)
})
t.Run("200Nodes-AllToAll-BigBatch", func(t *testing.T) {
subtestDistributeAndFetch(t, 200, 20, allToAll, batchFetchAll)
})

out, _ := json.MarshalIndent(benchmarkLog, "", " ")
ioutil.WriteFile("benchmark.json", out, 0666)
Expand Down Expand Up @@ -130,7 +133,7 @@ func subtestDistributeAndFetch(t *testing.T, numnodes, numblks int, df distFunc,
benchmarkLog = append(benchmarkLog, stats)
t.Logf("send/recv: %d / %d", nst.MessagesSent, nst.MessagesRecvd)
if st.DupBlksReceived != 0 {
//t.Fatalf("got %d duplicate blocks!", st.DupBlksReceived)
t.Fatalf("got %d duplicate blocks!", st.DupBlksReceived)
}
}

Expand Down Expand Up @@ -214,7 +217,7 @@ func onePeerPerBlock(t *testing.T, provs []Instance, blks []blocks.Block) {
}

func oneAtATime(t *testing.T, bs *Bitswap, ks []cid.Cid) {
ses := bs.NewSession(context.Background())
ses := bs.NewSession(context.Background()).(*Session)
for _, c := range ks {
_, err := ses.GetBlock(context.Background(), c)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
},
{
"author": "hsanjuan",
"hash": "QmR1nncPsZR14A4hWr39mq8Lm7BGgS68bHVT9nop8NpWEM",
"hash": "QmUdh9184Bozfinyn5YDhgPRg33E3KR3btfZXcVoFgTxD4",
"name": "go-ipfs-exchange-interface",
"version": "0.1.0"
"version": "0.1.1"
},
{
"author": "whyrusleeping",
Expand Down
3 changes: 2 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
lru "github.com/hashicorp/golang-lru"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
logging "github.com/ipfs/go-log"
loggables "github.com/libp2p/go-libp2p-loggables"
peer "github.com/libp2p/go-libp2p-peer"
Expand Down Expand Up @@ -70,7 +71,7 @@ type Session struct {

// NewSession creates a new bitswap session whose lifetime is bounded by the
// given context
func (bs *Bitswap) NewSession(ctx context.Context) *Session {
func (bs *Bitswap) NewSession(ctx context.Context) exchange.Fetcher {
s := &Session{
activePeers: make(map[peer.ID]struct{}),
liveWants: make(map[cid.Cid]time.Time),
Expand Down
2 changes: 1 addition & 1 deletion session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestSessionSplitFetch(t *testing.T) {
cids = append(cids, blk.Cid())
}

ses := inst[10].Exchange.NewSession(ctx)
ses := inst[10].Exchange.NewSession(ctx).(*Session)
ses.baseTickDelay = time.Millisecond * 10

for i := 0; i < 10; i++ {
Expand Down

0 comments on commit 84a7035

Please sign in to comment.