438 Commits

Author SHA1 Message Date
Toralf Wittner
c0b379b908
Derive some std::fmt::Debug impls. (#1226)
* Derive some `Debug` impls.

* And some more.

Also remove several #[inline] attributes.
2019-08-19 20:15:56 +02:00
Pierre Krieger
c722963c62
Bump multistream-select as well (#1225) 2019-08-15 14:46:11 +02:00
Pierre Krieger
181af7175f
Publish v0.12.0 (#1224) 2019-08-15 13:50:28 +02:00
Toralf Wittner
9793c42859 Replace listen_addr with local_addr. (#1223)
* Replace `listen_addr` with `local_addr`.

In `ListenerUpgrade`, `ConnectedPoint` and other event types where we
were previously using the listen address we now report the local address
of an incoming connection. The reason being that it is difficult to get
the listen address right. In case clients want to know, which listener
produced an incoming connection upgrade they are advised to use the
`ListenerId` for such purposes.

* Update transports/tcp/src/lib.rs

Co-Authored-By: Max Inden <mail@max-inden.de>
2019-08-15 13:18:19 +02:00
Toralf Wittner
c154771de0 core: Replace debug_assert!s with log messages. (#1222)
* core: Replace `debug_assert!`s with log messages.

* Remove `cfg!(debug_assertions)`.
2019-08-13 16:46:11 +02:00
Toralf Wittner
2c4b52a545 Return TCP listener errors. (#1218)
* Add listener ID and error event.

Report listener errors to client code so they are aware that an error
occurred within a listener. By default we continue to poll listeners
which produced an error, but clients can remove listeners by ID.

* tcp: Report errors.

Instead of silently waiting after errors we return all errors, but pause
after each error, before continuing.

* Add a test.

To ease testing, `Listener` is made generic and we test that no values
and errors are lost. Elapsed time between item generation is not
measured.

* Support the new methods in core-derive.

* Address review concerns.

* Remove `Display` impl of `ListenerId`.

* Add 'static bound to `on_listener_error` error.
2019-08-13 15:41:12 +02:00
Roman Borschel
589d280bb5
[multistream-select] Reduce roundtrips in protocol negotiation. (#1212)
* Remove tokio-codec dependency from multistream-select.

In preparation for the eventual switch from tokio to std futures.

Includes some initial refactoring in preparation for further work
in the context of https://github.com/libp2p/rust-libp2p/issues/659.

* Reduce default buffer sizes.

* Allow more than one frame to be buffered for sending.

* Doc tweaks.

* Remove superfluous (duplicated) Message types.

* Reduce roundtrips in multistream-select negotiation.

1. Enable 0-RTT: If the dialer only supports a single protocol, it can send
   protocol data (e.g. the actual application request) together with
   the multistream-select header and protocol proposal. Similarly,
   if the listener supports a proposed protocol, it can send protocol
   data (e.g. the actual application response) together with the
   multistream-select header and protocol confirmation.

2. In general, the dialer "settles on" an expected protocol as soon
   as it runs out of alternatives. Furthermore, both dialer and listener
   do not immediately flush the final protocol confirmation, allowing it
   to be sent together with application protocol data. Attempts to read
   from the negotiated I/O stream implicitly flushes any pending data.

3. A clean / graceful shutdown of an I/O stream always completes protocol
   negotiation.

The publich API of multistream-select changed slightly, requiring both
AsyncRead and AsyncWrite bounds for async reading and writing due to
the implicit buffering and "lazy" negotiation. The error types have
also been changed, but they were not previously fully exported.

Includes some general refactoring with simplifications and some more tests,
e.g. there was an edge case relating to a possible ambiguity when parsing
multistream-select protocol messages.

* Further missing commentary.

* Remove unused test dependency.

* Adjust commentary.

* Cleanup NegotiatedComplete::poll()

* Fix deflate protocol tests.

* Stabilise network_simult test.

The test implicitly relied on "slow" connection establishment
in order to have a sufficient probability of passing.
With the removal of roundtrips in multistream-select, it is now
more likely that within the up to 50ms duration between swarm1
and swarm2 dialing, the connection is already established, causing
the expectation of step == 1 to fail when receiving a Connected event,
since the step may then still be 0.

This commit aims to avoid these spurious errors by detecting runs
during which a connection is established "too quickly", repeating
the test run.

It still seems theoretically possible that, if connections are always
established "too quickly", the test runs forever. However, given that
the delta between swarm1 and swarm2 dialing is 0-50ms and that the
TCP transport is used, that seems probabilistically unlikely.
Nevertheless, the purpose of the artificial dialing delay between
swarm1 and swarm2 should be re-evaluated and possibly at least
the maximum delay further reduced.

* Complete negotiation between upgrades in libp2p-core.

While multistream-select, as a standalone library and providing
an API at the granularity of a single negotiation, supports
lazy negotiation (and in particular 0-RTT negotiation), in the
context of libp2p-core where any number of negotiations are
composed generically within the concept of composable "upgrades",
it is necessary to wait for protocol negotiation between upgrades
to complete.

* Clarify docs. Simplify listener upgrades.

Since reading from a Negotiated I/O stream implicitly flushes any pending
negotiation data, there is no pitfall involved in not waiting for completion.
2019-08-12 12:09:53 +02:00
Pierre Krieger
a9c9a0784c
Publish v0.11.0 (#1205)
* Publish v0.11.0

* Update CHANGELOG.md

Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com>
2019-07-19 10:58:49 +02:00
Max Inden
5861474d99 core/src/translation: Support dns4 and dns6 (#1204)
* core/src/translation: Add unit tests

* core/src/translation: Support dns4 and dns6

Add dns4 and dns6 as valid protocol replacements for the origin address
to construct external addresses of a given node.

* core/nodes/network: %s/nat_translation/address_translation/

When receiving an observed address on a tcp connection that we initiated, the
observed address contains our tcp dial port, not our tcp listen port. We know
which port we are listening on, thereby we can replace the port within the
observed address.

When receiving an observed address on a tcp connection that we did **not**
initiated, the observed address should contain our listening port. In case it
differs from our listening port there might be a NAT along the path.

With the above in mind, the function name `nat_translation` is misleading.
2019-07-18 18:41:09 +02:00
Toralf Wittner
01bce16d09
Add missing copyright header. (#1201) 2019-07-10 11:31:45 +02:00
Pierre Krieger
2802232d5a Add some doc to ProtocolName (#1197)
* Add some doc to ProtocolName

* Update core/src/upgrade/mod.rs

Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com>
2019-07-10 11:01:48 +02:00
Roman Borschel
dfbf5b65c5
Rename RawSwarm* to Network*. (#1194)
* Rename RawSwarm* to Network*.

To complete the cut performed in [1].

The only remaining mention of a "swarm" in libp2p-core is in some tests
which actually depend on libp2p-swarm.

[1]: https://github.com/libp2p/rust-libp2p/pull/1188

* Post-merge corrections.
2019-07-10 10:27:21 +02:00
Toralf Wittner
6aba7961d1 Replace unbounded channels with bounded ones. (#1191)
* Replace unbounded channels with bounded ones.

To remove the unbounded channels used for communicating with node tasks
an API similar to `futures::Sink` is used, i.e. sending is split into a
start and complete phase. The start phase returns `StartSend` and first
attempts to complete any pending send operations. Completing the send
means polling until `Poll::Ready(())` is returned.

In addition this PR has split the `handled_node_tasks` module into
several smaller ones (cf. `nodes::tasks`) and renamed some types:

- `nodes::handled_node_tasks::NodeTask` -> `nodes::tasks::task::Task`
- `nodes::handled_node_tasks::NodeTaskInner` -> `nodes::tasks::task::State`
- `nodes::handled_node_tasks::NodeTasks` -> `nodes::tasks::Manager`
- `nodes::handled_node_tasks::TaskClosedEvent` -> `nodes::tasks::Error`
- `nodes::handled_node_tasks::HandledNodesEvent` -> `nodes::tasks::Event`
- `nodes::handled_node_tasks::Task` -> `nodes::tasks::TaskEntry`
- `nodes::handled_node_tasks::ExtToInMessage` -> `nodes::tasks::task::ToTaskMessage`
- `nodes::handled_node_tasks::InToExtMessage` -> `nodes::tasks::task::FromTaskMessage`

* `take_over_to_complete` can be an `Option`.

Since it is always holding just a single pending message.

* `send_event_to_complete` can be an `Option`.

* Update core/src/nodes/tasks/manager.rs

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

* Update core/src/nodes/tasks/manager.rs

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

* Add comments to explain the need to flush sends ...

of take-over and event messages delivered over Sinks.
2019-07-09 16:47:24 +02:00
Shotaro Yamada
a0d278a479 Remove unused dependencies (#1195) 2019-07-08 19:17:51 +02:00
Toralf Wittner
68c36d87d3
Move swarm and protocols handler into swarm crate. (#1188)
Move swarm and protocols handler into swarm crate.
2019-07-04 14:47:59 +02:00
Pierre Krieger
404f1bdf4d
Publish v0.10.0 (#1185)
* Publish v0.10.0

* Add line for #1178
2019-06-25 13:56:59 +02:00
Pierre Krieger
aca0d46b37
Fix #1135 (#1178)
* Fix #1135

* Address review

* Update core/src/swarm/registry.rs
2019-06-25 13:32:27 +02:00
Pierre Krieger
6d5aa86cef
Cleanup in spawning tasks (#1181) 2019-06-24 12:18:07 +02:00
Shotaro Yamada
e4d43030eb Make <SubstreamRef as AsyncWrite>::shutdown imply flush (#1180)
* Make `<SubstreamRef as AsyncWrite>::shutdown` imply flush

* Use try_ready

* Apply suggestions from code review

Co-Authored-By: Toralf Wittner <tw@dtex.org>
2019-06-24 10:42:33 +02:00
Tony Arcieri
3b4f8d7094 zeroize: Upgrade to v0.9 (#1179) 2019-06-19 10:52:49 +02:00
Age Manning
f6ce1e6b3a Remove redundant loop (#1176) 2019-06-18 10:42:40 +02:00
Pierre Krieger
b6378ac526
PollParameters is now a trait (#1177)
* PollParameters is now a trait

* Fix unused variable
2019-06-18 10:23:26 +02:00
Pierre Krieger
78d6f44e46
Allow customizing the Swarm with TConnInfo (#1172) 2019-06-12 16:21:39 +02:00
Pierre Krieger
9d0dfa56c0
Publish v0.9.1 (#1168) 2019-06-05 18:04:59 +02:00
Pierre Krieger
134f472070
Implement Stream and Sink for EitherOutput (#1166) 2019-06-05 16:07:13 +02:00
Pierre Krieger
f51573b628
Publish v0.9.0 (#1160)
* Publish v0.9.0

* Update CHANGELOG.md

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

* Published soketto
2019-06-04 17:17:03 +02:00
Pierre Krieger
603fd5744f
No longer require fmt::Debug when not necessary (#1158) 2019-06-04 13:08:37 +02:00
Toralf Wittner
e56c4c10ed Reimplement the websocket transport. (#1150)
* Begin reimplementing the websocket transport.

* Add TLS support.

* Add support for redirects during handshake.

* Cosmetics.

* Remove unused error cases in tls module.

Left-overs from a previous implementation.

* No libp2p-websocket for wasm targets.

* Change tls::Config to make the server optional.

* Update transports/websocket/src/lib.rs

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

* Duplicate config methods.

As per PR review feedback.
2019-06-04 11:47:20 +02:00
Age Manning
34e7e35310 Add sign/verify raw_hash to secp256k1 (#1149) 2019-06-03 19:36:49 +02:00
Pierre Krieger
a27ce807ee
Some improvements to the docs of NetworkBehaviour (#1152)
* Some improvements to the docs of NetworkBehaviour

* Apply suggestions from code review

Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com>
2019-06-03 18:16:02 +02:00
Pierre Krieger
fbc6ea5c5e
Allow injecting an existing connection (#1157) 2019-06-03 17:27:43 +02:00
Pierre Krieger
7c108b66f2
Fix small todo in handled tasks (#1114)
* Fix small todo in handled tasks

* Address review
2019-05-23 15:16:46 +02:00
Pierre Krieger
6b78fa0cf7
Update dependencies (#1142)
* parking-lot to 0.8

* zeroize to 0.8
2019-05-23 11:14:34 +02:00
Pierre Krieger
93d89964e1
Add OptionalUpgrade (#1131) 2019-05-17 15:29:59 +02:00
Pierre Krieger
1d7df0c9ca
Bump versions (#1129) 2019-05-15 19:34:41 +02:00
Pierre Krieger
1be1eaf137
Add secp256k1::SecretKey::to_bytes (#1126) 2019-05-15 19:26:07 +02:00
Andre-Philippe Paquet
4c20d3134c Fix ED25519 signature validation (#1127) 2019-05-15 19:06:29 +02:00
Pierre Krieger
bd96b66fb5
Publish version 0.8.0 (#1123) 2019-05-15 16:50:43 +02:00
Pierre Krieger
87a352c84f
Add some diagnostics for the same address being reported despite not in list (#1124)
* Add more diagnostics for TCP

* Address review

* Publish libp2p-tcp 0.7.2

* Add another diagnostic
2019-05-15 14:48:26 +02:00
Pierre Krieger
3d4d8df713
Add an OptionalTransport type (#1116)
* Add OptionalTransport

* Fix copyright

* Some documentation

* Apply suggestions from code review

Co-Authored-By: Toralf Wittner <tw@dtex.org>
2019-05-15 11:26:43 +02:00
Pierre Krieger
53e22281cf
Reexport ConnectedPoint at the root (#1119) 2019-05-14 20:26:29 +02:00
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