mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 16:21:39 +00:00
Update the stable-futures branch to master (#1288)
* 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 * Revert CIPHERS set to null (#1273) * Update dependency versions (#1265) * Update versions of many dependencies * Bump version of rand * Updates for changed APIs in rand, ring, and webpki * Replace references to `snow::Session` `Session` no longer exists in `snow` but the replacement is two structs `HandshakeState` and `TransportState` Something will have to be done to harmonize `NoiseOutput.session` * Add precise type for UnparsedPublicKey * Update data structures/functions to match new snow's API * Delete diff.diff Remove accidentally committed diff file * Remove commented lines in identity/rsa.rs * Bump libsecp256k1 to 0.3.1 * Implement /plaintext/2.0.0 (#1236) * WIP * plaintext/2.0.0 * Refactor protobuf related issues to compatible with the spec * Rename: new PlainTextConfig -> PlainText2Config * Keep plaintext/1.0.0 as PlainText1Config * Config contains pubkey * Rename: proposition -> exchange * Add PeerId to Exchange * Check the validity of the remote's `Exchange` * Tweak * Delete unused import * Add debug log * Delete unused field: public_key_encoded * Delete unused field: local * Delete unused field: exchange_bytes * The inner instance should not be public * identity::Publickey::Rsa is not available on wasm * Delete PeerId from Config as it should be generated from the pubkey * Catch up for #1240 * Tweak * Update protocols/plaintext/src/error.rs Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Update protocols/plaintext/src/handshake.rs Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Update protocols/plaintext/src/error.rs Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Update protocols/plaintext/src/error.rs Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com> * Update protocols/plaintext/src/error.rs Co-Authored-By: Roman Borschel <romanb@users.noreply.github.com> * Rename: pubkey -> local_public_key * Delete unused error * Rename: PeerIdValidationFailed -> InvalidPeerId * Fix: HandShake -> Handshake * Use bytes insteadof Publickey to avoid code duplication * Replace with ProtobufError * Merge HandshakeContext<()> into HandshakeContext<Local> * Improve the peer ID validation to simplify the handshake * Propagate Remote to allow extracting the PeerId from the Remote * Collapse the same kind of errors into the variant * [noise]: `sodiumoxide 0.2.5` (#1276) Fixes https://github.com/RustSec/advisory-db/pull/192 * examples/ipfs-kad.rs: Remove outdated reference to `without_init` (#1280) * CircleCI Test Fix (#1282) * Disabling "Docker Layer Caching" because it breaks one of the circleci checks * Bump to trigger CircleCI build * unbump * zeroize: Upgrade to v1.0 (#1284) v1.0 final release is out. Release notes: https://github.com/iqlusioninc/crates/pull/279 * *: Consolidate protobuf scripts and update to rust-protobuf 2.8.1 (#1275) * *: Consolidate protobuf generation scripts * *: Update to rust-protobuf 2.8.1 * *: Mark protobuf generated modules with '_proto' * examples: Add distributed key value store (#1281) * examples: Add distributed key value store This commit adds a basic distributed key value store supporting GET and PUT commands using Kademlia and mDNS. * examples/distributed-key-value-store: Fix typo * Simple Warning Cleanup (#1278) * Cleaning up warnings - removing unused `use` * Cleaning up warnings - unused tuple value * Cleaning up warnings - removing dead code * Cleaning up warnings - fixing deprecated name * Cleaning up warnings - removing dead code * Revert "Cleaning up warnings - removing dead code" This reverts commit f18a765e4bf240b0ed9294ec3ae5dab5c186b801. * Enable the std feature of ring (#1289)
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use libp2p_core::identity;
|
||||
use snow::SnowError;
|
||||
use snow::error::Error as SnowError;
|
||||
use std::{error::Error, fmt, io};
|
||||
|
||||
/// libp2p_noise error type.
|
||||
|
@ -55,12 +55,48 @@ impl Buffer {
|
||||
}
|
||||
}
|
||||
|
||||
/// A passthrough enum for the two kinds of state machines in `snow`
|
||||
pub(crate) enum SnowState {
|
||||
Transport(snow::TransportState),
|
||||
Handshake(snow::HandshakeState)
|
||||
}
|
||||
|
||||
impl SnowState {
|
||||
pub fn read_message(&mut self, message: &[u8], payload: &mut [u8]) -> Result<usize, SnowError> {
|
||||
match self {
|
||||
SnowState::Handshake(session) => session.read_message(message, payload),
|
||||
SnowState::Transport(session) => session.read_message(message, payload),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_message(&mut self, message: &[u8], payload: &mut [u8]) -> Result<usize, SnowError> {
|
||||
match self {
|
||||
SnowState::Handshake(session) => session.write_message(message, payload),
|
||||
SnowState::Transport(session) => session.write_message(message, payload),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_remote_static(&self) -> Option<&[u8]> {
|
||||
match self {
|
||||
SnowState::Handshake(session) => session.get_remote_static(),
|
||||
SnowState::Transport(session) => session.get_remote_static(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_transport_mode(self) -> Result<snow::TransportState, SnowError> {
|
||||
match self {
|
||||
SnowState::Handshake(session) => session.into_transport_mode(),
|
||||
SnowState::Transport(_) => Err(SnowError::State(StateProblem::HandshakeAlreadyFinished)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A noise session to a remote.
|
||||
///
|
||||
/// `T` is the type of the underlying I/O resource.
|
||||
pub struct NoiseOutput<T> {
|
||||
io: T,
|
||||
session: snow::Session,
|
||||
session: SnowState,
|
||||
buffer: Buffer,
|
||||
read_state: ReadState,
|
||||
write_state: WriteState
|
||||
@ -76,9 +112,10 @@ impl<T> fmt::Debug for NoiseOutput<T> {
|
||||
}
|
||||
|
||||
impl<T> NoiseOutput<T> {
|
||||
fn new(io: T, session: snow::Session) -> Self {
|
||||
fn new(io: T, session: SnowState) -> Self {
|
||||
NoiseOutput {
|
||||
io, session,
|
||||
io,
|
||||
session,
|
||||
buffer: Buffer { inner: Box::new([0; TOTAL_BUFFER_LEN]) },
|
||||
read_state: ReadState::Init,
|
||||
write_state: WriteState::Init
|
||||
|
@ -20,10 +20,11 @@
|
||||
|
||||
//! Noise protocol handshake I/O.
|
||||
|
||||
mod payload;
|
||||
mod payload_proto;
|
||||
|
||||
use crate::error::NoiseError;
|
||||
use crate::protocol::{Protocol, PublicKey, KeypairIdentity};
|
||||
use crate::io::SnowState;
|
||||
use libp2p_core::identity;
|
||||
use futures::prelude::*;
|
||||
use futures::task;
|
||||
@ -271,7 +272,7 @@ impl<T> State<T> {
|
||||
/// Noise handshake pattern.
|
||||
fn new(
|
||||
io: T,
|
||||
session: Result<snow::Session, NoiseError>,
|
||||
session: Result<snow::HandshakeState, NoiseError>,
|
||||
identity: KeypairIdentity,
|
||||
identity_x: IdentityExchange
|
||||
) -> Result<Self, NoiseError> {
|
||||
@ -284,7 +285,7 @@ impl<T> State<T> {
|
||||
session.map(|s|
|
||||
State {
|
||||
identity,
|
||||
io: NoiseOutput::new(io, s),
|
||||
io: NoiseOutput::new(io, SnowState::Handshake(s)),
|
||||
dh_remote_pubkey_sig: None,
|
||||
id_remote_pubkey,
|
||||
send_identity
|
||||
@ -322,7 +323,7 @@ impl<T> State<T>
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok((remote, NoiseOutput { session: s, .. self.io }))
|
||||
Ok((remote, NoiseOutput { session: SnowState::Transport(s), .. self.io }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
// This file is generated by rust-protobuf 2.3.0. Do not edit
|
||||
// This file is generated by rust-protobuf 2.8.1. Do not edit
|
||||
// @generated
|
||||
|
||||
// https://github.com/Manishearth/rust-clippy/issues/702
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(clippy)]
|
||||
#![allow(clippy::all)]
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
@ -17,10 +17,15 @@
|
||||
#![allow(unsafe_code)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(unused_results)]
|
||||
//! Generated file from `src/io/handshake/payload.proto`
|
||||
|
||||
use protobuf::Message as Message_imported_for_functions;
|
||||
use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;
|
||||
|
||||
/// Generated files are compatible only with the same version
|
||||
/// of protobuf runtime.
|
||||
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_1;
|
||||
|
||||
#[derive(PartialEq,Clone,Default)]
|
||||
pub struct Identity {
|
||||
// message fields
|
||||
@ -31,6 +36,12 @@ pub struct Identity {
|
||||
pub cached_size: ::protobuf::CachedSize,
|
||||
}
|
||||
|
||||
impl<'a> ::std::default::Default for &'a Identity {
|
||||
fn default() -> &'a Identity {
|
||||
<Identity as ::protobuf::Message>::default_instance()
|
||||
}
|
||||
}
|
||||
|
||||
impl Identity {
|
||||
pub fn new() -> Identity {
|
||||
::std::default::Default::default()
|
||||
@ -38,6 +49,10 @@ impl Identity {
|
||||
|
||||
// bytes pubkey = 1;
|
||||
|
||||
|
||||
pub fn get_pubkey(&self) -> &[u8] {
|
||||
&self.pubkey
|
||||
}
|
||||
pub fn clear_pubkey(&mut self) {
|
||||
self.pubkey.clear();
|
||||
}
|
||||
@ -58,12 +73,12 @@ impl Identity {
|
||||
::std::mem::replace(&mut self.pubkey, ::std::vec::Vec::new())
|
||||
}
|
||||
|
||||
pub fn get_pubkey(&self) -> &[u8] {
|
||||
&self.pubkey
|
||||
}
|
||||
|
||||
// bytes signature = 2;
|
||||
|
||||
|
||||
pub fn get_signature(&self) -> &[u8] {
|
||||
&self.signature
|
||||
}
|
||||
pub fn clear_signature(&mut self) {
|
||||
self.signature.clear();
|
||||
}
|
||||
@ -83,10 +98,6 @@ impl Identity {
|
||||
pub fn take_signature(&mut self) -> ::std::vec::Vec<u8> {
|
||||
::std::mem::replace(&mut self.signature, ::std::vec::Vec::new())
|
||||
}
|
||||
|
||||
pub fn get_signature(&self) -> &[u8] {
|
||||
&self.signature
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Message for Identity {
|
||||
@ -94,7 +105,7 @@ impl ::protobuf::Message for Identity {
|
||||
true
|
||||
}
|
||||
|
||||
fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> {
|
||||
fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
while !is.eof()? {
|
||||
let (field_number, wire_type) = is.read_tag_unpack()?;
|
||||
match field_number {
|
||||
@ -127,7 +138,7 @@ impl ::protobuf::Message for Identity {
|
||||
my_size
|
||||
}
|
||||
|
||||
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> {
|
||||
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
if !self.pubkey.is_empty() {
|
||||
os.write_bytes(1, &self.pubkey)?;
|
||||
}
|
||||
@ -150,13 +161,13 @@ impl ::protobuf::Message for Identity {
|
||||
&mut self.unknown_fields
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &::std::any::Any {
|
||||
self as &::std::any::Any
|
||||
fn as_any(&self) -> &dyn (::std::any::Any) {
|
||||
self as &dyn (::std::any::Any)
|
||||
}
|
||||
fn as_any_mut(&mut self) -> &mut ::std::any::Any {
|
||||
self as &mut ::std::any::Any
|
||||
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
|
||||
self as &mut dyn (::std::any::Any)
|
||||
}
|
||||
fn into_any(self: Box<Self>) -> ::std::boxed::Box<::std::any::Any> {
|
||||
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
|
||||
self
|
||||
}
|
||||
|
||||
@ -208,14 +219,14 @@ impl ::protobuf::Message for Identity {
|
||||
|
||||
impl ::protobuf::Clear for Identity {
|
||||
fn clear(&mut self) {
|
||||
self.clear_pubkey();
|
||||
self.clear_signature();
|
||||
self.pubkey.clear();
|
||||
self.signature.clear();
|
||||
self.unknown_fields.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for Identity {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||
::protobuf::text_format::fmt(self, f)
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ pub mod x25519;
|
||||
|
||||
use crate::NoiseError;
|
||||
use libp2p_core::identity;
|
||||
use rand::FromEntropy;
|
||||
use rand::SeedableRng;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
/// The parameters of a Noise protocol, consisting of a choice
|
||||
|
Reference in New Issue
Block a user