Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

[devp2p] Update to 2018 edition #10716

Merged
merged 20 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions util/network-devp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ license = "GPL-3.0"
name = "ethcore-network-devp2p"
version = "1.12.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
log = "0.4"
mio = "0.6.8"
bytes = "0.4"
rand = "0.6"
tiny-keccak = "1.4"
rust-crypto = "0.2.34"
slab = "0.2"
igd = "0.7"
libc = "0.2.7"
Expand All @@ -21,18 +21,17 @@ ansi_term = "0.10"
rustc-hex = "1.0"
ethcore-io = { path = "../io", features = ["mio"] }
parity-bytes = "0.1"
parity-crypto = "0.4.0"
ethcore-network = { path = "../network" }
crypto = { package = "parity-crypto", version = "0.4.0"}
network = { package = "ethcore-network", path = "../network" }
ethereum-types = "0.6.0"
ethkey = { path = "../../accounts/ethkey" }
rlp = "0.4.0"
parity-path = "0.1"
ipnetwork = "0.12.6"
keccak-hash = "0.2.0"
parity-snappy = "0.1"
serde = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_derive = "1.0"
error-chain = { version = "0.12", default-features = false }
lru-cache = "0.1"

Expand Down
44 changes: 21 additions & 23 deletions util/network-devp2p/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
use std::time::Duration;

use bytes::{Buf, BufMut};
use crypto::aes::{AesCtr256, AesEcb256};
use ethereum_types::{H128, H256, H512};
use hash::{keccak, write_keccak};
use keccak_hash::{keccak, write_keccak};
use log::{debug, trace, warn};
use mio::{PollOpt, Ready, Token};
use mio::deprecated::{EventLoop, Handler, TryRead, TryWrite};
use mio::tcp::*;
use parity_bytes::*;
use crypto::aes::{AesCtr256, AesEcb256};
use mio::tcp::TcpStream;
use parity_bytes::Bytes;
use rlp::{Rlp, RlpStream};
use tiny_keccak::Keccak;

use ethkey::{crypto, Secret};
use handshake::Handshake;
use io::{IoContext, StreamToken};
use ethcore_io::{IoContext, StreamToken};
use ethkey::{crypto as ethcrypto, Secret};
use network::Error;

use crate::handshake::Handshake;

const ENCRYPTED_HEADER_LEN: usize = 32;
const RECEIVE_PAYLOAD: Duration = Duration::from_secs(30);
pub const MAX_PAYLOAD_SIZE: usize = (1 << 24) - 1;
Expand Down Expand Up @@ -297,7 +299,7 @@ const NULL_IV : [u8; 16] = [0;16];
impl EncryptedConnection {
/// Create an encrypted connection out of the handshake.
pub fn new(handshake: &mut Handshake) -> Result<EncryptedConnection, Error> {
let shared = crypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_ephemeral)?;
let shared = ethcrypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_ephemeral)?;
let mut nonce_material = H512::default();
if handshake.originated {
(&mut nonce_material[0..32]).copy_from_slice(handshake.remote_nonce.as_bytes());
Expand Down Expand Up @@ -391,13 +393,11 @@ impl EncryptedConnection {
return Err(Error::Auth);
}
EncryptedConnection::update_mac(&mut self.ingress_mac, &self.mac_encoder_key, &header[0..16])?;
{
let mac = &header[16..];
let mut expected = H256::zero();
self.ingress_mac.clone().finalize(expected.as_bytes_mut());
if mac != &expected[0..16] {
return Err(Error::Auth);
}
let mac = &header[16..];
let mut expected = H256::zero();
self.ingress_mac.clone().finalize(expected.as_bytes_mut());
if mac != &expected[0..16] {
return Err(Error::Auth);
}
self.decoder.decrypt(&mut header[..16])?;

Expand Down Expand Up @@ -426,13 +426,11 @@ impl EncryptedConnection {
self.ingress_mac.update(&payload[0..payload.len() - 16]);
EncryptedConnection::update_mac(&mut self.ingress_mac, &self.mac_encoder_key, &[0u8; 0])?;

{
let mac = &payload[(payload.len() - 16)..];
let mut expected = H128::default();
self.ingress_mac.clone().finalize(expected.as_bytes_mut());
if mac != &expected[..] {
return Err(Error::Auth);
}
let mac = &payload[(payload.len() - 16)..];
let mut expected = H128::default();
self.ingress_mac.clone().finalize(expected.as_bytes_mut());
if mac != &expected[..] {
return Err(Error::Auth);
}
self.decoder.decrypt(&mut payload[..self.payload_len + padding])?;
payload.truncate(self.payload_len);
Expand Down Expand Up @@ -496,7 +494,7 @@ mod tests {
use mio::Ready;
use parity_bytes::Bytes;

use io::*;
use ethcore_io::*;

use super::*;

Expand Down
11 changes: 7 additions & 4 deletions util/network-devp2p/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ use std::net::SocketAddr;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use ethereum_types::{H256, H520};
use hash::keccak;
use keccak_hash::keccak;
use log::{debug, trace, warn};
use lru_cache::LruCache;
use parity_bytes::Bytes;
use rlp::{Rlp, RlpStream};

use ethkey::{KeyPair, recover, Secret, sign};
use network::Error;
use network::IpFilter;
use node_table::*;
use PROTOCOL_VERSION;

use crate::node_table::*;
use crate::PROTOCOL_VERSION;

const ADDRESS_BYTES_SIZE: usize = 32; // Size of address type in bytes.
const ADDRESS_BITS: usize = 8 * ADDRESS_BYTES_SIZE; // Denoted by n in [Kademlia].
Expand Down Expand Up @@ -900,7 +902,8 @@ mod tests {
use rustc_hex::FromHex;

use ethkey::{Generator, Random};
use node_table::{Node, NodeEndpoint, NodeId};

use crate::node_table::{Node, NodeEndpoint, NodeId};

use super::*;

Expand Down
28 changes: 15 additions & 13 deletions util/network-devp2p/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
use std::time::Duration;

use ethereum_types::{H256, H520};
use hash::write_keccak;
use keccak_hash::write_keccak;
use log::{debug, trace};
use mio::tcp::*;
use parity_bytes::Bytes;
use rand::random;
use rlp::{Rlp, RlpStream};

use connection::Connection;
use ethcore_io::{IoContext, StreamToken};
use ethkey::{Generator, KeyPair, Public, Random, recover, Secret, sign};
use ethkey::crypto::{ecdh, ecies};
use host::HostInfo;
use io::{IoContext, StreamToken};
use network::Error;
use node_table::NodeId;

use crate::connection::Connection;
use crate::host::HostInfo;
use crate::node_table::NodeId;

#[derive(PartialEq, Eq, Debug)]
enum HandshakeState {
Expand Down Expand Up @@ -320,18 +322,18 @@ impl Handshake {

#[cfg(test)]
mod test {
use std::str::FromStr;
use std::str::FromStr;

use ethereum_types::{H256, H512};
use mio::tcp::TcpStream;
use rustc_hex::FromHex;
use ethereum_types::{H256, H512};
use mio::tcp::TcpStream;
use rustc_hex::FromHex;

use ethkey::Public;
use io::*;
use ethcore_io::*;
use ethkey::Public;

use super::*;
use super::*;

fn check_auth(h: &Handshake, version: u64) {
fn check_auth(h: &Handshake, version: u64) {
assert_eq!(
h.id,
H512::from_str("fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877").unwrap(),
Expand Down
Loading