From 7b4409135447e11e060ff1b2dde5c65c0fbf64b8 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Tue, 7 Jul 2020 08:50:18 -0700 Subject: [PATCH] fix(lint): fix lint & mod tidy --- go.mod | 1 - go.sum | 17 ------- impl/events.go | 3 ++ impl/initiating_test.go | 3 +- impl/integration_test.go | 73 +++++++++++++-------------- impl/responding_test.go | 9 ++-- transport/graphsync/graphsync_test.go | 7 +-- transport/transport.go | 2 +- 8 files changed, 52 insertions(+), 63 deletions(-) diff --git a/go.mod b/go.mod index c51b7d77..e3758b58 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c github.com/libp2p/go-libp2p v0.6.0 github.com/libp2p/go-libp2p-core v0.5.0 - github.com/libp2p/go-libp2p-peer v0.2.0 github.com/prometheus/common v0.10.0 github.com/stretchr/testify v1.5.1 github.com/whyrusleeping/cbor-gen v0.0.0-20200402171437-3d27c146c105 diff --git a/go.sum b/go.sum index bb4b7885..6d398c04 100644 --- a/go.sum +++ b/go.sum @@ -65,7 +65,6 @@ github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIi github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b h1:fkRZSPrYpk42PV3/lIXiL0LHetxde7vyYYvSsttQtfg= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b/go.mod h1:Q0GQOBtKf1oE10eSXSlhN45kDBdGvEcVOqMiffqX+N8= -github.com/filecoin-project/lotus v0.4.1 h1:rg9X3TY7ymT+m6ATIQ7xt8FW2CpCeznwOFfbONPMz84= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI= @@ -157,22 +156,6 @@ github.com/ipfs/go-ds-badger v0.0.5/go.mod h1:g5AuuCGmr7efyzQhLL8MzwqcauPojGPUaH github.com/ipfs/go-ds-badger v0.2.1/go.mod h1:Tx7l3aTph3FMFrRS838dcSJh+jjA7cX9DrGVwx/NOwE= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= github.com/ipfs/go-ds-leveldb v0.4.1/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s= -github.com/ipfs/go-graphsync v0.0.6-0.20200706043744-cce83184947b h1:rGRUbT7+ppNbZFvddfi+jmLWDtmreDxAoEv6+0LZIQw= -github.com/ipfs/go-graphsync v0.0.6-0.20200706043744-cce83184947b/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= -github.com/ipfs/go-graphsync v0.0.6-0.20200706054931-8241d2fe69e2 h1:om8VlCqu93Zf608yAL40dVuKc6dARUJzBZnjGT3YYNQ= -github.com/ipfs/go-graphsync v0.0.6-0.20200706054931-8241d2fe69e2/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= -github.com/ipfs/go-graphsync v0.0.6-0.20200706061258-3fe41bf10543 h1:ysS5XlF36zXYP/wZHEHKwgljg1iwMmm1vo01L7l5mkM= -github.com/ipfs/go-graphsync v0.0.6-0.20200706061258-3fe41bf10543/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= -github.com/ipfs/go-graphsync v0.0.6-0.20200706061822-013825e9d79a h1:deAybS+FtHM0ayzaL5BgmbuSRO7CteK02ZhbjcmCC6c= -github.com/ipfs/go-graphsync v0.0.6-0.20200706061822-013825e9d79a/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= -github.com/ipfs/go-graphsync v0.0.6-0.20200706074121-688c030b0d22 h1:lcEfV5GOX9C5RINCLnjeJ2/l/INuE2TEJPDoPsWHkZ8= -github.com/ipfs/go-graphsync v0.0.6-0.20200706074121-688c030b0d22/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= -github.com/ipfs/go-graphsync v0.0.6-0.20200706080831-f9f3a4f17d34 h1:LuxL7HEzNToE7IoZps8qCYnEhByU1Z+dEUaYEEMr+aU= -github.com/ipfs/go-graphsync v0.0.6-0.20200706080831-f9f3a4f17d34/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= -github.com/ipfs/go-graphsync v0.0.6-0.20200706092719-fc05cbee1dc0 h1:quYeHRwPBkJj29dAchlaX6QYol364aUjUs3mnRv0qOc= -github.com/ipfs/go-graphsync v0.0.6-0.20200706092719-fc05cbee1dc0/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= -github.com/ipfs/go-graphsync v0.0.6-0.20200706175901-e868862698b0 h1:Yb7NolSIm4GEvC2OOFm6Op5je3CxSR5BmAk9pCtSSyY= -github.com/ipfs/go-graphsync v0.0.6-0.20200706175901-e868862698b0/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= github.com/ipfs/go-graphsync v0.0.6-0.20200706184155-3e432f510b99 h1:mVU4DT7Isk4zh30dl74JO0EAqq7/LGERRKtZH4iG60M= github.com/ipfs/go-graphsync v0.0.6-0.20200706184155-3e432f510b99/go.mod h1:4htIl/cpQ2vS80RlH9LPaABTp7uYjybMiv3BlytKFh4= github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08= diff --git a/impl/events.go b/impl/events.go index 31f685ed..2577f1fa 100644 --- a/impl/events.go +++ b/impl/events.go @@ -90,6 +90,9 @@ func (m *manager) OnRequestReceived(chid datatransfer.ChannelID, request message return nil, err } chst, err := m.channels.GetByID(context.TODO(), chid) + if err != nil { + return nil, err + } if chst.Status() == datatransfer.ResponderPaused || chst.Status() == datatransfer.ResponderFinalizing { return nil, transport.ErrPause diff --git a/impl/initiating_test.go b/impl/initiating_test.go index d944383e..b74c6d35 100644 --- a/impl/initiating_test.go +++ b/impl/initiating_test.go @@ -287,7 +287,8 @@ func TestDataTransferInitiating(t *testing.T) { h.storedCounter = storedcounter.New(h.ds, datastore.NewKey("counter")) dt, err := NewDataTransfer(h.ds, h.network, h.transport, h.storedCounter) require.NoError(t, err) - dt.Start(ctx) + err = dt.Start(ctx) + require.NoError(t, err) h.dt = dt ev := eventVerifier{ expectedEvents: verify.expectedEvents, diff --git a/impl/integration_test.go b/impl/integration_test.go index ff62f1a6..bd6f38ad 100644 --- a/impl/integration_test.go +++ b/impl/integration_test.go @@ -45,12 +45,12 @@ func TestRoundTrip(t *testing.T) { dt1, err := NewDataTransfer(gsData.DtDs1, gsData.DtNet1, tp1, gsData.StoredCounter1) require.NoError(t, err) - dt1.Start(ctx) - + err = dt1.Start(ctx) + require.NoError(t, err) dt2, err := NewDataTransfer(gsData.DtDs2, gsData.DtNet2, tp2, gsData.StoredCounter2) require.NoError(t, err) - dt2.Start(ctx) - + err = dt2.Start(ctx) + require.NoError(t, err) finished := make(chan struct{}, 2) errChan := make(chan struct{}, 2) opened := make(chan struct{}, 2) @@ -181,31 +181,31 @@ func TestSimulatedRetrievalFlow(t *testing.T) { dt1, err := NewDataTransfer(gsData.DtDs1, gsData.DtNet1, tp1, gsData.StoredCounter1) require.NoError(t, err) - dt1.Start(ctx) - + err = dt1.Start(ctx) + require.NoError(t, err) dt2, err := NewDataTransfer(gsData.DtDs2, gsData.DtNet2, tp2, gsData.StoredCounter2) require.NoError(t, err) - dt2.Start(ctx) - + err = dt2.Start(ctx) + require.NoError(t, err) var chid datatransfer.ChannelID errChan := make(chan struct{}, 2) clientPausePoint := 0 clientFinished := make(chan struct{}, 1) finalVoucherResult := testutil.NewFakeDTType() encodedFVR, err := encoding.Encode(finalVoucherResult) + require.NoError(t, err) var clientSubscriber datatransfer.Subscriber = func(event datatransfer.Event, channelState datatransfer.ChannelState) { if event.Code == datatransfer.Accept { - dt2.PauseDataTransferChannel(ctx, chid) + err := dt2.PauseDataTransferChannel(ctx, chid) + require.NoError(t, err) timer := time.NewTimer(config.unpauseRequestorDelay) go func() { - select { - case <-ctx.Done(): - t.Fatal("should have unpaused") - case <-timer.C: - } - dt2.ResumeDataTransferChannel(ctx, chid) + <-timer.C + err := dt2.ResumeDataTransferChannel(ctx, chid) + require.NoError(t, err) if config.payForUnseal { - dt2.SendVoucher(ctx, chid, testutil.NewFakeDTType()) + err := dt2.SendVoucher(ctx, chid, testutil.NewFakeDTType()) + require.NoError(t, err) } }() } @@ -217,14 +217,14 @@ func TestSimulatedRetrievalFlow(t *testing.T) { encodedLVR, err := encoding.Encode(lastVoucherResult) require.NoError(t, err) if bytes.Equal(encodedLVR, encodedFVR) { - dt2.SendVoucher(ctx, chid, testutil.NewFakeDTType()) + require.NoError(t, dt2.SendVoucher(ctx, chid, testutil.NewFakeDTType())) } } if event.Code == datatransfer.Progress && clientPausePoint < len(config.pausePoints) && channelState.Received() > config.pausePoints[clientPausePoint] { - dt2.SendVoucher(ctx, chid, testutil.NewFakeDTType()) + require.NoError(t, dt2.SendVoucher(ctx, chid, testutil.NewFakeDTType())) clientPausePoint++ } if channelState.Status() == datatransfer.Completed { @@ -238,12 +238,8 @@ func TestSimulatedRetrievalFlow(t *testing.T) { if !config.payForUnseal { timer := time.NewTimer(config.unpauseResponderDelay) go func() { - select { - case <-ctx.Done(): - t.Fatal("should have unpaused") - case <-timer.C: - } - dt1.ResumeDataTransferChannel(ctx, chid) + <-timer.C + require.NoError(t, dt1.ResumeDataTransferChannel(ctx, chid)) }() } } @@ -313,12 +309,12 @@ func TestPauseAndResume(t *testing.T) { dt1, err := NewDataTransfer(gsData.DtDs1, gsData.DtNet1, tp1, gsData.StoredCounter1) require.NoError(t, err) - dt1.Start(ctx) - + err = dt1.Start(ctx) + require.NoError(t, err) dt2, err := NewDataTransfer(gsData.DtDs2, gsData.DtNet2, tp2, gsData.StoredCounter2) require.NoError(t, err) - dt2.Start(ctx) - + err = dt2.Start(ctx) + require.NoError(t, err) finished := make(chan struct{}, 2) errChan := make(chan struct{}, 2) opened := make(chan struct{}, 2) @@ -402,16 +398,16 @@ func TestPauseAndResume(t *testing.T) { case sentIncrement := <-sent: sentIncrements = append(sentIncrements, sentIncrement) if len(sentIncrements) == 5 { - dt1.PauseDataTransferChannel(ctx, chid) + require.NoError(t, dt1.PauseDataTransferChannel(ctx, chid)) time.Sleep(100 * time.Millisecond) - dt1.ResumeDataTransferChannel(ctx, chid) + require.NoError(t, dt1.ResumeDataTransferChannel(ctx, chid)) } case receivedIncrement := <-received: receivedIncrements = append(receivedIncrements, receivedIncrement) if len(receivedIncrements) == 10 { - dt2.PauseDataTransferChannel(ctx, chid) + require.NoError(t, dt2.PauseDataTransferChannel(ctx, chid)) time.Sleep(100 * time.Millisecond) - dt2.ResumeDataTransferChannel(ctx, chid) + require.NoError(t, dt2.ResumeDataTransferChannel(ctx, chid)) } case <-errChan: t.Fatal("received error on data transfer") @@ -443,14 +439,16 @@ func TestDataTransferSubscribing(t *testing.T) { sv.stubErrorPush() dt2, err := NewDataTransfer(gsData.DtDs2, gsData.DtNet2, tp2, gsData.StoredCounter2) require.NoError(t, err) - dt2.Start(ctx) + err = dt2.Start(ctx) + require.NoError(t, err) require.NoError(t, dt2.RegisterVoucherType(&testutil.FakeDTType{}, sv)) voucher := testutil.FakeDTType{Data: "applesauce"} baseCid := testutil.GenerateCids(1)[0] dt1, err := NewDataTransfer(gsData.DtDs1, gsData.DtNet1, tp1, gsData.StoredCounter1) require.NoError(t, err) - dt1.Start(ctx) + err = dt1.Start(ctx) + require.NoError(t, err) subscribe1Calls := make(chan struct{}, 1) subscribe1 := func(event datatransfer.Event, channelState datatransfer.ChannelState) { if event.Code == datatransfer.Error { @@ -583,6 +581,7 @@ func TestRespondingToPushGraphsyncRequests(t *testing.T) { dt1, err := NewDataTransfer(gsData.DtDs1, gsData.DtNet1, tp1, gsData.StoredCounter1) require.NoError(t, err) dt1.Start(ctx) + require.NoError(t, err) voucherResult := testutil.NewFakeDTType() err = dt1.RegisterVoucherResultType(voucherResult) require.NoError(t, err) @@ -667,7 +666,7 @@ func TestResponseHookWhenExtensionNotFound(t *testing.T) { dt1, err := NewDataTransfer(gsData.DtDs1, gsData.DtNet1, tp1, gsData.StoredCounter1) require.NoError(t, err) dt1.Start(ctx) - + require.NoError(t, err) t.Run("when it's not our extension, does not error and does not validate", func(t *testing.T) { //register a hook that validates the request so we don't fail in gs because the request //never gets processed @@ -723,7 +722,7 @@ func TestRespondingToPullGraphsyncRequests(t *testing.T) { dt1, err := NewDataTransfer(gsData.DtDs2, gsData.DtNet2, tp2, gsData.StoredCounter2) require.NoError(t, err) dt1.Start(ctx) - + require.NoError(t, err) require.NoError(t, dt1.RegisterVoucherType(&testutil.FakeDTType{}, sv)) voucher := testutil.NewFakeDTType() @@ -753,7 +752,7 @@ func TestRespondingToPullGraphsyncRequests(t *testing.T) { dt1, err := NewDataTransfer(gsData.DtDs2, gsData.DtNet2, tp2, gsData.StoredCounter2) require.NoError(t, err) dt1.Start(ctx) - + require.NoError(t, err) require.NoError(t, dt1.RegisterVoucherType(&testutil.FakeDTType{}, sv)) voucher := testutil.NewFakeDTType() dtRequest, err := message.NewRequest(id, true, voucher.Type(), voucher, testutil.GenerateCids(1)[0], gsData.AllSelector) diff --git a/impl/responding_test.go b/impl/responding_test.go index 495672ec..e47c5d70 100644 --- a/impl/responding_test.go +++ b/impl/responding_test.go @@ -237,7 +237,8 @@ func TestDataTransferResponding(t *testing.T) { h.network.Delegate.ReceiveRequest(h.ctx, h.peers[1], h.pushRequest) _, err := h.transport.EventHandler.OnRequestReceived(channelID(h.id, h.peers), h.pauseUpdate) require.NoError(t, err) - h.dt.PauseDataTransferChannel(h.ctx, channelID(h.id, h.peers)) + err = h.dt.PauseDataTransferChannel(h.ctx, channelID(h.id, h.peers)) + require.NoError(t, err) _, err = h.transport.EventHandler.OnRequestReceived(channelID(h.id, h.peers), h.resumeUpdate) require.EqualError(t, err, transport.ErrPause.Error()) }, @@ -464,6 +465,7 @@ func TestDataTransferResponding(t *testing.T) { _, err := h.transport.EventHandler.OnRequestReceived(channelID(h.id, h.peers), h.pullRequest) require.NoError(t, err) err = h.transport.EventHandler.OnChannelCompleted(channelID(h.id, h.peers), true) + require.NoError(t, err) require.Len(t, h.network.SentMessages, 1) response, ok := h.network.SentMessages[0].Message.(message.DataTransferResponse) require.True(t, ok) @@ -495,7 +497,8 @@ func TestDataTransferResponding(t *testing.T) { h.storedCounter = storedcounter.New(h.ds, datastore.NewKey("counter")) dt, err := NewDataTransfer(h.ds, h.network, h.transport, h.storedCounter) require.NoError(t, err) - dt.Start(ctx) + err = dt.Start(ctx) + require.NoError(t, err) h.dt = dt ev := eventVerifier{ expectedEvents: verify.expectedEvents, @@ -522,7 +525,7 @@ func TestDataTransferResponding(t *testing.T) { if verify.configureValidator != nil { verify.configureValidator(h.sv) } - err = h.dt.RegisterVoucherType(h.voucher, h.sv) + require.NoError(t, h.dt.RegisterVoucherType(h.voucher, h.sv)) h.srv = newSRV() if verify.configureRevalidator != nil { verify.configureRevalidator(h.srv) diff --git a/transport/graphsync/graphsync_test.go b/transport/graphsync/graphsync_test.go index 3fcf5d79..3ef210c6 100644 --- a/transport/graphsync/graphsync_test.go +++ b/transport/graphsync/graphsync_test.go @@ -630,7 +630,7 @@ func TestManager(t *testing.T) { action: func(gsData *harness) { gsData.fgs.LeaveRequestsOpen() stor, _ := gsData.outgoing.Selector() - gsData.transport.OpenChannel( + _ = gsData.transport.OpenChannel( gsData.ctx, gsData.other, datatransfer.ChannelID{ID: gsData.transferID, Responder: gsData.other, Initiator: gsData.self}, @@ -643,7 +643,8 @@ func TestManager(t *testing.T) { assertHasOutgoingMessage(t, requestReceived.Extensions, gsData.outgoing) completed := make(chan struct{}) go func() { - gsData.transport.PauseChannel(context.Background(), datatransfer.ChannelID{ID: gsData.transferID, Responder: gsData.other, Initiator: gsData.self}) + err := gsData.transport.PauseChannel(context.Background(), datatransfer.ChannelID{ID: gsData.transferID, Responder: gsData.other, Initiator: gsData.self}) + require.NoError(t, err) close(completed) }() time.Sleep(100 * time.Millisecond) @@ -697,7 +698,7 @@ func TestManager(t *testing.T) { requestUpdatedHookActions: &testutil.FakeRequestUpdatedActions{}, incomingResponseHookActions: &testutil.FakeIncomingResponseHookActions{}, } - transport.SetEventHandler(&data.events) + require.NoError(t, transport.SetEventHandler(&data.events)) if data.action != nil { data.action(gsData) } diff --git a/transport/transport.go b/transport/transport.go index 606b9b83..91a74278 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -17,7 +17,7 @@ import ( datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-data-transfer/message" ipld "github.com/ipld/go-ipld-prime" - peer "github.com/libp2p/go-libp2p-peer" + peer "github.com/libp2p/go-libp2p-core/peer" ) type errorType string