WIP: Version message and various sub structures

Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
This commit is contained in:
Deirdre Connolly 2019-09-10 16:27:10 -04:00 committed by Deirdre Connolly
parent 8c2b066885
commit ac0d9732a0
6 changed files with 59 additions and 18 deletions

6
zebra-chain/src/block.rs Normal file
View File

@ -0,0 +1,6 @@
//! Definitions of block datastructures.
/// A block in your blockchain.
pub struct Block {}
impl Block {}

View File

@ -1,7 +1,5 @@
#[cfg(test)] //! Blockchain-related datastructures for Zebra. 🦓
mod tests { #![deny(missing_docs)]
#[test]
fn it_works() { pub mod block;
assert_eq!(2 + 2, 4); pub mod types;
}
}

4
zebra-chain/src/types.rs Normal file
View File

@ -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);

View File

@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
zebra-chain = { path = "../zebra-chain" }

View File

@ -1,5 +1,5 @@
//! Networking code for Zebra. //! Networking code for Zebra. 🦓
#[deny(missing_docs)] #![deny(missing_docs)]
pub mod message; pub mod message;

View File

@ -1,5 +1,9 @@
//! Definitions of network messages. //! Definitions of network messages.
use std::net::{SocketAddr};
use zebra_chain;
/// A Bitcoin-like network message for the Zcash protocol. /// A Bitcoin-like network message for the Zcash protocol.
/// ///
/// The Zcash network protocol is mostly inherited from Bitcoin, and a list of /// The Zcash network protocol is mostly inherited from Bitcoin, and a list of
@ -25,8 +29,25 @@
pub enum Message { pub enum Message {
/// A `version` 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) /// [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. /// A `verack` message.
/// ///
@ -36,18 +57,15 @@ pub enum Message {
/// A `ping` message. /// A `ping` message.
/// ///
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#ping) /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#ping)
Ping { Ping(Nonce),
/// A random nonce.
nonce: u64,
},
/// A `pong` message. /// A `pong` message.
/// ///
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#pong) /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#pong)
Pong { Pong(
/// The nonce from the `Ping` message this was in response to. /// The nonce from the `Ping` message this was in response to.
nonce: u64, Nonce,
}, ),
/// A `reject` message. /// A `reject` message.
/// ///
@ -151,3 +169,17 @@ pub enum Message {
// Q: how do we want to implement serialization, exactly? do we want to have // 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 // something generic over stdlib Read and Write traits, or over async versions
// of those traits? // 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);