diff --git a/bitswap/benchmarks_test.go b/bitswap/benchmarks_test.go index d3aaf04f9..dd4cf5b6c 100644 --- a/bitswap/benchmarks_test.go +++ b/bitswap/benchmarks_test.go @@ -19,9 +19,9 @@ import ( bitswap "github.com/ipfs/go-bitswap" bssession "github.com/ipfs/go-bitswap/internal/session" + bsnet "github.com/ipfs/go-bitswap/network" testinstance "github.com/ipfs/go-bitswap/testinstance" tn "github.com/ipfs/go-bitswap/testnet" - bsnet "github.com/ipfs/go-bitswap/network" cid "github.com/ipfs/go-cid" delay "github.com/ipfs/go-ipfs-delay" mockrouting "github.com/ipfs/go-ipfs-routing/mock" @@ -53,14 +53,14 @@ type bench struct { var benches = []bench{ // Fetch from two seed nodes that both have all 100 blocks // - request one at a time, in series - bench{"3Nodes-AllToAll-OneAtATime", 3, 100, allToAll, oneAtATime}, + {"3Nodes-AllToAll-OneAtATime", 3, 100, allToAll, oneAtATime}, // - request all 100 with a single GetBlocks() call - bench{"3Nodes-AllToAll-BigBatch", 3, 100, allToAll, batchFetchAll}, + {"3Nodes-AllToAll-BigBatch", 3, 100, allToAll, batchFetchAll}, // Fetch from two seed nodes, one at a time, where: // - node A has blocks 0 - 74 // - node B has blocks 25 - 99 - bench{"3Nodes-Overlap1-OneAtATime", 3, 100, overlap1, oneAtATime}, + {"3Nodes-Overlap1-OneAtATime", 3, 100, overlap1, oneAtATime}, // Fetch from two seed nodes, where: // - node A has even blocks @@ -68,40 +68,40 @@ var benches = []bench{ // - both nodes have every third block // - request one at a time, in series - bench{"3Nodes-Overlap3-OneAtATime", 3, 100, overlap2, oneAtATime}, + {"3Nodes-Overlap3-OneAtATime", 3, 100, overlap2, oneAtATime}, // - request 10 at a time, in series - bench{"3Nodes-Overlap3-BatchBy10", 3, 100, overlap2, batchFetchBy10}, + {"3Nodes-Overlap3-BatchBy10", 3, 100, overlap2, batchFetchBy10}, // - request all 100 in parallel as individual GetBlock() calls - bench{"3Nodes-Overlap3-AllConcurrent", 3, 100, overlap2, fetchAllConcurrent}, + {"3Nodes-Overlap3-AllConcurrent", 3, 100, overlap2, fetchAllConcurrent}, // - request all 100 with a single GetBlocks() call - bench{"3Nodes-Overlap3-BigBatch", 3, 100, overlap2, batchFetchAll}, + {"3Nodes-Overlap3-BigBatch", 3, 100, overlap2, batchFetchAll}, // - request 1, then 10, then 89 blocks (similar to how IPFS would fetch a file) - bench{"3Nodes-Overlap3-UnixfsFetch", 3, 100, overlap2, unixfsFileFetch}, + {"3Nodes-Overlap3-UnixfsFetch", 3, 100, overlap2, unixfsFileFetch}, // Fetch from nine seed nodes, all nodes have all blocks // - request one at a time, in series - bench{"10Nodes-AllToAll-OneAtATime", 10, 100, allToAll, oneAtATime}, + {"10Nodes-AllToAll-OneAtATime", 10, 100, allToAll, oneAtATime}, // - request 10 at a time, in series - bench{"10Nodes-AllToAll-BatchFetchBy10", 10, 100, allToAll, batchFetchBy10}, + {"10Nodes-AllToAll-BatchFetchBy10", 10, 100, allToAll, batchFetchBy10}, // - request all 100 with a single GetBlocks() call - bench{"10Nodes-AllToAll-BigBatch", 10, 100, allToAll, batchFetchAll}, + {"10Nodes-AllToAll-BigBatch", 10, 100, allToAll, batchFetchAll}, // - request all 100 in parallel as individual GetBlock() calls - bench{"10Nodes-AllToAll-AllConcurrent", 10, 100, allToAll, fetchAllConcurrent}, + {"10Nodes-AllToAll-AllConcurrent", 10, 100, allToAll, fetchAllConcurrent}, // - request 1, then 10, then 89 blocks (similar to how IPFS would fetch a file) - bench{"10Nodes-AllToAll-UnixfsFetch", 10, 100, allToAll, unixfsFileFetch}, + {"10Nodes-AllToAll-UnixfsFetch", 10, 100, allToAll, unixfsFileFetch}, // - follow a typical IPFS request pattern for 1000 blocks - bench{"10Nodes-AllToAll-UnixfsFetchLarge", 10, 1000, allToAll, unixfsFileFetchLarge}, + {"10Nodes-AllToAll-UnixfsFetchLarge", 10, 1000, allToAll, unixfsFileFetchLarge}, // Fetch from nine seed nodes, blocks are distributed randomly across all nodes (no dups) // - request one at a time, in series - bench{"10Nodes-OnePeerPerBlock-OneAtATime", 10, 100, onePeerPerBlock, oneAtATime}, + {"10Nodes-OnePeerPerBlock-OneAtATime", 10, 100, onePeerPerBlock, oneAtATime}, // - request all 100 with a single GetBlocks() call - bench{"10Nodes-OnePeerPerBlock-BigBatch", 10, 100, onePeerPerBlock, batchFetchAll}, + {"10Nodes-OnePeerPerBlock-BigBatch", 10, 100, onePeerPerBlock, batchFetchAll}, // - request 1, then 10, then 89 blocks (similar to how IPFS would fetch a file) - bench{"10Nodes-OnePeerPerBlock-UnixfsFetch", 10, 100, onePeerPerBlock, unixfsFileFetch}, + {"10Nodes-OnePeerPerBlock-UnixfsFetch", 10, 100, onePeerPerBlock, unixfsFileFetch}, // Fetch from 199 seed nodes, all nodes have all blocks, fetch all 20 blocks with a single GetBlocks() call - bench{"200Nodes-AllToAll-BigBatch", 200, 20, allToAll, batchFetchAll}, + {"200Nodes-AllToAll-BigBatch", 200, 20, allToAll, batchFetchAll}, } func BenchmarkFixedDelay(b *testing.B) { @@ -127,9 +127,9 @@ type mixedBench struct { } var mixedBenches = []mixedBench{ - mixedBench{bench{"3Nodes-Overlap3-OneAtATime", 3, 10, overlap2, oneAtATime}, 1, 2}, - mixedBench{bench{"3Nodes-AllToAll-OneAtATime", 3, 10, allToAll, oneAtATime}, 1, 2}, - mixedBench{bench{"3Nodes-Overlap3-AllConcurrent", 3, 10, overlap2, fetchAllConcurrent}, 1, 2}, + {bench{"3Nodes-Overlap3-OneAtATime", 3, 10, overlap2, oneAtATime}, 1, 2}, + {bench{"3Nodes-AllToAll-OneAtATime", 3, 10, allToAll, oneAtATime}, 1, 2}, + {bench{"3Nodes-Overlap3-AllConcurrent", 3, 10, overlap2, fetchAllConcurrent}, 1, 2}, // mixedBench{bench{"3Nodes-Overlap3-UnixfsFetch", 3, 100, overlap2, unixfsFileFetch}, 1, 2}, } diff --git a/bitswap/bitswap.go b/bitswap/bitswap.go index 0297c0989..b7f763df5 100644 --- a/bitswap/bitswap.go +++ b/bitswap/bitswap.go @@ -183,13 +183,13 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, sm = bssm.New(ctx, sessionFactory, sim, sessionPeerManagerFactory, bpm, pm, notif, network.Self()) bs := &Bitswap{ - blockstore: bstore, - network: network, - process: px, - newBlocks: make(chan cid.Cid, HasBlockBufferSize), - provideKeys: make(chan cid.Cid, provideKeysBufferSize), - pm: pm, - pqm: pqm, + blockstore: bstore, + network: network, + process: px, + newBlocks: make(chan cid.Cid, HasBlockBufferSize), + provideKeys: make(chan cid.Cid, provideKeysBufferSize), + pm: pm, + pqm: pqm, sm: sm, sim: sim, notif: notif, diff --git a/bitswap/internal/blockpresencemanager/blockpresencemanager_test.go b/bitswap/internal/blockpresencemanager/blockpresencemanager_test.go index 579dbfcda..0d65c457e 100644 --- a/bitswap/internal/blockpresencemanager/blockpresencemanager_test.go +++ b/bitswap/internal/blockpresencemanager/blockpresencemanager_test.go @@ -208,24 +208,24 @@ func TestAllPeersDoNotHaveBlock(t *testing.T) { } testcases := []testcase{ - testcase{[]peer.ID{p0}, []cid.Cid{c0}, []cid.Cid{}}, - testcase{[]peer.ID{p1}, []cid.Cid{c0}, []cid.Cid{c0}}, - testcase{[]peer.ID{p2}, []cid.Cid{c0}, []cid.Cid{}}, + {[]peer.ID{p0}, []cid.Cid{c0}, []cid.Cid{}}, + {[]peer.ID{p1}, []cid.Cid{c0}, []cid.Cid{c0}}, + {[]peer.ID{p2}, []cid.Cid{c0}, []cid.Cid{}}, - testcase{[]peer.ID{p0}, []cid.Cid{c1}, []cid.Cid{c1}}, - testcase{[]peer.ID{p1}, []cid.Cid{c1}, []cid.Cid{}}, - testcase{[]peer.ID{p2}, []cid.Cid{c1}, []cid.Cid{}}, + {[]peer.ID{p0}, []cid.Cid{c1}, []cid.Cid{c1}}, + {[]peer.ID{p1}, []cid.Cid{c1}, []cid.Cid{}}, + {[]peer.ID{p2}, []cid.Cid{c1}, []cid.Cid{}}, - testcase{[]peer.ID{p0}, []cid.Cid{c2}, []cid.Cid{c2}}, - testcase{[]peer.ID{p1}, []cid.Cid{c2}, []cid.Cid{}}, - testcase{[]peer.ID{p2}, []cid.Cid{c2}, []cid.Cid{c2}}, + {[]peer.ID{p0}, []cid.Cid{c2}, []cid.Cid{c2}}, + {[]peer.ID{p1}, []cid.Cid{c2}, []cid.Cid{}}, + {[]peer.ID{p2}, []cid.Cid{c2}, []cid.Cid{c2}}, // p0 recieved DONT_HAVE for c1 & c2 (but not for c0) - testcase{[]peer.ID{p0}, []cid.Cid{c0, c1, c2}, []cid.Cid{c1, c2}}, - testcase{[]peer.ID{p0, p1}, []cid.Cid{c0, c1, c2}, []cid.Cid{}}, + {[]peer.ID{p0}, []cid.Cid{c0, c1, c2}, []cid.Cid{c1, c2}}, + {[]peer.ID{p0, p1}, []cid.Cid{c0, c1, c2}, []cid.Cid{}}, // Both p0 and p2 received DONT_HAVE for c2 - testcase{[]peer.ID{p0, p2}, []cid.Cid{c0, c1, c2}, []cid.Cid{c2}}, - testcase{[]peer.ID{p0, p1, p2}, []cid.Cid{c0, c1, c2}, []cid.Cid{}}, + {[]peer.ID{p0, p2}, []cid.Cid{c0, c1, c2}, []cid.Cid{c2}}, + {[]peer.ID{p0, p1, p2}, []cid.Cid{c0, c1, c2}, []cid.Cid{}}, } for i, tc := range testcases { diff --git a/bitswap/internal/decision/engine.go b/bitswap/internal/decision/engine.go index 6e69ca657..6950f59e5 100644 --- a/bitswap/internal/decision/engine.go +++ b/bitswap/internal/decision/engine.go @@ -163,7 +163,7 @@ type Engine struct { sendDontHaves bool - self peer.ID + self peer.ID } // NewEngine creates a new block sending engine for the given block store diff --git a/bitswap/internal/decision/engine_test.go b/bitswap/internal/decision/engine_test.go index 2cf9e773a..ac370d0db 100644 --- a/bitswap/internal/decision/engine_test.go +++ b/bitswap/internal/decision/engine_test.go @@ -236,31 +236,31 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { testCases := []testCase{ // Just send want-blocks - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: vowels, sendDontHave: false, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: vowels, }, }, }, // Send want-blocks and want-haves - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: vowels, wantHaves: "fgh", sendDontHave: false, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: vowels, haves: "fgh", }, @@ -269,16 +269,16 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { // Send want-blocks and want-haves, with some want-haves that are not // present, but without requesting DONT_HAVES - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: vowels, wantHaves: "fgh123", sendDontHave: false, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: vowels, haves: "fgh", }, @@ -287,16 +287,16 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { // Send want-blocks and want-haves, with some want-haves that are not // present, and request DONT_HAVES - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: vowels, wantHaves: "fgh123", sendDontHave: true, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: vowels, haves: "fgh", dontHaves: "123", @@ -306,16 +306,16 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { // Send want-blocks and want-haves, with some want-blocks and want-haves that are not // present, but without requesting DONT_HAVES - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "aeiou123", wantHaves: "fgh456", sendDontHave: false, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: "aeiou", haves: "fgh", dontHaves: "", @@ -325,16 +325,16 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { // Send want-blocks and want-haves, with some want-blocks and want-haves that are not // present, and request DONT_HAVES - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "aeiou123", wantHaves: "fgh456", sendDontHave: true, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: "aeiou", haves: "fgh", dontHaves: "123456", @@ -343,48 +343,48 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { }, // Send repeated want-blocks - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "ae", sendDontHave: false, }, - testCaseEntry{ + { wantBlks: "io", sendDontHave: false, }, - testCaseEntry{ + { wantBlks: "u", sendDontHave: false, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: "aeiou", }, }, }, // Send repeated want-blocks and want-haves - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "ae", wantHaves: "jk", sendDontHave: false, }, - testCaseEntry{ + { wantBlks: "io", wantHaves: "lm", sendDontHave: false, }, - testCaseEntry{ + { wantBlks: "u", sendDontHave: false, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: "aeiou", haves: "jklm", }, @@ -393,26 +393,26 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { // Send repeated want-blocks and want-haves, with some want-blocks and want-haves that are not // present, and request DONT_HAVES - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "ae12", wantHaves: "jk5", sendDontHave: true, }, - testCaseEntry{ + { wantBlks: "io34", wantHaves: "lm", sendDontHave: true, }, - testCaseEntry{ + { wantBlks: "u", wantHaves: "6", sendDontHave: true, }, }, exp: []testCaseExp{ - testCaseExp{ + { blks: "aeiou", haves: "jklm", dontHaves: "123456", @@ -421,13 +421,13 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { }, // Send want-block then want-have for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "a", sendDontHave: true, }, - testCaseEntry{ + { wantHaves: "a", sendDontHave: true, }, @@ -435,67 +435,67 @@ func TestPartnerWantHaveWantBlockNonActive(t *testing.T) { // want-have should be ignored because there was already a // want-block for the same CID in the queue exp: []testCaseExp{ - testCaseExp{ + { blks: "a", }, }, }, // Send want-have then want-block for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantHaves: "b", sendDontHave: true, }, - testCaseEntry{ + { wantBlks: "b", sendDontHave: true, }, }, // want-block should overwrite existing want-have exp: []testCaseExp{ - testCaseExp{ + { blks: "b", }, }, }, // Send want-block then want-block for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "a", sendDontHave: true, }, - testCaseEntry{ + { wantBlks: "a", sendDontHave: true, }, }, // second want-block should be ignored exp: []testCaseExp{ - testCaseExp{ + { blks: "a", }, }, }, // Send want-have then want-have for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantHaves: "a", sendDontHave: true, }, - testCaseEntry{ + { wantHaves: "a", sendDontHave: true, }, }, // second want-have should be ignored exp: []testCaseExp{ - testCaseExp{ + { haves: "a", }, }, @@ -573,13 +573,13 @@ func TestPartnerWantHaveWantBlockActive(t *testing.T) { testCases := []testCase{ // Send want-block then want-have for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "a", sendDontHave: true, }, - testCaseEntry{ + { wantHaves: "a", sendDontHave: true, }, @@ -587,20 +587,20 @@ func TestPartnerWantHaveWantBlockActive(t *testing.T) { // want-have should be ignored because there was already a // want-block for the same CID in the queue exp: []testCaseExp{ - testCaseExp{ + { blks: "a", }, }, }, // Send want-have then want-block for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantHaves: "b", sendDontHave: true, }, - testCaseEntry{ + { wantBlks: "b", sendDontHave: true, }, @@ -608,50 +608,50 @@ func TestPartnerWantHaveWantBlockActive(t *testing.T) { // want-have is active when want-block is added, so want-have // should get sent, then want-block exp: []testCaseExp{ - testCaseExp{ + { haves: "b", }, - testCaseExp{ + { blks: "b", }, }, }, // Send want-block then want-block for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantBlks: "a", sendDontHave: true, }, - testCaseEntry{ + { wantBlks: "a", sendDontHave: true, }, }, // second want-block should be ignored exp: []testCaseExp{ - testCaseExp{ + { blks: "a", }, }, }, // Send want-have then want-have for same CID - testCase{ + { wls: []testCaseEntry{ - testCaseEntry{ + { wantHaves: "a", sendDontHave: true, }, - testCaseEntry{ + { wantHaves: "a", sendDontHave: true, }, }, // second want-have should be ignored exp: []testCaseExp{ - testCaseExp{ + { haves: "a", }, }, diff --git a/bitswap/network/ipfs_impl_test.go b/bitswap/network/ipfs_impl_test.go index 475fcfc6a..0d7968ecb 100644 --- a/bitswap/network/ipfs_impl_test.go +++ b/bitswap/network/ipfs_impl_test.go @@ -447,10 +447,10 @@ func TestSupportsHave(t *testing.T) { } testCases := []testCase{ - testCase{bsnet.ProtocolBitswap, true}, - testCase{bsnet.ProtocolBitswapOneOne, false}, - testCase{bsnet.ProtocolBitswapOneZero, false}, - testCase{bsnet.ProtocolBitswapNoVers, false}, + {bsnet.ProtocolBitswap, true}, + {bsnet.ProtocolBitswapOneOne, false}, + {bsnet.ProtocolBitswapOneZero, false}, + {bsnet.ProtocolBitswapNoVers, false}, } for _, tc := range testCases { diff --git a/bitswap/testinstance/testinstance.go b/bitswap/testinstance/testinstance.go index 2ee6be8bd..05e3d515e 100644 --- a/bitswap/testinstance/testinstance.go +++ b/bitswap/testinstance/testinstance.go @@ -5,8 +5,8 @@ import ( "time" bitswap "github.com/ipfs/go-bitswap" - tn "github.com/ipfs/go-bitswap/testnet" bsnet "github.com/ipfs/go-bitswap/network" + tn "github.com/ipfs/go-bitswap/testnet" ds "github.com/ipfs/go-datastore" delayed "github.com/ipfs/go-datastore/delayed" ds_sync "github.com/ipfs/go-datastore/sync" diff --git a/bitswap/testnet/virtual.go b/bitswap/testnet/virtual.go index 48ef7b435..66f5e8216 100644 --- a/bitswap/testnet/virtual.go +++ b/bitswap/testnet/virtual.go @@ -271,9 +271,9 @@ func (mp *messagePasser) Reset() error { } var oldProtos = map[protocol.ID]struct{}{ - bsnet.ProtocolBitswapNoVers: struct{}{}, - bsnet.ProtocolBitswapOneZero: struct{}{}, - bsnet.ProtocolBitswapOneOne: struct{}{}, + bsnet.ProtocolBitswapNoVers: {}, + bsnet.ProtocolBitswapOneZero: {}, + bsnet.ProtocolBitswapOneOne: {}, } func (mp *messagePasser) SupportsHave() bool {