From 1d0517fe56081d6f6495d41598fd0ee0e8c0c400 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Thu, 12 Sep 2019 03:23:51 -0700 Subject: [PATCH] Split parts of message.rs into constants.rs, types.rs --- zebra-network/src/constants.rs | 6 ++++++ zebra-network/src/lib.rs | 2 ++ zebra-network/src/message.rs | 26 +++++--------------------- zebra-network/src/types.rs | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 zebra-network/src/constants.rs create mode 100644 zebra-network/src/types.rs diff --git a/zebra-network/src/constants.rs b/zebra-network/src/constants.rs new file mode 100644 index 00000000..ce97177e --- /dev/null +++ b/zebra-network/src/constants.rs @@ -0,0 +1,6 @@ +//! Definitions of constants. + +use crate::types::*; + +/// The Zcash version used on mainnet. +pub const ZCASH_VERSION: Version = Version(170_007); diff --git a/zebra-network/src/lib.rs b/zebra-network/src/lib.rs index e833d631..cb9c8baf 100644 --- a/zebra-network/src/lib.rs +++ b/zebra-network/src/lib.rs @@ -3,3 +3,5 @@ #![deny(missing_docs)] pub mod message; +pub mod types; +mod constants; diff --git a/zebra-network/src/message.rs b/zebra-network/src/message.rs index 15342976..46f5e560 100644 --- a/zebra-network/src/message.rs +++ b/zebra-network/src/message.rs @@ -4,7 +4,7 @@ use std::net::SocketAddr; use chrono::{DateTime, Utc}; -use zebra_chain; +use crate::types::*; /// A Bitcoin-like network message for the Zcash protocol. /// @@ -242,26 +242,10 @@ pub enum Message { // Q: how do we want to implement serialization, exactly? do we want to have // something generic over stdlib Read and Write traits, or over async versions // of those traits? - -/// A protocol version magic number. -pub struct Version(pub u32); - -/// Bitfield of features to be enabled for this connection. -// Tower provides utilities for service discovery, so this might go -// away in the future in favor of that. -pub struct Services(pub u64); - -/// A network address but with some extra flavor. -/// -/// When a network address is needed somewhere, this structure is -/// used. Network addresses are not prefixed with a timestamp in the -/// version message. -/// -/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#Network_address) -pub struct NetworkAddress(pub Services, pub SocketAddr); - -/// A nonce used in the networking layer to identify messages. -pub struct Nonce(pub u64); +// +// Note: because of the way the message structure is defined (checksum comes +// first) we can't write the message headers before collecting the whole body +// into a buffer /// Reject Reason CCodes /// diff --git a/zebra-network/src/types.rs b/zebra-network/src/types.rs new file mode 100644 index 00000000..855c173e --- /dev/null +++ b/zebra-network/src/types.rs @@ -0,0 +1,24 @@ +//! Newtype wrappers assigning semantic meaning to primitive types. + +use std::net::SocketAddr; + +/// A protocol version magic number. +pub struct Version(pub u32); + +/// Bitfield of features to be enabled for this connection. +// Tower provides utilities for service discovery, so this might go +// away in the future in favor of that. +pub struct Services(pub u64); + +/// A nonce used in the networking layer to identify messages. +pub struct Nonce(pub u64); + +/// A network address but with some extra flavor. +/// +/// When a network address is needed somewhere, this structure is +/// used. Network addresses are not prefixed with a timestamp in the +/// version message. +/// +/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#Network_address) +// XXX this doesn't quite fit here +pub struct NetworkAddress(pub Services, pub SocketAddr);