39 Commits

Author SHA1 Message Date
Roman Borschel
86402311fc
[multistream-select] Listener conformity for failed negotiations. (#1871)
* [multistream-select] Listener conformity for failed negotiations.

When `V1Lazy` is used and the listener does not support the
optimistic (and singular) proposal of the dialer, it currently
happens that dialer and listener get a different outcome of
the negotiation. The dialer eventually detects the failed
negotiation as soon as it tries to read from the stream, but
the listener either encounters an invalid message or unexpected
premature EOF, depending on the payload that the dialer sent
prematurely after its protocol proposal. In these cases the
listener must be lenient and fail the negotiation "normally",
i.e. not with a protocol violation or an I/O error.

* Update misc/multistream-select/src/tests.rs

Co-authored-by: Max Inden <mail@max-inden.de>

* Refine error handling.

Only be lenient with garbage or sudden EOF when reading
just after having sent a protocol rejection.

* Update misc/multistream-select/src/listener_select.rs

Co-authored-by: Max Inden <mail@max-inden.de>

Co-authored-by: Max Inden <mail@max-inden.de>
2020-12-02 16:40:58 +01:00
Roman Borschel
65c4bf88dc
[multistream] Make the lazy variant more interoperable. (#1855)
* Make the lazy variant interoperable.

The remaining optimisation for `V1Lazy` for a listener
in the negotiation, whereby the listener delays flushing
of the multistream version header, is hereby removed.
The remaining effect of `V1Lazy` is only on the side of
the dialer, which delays flushing of its singular
protocol proposal in order to send it together with
the first application data (or an attempt is made to
read from the negotiated stream, which similarly
triggers a flush of the protocol proposal). This
permits `V1Lazy` dialers to be interoperable with
`V1` listeners. The remaining theoretical pitfall whereby
application data gets misinterpreted as another protocol
proposal by a listener remains, however unlikely.

`V1` remains the default, but we may eventually risk
just making this lazy dialer flush a part of the default
`V1` implementation, removing the dedicated `V1Lazy`
version identifier.

* Update CHANGELOG

* Separate versions from mere header lines.

Every multistream-select version maps to a specific header line,
but there may be different variants of the same multistream-select
version using the same header line, i.e. the same wire protocol.

* Cleanup

* Update misc/multistream-select/CHANGELOG.md
2020-11-25 10:21:02 +01:00
Max Inden
e3af8b7d03
*: Apply clippy suggestions and enable clippy on CI (#1850)
* *: Apply clippy suggestions

* .github: Add clippy check

* protocols/kad/record: Implement custom PartialEq for ProviderRecord
2020-11-24 15:59:22 +01:00
Roman Borschel
edb99eded6
[multistream-select] Fix ls response encoding/decoding (spec-compliance). (#1811)
* Fix ls response encoding/decoding.

Thereby remove the now unnecessary arbitrary protocol name
length limit. Since it an 'ls' response is always terminated
with a dedicated newline (and thus ends with two newlines),
an 'ls' response with a single protocol can be disambiguated
from a single protocol response by this additional newline.

* More commentary

* Update versions and changelogs.

* Resolve remaining conflict.

* Permit empty ls responses, as before.
2020-11-18 12:03:07 +01:00
Max Inden
70bb2d7c11
misc/multistream-select: Interpretation of EOF as Failed negotiation (#1823)
Treat EOF error as [`NegotiationError::Failed`], not as
[`NegotiationError::ProtocolError`], allowing dropping or closing an I/O stream
as a permissible way to "gracefully" fail a negotiation.

This is e.g. important when a listener rejects a protocol with
[`Message::NotAvailable`] and the dialer does not have alternative protocols to
propose. Then the dialer will stop the negotiation and drop the corresponding
stream. As a listener this EOF should be interpreted as a failed negotiation.
2020-11-09 16:04:00 +01:00
Roman Borschel
e5adb67d73
[multistream-select] Temporarily disable "parallel" negotiation. (#1807)
* [multistream-select] Temp. disable "parallel" negotiation.

In order to later change the "ls" responses for spec-compliance.

* Update version.

* Update misc/multistream-select/CHANGELOG.md

Co-authored-by: Max Inden <mail@max-inden.de>

Co-authored-by: Max Inden <mail@max-inden.de>
2020-10-20 15:11:20 +02:00
Roman Borschel
3e31ea9337
[multistream-select] Fix panic with V1Lazy (regression) and more convenient transport boxing. (#1783)
* [multistream-select] Fix panic with V1Lazy and add integration tests.

Fixes a panic when using the `V1Lazy` negotiation protocol,
a regression introduced in https://github.com/libp2p/rust-libp2p/pull/1484.

Thereby adds integration tests for a transport upgrade with both
`V1` and `V1Lazy` to the `multistream-select` crate to prevent
future regressions.

* Cleanup.

* Update changelog.
2020-10-07 11:10:54 +02:00
Roman Borschel
8cec457b5e
[multistream-select] Require remaining negotiation data to be flushed. (#1781)
* Require remaining negotiation data to be flushed.

There appears to still be an edge-case whereby the
`remaining` data to send w.r.t. protocol negotiation to send
is successfully written before a `poll_read` on a `Negotiated` stream,
but where the subsequent `poll_flush()` is pending.
Now `remaining` is empty and the next `poll_read()`
will go straight to reading from the underlying
I/O stream, despite the flush not having happened
yet, which can lead to a form of deadlock during
protocol negotiation.

Rather than complicating the existing code further in
order to accommodate for this case, it seems preferable
to simplify the code by giving up on this optimisation
that only affects the last negotiation protocol message
sent by the "listener". So we give up on the ability
to combine data sent by the "listener" immediately
after protocol negotiation together with the final
negotiation frame in the same transport-level frame/packet.

* Update changelog.

* Add missing comma.
2020-10-01 12:29:51 +02:00
dependabot[bot]
3c72b07e55
Update atomic requirement from 0.4.6 to 0.5.0 (#1766)
* Update atomic requirement from 0.4.6 to 0.5.0

Updates the requirements on [atomic](https://github.com/Amanieu/atomic-rs) to permit the latest version.
- [Release notes](https://github.com/Amanieu/atomic-rs/releases)
- [Commits](https://github.com/Amanieu/atomic-rs/compare/v0.4.6...v0.5.0)

Signed-off-by: dependabot[bot] <support@github.com>

* .github/workflows: Update Rust nightly

* misc/multistream-select: Don't mention private item in public doc

* .github/workflows: Update renamed doc flag

* core/src/connection/pool: Don't mention private item in public doc

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <mail@max-inden.de>
2020-09-17 10:41:23 +02:00
Demi Obenour
9178459cc8
Automatic fixes by cargo-fix (#1662) 2020-07-27 22:27:33 +02:00
Taiki Endo
9aaf042410
Remove uses of pin_project::project attribute (#1604)
pin-project will deprecate the project attribute due to some unfixable
limitations.

Refs: https://github.com/taiki-e/pin-project/issues/225
2020-06-09 18:01:57 +02: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
fc4dec581e
Check documentation intra-link (#1432)
* Fix broken links in rustdoc

This fixes all of the rustdoc warnings on nightly.

* Check documentation intra-link

* Fix config

* Fix bad indent

* Make nightly explicit

* More links fixes

* Fix link broken after master merge

Co-authored-by: Demi Obenour <48690212+DemiMarie-parity@users.noreply.github.com>
2020-02-10 15:17:07 +01:00
Toralf Wittner
2bc8d9590d Update to bytes v0.5
Except for `multiaddr` which encapsulates its use of bytes v0.4 now.
2019-12-21 15:42:24 +01:00
Roman S. Borschel
1e8a90c606 Remove a write optimisation in Negotiated. 2019-12-09 21:13:55 +01:00
Toralf Wittner
173fc04b30 Fix tests. 2019-12-07 15:11:46 +01:00
Pierre Krieger
abe2f2afc1
Merge master into stable-futures (#1271)
* Configurable multistream-select protocol. Add V1Lazy variant. (#1245)

Make the multistream-select protocol (version) configurable
on transport upgrades as well as for individual substreams.

Add a "lazy" variant of multistream-select 1.0 that delays
sending of negotiation protocol frames as much as possible
but is only safe to use under additional assumptions that
go beyond what is required by the multistream-select v1
specification.

* Improve the code readability of the chat example (#1253)

* Add bridged chats (#1252)

* Try fix CI (#1261)

* Print Rust version on CI

* Don't print where not appropriate

* Change caching strategy

* Remove win32 build

* Remove win32 from list

* Update libsecp256k1 dep to 0.3.0 (#1258)

* Update libsecp256k1 dep to 0.3.0

* Sign now cannot fail

* Upgrade url and percent-encoding deps to 2.1.0 (#1267)

* Upgrade percent-encoding dep to 2.1.0

* Upgrade url dep to 2.1.0

* Fix more conflicts

* Revert CIPHERS set to null (#1273)
2019-10-10 11:31:44 +02:00
Roman Borschel
e177486ca8
Fix Display impl for NegotiationError. (#1243) 2019-09-10 10:16:15 +02:00
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
Roman Borschel
bf8c97049a [multistream-select] Fix restoring remaining buffer on write error in Negotiated I/O streams. (#1228)
* Fix restoring remaining buffer on write error.

* Bump patch version.
2019-08-19 18:21:17 +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
Roman Borschel
2fd941122a
Remove tokio-codec dependency from multistream-select. (#1203)
* 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.
2019-07-29 17:06:23 +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
96e559b503
Wrap multistream-select streams under a Negotiated (#1001) 2019-03-19 17:27:30 +01:00
Roman Borschel
eeed66707b Address edition-2018 idioms. (#929) 2019-02-11 14:58:15 +01:00
Toralf Wittner
e23b2733e2
Fix some rustc/clippy warnings. (#895) 2019-01-30 15:41:54 +01:00
Toralf Wittner
f1959252b7
multistream-select: Less allocations. (#800) 2019-01-09 15:09:35 +01:00
Toralf Wittner
a152e18821
Simplify handling of upgrade information. (#761) 2018-12-11 15:13:10 +01:00
Toralf Wittner
2253c82b86
multistream-select: Update to 2018 edition. (#766) 2018-12-11 10:45:28 +01:00
Pierre Krieger
1da97242da
Remove the NamesIter: Clone requirement (#663)
* Remove the NamesIter: Clone requirement

* Fix concerns
2018-11-22 18:15:35 +01:00
James Ray
0f3ef5ee0a eg. -> e.g.; ie. -> i.e. via repren (#592)
* eg. -> e.g.; ie. -> i.e. via repren

* se.g. -> seg.
2018-11-02 16:40:00 +01:00
jamartin9
490ae980c7 #399 remove tokio_current_thread tests (#577)
* remove tokio_current_thread tests

* Review changes:
Removed newline
Moved uds tokio test crate to top to avoid self and keep with convention of other test crates
Removed sleep from uds test and block until all futures are completed.
2018-10-25 11:26:37 +02:00
Toralf Wittner
fd4ae72f8c
multistream-select: use FramedWrite from tokio-codec. (#539) 2018-10-10 09:16:21 +02:00
Pierre Krieger
0c43c76965
Implement close() from Sink (#492) 2018-09-17 15:01:37 +02:00
Toralf Wittner
b5acf226f9
multistream-select: Include \n in length. (#439)
* multistream-select: Include `\n` in length.

* Add comment to explain the +1.

* Re-enable test.
2018-09-03 11:13:42 +02:00
Pierre Krieger
ccc5aacafc Fix #440 (#441)
* Fix #440

* Ignore failing test
2018-09-03 10:25:16 +02:00
Toralf Wittner
c02dea8128
Introduce several concrete future types. (#433)
* multisteam-select: introduce `DialerFuture`.

* multistream-select: add more concrete futures.

* multistream-select: add ListenerFuture.

* multistream-select: add ListenerSelectFuture

* Formatting.

* Add DialerSelectFuture type alias.

* Add UpgradeApplyFuture and NegotiationFuture.

* In iterator wrappers also pass-through size_hint.

* Minor refactoring.

* Address review comments.

* Add some comments.

* Hide state enums in wrapping structs.
2018-08-30 23:25:16 +02:00
Toralf Wittner
f457ca5490
Correctly encode and decode multistream-select ls. (#438) 2018-08-30 23:13:06 +02:00
Benjamin Kampmann
2ea49718f3
Clean up directory structure (#426)
* Remove unused circular-buffer crate
* Move transports into subdirectory
* Move misc into subdirectory
* Move stores into subdirectory
* Move multiplexers
* Move protocols
* Move libp2p top layer
* Fix Test: skip doctest if secio isn't enabled
2018-08-29 11:24:44 +02:00