Skip to content

Commit aeb7336

Browse files
acudzelig
authored andcommitted
swarm/network: disallow historical retrieval requests (#17936)
1 parent 97fb083 commit aeb7336

5 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎swarm/network/stream/delivery_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
416416
return fmt.Errorf("No registry")
417417
}
418418
registry := item.(*Registry)
419-
err = registry.Subscribe(sid, NewStream(swarmChunkServerStreamName, "", true), NewRange(0, 0), Top)
419+
err = registry.Subscribe(sid, NewStream(swarmChunkServerStreamName, "", true), nil, Top)
420420
if err != nil {
421421
return err
422422
}

‎swarm/network/stream/messages.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ type SubscribeErrorMsg struct {
158158
}
159159

160160
func (p *Peer) handleSubscribeErrorMsg(req *SubscribeErrorMsg) (err error) {
161+
//TODO the error should be channeled to whoever calls the subscribe
161162
return fmt.Errorf("subscribe to peer %s: %v", p.ID(), req.Error)
162163
}
163164

‎swarm/network/stream/snapshot_retrieval_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func runFileRetrievalTest(nodeCount int) error {
218218
reader, _ := fileStore.Retrieve(context.TODO(), hash)
219219
//check that we can read the file size and that it corresponds to the generated file size
220220
if s, err := reader.Size(ctx, nil); err != nil || s != int64(len(randomFiles[i])) {
221-
log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id)
221+
log.Debug("Retrieve error", "err", err, "hash", hash, "nodeId", id)
222222
time.Sleep(500 * time.Millisecond)
223223
continue REPEAT
224224
}
@@ -309,7 +309,7 @@ func runRetrievalTest(chunkCount int, nodeCount int) error {
309309
reader, _ := fileStore.Retrieve(context.TODO(), hash)
310310
//check that we can read the chunk size and that it corresponds to the generated chunk size
311311
if s, err := reader.Size(ctx, nil); err != nil || s != int64(chunkSize) {
312-
log.Warn("Retrieve error", "err", err, "hash", hash, "nodeId", id, "size", s)
312+
log.Debug("Retrieve error", "err", err, "hash", hash, "nodeId", id, "size", s)
313313
time.Sleep(500 * time.Millisecond)
314314
continue REPEAT
315315
}

‎swarm/network/stream/snapshot_sync_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
310310
_, err = lstore.Get(ctx, chunk)
311311
}
312312
if err != nil {
313-
log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
313+
log.Debug(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
314314
// Do not get crazy with logging the warn message
315315
time.Sleep(500 * time.Millisecond)
316316
continue REPEAT
@@ -514,7 +514,7 @@ func testSyncingViaDirectSubscribe(t *testing.T, chunkCount int, nodeCount int)
514514
_, err = lstore.Get(ctx, chunk)
515515
}
516516
if err != nil {
517-
log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
517+
log.Debug(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
518518
// Do not get crazy with logging the warn message
519519
time.Sleep(500 * time.Millisecond)
520520
continue REPEAT

‎swarm/network/stream/stream.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package stream
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"math"
2324
"sync"
@@ -96,7 +97,10 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy
9697
delivery.getPeer = streamer.getPeer
9798

9899
if options.DoServeRetrieve {
99-
streamer.RegisterServerFunc(swarmChunkServerStreamName, func(_ *Peer, _ string, _ bool) (Server, error) {
100+
streamer.RegisterServerFunc(swarmChunkServerStreamName, func(_ *Peer, _ string, live bool) (Server, error) {
101+
if !live {
102+
return nil, errors.New("only live retrieval requests supported")
103+
}
100104
return NewSwarmChunkServer(delivery.chunkStore), nil
101105
})
102106
}
@@ -279,7 +283,6 @@ func (r *Registry) Subscribe(peerId enode.ID, s Stream, h *Range, priority uint8
279283
if err != nil {
280284
return err
281285
}
282-
283286
if s.Live && h != nil {
284287
if err := peer.setClientParams(
285288
getHistoryStream(s),

0 commit comments

Comments
 (0)