381 Commits

Author SHA1 Message Date
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
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