mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-08-01 01:11:58 +00:00
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)
This commit is contained in:
@@ -70,8 +70,8 @@ impl<TInner> Negotiated<TInner> {
|
||||
|
||||
/// Creates a `Negotiated` in state [`State::Expecting`] that is still
|
||||
/// expecting confirmation of the given `protocol`.
|
||||
pub(crate) fn expecting(io: MessageReader<TInner>, protocol: Protocol) -> Self {
|
||||
Negotiated { state: State::Expecting { io, protocol } }
|
||||
pub(crate) fn expecting(io: MessageReader<TInner>, protocol: Protocol, version: Version) -> Self {
|
||||
Negotiated { state: State::Expecting { io, protocol, version } }
|
||||
}
|
||||
|
||||
/// Polls the `Negotiated` for completion.
|
||||
@@ -100,27 +100,29 @@ impl<TInner> Negotiated<TInner> {
|
||||
// Read outstanding protocol negotiation messages.
|
||||
loop {
|
||||
match mem::replace(&mut self.state, State::Invalid) {
|
||||
State::Expecting { mut io, protocol } => {
|
||||
State::Expecting { mut io, protocol, version } => {
|
||||
let msg = match io.poll() {
|
||||
Ok(Async::Ready(Some(msg))) => msg,
|
||||
Ok(Async::NotReady) => {
|
||||
self.state = State::Expecting { io, protocol };
|
||||
self.state = State::Expecting { io, protocol, version };
|
||||
return Ok(Async::NotReady)
|
||||
}
|
||||
Ok(Async::Ready(None)) => {
|
||||
self.state = State::Expecting { io, protocol };
|
||||
self.state = State::Expecting { io, protocol, version };
|
||||
return Err(ProtocolError::IoError(
|
||||
io::ErrorKind::UnexpectedEof.into()).into())
|
||||
}
|
||||
Err(err) => {
|
||||
self.state = State::Expecting { io, protocol };
|
||||
self.state = State::Expecting { io, protocol, version };
|
||||
return Err(err.into())
|
||||
}
|
||||
};
|
||||
|
||||
if let Message::Header(Version::V1) = &msg {
|
||||
self.state = State::Expecting { io, protocol };
|
||||
continue
|
||||
if let Message::Header(v) = &msg {
|
||||
if v == &version {
|
||||
self.state = State::Expecting { io, protocol, version };
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if let Message::Protocol(p) = &msg {
|
||||
@@ -152,7 +154,14 @@ impl<TInner> Negotiated<TInner> {
|
||||
enum State<R> {
|
||||
/// In this state, a `Negotiated` is still expecting to
|
||||
/// receive confirmation of the protocol it as settled on.
|
||||
Expecting { io: MessageReader<R>, protocol: Protocol },
|
||||
Expecting {
|
||||
/// The underlying I/O stream.
|
||||
io: MessageReader<R>,
|
||||
/// The expected protocol (i.e. name and version).
|
||||
protocol: Protocol,
|
||||
/// The expected multistream-select protocol version.
|
||||
version: Version
|
||||
},
|
||||
|
||||
/// In this state, a protocol has been agreed upon and may
|
||||
/// only be pending the sending of the final acknowledgement,
|
||||
|
Reference in New Issue
Block a user