1261 Commits

Author SHA1 Message Date
Toralf Wittner
7d1a0238de
Add shutdown functionality to NodeStream. (#560)
Add shutdown functionality to `NodeStream`.

Add `NodeStream::shutdown` to allow triggering the shutdown process,
and `NodeStream::poll_shutdown` as the internal way to drive any
potential shutdown to completion.
2018-10-15 10:42:11 +02:00
Toralf Wittner
da05a10790
Shut down yamux and fix mplex shutdown. (#559)
mplex gets a new flag `is_shutdown` to keep track of when `shutdown` has
been called. We need to make certain that after the shutdown no more
`Sink::poll_complete` or `Sink::start_send` calls are being made which
may result in a panic.
2018-10-11 15:43:34 +02:00
Toralf Wittner
7016b86b3a
Add StreamMuxer::flush. (#534)
Update the `StreamMuxer` trait.

- `read_substream`, `write_substream` and `flush_substream` now return `Poll` instead of `Result`.
- A new `Shutdown` enum allows for half-closing of substreams and is used in `shutdown_substream`.
- `close_inbound` and `close_outbound` have been merged into `shutdown` which takes a `Shutdown` parameter to allow closing only one direction.
- Add a new `flush_all` method  to allow flushing after a series of actions (e.g. multiple `shutdown_substream`).

W.r.t. flushing the general idea is that normal use drains buffers over time. Shutting down a substream does not imply flushing, so can be followed by `flush_substream` or (if multiple substreams are to be shut down) a single `flush_all`. Shutting down the muxer itself proceeds likewise, i.e. `shutdown` followed by `flush_all`.
2018-10-11 10:35:14 +02:00
David
0c7f313146 Tests for nodes/listeners.rs (#541)
* Add unit tests for core::nodes::NodeStream

* Move DummyMuxer to core/tests

* Address grumbles

* Impl Debug for SubstreamRef<P>

* Add test for poll()

* Don't need to open a substream

* pretty printer test

* More tests for NodeStream poll()

* ListenerStream unit tests: transport() and listeners()

* Tests for nodes/listeners.rs

* Add a few tests to help illustrate the "drowning" behaviour of busy listeners

* Address grumbles

* Remove non-project specific stuff

* Address grumbles

* Prefer freestanding function
2018-10-10 16:27:07 +02:00
Pierre Krieger
dec7cd13b2
Deny relative addresses for UNIX domain sockets (#548) 2018-10-10 13:17:26 +02:00
Toralf Wittner
9bdaabc884
Optimise Multiaddr::append. (#549)
Append to the existing vector instead of allocating a temporary one and
copying bytes over.
2018-10-10 11:07:30 +02:00
Toralf Wittner
fd4ae72f8c
multistream-select: use FramedWrite from tokio-codec. (#539) 2018-10-10 09:16:21 +02:00
Pierre Krieger
68632ce26b
Fix secio compied with --no-default-features (#545) 2018-10-09 11:21:35 +02:00
Toralf Wittner
276bc9c07a
multiaddr: explain the use of &str for Unix. (#543)
multiaddr: explain the use of `&str` for `Unix`.

Closes #408.
2018-10-08 14:51:24 +02:00
Toralf Wittner
f2c3a149d7
Model HandshakeContext with explicit state transitions. (#532)
Instead of having one struct with uninitialised fields
which are mutated, have explicit states and ensure that the types
show that there is no ambiguity which data is available or not.
Consequently, this removes quite a few `unwrap`/`expect` calls.
2018-10-08 14:37:36 +02:00
Toralf Wittner
e05422c05f multiaddr: add support for onion protocol. (#542)
* multiaddr: add support for onion protocol.

* Comment `read_onion`.

* Split onion into address and port parts.
2018-10-08 11:13:00 +02:00
David
d81f4e264f Add unit tests for core::nodes::NodeStream (#535)
* Add unit tests for core::nodes::NodeStream

* Move DummyMuxer to core/tests

* Address grumbles

* Impl Debug for SubstreamRef<P>

* Add test for poll()

* Don't need to open a substream

* pretty printer test

* More tests for NodeStream poll()

* Remove contentious test of Debug
2018-10-05 11:55:32 +02:00
Pierre Krieger
c032afbde5
Implement GET_PROVIDERS/ADD_PROVIDER Kademlia messages (#530)
* Implement GET_PROVIDERS/ADD_PROVIDER Kademlia messages

* Use multihash and peer id in protocol.rs

* Fix Kademlia example
2018-10-01 18:40:35 +02:00
Pierre Krieger
e3efc2dc9a
Make secio almost compile for asmjs/wasm (#519)
* Use the sha2 crate in the handshake

* Return a Digest in algo_support instead of a ring ref

* Switch to ed25519-dalek for keys

* Make ring more or less optional

* Switch to ed25519_dalek for the verification

* Extract the key exchange to its own module

* Remove the ring RNG from the handshake

* Some warning fixes and forgot file

* Move key exchange to own module

* Remove usage of ring::digest

* Remove ring from handshake entirely

* Implement ECDH for WebCrypto

* Remove the libp2p-secio feature

* Fix ring being included

* Address some concerns

* Provde some panics in WebCrypto

* Prove the Hmac panic

* Prove more panics
2018-10-01 15:42:40 +02:00
Pierre Krieger
7208bba92b
Make it possible to accept/deny nodes in CollectionsStream (#512)
* Provide poll() as a regular method when we can't fail

* Add a CollectionReachEvent that allows accepting

* Add small TODO in handled_node

* Implement Debug on collection events

* Implement Debug for CollectionStream

* Implement Debug for structs in handled_node_tasks

* Attempt to fix compilation errors with stable Rust

* Prove the unwrap
2018-10-01 14:49:17 +02:00
Pierre Krieger
4ff7d686a4
Fix polling in handled_node.rs (#531) 2018-10-01 14:24:01 +02:00
Pierre Krieger
a9eefe1015
Remove notifying tasks (#528) 2018-10-01 11:18:00 +02:00
Pierre Krieger
895557cb82
Fix handler not properly shut down, and write test for this (#514)
* Fix handler not properly shut down, and write test

* Remove to_notify from the test
2018-10-01 11:17:34 +02:00
Eyal Kalderon
ad0807b3f3 Use unsigned-varints, add BLAKE2 support in multihash (#525)
* Add support for unsigned varints

* Depend on unsigned-varint 0.2 without default features

* Change hash code type from u8 to u64

* Fix hash codes and enum variants for BLAKE2 to fit the standard (see #524)

* Run cargo fmt on crate

* Expand hash_types test to include all variants

* Add support for BLAKE2b-512 and BLAKE2s-256

* Depend on blake2 crate 0.7 with no default features

* Update encode! macro for support for blake2 crate

* Update all tests to include BLAKE2b-512 and BLAKE2s-256

* Reduce hash code size from u64 to u16

* Fix typo in doc comment

* Bump tiny-keccak to version 1.4

* Remove unnecessary default-features = false in Cargo.toml
2018-10-01 09:58:11 +02:00
Qian LinFeng
4fa680e282 Upgrade smallvec version to fix license issue (#526) 2018-09-30 16:18:19 +02:00
James Ray
bf066773e3 ybsubscribing -> unsubscribing (#513) 2018-09-24 09:32:20 +02:00
Pierre Krieger
ee9ff643a5
Split collection.rs in two (#507)
* Split collection.rs in two

* Fix forgot to interrupt inner task

* Another fix in collection.rs

* More qed
2018-09-21 17:31:52 +02:00
Pierre Krieger
4fe92f81e8
Fix logic error in public key mismatch (#510) 2018-09-21 17:11:27 +02:00
Toralf Wittner
b61d9faece
multiaddr: future-proof error type (#506) 2018-09-21 10:39:36 +02:00
Toralf Wittner
3f3d81cc95
Map AsyncWrite::shutdown to Sink::close. (#505) 2018-09-21 10:10:45 +02:00
Pierre Krieger
a988926c3e
Fix the ping dialer never closed (#504)
* Fix the ping dialer never closed

* Fix not ready
2018-09-21 10:06:04 +02:00
Pierre Krieger
a910797f22
Fix invalid state after peer id mismatch (#503) 2018-09-21 09:32:23 +02:00
Pierre Krieger
4d8da24c64
Fix the Default implementation of Ping (#501) 2018-09-20 19:53:31 +02:00
Toralf Wittner
84b089cacc
Refactor multiaddr crate. (#498)
Refactor multiaddr crate.

- Remove `AddrComponent`. Instead `Protocol` directly contains its
associated data.

- Various smaller changes around conversions to Multiaddr from other
types, e.g. socket addresses.

- Expand tests to include property tests which test encoding/decoding
identity.
2018-09-20 19:51:00 +02:00
Pierre Krieger
1969bde4fe
Rework the Ping protocol (#497)
* Rework the Ping upgrade

* Fix concerns
2018-09-20 16:55:57 +02:00
Pierre Krieger
f2a5eee5e8
Add a NodeHandler trait (#495)
* Add a NodeHandler trait

* Fix compilation

* Some fixes
2018-09-19 16:33:29 +02:00
Toralf Wittner
7fb09fbf20
secio: keep ciphertext if start_send is not ready (#494)
* secio: keep ciphertext if start_send is not ready

Otherwise ciphertext may be thrown away and once sent, the cipher states
have diverged, resulting in nonsense messages on decryption side.

* Also attempt to send pending data `Sink::close`.

* Inline `send_pending`.
2018-09-18 22:51:13 +02:00
Pierre Krieger
8cf17f49e1
Add a basic test to listeners (#489) 2018-09-18 15:56:29 +02:00
Pierre Krieger
783522f54c
Prove the panics (#491) 2018-09-17 17:15:27 +02:00
Pierre Krieger
0c43c76965
Implement close() from Sink (#492) 2018-09-17 15:01:37 +02:00
Pierre Krieger
3e53a9dcc7
Fix additional addresses not tried (#483)
* Fix additional addresses not tried

* More fixes

* Produce a dialing error if unsupported multiaddr
2018-09-17 10:30:10 +02:00
Pierre Krieger
d719ac6037
Revert "Revert "remove rustc-serialize (#359) (#386)" (#466)" (#477)
This reverts commit 0a3d4cdfade1656d72ca99751e94e179bdaec221.
2018-09-17 10:05:37 +02:00
Pierre Krieger
2a7a48b496
Fix old task not interrupted after replacing (#482) 2018-09-14 20:40:28 +02:00
Pierre Krieger
063ab178a9
Add an alternative to the swarm (#472)
* Rewrite the swarm

* Small improvement to Debug of ListenersStream

* Fix Swarm::Replaced never being produced

* Fix logic problem when reaching a node in swarm

* Small comment in swarm

* Add closed_multiaddr to Replaced event

* Add address to NodeClosed and NodeError

* Fix concerns

* Remove StreamMuxer::boxed
2018-09-14 13:18:10 +02:00
Toralf Wittner
0614b0d44e
secio: don't panic in agree_ephemeral. (#480)
Given that echoing back our local key and nonce would result in equal
digest values, we should treat this as an error instead of panicking.
2018-09-14 11:37:40 +02:00
Toralf Wittner
b2756c8fa9
Make Multiaddr::iter borrow data (#478)
* Use `unsigned-varint` crate.

* Implement `Display` for `Protocol`.

Gives `ToString` for free.

* Use `Cow` in `AddrComponent`.

* Add `AddrComponent::acquire`.

* Document `AddrComponent::acquire`.
2018-09-14 10:21:14 +02:00
Arkadiy Paronyan
5980a4538e
Secp256k1 key generation (#474) 2018-09-13 10:26:52 +02:00
Toralf Wittner
6a5681aed7
secio: Add NULL cipher and allow more configuration. (#468)
* Introduce NULL cipher and allow more configuration.

* Back to using the hash-code for handshake.

Using `Endpoint` would be incompatible with the existing protocol.

* Add comments.
2018-09-12 09:10:05 +02:00
Pierre Krieger
5ecdb71c29
Populate TcpConfig with more config (#454) 2018-09-11 12:04:35 +02:00
Pierre Krieger
fd4b7488be
Add some comments about the notification behaviour of muxers (#453) 2018-09-11 11:17:44 +02:00
Toralf Wittner
cfdfca1a06
Similar to #469, consider endpoint while retaining. (#470) 2018-09-10 14:03:38 +02:00
Toralf Wittner
ec6ec92a79
mplex: fix destroy_substream (#469)
Retain all incoming buffer elements with different substream ID or equal
Endpoint. The latter was previously not considered which could result in
the removal of data for another substream with same ID but opposite
Endpoint.
2018-09-10 10:21:19 +02:00
Pierre Krieger
304e9c72c8
Report the entire peers after a result (#467) 2018-09-07 16:46:34 +02:00
Pierre Krieger
0a3d4cdfad
Revert "remove rustc-serialize (#359) (#386)" (#466)
This reverts commit 73996885cb2d645ee91361204c33e7039290aabc.
2018-09-07 14:05:42 +02:00
Pierre Krieger
e45dce2d9a
Switch to twofish by default (#465) 2018-09-06 17:35:25 +02:00