This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
network/newstream: new stream! protocol base implementation #1500
Merged
Merged
Changes from all commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
4b615a5
network/syncer: initial commit
acud 081fd9f
network/syncer: change receiver name
acud 271a3b6
network/syncer: finalize bin index exchange test
acud 089d73c
network/syncer: add logic to determin peer transitions within depth
acud 30475f0
network/syncer: more tests on establishing the correct initial stream…
acud e6e1ce5
network/syncer: create test case for nodes moving inside network depth
acud c0c087f
fixed the node item tests
acud 660635b
network/syncer: general test case
acud f31557c
network/syncer: address some pr comments
acud 800f247
network/syncer: fix pivot test - cursors were not saved
acud 0003cc0
network/syncer: cleanup
acud 5554fac
network/syncer: change cursor test condition
acud 93135bc
network/syncer: fix dynamic test
acud ce9b517
network/syncer: add exclusivity test to bin cursors, cleanup
acud 1906319
network/syncer: test node moves out of depth
acud bee9574
network/syncer: add sync fetchers, remove unused vars
acud dac9397
network/syncer: simplify test
acud debc16b
network/syncer: check historical streams
acud 7f97475
network/syncer: check historical streams
acud 869796b
network/syncer: rename function
acud 5a0044b
network/syncer: check historical streams
acud ba548ac
network/syncer: assert streams removed on peer moved out of depth
acud 3838de5
network/syncer: delete after channel close
acud 966b2fe
network/syncer: add test to cover node moves into depth after leaving it
acud 3889233
network/syncer: change syncBins to accomodate for both conventional p…
acud 021759e
network/syncer: eliminate shadowing
acud 6c272ba
wip try to find why this is not passing
acud b6d513c
network/syncer: TestNodeRemovesAndReestablishCurosrs passes
acud f600449
network/syncer: removed check that fails sporadically
acud 4ee79de
network/syncer: cleanup
acud bd27ba4
network/syncer: add syncing test from stream pkg
acud c52f631
network/syncer: wip full syncing test
acud 375100a
network/syncer: cleanup
acud 56fe4e3
network/syncer: upload content to one node. test now expectedly fails
acud 9a4e321
network/syncer: push data to one node then add the second one in orde…
acud 516343b
network/syncer: add syncer method stubs
acud 85179b6
network/syncer: reshuffle
acud b04e261
network/syncer: reinstate lock
acud 0c394d8
network/syncer: test fails as wanted
acud 61e4e7f
network/syncer: wip add roundtrip handling
acud f327559
network/syncer: just test for full sync at this point
acud fb228c2
network/syncer: wip chunk delivery
acud 6a8faba
network/syncer: wip add intervals persistence from stream pkg, wip ba…
acud 4be53a4
network/syncer: wip add intervals persistence from stream pkg, wip ba…
acud c522e90
network/syncer: wip chunk delivery
acud 60a12e7
network/syncer: store some chunks
acud f73813e
network/syncer: historical syncing works
acud e556bbb
network/syncer: fix a few holes due to introduced concurrency
acud 84a7e94
network/stream/intervals: fix commit
acud ce1bc0c
network/syncer: import stream ID from stream pkg
acud fba0520
network/syncer: wip abstract StreamProvider
acud d387680
network/stream/intervals: add ceiling argument to the Next method
janos e78b364
network/syncer: wip stream provider abstraction
acud 509cb36
network/syncer: wip abstraction
acud 6a11e30
network/syncer: rename sync provider file
acud 97d5592
network/syncer: make new abstraction compile
acud 18780ab
network/syncer: tests run but still not green
acud 5f71255
network/syncer: cursors tests green when disbaling auto sync
acud d3da784
network/syncer: wip make sync test pass
acud ee43872
network/syncer: TestNodesExchangeCorrectBinIndexes green
acud 179110f
network/syncer: wip make tests pass
acud 35ed804
network/syncer: TestNodesExchangeCorrectBinIndexesInPivot green
acud 8c689b2
network/syncer: introduce stream init behavior
acud aaf81bd
network/syncer: synchronise cursor delete
acud 912a7f0
network/syncer: wip make tests pass
acud 9d72a98
network/syncer: wip make tests pass
acud a50504b
network/syncer: test full sync mostly passes
acud 4d6895a
network/stream/intervals: indicate if the Next range is empty
janos 58343dc
network/syncer: cleanup
acud e1e9aeb
network/syncer: cleanup
acud 5a282c7
network/syncer: fix TestNodeRemovesAndReestablishCursors peers map ac…
janos b93fa24
network/syncer: fix TestNodesExchangeCorrectBinIndexes data races
janos 9c6b173
network/syncer: fix data races
janos 7612f1b
network/syncer: remove panics, better tracing, set chunk as Set on Get
acud d11e669
network/syncer: fix panic on close of closed channel, cleanup
acud eaac56a
network: rename syncer->newstream
acud 5b46ad3
network/newstream: rename package, improve docs
acud 1c3fd87
network/newstream: rename peer_test.go
acud 5a408cd
network/newstream: clean out spec for initial merge - just wire and b…
acud c8603c8
docs: propagate changes to wire protocol to the docs
acud 1e7946e
network/bitvector: remove panic
acud b128333
network, storage: clean diff for initial pr
acud df8d517
vendor: clean diff
acud c99b3bc
pss: clean diff
acud 6986049
network/newstream: fix linter
acud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2019 The Swarm Authors | ||
// This file is part of the Swarm library. | ||
// | ||
// The Swarm library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The Swarm library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the Swarm library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package newstream | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/p2p/enode" | ||
"github.com/ethersphere/swarm/network" | ||
"github.com/ethersphere/swarm/storage/localstore" | ||
"github.com/ethersphere/swarm/storage/mock" | ||
) | ||
|
||
var ( | ||
loglevel = flag.Int("loglevel", 5, "verbosity of logs") | ||
) | ||
|
||
func init() { | ||
flag.Parse() | ||
|
||
log.PrintOrigins(true) | ||
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(os.Stderr, log.TerminalFormat(false)))) | ||
} | ||
|
||
func newTestLocalStore(id enode.ID, addr *network.BzzAddr, globalStore mock.GlobalStorer) (localStore *localstore.DB, cleanup func(), err error) { | ||
dir, err := ioutil.TempDir("", "swarm-stream-") | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
cleanup = func() { | ||
os.RemoveAll(dir) | ||
} | ||
|
||
var mockStore *mock.NodeStore | ||
if globalStore != nil { | ||
mockStore = globalStore.NewNodeStore(common.BytesToAddress(id.Bytes())) | ||
} | ||
|
||
localStore, err = localstore.New(dir, addr.Over(), &localstore.Options{ | ||
MockStore: mockStore, | ||
}) | ||
if err != nil { | ||
cleanup() | ||
return nil, nil, err | ||
} | ||
return localStore, cleanup, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2019 The Swarm Authors | ||
// This file is part of the Swarm library. | ||
// | ||
// The Swarm library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The Swarm library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the Swarm library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package newstream | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"sync" | ||
"time" | ||
|
||
"github.com/ethersphere/swarm/chunk" | ||
"github.com/ethersphere/swarm/network" | ||
"github.com/ethersphere/swarm/network/bitvector" | ||
"github.com/ethersphere/swarm/state" | ||
) | ||
|
||
var ErrEmptyBatch = errors.New("empty batch") | ||
|
||
const ( | ||
HashSize = 32 | ||
BatchSize = 16 | ||
) | ||
|
||
// Peer is the Peer extension for the streaming protocol | ||
type Peer struct { | ||
*network.BzzPeer | ||
mtx sync.Mutex | ||
providers map[string]StreamProvider | ||
intervalsStore state.Store | ||
|
||
streamCursorsMu sync.Mutex | ||
streamCursors map[string]uint64 // key: Stream ID string representation, value: session cursor. Keeps cursors for all streams. when unset - we are not interested in that bin | ||
dirtyStreams map[string]bool // key: stream ID, value: whether cursors for a stream should be updated | ||
activeBoundedGets map[string]chan struct{} | ||
openWants map[uint]*want // maintain open wants on the client side | ||
openOffers map[uint]offer // maintain open offers on the server side | ||
quit chan struct{} // closed when peer is going offline | ||
} | ||
|
||
// NewPeer is the constructor for Peer | ||
func NewPeer(peer *network.BzzPeer, i state.Store, providers map[string]StreamProvider) *Peer { | ||
p := &Peer{ | ||
BzzPeer: peer, | ||
providers: providers, | ||
intervalsStore: i, | ||
streamCursors: make(map[string]uint64), | ||
dirtyStreams: make(map[string]bool), | ||
openWants: make(map[uint]*want), | ||
openOffers: make(map[uint]offer), | ||
quit: make(chan struct{}), | ||
} | ||
return p | ||
} | ||
func (p *Peer) Left() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used at one place. Why not directly inline There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
close(p.quit) | ||
} | ||
|
||
// HandleMsg is the message handler that delegates incoming messages | ||
func (p *Peer) HandleMsg(ctx context.Context, msg interface{}) error { | ||
switch msg := msg.(type) { | ||
default: | ||
return fmt.Errorf("unknown message type: %T", msg) | ||
} | ||
return nil | ||
} | ||
|
||
type offer struct { | ||
ruid uint | ||
stream ID | ||
hashes []byte | ||
requested time.Time | ||
} | ||
|
||
type want struct { | ||
ruid uint | ||
from uint64 | ||
to uint64 | ||
stream ID | ||
hashes map[string]bool | ||
bv *bitvector.BitVector | ||
requested time.Time | ||
remaining uint64 | ||
chunks chan chunk.Chunk | ||
done chan error | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a separate
common_test
file?