447 Commits

Author SHA1 Message Date
Toralf Wittner
057b379541 Replace secp256k1 crate with libsecp256k1. (#1029)
* Replace `secp256k1` crate with `libsecp256k1`.

Unfortunately we could not implement `AsRef<[u8]>` for `SecretKey`
as the crate does not provide a means to do so.

* Fix `DecodingError` invocation.

* Remove the cc for wasm

* Revert "Remove the cc for wasm"

This reverts commit 3a19db35e62931c6e9ffbff6c21f9b0d7ae5403a.

* Fix CircleCI build
2019-05-14 19:33:30 +02:00
Pierre Krieger
c2398adf67
Add implementations of prepare_uninitialized_buffer and read_buf where relevant (#1107)
* Fix #1080

* Fix browser WebSockets
2019-05-10 11:26:18 +02:00
Pierre Krieger
089e349671
Pass the ConnectedPoint to into_handler() (#1085) 2019-05-10 11:05:22 +02:00
Toralf Wittner
fd0e48bf37 Add IntoProtocolsHandler::inbound_protocol. (#1099) 2019-05-08 20:23:28 +02:00
Roman Borschel
8537eb38b9
Integrate identity keys with libp2p-noise for authentication. (#1027)
* Integrate use of identity keys into libp2p-noise.

In order to make libp2p-noise usable with a `Swarm`, which requires a
`Transport::Output` that is a pair of a peer ID and an implementation
of `StreamMuxer`, it is necessary to bridge the gap between static
DH public keys and public identity keys from which peer IDs are derived.

Because the DH static keys and the identity keys need not be
related, it is thus generally necessary that the public identity keys are
exchanged as part of the Noise handshake, which the Noise protocol
accomodates for through the use of handshake message payloads.

The implementation of the existing (IK, IX, XX) handshake patterns is thus
changed to send the public identity keys in the handshake payloads.
Additionally, to facilitate the use of any identity keypair with Noise
handshakes, the static DH public keys are signed using the identity
keypairs and the signatures sent alongside the public identity key
in handshake payloads, unless the static DH public key is "linked"
to the public identity key by other means, e.g. when an Ed25519 identity
keypair is (re)used as an X25519 keypair.

* libp2p-noise doesn't build for wasm.

Thus the development transport needs to be still constructed with secio
for transport security when building for wasm.

* Documentation tweaks.

* For consistency, avoid wildcard enum imports.

* For consistency, avoid wildcard enum imports.

* Slightly simplify io:🤝:State::finish.

* Simplify creation of 2-byte arrays.

* Remove unnecessary cast and obey 100 char line limit.

* Update protocols/noise/src/protocol.rs

Co-Authored-By: romanb <romanb@users.noreply.github.com>

* Address more review comments.

* Cosmetics

* Cosmetics

* Give authentic DH keypairs a distinct type.

This has a couple of advantages:

  * Signing the DH public key only needs to happen once, before
    creating a `NoiseConfig` for an authenticated handshake.

  * The identity keypair only needs to be borrowed and can be
    dropped if it is not used further outside of the Noise
    protocol, since it is no longer needed during Noise handshakes.

  * It is explicit in the construction of a `NoiseConfig` for
    a handshake pattern, whether it operates with a plain `Keypair`
    or a keypair that is authentic w.r.t. a public identity key
    and future handshake patterns may be built with either.

  * The function signatures for constructing `NoiseConfig`s for
    handshake patterns are simplified and a few unnecessary trait
    bounds removed.

* Post-merge corrections.

* Add note on experimental status of libp2p-noise.
2019-05-07 10:22:42 +02:00
Toralf Wittner
77ce5a52dd
Add ranked address collection. (#1096)
Keep external addresses in a ranked collection and ensure iteration is
performed in order from highest to lowest rank.
2019-05-02 19:46:27 +02:00
Fedor Sakharov
68df8c07cf muxing: adds an error type to streammuxer (#1083)
* muxing: adds an error type to streammuxer

* Update examples/chat.rs

Co-Authored-By: montekki <fedor.sakharov@gmail.com>

* make the trait error type bound to io error
2019-04-28 13:42:18 +02:00
Pierre Krieger
ce4ca3cc75
Switch to wasm-timer (#1071) 2019-04-25 15:08:06 +02:00
Pierre Krieger
a375d558b1
Add a OneSubstreamMuxer (#1079)
* Add a OneSubstreamMuxer

* Renames and tweaks

* Add the file back
2019-04-23 15:08:59 +02:00
Pierre Krieger
b4345ee8ba
Bump to 0.7.0 (#1081)
* Bump to 0.7.0

* Update CHANGELOG.md

Co-Authored-By: tomaka <pierre.krieger1708@gmail.com>

* Update for #1078

* New version of multihash and multiaddr as well
2019-04-23 13:03:29 +02:00
Roman Borschel
8cde987e6d Rename KeepAlive constructors. (#1078)
* KeepAlive::Now => KeepAlive::No
  * KeepAlive::Forever => KeepAlive::Yes

As suggested in #1072.
2019-04-23 11:58:49 +02:00
Pierre Krieger
5c34f8a0ed
&mut self -> &mut Self (#1073) 2019-04-23 10:54:25 +02:00
Roman Borschel
45f308c815
Small addendum to #1072. (#1077)
* Small addendum to #1072.

  * Missed two review comments related to documentation.
  * Avoid creating new `Delay`s when possible, i.e. when the deadline
    did not change, since they're not exactly cheap and returning
    `KeepAlive::Until(t)` with the same instant `t` over a prolonged
    period of time is common.

* Even better.
2019-04-21 15:48:50 +02:00
Roman Borschel
d5c6370b15
Remove libp2p-ping keep-alive functionality. (#1067)
* Fix connection & handler shutdown when using `KeepAlive::Now`.

Delay::new(Instant::now()) is never immediately ready, resulting in
`KeepAlive::Now` to have no effect, since the delay is re-created on
every execution of `poll()` in the `NodeHandlerWrapper`. It can also
send the node handler into a busy-loop, since every newly
created Delay will trigger a task wakeup, which creates a new Delay
with Instant::now(), and so forth.

The use of `Delay::new(Instant::now())` for "immediate" connection shutdown
is therefore removed here entirely. An important assumption is thereby
that as long as the node handler non-empty `negotiating_in` and `negotiating_out`,
the handler is not dependent on such a Delay for task wakeup.

* Correction to the libp2p-ping connection timeout.

The current connection timeout is always short of one `interval`,
because the "countdown" begins with the last received or sent pong
(depending on the policy). In effect, the current default config has
a connection timeout of 5 seconds (20 - 15) from the point when a ping is sent.

Instead, the "countdown" of the connection timeout should always begin
with the next scheduled ping. That also makes all configurations valid,
avoiding pitfalls.

The important properties of the ping handler are now checked to hold for all
configurations, in particular:

  * The next ping must be scheduled no earlier than the ping interval
    and no later than the connection timeout.

  * The "countdown" for the connection timeout starts on the next ping,
    i.e. the full connection timeout remains at the instant when the
    next ping is sent.

* Do not keep connections alive.

The ping protocol is not supposed to keep otherwise idle connections
alive, only to add an additional condition for terminating them in
the form of a configurable number of consecutive failed ping requests.

In this context, the `PingPolicy` does not seem useful any longer.
2019-04-20 16:16:31 +02:00
Roman Borschel
8d388d25d4
Fix connection & handler shutdown when using KeepAlive::Now. (#1072)
* Fix connection & handler shutdown when using `KeepAlive::Now`.

Delay::new(Instant::now()) is never immediately ready, resulting in
`KeepAlive::Now` to have no effect, since the delay is re-created on
every execution of `poll()` in the `NodeHandlerWrapper`. It can also
send the node handler into a busy-loop, since every newly
created Delay will trigger a task wakeup, which creates a new Delay
with Instant::now(), and so forth.

The use of `Delay::new(Instant::now())` for "immediate" connection shutdown
is therefore removed here entirely. An important assumption is thereby
that as long as the node handler non-empty `negotiating_in` and `negotiating_out`,
the handler is not dependent on such a Delay for task wakeup.

* Trigger CI.
2019-04-20 16:00:21 +02:00
Fedor Sakharov
7dc95e78f7 swarm: ban connections based on peerid (#1065)
* swarm: ban connections based on peerid

* Update core/src/swarm/swarm.rs

Co-Authored-By: montekki <fedor.sakharov@gmail.com>

* Update core/src/swarm/swarm.rs

Co-Authored-By: montekki <fedor.sakharov@gmail.com>

* remove the testing code

* close connections on ban ban_peer_id

* adds code to unban a peer

* simplify connection closing code

* remove blank line

* ignore DialPeer actions and inject_dial_failure

* Update core/src/swarm/swarm.rs

Co-Authored-By: montekki <fedor.sakharov@gmail.com>

* Update core/src/swarm/swarm.rs

Co-Authored-By: montekki <fedor.sakharov@gmail.com>

* bring back the .expect()
2019-04-18 18:17:14 +02:00
Toralf Wittner
ca58f8029c
Remove Transport::nat_traversal and refactor multiaddr. (#1052)
The functionality is available through `Multiaddr::replace`.
What we currently call "nat_traversal" is merley a replacement of an IP
address prefix in a `Multiaddr`, hence it can be done directly on
`Multiaddr` values instead of having to go through a `Transport`.

In addition this PR consolidates changes made to `Multiaddr` in
previous commits which resulted in lots of deprecations. It adds some
more (see below for the complete list of API changes) and removes all
deprecated functionality, requiring a minor version bump.

Here are the changes to `multiaddr` compared to the currently published
version:

1.  Removed `into_bytes` (use `to_vec` instead).
2.  Renamed `to_bytes` to `to_vec`.
3.  Removed `from_bytes` (use the `TryFrom` impl instead).
4.  Added `with_capacity`.
5.  Added `len`.
6.  Removed `as_slice` (use `AsRef` impl instead).
7.  Removed `encapsulate` (use `push` or `with` instead).
8.  Removed `decapsulate` (use `pop` instead).
9.  Renamed `append` to `push`.
10. Added `with`.
11. Added `replace`.
12. Removed `ToMultiaddr` trait (use `TryFrom` instead).
2019-04-17 20:12:31 +02:00
Pierre Krieger
a4173705db
Add some TryFrom implementations (#1060) 2019-04-17 14:16:50 +02:00
Pierre Krieger
a953b613cf
Add NetworkBehaviour::inject_new_external_addr (#1063) 2019-04-16 17:00:20 +02:00
Roman Borschel
bee5c58b27
libp2p-ping improvements. (#1049)
* libp2p-ping improvements.

  * re #950: Removes use of the `OneShotHandler`, but still sending each
    ping over a new substream, as seems to be intentional since #828.

  * re #842: Adds an integration test that exercises the ping behaviour through
    a Swarm, requiring the RTT to be below a threshold. This requires disabling
    Nagle's algorithm as it can interact badly with delayed ACKs (and has been
    observed to do so in the context of the new ping example and integration test).

  * re #864: Control of the inbound and outbound (sub)stream protocol upgrade
    timeouts has been moved from the `NodeHandlerWrapperBuilder` to the
    `ProtocolsHandler`. That may also alleviate the need for a custom timeout
    on an `OutboundSubstreamRequest` as a `ProtocolsHandler` is now free to
    adjust these timeouts over time.

Other changes:

  * A new ping example.
  * Documentation improvements.

* More documentation improvements.

* Add PingPolicy and ensure no event is dropped.

* Remove inbound_timeout/outbound_timeout.

As per review comment, the inbound timeout is now configured
as part of the `listen_protocol` and the outbound timeout as
part of the `OutboundSubstreamRequest`.

* Simplify and generalise.

Generalise `ListenProtocol` to `SubstreamProtocol`, reusing it in
the context of `ProtocolsHandlerEvent::OutboundSubstreamRequest`.

* Doc comments for SubstreamProtocol.

* Adapt to changes in master.

* Relax upper bound for ping integration test rtt.

For "slow" CI build machines?
2019-04-16 15:57:29 +02:00
Pierre Krieger
9b6336672b
Add NetworkBehaviour methods for listened addresses (#1061) 2019-04-16 15:36:08 +02:00
Toralf Wittner
05a74aed43
Expand wildcard IP addresses in TCP transport. (#1044)
Wildcard IP addresses (e.g. 0.0.0.0) are used to listen on all host
interfaces. To report those addresses such that clients know about them
and can actually make use of them we use the `get_if_addrs` crate and
maintain a collection of addresses. We report the whole expansion at the
very beginning of the listener stream with `ListenerEvent::NewAddress`
events and add new addresses should they come to our attention.

What remains to be done is to potentially allow users to filter IP
addresses, for example the local loopback one, and to detect expired
addresses not only if a new address is discovered.
2019-04-11 22:51:07 +02:00
Toralf Wittner
6917b8f543
Have Transport::Listeners produce ListenerEvents. (#1032)
Replace the listener and address pair returned from `Transport::listen_on` with just a listener that produces `ListenerEvent` values which include upgrades as well as address changes.
2019-04-10 10:29:21 +02:00
Pierre Krieger
480cf380d7
Add ExpandedSwarm (#1046) 2019-04-07 18:34:14 -03:00
Pierre Krieger
b176032a07
Generalize TPeerId into TConnInfo (#1045)
* Generalize TPeerId into TConnInfo

* Final fixes
2019-04-05 13:37:12 -03:00
Pierre Krieger
935825089d
Add getters to RawSwarm (#1037) 2019-04-04 16:49:00 -03:00
Age Manning
1dcb3e5b1c Allow oneshot handler's inactivity_timeout to be configurable (#1039) 2019-04-04 16:28:18 -03:00
Toralf Wittner
fac1ba12ec
Remove ProtocolsHandlerUpgrErr::MuxerDeniedSubstream. (#1043)
Closes #1042.
2019-04-04 19:11:59 +02:00
Pierre Krieger
1d4324ab70
Split the Swarm from the NetworkBehaviour (#1035) 2019-04-04 12:25:42 -03:00
Roman Borschel
8f77e9c45e
Add missing zeroize() call for secp256k1::SecretKey::from_bytes. (#1040)
* Add missing zeroize() call for secp256k1.

* Add a test.
2019-04-03 10:31:09 +02:00
Pierre Krieger
dfc425ea54
Also publish multistream-select 0.4 (#1034) 2019-03-29 14:05:40 -03:00
Pierre Krieger
235ad98863
Publish v0.6.0 (#1031) 2019-03-29 11:41:42 -03:00
Pierre Krieger
be4f8ca908
Add a Toggle NetworkBehaviour (#1024) 2019-03-29 10:17:11 -03:00
mattrutherford
7549948945
Use bounded channels in transport (#987)
* Implement DialFuture

* Update with recommended changes to buffer size, `expect()` and `close()`
2019-03-28 22:34:53 +00:00
Pierre Krieger
03ce6a6ed5
Add method to query external addresses (#1022) 2019-03-28 15:58:02 -03:00
Pierre Krieger
ebbe197d9c
Remove remnants of shutdown process (#1020) 2019-03-28 15:36:26 -03:00
Pierre Krieger
538c3dffdf
Improve Debug and Display for PeerId (#1019)
* Improve Debug and Display for PeerId

* Update core/src/peer_id.rs

Co-Authored-By: tomaka <pierre.krieger1708@gmail.com>
2019-03-23 10:08:07 +01:00
Pierre Krieger
34db72a080
Split address reach error and node reach error (#1013)
* Split address reach error and node reach error

* Small comments about order of operatoins

* Minor doc change
2019-03-20 20:28:55 +01:00
Pierre Krieger
96e559b503
Wrap multistream-select streams under a Negotiated (#1001) 2019-03-19 17:27:30 +01:00
Fedor Sakharov
63e9e39538 swarm: return references from external_addresses (#1008) 2019-03-19 15:23:58 +01:00
Roman Borschel
9575fa6c08
Documentation updates (#1005)
* Documentation updates:

  * libp2p: Update the top-level module documentation, already including
    intra-rustdoc links, removing outdated documentation, updating examples and
    polishing the text.

  * libp2p-core: Update the transport documentation to clarify that a `Transport`
    is really an abstraction only for connection-oriented transports.

* More links

* Fix typo.

* Address review comments.

* More doc tweaks.

  * Mention the necessity of creating an identity keypair.
  * Remove another mention of the removed Topology trait.
2019-03-19 12:45:57 +01:00
Pierre Krieger
1820bcb5ef
Version 0.5.0 (#999) 2019-03-13 10:14:55 +01:00
Pierre Krieger
8059a693a3
Cleaner shutdown process (#992)
* Cleaner shutdown process

* Finish

* Fix Yamux panic

* Remove irrelevant tests

* Update core/src/nodes/handled_node_tasks.rs

Co-Authored-By: tomaka <pierre.krieger1708@gmail.com>

* Fix yamux error handling

* Update yamux
2019-03-11 17:19:50 +01:00
Roman Borschel
2c66f82b11
Consolidate keypairs in core. (#972)
* Consolidate keypairs in core.

Introduce the concept of a node's identity keypair in libp2p-core,
instead of only the public key:

  * New module: libp2p_core::identity with submodules for the currently
    supported key types. An identity::Keypair and identity::PublicKey
    support the creation and verification of signatures. The public key
    supports encoding/decoding according to the libp2p specs.

  * The secio protocol is simplified as a result of moving code to libp2p-core.

  * The noise protocol is slightly simplified by consolidating ed25519
    keypairs in libp2p-core and using x25519-dalek for DH. Furthermore,
    Ed25519 to X25519 keypair conversion is now complete and tested.

Generalise over the DH keys in the noise protocol.

Generalise over the DH keys and thus DH parameter in handshake patterns
of the Noise protocol, such that it is easy to support other DH schemes
in the future, e.g. X448.

* Address new review comments.
2019-03-11 13:42:53 +01:00
Pierre Krieger
a64b18d5ab
Don't call the handler after it has shut down (#985) 2019-03-01 11:45:33 +01:00
Pierre Krieger
b1d55cc7cd
Fall back if no tokio executor available (#975) 2019-02-28 12:48:27 +01:00
Pierre Krieger
040d8c8c9a
Bump to v0.4 (#964) 2019-02-20 16:39:30 +01:00
Pierre Krieger
747478a55d
Fix simultaneous dialing test (#957) 2019-02-20 16:25:34 +01:00
Pierre Krieger
a380889e90
Add many tests for the raw swarm (#962) 2019-02-20 16:03:05 +01:00
Pierre Krieger
e1ad88f757
Fix an infinite loop in ProtocolsHandlerSelect (#961) 2019-02-20 15:06:49 +01:00