Add InventoryType, InventoryVector, and Message::{Inventory, GetData, NotFound}
This commit is contained in:
parent
7fb71a7a9e
commit
a2e50833be
|
@ -2,3 +2,35 @@
|
||||||
|
|
||||||
/// A u32 which represents a block height value.
|
/// A u32 which represents a block height value.
|
||||||
pub struct BlockHeight(pub u32);
|
pub struct BlockHeight(pub u32);
|
||||||
|
|
||||||
|
/// InventoryType
|
||||||
|
///
|
||||||
|
/// [Bitcoin·reference](https://en.bitcoin.it/wiki/Protocol_documentation#Inventory_Vectors)
|
||||||
|
pub enum InventoryType {
|
||||||
|
/// Any data of with this number may be ignored.
|
||||||
|
Error = 0x00,
|
||||||
|
|
||||||
|
/// Hash is related to a transaction.
|
||||||
|
MsgTx = 0x01,
|
||||||
|
|
||||||
|
/// Hash is related to a data block.
|
||||||
|
MsgBlock = 0x02,
|
||||||
|
|
||||||
|
/// Hash of a block header, but only to be used in getdata
|
||||||
|
/// message. Indicates the reply should be a merkleblock message
|
||||||
|
/// rather than a block message; this only works if a bloom filter
|
||||||
|
/// has been set.
|
||||||
|
// XXX: Since we don't intend to include the bloom filter to
|
||||||
|
// start, do we need this?
|
||||||
|
MsgFilteredBlock = 0x03,
|
||||||
|
|
||||||
|
/// Hash of a block header, but only to be used in getdata
|
||||||
|
/// message. Indicates the reply should be a cmpctblock
|
||||||
|
/// message. See
|
||||||
|
/// [BIP-152](https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki)
|
||||||
|
/// for more info.
|
||||||
|
MsgCmpctBlock = 0x04,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inventory Vector
|
||||||
|
pub struct InventoryVector(pub InventoryType, pub [u8; 32]);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Definitions of network messages.
|
//! Definitions of network messages.
|
||||||
|
|
||||||
use std::net::{SocketAddr};
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ pub enum Message {
|
||||||
///
|
///
|
||||||
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#version)
|
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#version)
|
||||||
Version {
|
Version {
|
||||||
|
|
||||||
/// The network version number supported by the sender.
|
/// The network version number supported by the sender.
|
||||||
version: Version,
|
version: Version,
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ pub enum Message {
|
||||||
|
|
||||||
/// Whether the remote peer should announce relayed
|
/// Whether the remote peer should announce relayed
|
||||||
/// transactions or not, see [BIP 0037](https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki)
|
/// transactions or not, see [BIP 0037](https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki)
|
||||||
relay: bool
|
relay: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A `verack` message.
|
/// A `verack` message.
|
||||||
|
@ -91,7 +90,6 @@ pub enum Message {
|
||||||
///
|
///
|
||||||
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#reject)
|
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#reject)
|
||||||
Reject {
|
Reject {
|
||||||
|
|
||||||
/// Type of message rejected.
|
/// Type of message rejected.
|
||||||
// Q: can we just reference the Type, rather than instantiate an instance of the enum type?
|
// Q: can we just reference the Type, rather than instantiate an instance of the enum type?
|
||||||
message: Box<Message>,
|
message: Box<Message>,
|
||||||
|
@ -109,13 +107,25 @@ pub enum Message {
|
||||||
//
|
//
|
||||||
// Q: can we tell Rust that this field is optional? Or just
|
// Q: can we tell Rust that this field is optional? Or just
|
||||||
// default its value to an empty array, I guess.
|
// default its value to an empty array, I guess.
|
||||||
data: [u8; 32]
|
data: [u8; 32],
|
||||||
},
|
},
|
||||||
|
|
||||||
/// An `addr` message.
|
/// An `addr` message.
|
||||||
///
|
///
|
||||||
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#addr)
|
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#addr)
|
||||||
Addr {/* XXX add fields */},
|
Addr {
|
||||||
|
/// Number of address entries (max: 1000)
|
||||||
|
count: u16,
|
||||||
|
|
||||||
|
/// Address of other nodes on the network, preceeded by a timestamp.
|
||||||
|
// Starting version 31402, addresses are prefixed with a
|
||||||
|
// timestamp. If no timestamp is present, the addresses should
|
||||||
|
// not be relayed to other peers, unless it is indeed
|
||||||
|
// confirmed they are up.
|
||||||
|
//
|
||||||
|
// XXX: I don't know how this serializes.
|
||||||
|
address_list: (Timestamp, Vec<NetworkAddress>),
|
||||||
|
},
|
||||||
|
|
||||||
/// A `getaddr` message.
|
/// A `getaddr` message.
|
||||||
///
|
///
|
||||||
|
@ -148,17 +158,40 @@ pub enum Message {
|
||||||
// XXX the bitcoin reference above suggests this can be 1.8 MB in bitcoin -- maybe
|
// XXX the bitcoin reference above suggests this can be 1.8 MB in bitcoin -- maybe
|
||||||
// larger in Zcash, since Zcash objects could be bigger (?) -- does this tilt towards
|
// larger in Zcash, since Zcash objects could be bigger (?) -- does this tilt towards
|
||||||
// having serialization be async?
|
// having serialization be async?
|
||||||
Inventory {/* XXX add fields */},
|
Inventory {
|
||||||
|
/// Number of inventory entries.
|
||||||
|
count: u64,
|
||||||
|
|
||||||
|
/// Inventory vectors.
|
||||||
|
inventory: Vec<zebra_chain::types::InventoryVector>,
|
||||||
|
},
|
||||||
|
|
||||||
/// A `getdata` message.
|
/// A `getdata` message.
|
||||||
///
|
///
|
||||||
|
/// `getdata` is used in response to `inv`, to retrieve the content of
|
||||||
|
/// a specific object, and is usually sent after receiving an `inv`
|
||||||
|
/// packet, after filtering known elements.
|
||||||
|
///
|
||||||
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#getdata)
|
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#getdata)
|
||||||
GetData {/* XXX add fields */},
|
GetData {
|
||||||
|
/// Number of inventory entries.
|
||||||
|
count: u64,
|
||||||
|
|
||||||
|
/// Inventory vectors.
|
||||||
|
inventory: Vec<zebra_chain::types::InventoryVector>,
|
||||||
|
},
|
||||||
|
|
||||||
/// A `notfound` message.
|
/// A `notfound` message.
|
||||||
///
|
///
|
||||||
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#notfound)
|
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#notfound)
|
||||||
NotFound {/* XXX add fields */},
|
// See note above on `Inventory`.
|
||||||
|
NotFound {
|
||||||
|
/// Number of inventory entries.
|
||||||
|
count: u64,
|
||||||
|
|
||||||
|
/// Inventory vectors.
|
||||||
|
inventory: Vec<zebra_chain::types::InventoryVector>,
|
||||||
|
},
|
||||||
|
|
||||||
/// A `tx` message.
|
/// A `tx` message.
|
||||||
///
|
///
|
||||||
|
@ -230,7 +263,9 @@ pub struct NetworkAddress(pub Services, pub SocketAddr);
|
||||||
/// A nonce used in the networking layer to identify messages.
|
/// A nonce used in the networking layer to identify messages.
|
||||||
pub struct Nonce(pub u64);
|
pub struct Nonce(pub u64);
|
||||||
|
|
||||||
|
/// Reject Reason CCodes
|
||||||
|
///
|
||||||
|
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#reject)
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub enum RejectReason {
|
pub enum RejectReason {
|
||||||
|
@ -241,5 +276,5 @@ pub enum RejectReason {
|
||||||
Nonstandard = 0x40,
|
Nonstandard = 0x40,
|
||||||
Dust = 0x41,
|
Dust = 0x41,
|
||||||
InsufficientFee = 0x42,
|
InsufficientFee = 0x42,
|
||||||
Checkpoint = 0x43
|
Checkpoint = 0x43,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue