Commit Graph

5309 Commits

Author SHA1 Message Date
Henry de Valence 501db9fcc8 Add AddressBook::is_potentially_connected()
This allows checking whether a SocketAddr could potentially be
connected, based on the contents of the address book.
2019-10-21 14:40:03 -04:00
Henry de Valence fe9cef261d Allow draining AddressBook entries oldest-first. 2019-10-21 14:40:03 -04:00
Henry de Valence 39d38a8647 Rewrite AddressBook to use a BTreeSet.
The previous implementation failed when timestamps were duplicated between
peers, because there was not a 1-1 relationship between timestamps and peers.
2019-10-21 14:40:03 -04:00
Henry de Valence 5e9ac87f57 Collect into an AddressBook in connect. 2019-10-21 14:40:03 -04:00
Henry de Valence ecd57f43ed Implement Extend and Drain for AddressBook. 2019-10-21 14:40:03 -04:00
Henry de Valence 0bfd57def2 Add iteration functions to `AddressBook`.
The disconnected_peers() function allows us to prevent duplicate
connections without maintaining shared state between the peerset and the
dial-additional-peers task.
2019-10-21 14:40:03 -04:00
Henry de Valence b03a83fa86 Simplify TimestampCollector.
Previously, the TimestampCollector was intended to own the address book
data, so it was intended to be cloneable and hold shared state among all
of its handles.  This is now modeled more directly by an
`Arc<Mutex<AddressBook>>`, so the only functionality left in the
`TimestampCollector` is setting up the inital worker, which is better
called `spawn` than `new`.

This also fixes a problem introduced in the previous commit where the
`TimestampCollector` was dropped, causing the worker task to shut down
early.
2019-10-21 14:40:03 -04:00
Henry de Valence 53be838d51 Extract `TimestampData` to `AddressBook`.
This allows us to hide the `TimestampCollector` and to expose only the
address book data required by the inbound request service.  It also lets
us have a common data structure (the `AddressBook`) for collecting peer
information that can be used to manage information that other peers
report to us.
2019-10-21 14:40:03 -04:00
Henry de Valence 15a698b23c Use MetaAddr in the timestamp collector.
We will need service bits information to report on peer addresses, so we
need to collect it in the timestamp collector.
2019-10-21 14:40:03 -04:00
Henry de Valence 9ec1e01c8f Add a config command. 2019-10-18 21:00:01 -04:00
Henry de Valence ad43a61fb4 Ensure that all types appearing in public types are exported. 2019-10-18 16:11:01 -07:00
Henry de Valence 1f0a7e5e73 Remove Codec::builder doctest.
Doctests can only test public API, so now that the Codec is private, we can't
have a doctest.  Since this test was only a code example (no behaviour test),
there's no value in replacing it with a unit test.
2019-10-18 16:11:01 -07:00
Henry de Valence c7e0d63bed Export the BoxedZebraService type alias.
This gives API consumers a convenient name, and makes the Rustdoc output
significantly cleaner (because `init` can return a `BoxedZebraService`, not a
`Box<dyn ...ManyTypeConstraints.......>`.
2019-10-18 16:11:01 -07:00
Henry de Valence 1c6c4140ed Add a nice comment to zebra-network. 2019-10-18 16:11:01 -07:00
Henry de Valence f0bb2bff77 Do not export zebra-network internals.
Until we finish outbound peer dialing, this still contains
one module that re-exports the `PeerConnector`.
2019-10-18 16:11:01 -07:00
Henry de Valence 7c35e7e6c0 Delete the listen stub command. 2019-10-18 16:11:01 -07:00
Henry de Valence d4dc4f0d04 Add tracing output on unhandled peer requests 2019-10-18 16:11:01 -07:00
Henry de Valence 54948b07e2 Add a peer listener task. 2019-10-18 16:11:01 -07:00
Henry de Valence 5847b490da Move PeerSet setup logic into a peer_set::init() 2019-10-18 16:11:01 -07:00
Henry de Valence 63cf340ab4 Add fields to zebra-network Config. 2019-10-18 16:11:01 -07:00
Henry de Valence 0a56830eab Ascii-fy the command string in message header trace 2019-10-17 13:22:33 -04:00
Henry de Valence 17b93523bd Restore PeerSet code in connect stub.
This was commented out because making the PeerConnector take a TcpStream
meant that the PeerConnector futures couldn't be constructed in the same
way as before, but now that the PeerConnector is Buffer'able, we can
just clone a buffered copy.
2019-10-17 09:34:18 -07:00
Henry de Valence ff27334e81 Make PeerConnector tower::Buffer'able 2019-10-17 09:34:18 -07:00
Henry de Valence db7ac53f3b Add a Mutex<HashSet<Nonce>> to detect self-conns. 2019-10-17 09:34:18 -07:00
Henry de Valence ed335e68f4 Remove outdated comment
Now that the `PeerConnector` handles both incoming and outgoing
handshakes, determining the next peer address is definitely out of scope
-- it takes a pre-existing tcp connection.
2019-10-17 09:34:18 -07:00
Henry de Valence 31651cf87c Fix copy-paste bug in Codec
Co-authored-by: George Tankersley <george@zfnd.org>
2019-10-17 09:34:18 -07:00
Henry de Valence 8a1aa71736 Modify PeerConnector to also handle inbound conns.
Because the Bitcoin handshake is symmetric, we can reuse the same logic
for both incoming and outgoing connections.
2019-10-17 09:34:18 -07:00
Henry de Valence 5b801400c1 Update zebra-chain/Cargo.toml 2019-10-17 09:33:10 -07:00
Deirdre Connolly 980ce4593b Fix merge artifacts in Cargo.toml 2019-10-17 09:33:10 -07:00
Deirdre Connolly 0db69addec Add custom Debug impl for DecodeState
Relates to #63
2019-10-17 09:33:10 -07:00
Deirdre Connolly 96ad551681 Remove unnecessary write_all impl 2019-10-17 09:33:10 -07:00
Deirdre Connolly 051dc2f039 Implement custom Debug for Magic types
Related to #63
2019-10-17 09:33:10 -07:00
Deirdre Connolly 65d988471a Implement custom Debug for Sha256dChecksum
Relates to #63
2019-10-17 09:33:10 -07:00
Deirdre Connolly 539a16979b Implement custom Debug impl for BlockHeaderHash
Includes a testcase and write_all implementation for Sha256dWriter.

Related to #63
2019-10-17 09:33:10 -07:00
Henry de Valence f6e62b0f5e Remove failure from zebra-chain, zebra-network.
Failure uses a distinct Fail trait rather than the standard library's
Error trait, which causes a lot of interoperability problems with tower
and other Error-using crates.  Since failure was created, the standard
library's Error trait was improved, and its conveniences are now
available without the custom Fail trait using `thiserror` (for easy
error derives) and `anyhow` (for a better boxed Error).
2019-10-16 13:16:52 -04:00
Deirdre Connolly 199038e6b8 Rename bound vars in match arms for PeerServer state machine
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-10-15 14:49:11 -04:00
Henry de Valence fc872ea03f Remove async-await feature of futures. 2019-10-15 14:49:11 -04:00
Henry de Valence 373a8fbcfd Refactor PeerServer event loop to avoid select! 2019-10-15 14:49:11 -04:00
Henry de Valence 16f51e4d48 Add a timeout to the `PeerServer` event loop.
I think this code could be cleaned up significantly (e.g., removing the
other use of select!) but that's potentially a larger change than this
PR.
2019-10-15 14:49:11 -04:00
Henry de Valence b45efbdaf2
Add peer count data to TimestampData::update trace (#66)
* Add peer count data to TimestampData::update trace

* Update docstring typo
2019-10-11 12:41:37 -07:00
Henry de Valence ae1a164ff8
Beginning of peerset implementation. (#62)
* Don't expose submodules of zebra_network::peer.

* PeerSet, PeerDiscover stubs.

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* Initial work on PeerSet.

This is adapted from the MIT-licensed tower-balance implementation.

* Use PeerSet in the connect stub.
2019-10-10 18:15:24 -07:00
Henry de Valence 4f88bddd2b Remove zebra-reactor.
This functionality will just go in zebrad and use abscissa, allowing
configs, component registries, etc.

Closes #59
2019-10-10 20:52:39 -04:00
Deirdre Connolly dc18e8f24c Remove .expect()s for block and transaction, they might fail for writer reasons 2019-10-09 22:25:37 -04:00
Deirdre Connolly e1f2eaa446 Add details about max_count to read_list docstring 2019-10-09 22:25:37 -04:00
Deirdre Connolly 4ec7590b42 Add placeholders for remaining messages in write_body 2019-10-09 22:25:37 -04:00
Deirdre Connolly d8986098c6 Add write_body implementations for GetData, NotFound, and a placeholder for Reject 2019-10-09 22:25:37 -04:00
Deirdre Connolly 483d6584f9 Add Block msg reader and writers, and Tx msg writer 2019-10-09 22:25:37 -04:00
Deirdre Connolly 8dc9181610 Fill out write_body for GetBlocks, GetHeaders, Headers messages 2019-10-09 22:25:37 -04:00
Deirdre Connolly a0302a5507 Implement read_getaddr 2019-10-09 22:25:37 -04:00
Deirdre Connolly cfbe8dfdbf Add comments about the 500 blocks /2000 headers max numbers are speculative based on Bitcoin docs 2019-10-09 22:25:37 -04:00