From 7f5f2f40947080233a55ff4ea8d2e759901f16aa Mon Sep 17 00:00:00 2001 From: Jeromy Date: Wed, 19 Sep 2018 14:39:37 -0700 Subject: [PATCH] fix session exchange interface implementation --- bitswap.go | 2 ++ dup_blocks_test.go | 7 +++++-- package.json | 4 ++-- session.go | 3 ++- session_test.go | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bitswap.go b/bitswap.go index b8dd498c..19db835a 100644 --- a/bitswap.go +++ b/bitswap.go @@ -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 diff --git a/dup_blocks_test.go b/dup_blocks_test.go index 3a3f79de..326efc4a 100644 --- a/dup_blocks_test.go +++ b/dup_blocks_test.go @@ -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) @@ -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) } } @@ -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 { diff --git a/package.json b/package.json index 269be462..6cc27dc0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/session.go b/session.go index 191c280f..c3cf4ab8 100644 --- a/session.go +++ b/session.go @@ -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" @@ -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[string]time.Time), diff --git a/session_test.go b/session_test.go index 8769d891..c5a00a90 100644 --- a/session_test.go +++ b/session_test.go @@ -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++ {