From 654a51a88a294299c092fb596fc2641fafb76838 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Fri, 31 May 2019 12:33:36 +0200 Subject: [PATCH] swarm/network/stream: remove dead code --- swarm/network/stream/intervals_test.go | 4 ---- swarm/network/stream/messages.go | 2 +- swarm/network/stream/stream.go | 19 ------------------- swarm/network/stream/streamer_test.go | 26 +------------------------- swarm/network/stream/syncer.go | 9 --------- 5 files changed, 2 insertions(+), 58 deletions(-) diff --git a/swarm/network/stream/intervals_test.go b/swarm/network/stream/intervals_test.go index 660954857e..02f012b2ae 100644 --- a/swarm/network/stream/intervals_test.go +++ b/swarm/network/stream/intervals_test.go @@ -314,10 +314,6 @@ func (c *testExternalClient) NeedData(ctx context.Context, hash []byte) func(con return wait } -func (c *testExternalClient) BatchDone(Stream, uint64, []byte, []byte) func() (*TakeoverProof, error) { - return nil -} - func (c *testExternalClient) Close() {} type testExternalServer struct { diff --git a/swarm/network/stream/messages.go b/swarm/network/stream/messages.go index 339101b883..830bcae247 100644 --- a/swarm/network/stream/messages.go +++ b/swarm/network/stream/messages.go @@ -265,7 +265,7 @@ func (p *Peer) handleOfferedHashesMsg(ctx context.Context, req *OfferedHashesMsg } } select { - case c.next <- c.batchDone(p, req, hashes): + case c.next <- c.AddInterval(req.From, req.To): case <-c.quit: log.Debug("client.handleOfferedHashesMsg() quit") case <-ctx.Done(): diff --git a/swarm/network/stream/stream.go b/swarm/network/stream/stream.go index 9cdf5c04b4..ee461b7b27 100644 --- a/swarm/network/stream/stream.go +++ b/swarm/network/stream/stream.go @@ -544,7 +544,6 @@ func (c *client) NextInterval() (start, end uint64, err error) { // Client interface for incoming peer Streamer type Client interface { NeedData(context.Context, []byte) func(context.Context) error - BatchDone(Stream, uint64, []byte, []byte) func() (*TakeoverProof, error) Close() } @@ -574,24 +573,6 @@ func (c *client) nextBatch(from uint64) (nextFrom uint64, nextTo uint64) { return } -func (c *client) batchDone(p *Peer, req *OfferedHashesMsg, hashes []byte) error { - if tf := c.BatchDone(req.Stream, req.From, hashes, req.Root); tf != nil { - tp, err := tf() - if err != nil { - return err - } - - if err := p.Send(context.TODO(), tp); err != nil { - return err - } - if c.to > 0 && tp.Takeover.End >= c.to { - return p.streamer.Unsubscribe(p.Peer.ID(), req.Stream) - } - return nil - } - return c.AddInterval(req.From, req.To) -} - func (c *client) close() { select { case <-c.quit: diff --git a/swarm/network/stream/streamer_test.go b/swarm/network/stream/streamer_test.go index 767112b2b4..9602bc6da2 100644 --- a/swarm/network/stream/streamer_test.go +++ b/swarm/network/stream/streamer_test.go @@ -81,7 +81,6 @@ type testClient struct { t string wait0 chan bool wait2 chan bool - batchDone chan bool receivedHashes map[string][]byte } @@ -90,7 +89,6 @@ func newTestClient(t string) *testClient { t: t, wait0: make(chan bool), wait2: make(chan bool), - batchDone: make(chan bool), receivedHashes: make(map[string][]byte), } } @@ -111,11 +109,6 @@ func (self *testClient) NeedData(ctx context.Context, hash []byte) func(context. return nil } -func (self *testClient) BatchDone(Stream, uint64, []byte, []byte) func() (*TakeoverProof, error) { - close(self.batchDone) - return nil -} - func (self *testClient) Close() {} type testServer struct { @@ -620,26 +613,9 @@ func TestStreamerDownstreamOfferedHashesMsgExchange(t *testing.T) { close(tc.wait0) - timeout := time.NewTimer(100 * time.Millisecond) - defer timeout.Stop() - - select { - case <-tc.batchDone: - t.Fatal("batch done early") - case <-timeout.C: - } + time.Sleep(100 * time.Millisecond) close(tc.wait2) - - timeout2 := time.NewTimer(10000 * time.Millisecond) - defer timeout2.Stop() - - select { - case <-tc.batchDone: - case <-timeout2.C: - t.Fatal("timeout waiting batchdone call") - } - } func TestStreamerRequestSubscriptionQuitMsgExchange(t *testing.T) { diff --git a/swarm/network/stream/syncer.go b/swarm/network/stream/syncer.go index 7957a8bf70..e8359ef70e 100644 --- a/swarm/network/stream/syncer.go +++ b/swarm/network/stream/syncer.go @@ -203,15 +203,6 @@ func (s *SwarmSyncerClient) NeedData(ctx context.Context, key []byte) (wait func return s.netStore.FetchFunc(ctx, key) } -// BatchDone -func (s *SwarmSyncerClient) BatchDone(stream Stream, from uint64, hashes []byte, root []byte) func() (*TakeoverProof, error) { - // TODO: reenable this with putter/getter refactored code - // if s.chunker != nil { - // return func() (*TakeoverProof, error) { return s.TakeoverProof(stream, from, hashes, root) } - // } - return nil -} - func (s *SwarmSyncerClient) Close() {} // base for parsing and formating sync bin key