173 Commits

Author SHA1 Message Date
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
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
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
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
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
Pierre Krieger
6e0a38bb4a
Rewrite the WebCrypto ECDH using wasm-bindgen (#980)
* Rewrite the WebCrypto ECDH

* Add comment about the unsafe
2019-04-10 18:52:31 -03:00
Roman Borschel
a266b1e724
Patch reading/writing frame lengths in libp2p-noise. (#1050)
* Patch reading/writing frame lengths in libp2p-noise.

Extracted from https://github.com/libp2p/rust-libp2p/pull/1027 since its
fate it still undetermined.

* Fix formatting.
2019-04-10 17:54:24 +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
Toralf Wittner
98b2517403
Change Multiaddr representation to Bytes. (#1041)
* Change `Multiaddr` representation to `Bytes`.

* Mark several `Multiaddr` methods as deprecated.
2019-04-08 10:57:09 +02:00
Pierre Krieger
235ad98863
Publish v0.6.0 (#1031) 2019-03-29 11:41:42 -03:00
elferdo
603c7be7c2
[Kademlia] Rehash PeerId before inserting in a KBucketsTable (#1025)
Add KadHash as the type to be used as key within KBuckets and replace PeerId.
2019-03-26 16:17:34 +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
761c46ef19
Revert accidental change in Kademlia (#1018) 2019-03-20 18:55:09 +01:00
Pierre Krieger
1e8a976af6
Add kbuckets_entries (#1016) 2019-03-20 18:36:01 +01:00
Pierre Krieger
8de3cddfe8
Bugfix in Kademlia disconnected (#1017) 2019-03-20 17:52:35 +01:00
Pierre Krieger
7b2980133d
Simplify the Addresses (#1012)
* Simplify the Addresses

* Remove println
2019-03-20 17:30:00 +01:00
Pierre Krieger
7be97b4f93
Rewrite the Kademlia k-buckets to be more explicit (#996)
* Some k-buckets improvements

* Apply suggestions from code review

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

* Use NonZeroUsize for the distance

* Update TODO comment
2019-03-20 17:09:48 +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
Pierre Krieger
fc535f532b
Some Kademlia improvements (#994)
* Move QueryTarget to the behaviour

* Rework query system

* Add a few tests

* Add some Kademlia tests

* More tests

* Don't return self entry

* Fix tests
2019-03-18 18:20:57 +01:00
Roman Borschel
f4e7fed742
Remove unused test keys. (#1006) 2019-03-18 15:47:50 +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
245f6fd3b6
Bump to v0.4.2 (#981) 2019-02-27 18:31:41 +01:00
Pierre Krieger
2e57282efd
Ping wasn't working anymore (#979)
* Fix ping

* Update protocols/ping/src/handler.rs

Co-Authored-By: tomaka <pierre.krieger1708@gmail.com>
2019-02-27 18:12:51 +01:00
Pierre Krieger
c3670c4bf3
Disconnect only after the identify answer (#977) 2019-02-27 11:15:07 +01:00
Pierre Krieger
6143a33f18
Fix version of noise (#966) 2019-02-20 17:56:38 +01:00
Pierre Krieger
040d8c8c9a
Bump to v0.4 (#964) 2019-02-20 16:39:30 +01:00
Pierre Krieger
e2f99efb30
Fix the identify test multiplexer (#952) 2019-02-18 17:22:09 +01:00
Pierre Krieger
6cb2c71ca3
Revert erroneous change in identification delay, and add test for it (#949)
* Revert erroneous id change, and add test

* Improve test
2019-02-18 13:59:12 +01:00
Pierre Krieger
1100325e63
Improve nodes state (#917)
* Improve the state consistency in src/nodes

* Add a user data parameter to tasks

* Remove the tasks HashMap in CollectionStream

* Add TODO
2019-02-14 13:46:52 +01:00
Pierre Krieger
b7fa7f38b1
Add IdentifyEvent::SendBack (#941) 2019-02-14 12:07:13 +01:00
Pierre Krieger
3548c29dcf
Improvements to the helpers in upgrade::transfer (#937)
* Improvements to the helpers in upgrade::transfer

* Fix floodsub
2019-02-14 11:00:46 +01:00
Pierre Krieger
e9535c5c02
Add a proper list of addresses type for Kademlia (#928)
* Add a proper list of addresses type for Kademlia

* Some adjustements
2019-02-12 12:56:39 +01:00
Roman Borschel
eeed66707b Address edition-2018 idioms. (#929) 2019-02-11 14:58:15 +01:00
Pierre Krieger
229f5f66bd
Send external addresses first in identify (#930) 2019-02-08 10:46:04 +01:00
Benjamin Kampmann
bf5ed98895
Update Dependencies (#931)
* update secio dependencies: ed25519-dalek, sha2, hmac
* Update websocket dependencies
* Update multiaddr dependencies
2019-02-08 08:56:31 +01:00
Pierre Krieger
5cac5b5573
Report external addresses in identify (#926) 2019-02-07 11:04:04 +01:00
Pierre Krieger
a22121c8e7
Limit Kademlia messages to 4kiB (#920) 2019-02-06 14:33:45 +01:00
Pierre Krieger
479924f8dc
Bump libp2p, libp2p-core, libp2p-core-derive and libp2p-kad (#916)
* Bump libp2p-core, libp2p-core-derive and libp2p-kad

* Bump libp2p as well
2019-02-04 15:46:08 +01:00
Pierre Krieger
c9b7e237b6
Add NetworkBehaviour::inject_replaced (#914)
* Add NetworkBehaviour::inject_replaced

* Address style

* Forgot to call set_disconnected

* Also add incoming addresses to kbuckets
2019-02-04 15:21:50 +01:00
Pierre Krieger
780f4ddbc1
Avoid duplicate addresses in kbuckets (#906)
* Avoid duplicate addresses in kbuckets

* Bump kad to 0.3.1
2019-01-31 10:37:37 +01:00
Pierre Krieger
fcb2ac36e6
Bump to v0.3.0 (#905) 2019-01-30 16:50:47 +01:00
Pierre Krieger
663ec7e8da
connection_keep_alive() now returns KeepAlive (#899)
* connection_keep_alive() now returns Option<Instant>

* Use KeepAlive instead of Option<Instant>
2019-01-30 16:37:34 +01:00
Toralf Wittner
bbf56c6371
Update protobuf to version 2.3.0 (#904)
Initially I had hoped that the deprecated `#![allow(clippy)]` would no
longer be put into the generated rust files, but -- as of 2019-01-30 --
it still is (see [1] for details). Since we explicitly update the
protobuf files I decided to *manually edit the generated code* and
replace this with `#![allow(clippy:all)]`. Hopefully, by the time we do
the next upgrade, no such manual tweaking would be necessary anymore. I
think the benefit of a less polluted clippy output is worth it this
time.

[1]: https://github.com/stepancheg/rust-protobuf/pull/332
2019-01-30 16:25:45 +01:00
Pierre Krieger
3b0a322bbd
Use rand 0.6.5 in libp2p-noise (#902) 2019-01-30 16:05:40 +01:00
Toralf Wittner
e23b2733e2
Fix some rustc/clippy warnings. (#895) 2019-01-30 15:41:54 +01:00