1168 Commits

Author SHA1 Message Date
folex
fe0a141e0e bucket: cleanup 2020-03-20 19:45:04 +03:00
folex
d8b42a5cb1 bucket: apply_pending works 2020-03-20 19:36:33 +03:00
folex
c096db5e59 bucket: apply_pending WIP 2020-03-20 18:46:47 +03:00
folex
0d66695d3b update works 2020-03-20 18:35:57 +03:00
folex
2aa6fbc93f insert works 2020-03-20 18:11:19 +03:00
Pierre Krieger
92ce5d6179
Allow customizing the Kademlia maximum packet size (#1502)
* Allow customizing the Kademlia maximum packet size

* Address concern
2020-03-19 21:23:05 +01:00
Pierre Krieger
439dc8246e
Allow customizing the delay before closing a Kademlia connection (#1477)
* Reduce the delay before closing a Kademlia connection

* Rework pull request

* Update protocols/kad/src/behaviour.rs

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

* Update protocols/kad/src/behaviour.rs

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

* Rework the pull request

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2020-03-19 17:01:34 +01:00
folex
51b441247f cleanup 2020-03-19 18:38:37 +03:00
folex
235d23dcaa Refactor duplicated code 2020-03-19 18:36:38 +03:00
folex
9b93e500a7 arrrgh 2020-03-19 16:40:04 +03:00
folex
1dc62e61f2 use trust-graph 2020-03-19 15:50:12 +03:00
folex
87b8e23553 cleanup 2020-03-19 15:12:48 +03:00
folex
84fc48f1ac Add public key to buckets 2020-03-19 14:52:59 +03:00
Roman Borschel
4e63710a6f
Clean up libp2p-core tests. (#1498) 2020-03-19 10:51:46 +01:00
vms
e9240755f8 contact 2020-03-19 12:32:08 +03:00
folex
619ed94e64 Add public key to buckets WIP 2020-03-19 12:11:04 +03:00
folex
783ff2575e Add public key to buckets WIP 2020-03-18 18:16:36 +03:00
Pierre Krieger
97a02950bb
Reexport MemoryStoreConfig (#1499) 2020-03-18 14:56:53 +01:00
Max Inden
522020e0a4
protocols/kad: Do not attempt to store expired record in record store (#1496)
* protocols/kad: Do not attempt to store expired record in record store

`Kademlia::record_received` calculates the expiration time of a record
before inserting it into the record store. Instead of inserting the
record into the record store in any case, with this patch the record is
only inserted if it is not expired. If the record is expired a
`KademliaHandlerIn::Reset` for the given (sub) stream is triggered.

This would serve as a tiny defense mechanism against an attacker trying
to fill a node's record store with expired records before the record
store's clean up procedure removes the records.

* protocols/kad: Send regular ack when record discarded due to expiration

With this commit the remote receives a
[`KademliaHandlerIn::PutRecordRes`] even in the case where the record is
discarded due to being expired.  Given that the remote sent the local
node a [`KademliaHandlerEvent::PutRecord`] request, the remote perceives
the local node as one node among the k closest nodes to the target.
Returning a [`KademliaHandlerIn::Reset`] instead of an
[`KademliaHandlerIn::PutRecordRes`] to have the remote try another node
would only result in the remote node to contact an even more distant
node. In addition returning [`KademliaHandlerIn::PutRecordRes`] does not
reveal any internal information to a possibly malicious remote node.

* protocols/kad/src/behaviour: Use `now` and reword expiration comment

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2020-03-18 14:31:01 +01:00
Max Inden
29471467e3
protocols/kad: Fix right shift overflow panic in record_received (#1492)
* protocols/kad: Add test to reproduce right shift overflow panic

* protocols/kad: Fix right shift overflow panic in record_received

Within `Behaviour::record_received` the exponentially decreasing
expiration based on the distance to the target for a record is
calculated as following:

1. Calculate the amount of nodes between us and the record key beyond
the k replication constant as `n`.

2. Shift the configured record time-to-live `n` times to the right to
calculate an exponentially decreasing expiration.

The configured record time-to-live is a u64. If `n` is larger or equal
to 64 the right shift will lead to an overflow which panics in debug
mode.

This patch uses a checked right shift instead, defaulting to 0 (`now +
0`) for the expiration on overflow.

* protocols/kad: Put attribute below comment

* protocols/kad: Extract shifting logic and rework test

Extract right shift into isolated function and replace complex
regression test with small isolated one.

* protocols/kad/src/behaviour: Refactor exp_decr_expiration

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
2020-03-18 10:15:33 +01:00
folex
1b3a30aa6c Add public key to buckets WIP 2020-03-17 18:35:39 +03:00
folex
e8bce909d0 Exchange public key WIP 2020-03-17 17:59:33 +03:00
folex
eaae132be1 Exchange public key WIP 2020-03-17 15:26:33 +03:00
folex
263c237070 Exchange public key WIP 2020-03-17 14:17:16 +03:00
folex
c844d3cb7d Merge branch 'master' into bucket_ordering 2020-03-17 14:02:31 +03:00
folex
9b52ca6d0f Exchange public key WIP 2020-03-17 14:02:16 +03:00
folex
4f7d290b7a Exchange public key WIP 2020-03-17 13:24:01 +03:00
folex
13c48c0f19 Exchange public key WIP 2020-03-16 21:00:06 +03:00
folex
912b4d7021 Exchange public key WIP 2020-03-16 19:35:22 +03:00
folex
3ed32a6a1b pass local key 2020-03-16 19:13:00 +03:00
Roman Borschel
58ee13b630
Fix regression w.r.t. reporting of dial errors. (#1493)
* Fix regression w.r.t. reporting of dial errors.

PR [1440] introduced a regression w.r.t. the reporting of
dial errors. In particular, if a connection attempt fails
due to an invalid remote peer ID, any remaining addresses
for the same peer would not be tried (intentional) but
the dial failure would not be reported to the behaviour,
causing e.g. libp2p-kad queries to potentially stall.

In hindsight, I figured it is better to preserve the
previous behaviour to still try alternative addresses
of the peer even on invalid peer ID errors on an earlier
address. In particular because in the context of libp2p-kad
it is not uncommon for peers to report localhost addresses
while the local node actually has e.g. an ipfs node running
on that address, obviously with a different peer ID, which
is the scenario causing frequent invalid peer ID (mismatch)
errors when running the ipfs-kad example.

This commit thus restores the previous behaviour w.r.t.
trying all remaining addresses on invalid peer ID errors
as well as making sure `inject_dial_error` is always
called when the last attempt failed.

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

* Remove an fmt::Debug requirement.
2020-03-16 16:53:21 +01:00
folex
0343c129a5 Add Contact 2020-03-16 18:39:05 +03:00
folex
65bb4f2b7d Comment out tests for better IDE experience, add some comments 2020-03-16 16:54:53 +03:00
folex
645a898561
Merge pull request #2 from libp2p/master
Merge
2020-03-16 16:52:23 +03:00
Pierre Krieger
96cd509c60
Feature-gate all dependencies (#1467)
* Feature-gate all dependencies

* Fix root doctest

* Fix WASM build
2020-03-11 15:33:22 +01:00
Pierre Krieger
31271fc824
Update multistream-select to stable futures (#1484)
* Update multistream-select to stable futures

* Fix intradoc links
2020-03-11 14:49:41 +01:00
Pierre Krieger
2084fadd86
Remove integration test (#1490)
* Remove integration test

* Remove from top list
2020-03-11 14:05:02 +01:00
Pierre Krieger
10089c5f46
Use upstream version of multihash instead of a fork (#1472)
The changes from the libp2p fork have been backported to upstream, hence
upstream can now be used instead.
2020-03-05 16:49:36 +01:00
Roman Borschel
8337687b3a
Multiple connections per peer (#1440)
* Allow multiple connections per peer in libp2p-core.

Instead of trying to enforce a single connection per peer,
which involves quite a bit of additional complexity e.g.
to prioritise simultaneously opened connections and can
have other undesirable consequences [1], we now
make multiple connections per peer a feature.

The gist of these changes is as follows:

The concept of a "node" with an implicit 1-1 correspondence
to a connection has been replaced with the "first-class"
concept of a "connection". The code from `src/nodes` has moved
(with varying degrees of modification) to `src/connection`.
A `HandledNode` has become a `Connection`, a `NodeHandler` a
`ConnectionHandler`, the `CollectionStream` was the basis for
the new `connection::Pool`, and so forth.

Conceptually, a `Network` contains a `connection::Pool` which
in turn internally employs the `connection::Manager` for
handling the background `connection::manager::Task`s, one
per connection, as before. These are all considered implementation
details. On the public API, `Peer`s are managed as before through
the `Network`, except now the API has changed with the shift of focus
to (potentially multiple) connections per peer. The `NetworkEvent`s have
accordingly also undergone changes.

The Swarm APIs remain largely unchanged, except for the fact that
`inject_replaced` is no longer called. It may now practically happen
that multiple `ProtocolsHandler`s are associated with a single
`NetworkBehaviour`, one per connection. If implementations of
`NetworkBehaviour` rely somehow on communicating with exactly
one `ProtocolsHandler`, this may cause issues, but it is unlikely.

[1]: https://github.com/paritytech/substrate/issues/4272

* Fix intra-rustdoc links.

* Update core/src/connection/pool.rs

Co-Authored-By: Max Inden <mail@max-inden.de>

* Address some review feedback and fix doc links.

* Allow responses to be sent on the same connection.

* Remove unnecessary remainders of inject_replaced.

* Update swarm/src/behaviour.rs

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

* Update swarm/src/lib.rs

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

* Update core/src/connection/manager.rs

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

* Update core/src/connection/manager.rs

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

* Update core/src/connection/pool.rs

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

* Incorporate more review feedback.

* Move module declaration below imports.

* Update core/src/connection/manager.rs

Co-Authored-By: Toralf Wittner <tw@dtex.org>

* Update core/src/connection/manager.rs

Co-Authored-By: Toralf Wittner <tw@dtex.org>

* Simplify as per review.

* Fix rustoc link.

* Add try_notify_handler and simplify.

* Relocate DialingConnection and DialingAttempt.

For better visibility constraints.

* Small cleanup.

* Small cleanup. More robust EstablishedConnectionIter.

* Clarify semantics of `DialingPeer::connect`.

* Don't call inject_disconnected on InvalidPeerId.

To preserve the previous behavior and ensure calls to
`inject_disconnected` are always paired with calls to
`inject_connected`.

* Provide public ConnectionId constructor.

Mainly needed for testing purposes, e.g. in substrate.

* Move the established connection limit check to the right place.

* Clean up connection error handling.

Separate connection errors into those occuring during
connection setup or upon rejecting a newly established
connection (the `PendingConnectionError`) and those
errors occurring on previously established connections,
i.e. for which a `ConnectionEstablished` event has
been emitted by the connection pool earlier.

* Revert change in log level and clarify an invariant.

* Remove inject_replaced entirely.

* Allow notifying all connection handlers.

Thereby simplify by introducing a new enum `NotifyHandler`,
used with a single constructor `NetworkBehaviourAction::NotifyHandler`.

* Finishing touches.

Small API simplifications and code deduplication.
Some more useful debug logging.

Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Toralf Wittner <tw@dtex.org>
2020-03-04 13:49:25 +01:00
Pierre Krieger
7cbb3cf8f3
Add Mdns::discovered_nodes (#1480) 2020-03-02 17:11:28 +01:00
Toralf Wittner
d8bb9990c0
Require latest yamux version. (#1479) 2020-02-28 13:30:59 +01:00
Pierre Krieger
2c40f2880e
Publish 0.16.2 (#1476) v0.16.2 2020-02-28 10:54:52 +01:00
Toralf Wittner
96cc7912a3
Keep polling connection when closing. (#1474)
The API contract of Yamux is that the connection has to be polled
until `None` or some `Err(_)` is returned. Therefore while closing
we need to keep polling the connection. Only polling the control
channel will not have an effect but `close` will always return
`Poll::Pending` as the connection does not make progress.
2020-02-27 16:04:03 +01:00
Demi Obenour
62ea7c165b
Upgrade crypto libs (#1470) 2020-02-26 13:23:52 +01:00
Toralf Wittner
2ea459dcdc
kad: Export QueryId and add Kademlia::protocol_name. (#1469)
The `QueryId` type should be exported as it is used in the
`NetworkBehaviour::ProtocolsHandler` type of `Kademlia`.

`Kademlia::protocol_name` is added for convenience.
2020-02-25 11:59:38 +01:00
vms
688aa5bc79
Move mdns (#1458)
* move mdns

* alphabetic ordering in Cargo.toml

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
2020-02-24 19:36:55 +01:00
Mazdak Farrokhzad
4496337f93
Onion3Addr::acquire: fix bug due to differing lifetimes (#1468)
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
2020-02-24 18:42:43 +01:00
Guillaume GONI
4472840acf
NetworkBehaviour derive fix IntoProtocolsHandler/ProtocolsHandler::select ambiguity (#1466)
* NetworkBehaviour derive fix IntoProtocolsHandler/ProtocolsHandler::select ambiguity

* Missing space misc/core-derive/src/lib.rs

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

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
2020-02-24 16:56:36 +01:00
Ashley
e84cbf278a
Add a js implementation of wasm-ext. (#1454)
* Squashed commit of the following:

commit 8d11f27165aecb6275c6a435e36d4fc38193b601
Author: Ashley Ruglys <ashley.ruglys@gmail.com>
Date:   Thu Feb 13 16:27:26 2020 +0100

    Fix implementation

commit 8f60187bcc3b57069eb8bd7ac530d9da3da4176e
Author: Ashley Ruglys <ashley.ruglys@gmail.com>
Date:   Thu Feb 13 12:38:35 2020 +0100

    Add implementation

commit 445fadea709c930b83b4f7905c030bb29c776eed
Author: Ashley Ruglys <ashley.ruglys@gmail.com>
Date:   Wed Feb 12 16:45:31 2020 +0100

    Use different features on different targets

commit e5d47c19fc06b96bad16f433a1526ecf4d9ce99b
Author: Ashley Ruglys <ashley.ruglys@gmail.com>
Date:   Mon Feb 10 13:23:50 2020 +0100

    Use ring on native

commit 8def133f8230885535765f8e244162cdb8901a34
Author: Ashley Ruglys <ashley.ruglys@gmail.com>
Date:   Fri Feb 7 14:46:52 2020 +0100

    Use the sha2 crate for sha512 hashing

commit 268880d2ed6510a0339d70184d7ad88f3efb39c4
Author: Ashley <ashley.ruglys@gmail.com>
Date:   Fri Feb 7 01:25:29 2020 +0100

    Fix documentation

commit 9769bc5242972c2c74e9b5e36960ca2513ddbb33
Author: Ashley <ashley.ruglys@gmail.com>
Date:   Fri Feb 7 01:17:20 2020 +0100

    Switch snow resolver to default

commit ac22537385ff81b274aec14a8c6f47a0b59606ce
Author: Ashley <ashley.ruglys@gmail.com>
Date:   Thu Feb 6 20:34:50 2020 +0100

    hmm...

* Feature gate

* Rename -> websocket_transport

* Update transports/wasm-ext/Cargo.toml

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

* Update transports/wasm-ext/src/lib.rs

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

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
2020-02-19 15:10:07 +01:00
Pierre Krieger
bfc1934dc0
Remove change that didn't make it (#1461) 2020-02-18 18:46:13 +01:00