[][src]Enum zebra_network::protocol::external::message::Message

pub enum Message {
    Version {
        version: Version,
        services: PeerServices,
        timestamp: DateTime<Utc>,
        address_recv: (PeerServices, SocketAddr),
        address_from: (PeerServices, SocketAddr),
        nonce: Nonce,
        user_agent: String,
        start_height: BlockHeight,
        relay: bool,
    },
    Verack,
    Ping(Nonce),
    Pong(Nonce),
    Reject {
        message: String,
        ccode: RejectReason,
        reason: String,
        data: Option<[u8; 32]>,
    },
    Addr(Vec<MetaAddr>),
    GetAddr,
    Block(Box<Block>),
    GetBlocks {
        block_locator_hashes: Vec<BlockHeaderHash>,
        hash_stop: BlockHeaderHash,
    },
    Headers(Vec<BlockHeader>),
    GetHeaders {
        block_locator_hashes: Vec<BlockHeaderHash>,
        hash_stop: BlockHeaderHash,
    },
    Inv(Vec<InventoryHash>),
    GetData(Vec<InventoryHash>),
    NotFound(Vec<InventoryHash>),
    Tx(Box<Transaction>),
    Mempool,
    FilterLoad {
        filter: Filter,
        hash_functions_count: u32,
        tweak: Tweak,
        flags: u8,
    },
    FilterAdd {
        data: Vec<u8>,
    },
    FilterClear,
}

A Bitcoin-like network message for the Zcash protocol.

The Zcash network protocol is mostly inherited from Bitcoin, and a list of Bitcoin network messages can be found on the Bitcoin wiki.

That page describes the wire format of the messages, while this enum stores an internal representation. The internal representation is unlinked from the wire format, and the translation between the two happens only during serialization and deserialization. For instance, Bitcoin identifies messages by a 12-byte ascii command string; we consider this a serialization detail and use the enum discriminant instead. (As a side benefit, this also means that we have a clearly-defined validation boundary for network messages during serialization).

Variants

Version

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

Fields of Version

version: Version

The network version number supported by the sender.

services: PeerServices

The network services advertised by the sender.

timestamp: DateTime<Utc>

The time when the version message was sent.

address_recv: (PeerServices, SocketAddr)

The network address of the node receiving this message, and its advertised network services.

Q: how does the handshake know the remote peer's services already?

address_from: (PeerServices, SocketAddr)

The network address of the node sending this message, and its advertised network services.

nonce: Nonce

Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.

user_agent: String

The Zcash user agent advertised by the sender.

start_height: BlockHeight

The last block received by the emitting node.

relay: bool

Whether the remote peer should announce relayed transactions or not, see BIP 0037

Verack

A verack message.

Bitcoin reference

Ping(Nonce)

A ping message.

Bitcoin reference

Pong(Nonce)

A pong message.

Bitcoin reference

Reject

A reject message.

Bitcoin reference

Fields of Reject

message: String

Type of message rejected.

ccode: RejectReason

RejectReason code relating to rejected message.

reason: String

Human-readable version of rejection reason.

data: Option<[u8; 32]>

Optional extra data provided for some errors.

Addr(Vec<MetaAddr>)

An addr message.

Bitcoin reference

GetAddr

A getaddr message.

Bitcoin reference

Block(Box<Block>)

A block message.

Bitcoin reference

GetBlocks

A getblocks message.

Requests the list of blocks starting right after the last known hash in block_locator_hashes, up to hash_stop or 500 blocks, whichever comes first.

You can send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller's main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.

Bitcoin reference

Fields of GetBlocks

block_locator_hashes: Vec<BlockHeaderHash>

Block locators, from newest back to genesis block.

hash_stop: BlockHeaderHash

BlockHeaderHash of the last desired block.

Set to zero to get as many blocks as possible (500).

Headers(Vec<BlockHeader>)

A headers message.

Returns block headers in response to a getheaders packet.

Bitcoin reference

GetHeaders

A getheaders message.

Requests a series of block headers starting right after the last known hash in block_locator_hashes, up to hash_stop or 2000 blocks, whichever comes first.

You can send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller's main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.

Bitcoin reference

Fields of GetHeaders

block_locator_hashes: Vec<BlockHeaderHash>

Block locators, from newest back to genesis block.

hash_stop: BlockHeaderHash

BlockHeaderHash of the last desired block header.

Set to zero to get as many block headers as possible (2000).

Inv(Vec<InventoryHash>)

An inv message.

Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to getblocks.

Bitcoin reference

GetData(Vec<InventoryHash>)

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

NotFound(Vec<InventoryHash>)

A notfound message.

Bitcoin reference

Tx(Box<Transaction>)

A tx message.

Bitcoin reference

Mempool

A mempool message.

This was defined in [BIP35], which is included in Zcash.

Bitcoin reference [BIP35]: https://github.com/bitcoin/bips/blob/master/bip-0035.mediawiki

FilterLoad

A filterload message.

This was defined in [BIP37], which is included in Zcash.

Bitcoin reference [BIP37]: https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki

Fields of FilterLoad

filter: Filter

The filter itself is simply a bit field of arbitrary byte-aligned size. The maximum size is 36,000 bytes.

hash_functions_count: u32

The number of hash functions to use in this filter. The maximum value allowed in this field is 50.

tweak: Tweak

A random value to add to the seed value in the hash function used by the bloom filter.

flags: u8

A set of flags that control how matched items are added to the filter.

FilterAdd

A filteradd message.

This was defined in [BIP37], which is included in Zcash.

Bitcoin reference [BIP37]: https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki

Fields of FilterAdd

data: Vec<u8>

The data element to add to the current filter.

FilterClear

A filterclear message.

This was defined in [BIP37], which is included in Zcash.

Bitcoin reference [BIP37]: https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki

Trait Implementations

impl Clone for Message[src]

impl Debug for Message[src]

impl Eq for Message[src]

impl<E> From<E> for Message where
    E: Error
[src]

impl PartialEq<Message> for Message[src]

impl StructuralEq for Message[src]

impl StructuralPartialEq for Message[src]

Auto Trait Implementations

impl RefUnwindSafe for Message

impl Send for Message

impl Sync for Message

impl Unpin for Message

impl UnwindSafe for Message

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]