diff --git a/src/lib.rs b/src/lib.rs index fbfe9213f..12b0e4175 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -178,6 +178,7 @@ pub mod toxcore_tests { pub mod toxcore { #[macro_use] pub mod binary_io; + pub mod binary_io_new; pub mod crypto_core; pub mod dht; pub mod dht_node; diff --git a/src/toxcore/dht_new/binary_io.rs b/src/toxcore/binary_io_new.rs similarity index 95% rename from src/toxcore/dht_new/binary_io.rs rename to src/toxcore/binary_io_new.rs index 5b47799eb..03e340e94 100644 --- a/src/toxcore/dht_new/binary_io.rs +++ b/src/toxcore/binary_io_new.rs @@ -19,12 +19,11 @@ along with Tox. If not, see . */ -/*! Encoding/decoding traits for TCP mod +/*! Encoding/decoding traits */ -// FIXME: merge with toxcore/binary_io.rs - use toxcore::crypto_core::*; + pub use nom::IResult; pub use cookie_factory::GenError; diff --git a/src/toxcore/dht_new/mod.rs b/src/toxcore/dht_new/mod.rs index d61203df7..e93a7e2fc 100644 --- a/src/toxcore/dht_new/mod.rs +++ b/src/toxcore/dht_new/mod.rs @@ -24,6 +24,5 @@ */ pub mod packet; -pub mod binary_io; pub mod kbucket; pub mod packed_node; diff --git a/src/toxcore/dht_new/packed_node.rs b/src/toxcore/dht_new/packed_node.rs index e29a639d3..e3cf54fdc 100644 --- a/src/toxcore/dht_new/packed_node.rs +++ b/src/toxcore/dht_new/packed_node.rs @@ -33,7 +33,7 @@ use std::net::{ SocketAddr, }; -use toxcore::dht_new::binary_io::*; +use toxcore::binary_io_new::*; use toxcore::crypto_core::*; /** `PackedNode` format is a way to store the node info in a small yet easy to diff --git a/src/toxcore/dht_new/packet.rs b/src/toxcore/dht_new/packet.rs index cf9aa4f4d..65a543a81 100644 --- a/src/toxcore/dht_new/packet.rs +++ b/src/toxcore/dht_new/packet.rs @@ -45,7 +45,7 @@ use std::net::{ Ipv6Addr, }; -use toxcore::dht_new::binary_io::*; +use toxcore::binary_io_new::*; use toxcore::crypto_core::*; use toxcore::dht_new::packed_node::PackedNode; diff --git a/src/toxcore/tcp/binary_io.rs b/src/toxcore/tcp/binary_io.rs deleted file mode 100644 index 63311fd66..000000000 --- a/src/toxcore/tcp/binary_io.rs +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (C) 2013 Tox project All Rights Reserved. - Copyright © 2017 Zetok Zalbavar - Copyright © 2017 Roman Proskuryakov - - This file is part of Tox. - - Tox is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Tox is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Tox. If not, see . -*/ - -/*! Encoding/decoding traits for TCP mod -*/ - -// FIXME: merge with toxcore/binary_io.rs - -use toxcore::crypto_core::*; - -pub use nom::IResult; -pub use cookie_factory::GenError; - -/// The trait provides method to deserialize struct from raw bytes -pub trait FromBytes : Sized { - /// Deserialize struct using `nom` from raw bytes - fn from_bytes(i: &[u8]) -> IResult<&[u8], Self>; -} - -/// The trait provides method to serialize struct into raw bytes -pub trait ToBytes : Sized { - /// Serialize struct into raw bytes using `cookie_factory` - fn to_bytes<'a>(&self, buf: (&'a mut [u8], usize)) -> Result<(&'a mut [u8], usize), GenError>; -} - -impl FromBytes for PublicKey { - named!(from_bytes, map_opt!(take!(PUBLICKEYBYTES), PublicKey::from_slice)); -} - -impl FromBytes for Nonce { - named!(from_bytes, map_opt!(take!(NONCEBYTES), Nonce::from_slice)); -} diff --git a/src/toxcore/tcp/codec.rs b/src/toxcore/tcp/codec.rs index 857f2c1e9..422d7f863 100644 --- a/src/toxcore/tcp/codec.rs +++ b/src/toxcore/tcp/codec.rs @@ -22,9 +22,9 @@ /*! Codec implementation for encoding/decoding TCP Packets in terms of tokio-io */ +use toxcore::binary_io_new::*; use toxcore::tcp::packet::*; use toxcore::tcp::secure::*; -use toxcore::tcp::binary_io::*; use nom::Offset; use std::io::{Error, ErrorKind}; diff --git a/src/toxcore/tcp/handshake/codec.rs b/src/toxcore/tcp/handshake/codec.rs index f678dd407..403de5e6d 100644 --- a/src/toxcore/tcp/handshake/codec.rs +++ b/src/toxcore/tcp/handshake/codec.rs @@ -23,8 +23,8 @@ */ +use toxcore::binary_io_new::*; use toxcore::tcp::handshake::packet::*; -use toxcore::tcp::binary_io::*; use nom::Offset; use bytes::BytesMut; diff --git a/src/toxcore/tcp/handshake/packet.rs b/src/toxcore/tcp/handshake/packet.rs index 71bdde441..d55833787 100644 --- a/src/toxcore/tcp/handshake/packet.rs +++ b/src/toxcore/tcp/handshake/packet.rs @@ -24,8 +24,8 @@ handshake using [`diagram`](https://zetok.github.io/tox-spec/#handshake-diagram) */ +use toxcore::binary_io_new::*; use toxcore::crypto_core::*; -use toxcore::tcp::binary_io::*; /** The request of the client to create a TCP handshake. diff --git a/src/toxcore/tcp/mod.rs b/src/toxcore/tcp/mod.rs index 8d2762cf7..2e47163ae 100644 --- a/src/toxcore/tcp/mod.rs +++ b/src/toxcore/tcp/mod.rs @@ -23,9 +23,9 @@ */ +use toxcore::binary_io_new::*; use toxcore::crypto_core::*; -pub mod binary_io; pub mod handshake; pub mod secure; pub mod packet; @@ -33,7 +33,6 @@ pub mod codec; pub mod server; use self::handshake::*; -use self::binary_io::*; use futures::{self, Stream, Sink, Future}; use std::io::{Error, ErrorKind}; diff --git a/src/toxcore/tcp/packet.rs b/src/toxcore/tcp/packet.rs index 954446518..398732abf 100644 --- a/src/toxcore/tcp/packet.rs +++ b/src/toxcore/tcp/packet.rs @@ -23,8 +23,8 @@ to [Tox spec](https://zetok.github.io/tox-spec/#encrypted-payload-types) */ +use toxcore::binary_io_new::*; use toxcore::crypto_core::*; -use toxcore::tcp::binary_io::*; use nom::{be_u8, be_u16, be_u64, rest};