diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs new file mode 100644 index 000000000..6fca28c4e --- /dev/null +++ b/zebra-chain/src/block.rs @@ -0,0 +1,6 @@ +//! Definitions of block datastructures. + +/// A block in your blockchain. +pub struct Block {} + +impl Block {} diff --git a/zebra-chain/src/lib.rs b/zebra-chain/src/lib.rs index 31e1bb209..2dde7819b 100644 --- a/zebra-chain/src/lib.rs +++ b/zebra-chain/src/lib.rs @@ -1,7 +1,5 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} +//! Blockchain-related datastructures for Zebra. 🦓 +#![deny(missing_docs)] + +pub mod block; +pub mod types; diff --git a/zebra-chain/src/types.rs b/zebra-chain/src/types.rs new file mode 100644 index 000000000..f10829087 --- /dev/null +++ b/zebra-chain/src/types.rs @@ -0,0 +1,4 @@ +//! Newtype wrappers for primitive data types with semantic meaning. + +/// A u32 which represents a block height value. +pub struct BlockHeight(pub u32); diff --git a/zebra-network/Cargo.toml b/zebra-network/Cargo.toml index 6e3a55892..e0c56d0ab 100644 --- a/zebra-network/Cargo.toml +++ b/zebra-network/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +zebra-chain = { path = "../zebra-chain" } diff --git a/zebra-network/src/lib.rs b/zebra-network/src/lib.rs index eef182440..e833d631d 100644 --- a/zebra-network/src/lib.rs +++ b/zebra-network/src/lib.rs @@ -1,5 +1,5 @@ -//! Networking code for Zebra. +//! Networking code for Zebra. 🦓 -#[deny(missing_docs)] +#![deny(missing_docs)] -pub mod message; \ No newline at end of file +pub mod message; diff --git a/zebra-network/src/message.rs b/zebra-network/src/message.rs index eff675d38..950ed0148 100644 --- a/zebra-network/src/message.rs +++ b/zebra-network/src/message.rs @@ -1,5 +1,9 @@ //! Definitions of network messages. +use std::net::{SocketAddr}; + +use zebra_chain; + /// A Bitcoin-like network message for the Zcash protocol. /// /// The Zcash network protocol is mostly inherited from Bitcoin, and a list of @@ -25,8 +29,25 @@ pub enum Message { /// A `version` message. /// + /// Note that although this is called `version` in Bitcoin, its role is really + /// analogous to a `ClientHello` message in TLS, used to begin a handshake, and + /// is distinct from a simple version number. + /// /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#version) - Version {/* XXX add fields */}, + Version { + /// The network version number supported by the sender. + version: Version, + /// The network services advertised by the sender. + services: Services, + /// The time when the version message was sent. + timestamp: Timestamp, + address_receiving: NetworkAddress, + address_from: NetworkAddress, + nonce: Nonce, + user_agent: String, + start_height: zebra_chain::types::BlockHeight, + relay: bool + }, /// A `verack` message. /// @@ -36,18 +57,15 @@ pub enum Message { /// A `ping` message. /// /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#ping) - Ping { - /// A random nonce. - nonce: u64, - }, + Ping(Nonce), /// A `pong` message. /// /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#pong) - Pong { + Pong( /// The nonce from the `Ping` message this was in response to. - nonce: u64, - }, + Nonce, + ), /// A `reject` message. /// @@ -151,3 +169,17 @@ 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); + +// Tower provides utilities for service discovery, so this might go +// away in the future in favor of that. +pub struct Services(pub u64); + +pub struct Timestamp(pub i64); + +pub struct NetworkAddress(pub Services, pub SocketAddr); + +/// A nonce used in the networking layer to identify messages. +pub struct Nonce(pub u64);