Rename `Services` to `PeerServices`.
This field is called `services` in Bitcoin and Zcash, but because we use that word internally for other purposes, calling it `PeerServices` disambiguates the meaning to "the services advertised by the peer", rather than, e.g., a `tower::Service`.
This commit is contained in:
parent
47513b1ae7
commit
9603a29399
|
|
@ -10,7 +10,7 @@ use zebra_chain::serialization::{
|
||||||
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::protocol::types::Services;
|
use crate::protocol::types::PeerServices;
|
||||||
|
|
||||||
/// An address with metadata on its advertised services and last-seen time.
|
/// An address with metadata on its advertised services and last-seen time.
|
||||||
///
|
///
|
||||||
|
|
@ -23,7 +23,7 @@ pub struct MetaAddr {
|
||||||
/// The peer's address.
|
/// The peer's address.
|
||||||
pub addr: SocketAddr,
|
pub addr: SocketAddr,
|
||||||
/// The services advertised by the peer.
|
/// The services advertised by the peer.
|
||||||
pub services: Services,
|
pub services: PeerServices,
|
||||||
/// When the peer was last seen.
|
/// When the peer was last seen.
|
||||||
pub last_seen: DateTime<Utc>,
|
pub last_seen: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +41,7 @@ impl ZcashDeserialize for MetaAddr {
|
||||||
fn zcash_deserialize<R: Read>(mut reader: R) -> Result<Self, SerializationError> {
|
fn zcash_deserialize<R: Read>(mut reader: R) -> Result<Self, SerializationError> {
|
||||||
Ok(MetaAddr {
|
Ok(MetaAddr {
|
||||||
last_seen: Utc.timestamp(reader.read_u32::<LittleEndian>()? as i64, 0),
|
last_seen: Utc.timestamp(reader.read_u32::<LittleEndian>()? as i64, 0),
|
||||||
services: Services(reader.read_u64::<LittleEndian>()?),
|
services: PeerServices(reader.read_u64::<LittleEndian>()?),
|
||||||
addr: reader.read_socket_addr()?,
|
addr: reader.read_socket_addr()?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -341,14 +341,14 @@ impl Codec {
|
||||||
fn read_version<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
|
fn read_version<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
|
||||||
Ok(Message::Version {
|
Ok(Message::Version {
|
||||||
version: Version(reader.read_u32::<LittleEndian>()?),
|
version: Version(reader.read_u32::<LittleEndian>()?),
|
||||||
services: Services(reader.read_u64::<LittleEndian>()?),
|
services: PeerServices(reader.read_u64::<LittleEndian>()?),
|
||||||
timestamp: Utc.timestamp(reader.read_i64::<LittleEndian>()?, 0),
|
timestamp: Utc.timestamp(reader.read_i64::<LittleEndian>()?, 0),
|
||||||
address_recv: (
|
address_recv: (
|
||||||
Services(reader.read_u64::<LittleEndian>()?),
|
PeerServices(reader.read_u64::<LittleEndian>()?),
|
||||||
reader.read_socket_addr()?,
|
reader.read_socket_addr()?,
|
||||||
),
|
),
|
||||||
address_from: (
|
address_from: (
|
||||||
Services(reader.read_u64::<LittleEndian>()?),
|
PeerServices(reader.read_u64::<LittleEndian>()?),
|
||||||
reader.read_socket_addr()?,
|
reader.read_socket_addr()?,
|
||||||
),
|
),
|
||||||
nonce: Nonce(reader.read_u64::<LittleEndian>()?),
|
nonce: Nonce(reader.read_u64::<LittleEndian>()?),
|
||||||
|
|
@ -505,7 +505,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn version_message_round_trip() {
|
fn version_message_round_trip() {
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
let services = Services(0x1);
|
let services = PeerServices(0x1);
|
||||||
let timestamp = Utc.timestamp(1568000000, 0);
|
let timestamp = Utc.timestamp(1568000000, 0);
|
||||||
|
|
||||||
let rt = Runtime::new().unwrap();
|
let rt = Runtime::new().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ pub enum Message {
|
||||||
version: Version,
|
version: Version,
|
||||||
|
|
||||||
/// The network services advertised by the sender.
|
/// The network services advertised by the sender.
|
||||||
services: Services,
|
services: PeerServices,
|
||||||
|
|
||||||
/// The time when the version message was sent.
|
/// The time when the version message was sent.
|
||||||
timestamp: DateTime<Utc>,
|
timestamp: DateTime<Utc>,
|
||||||
|
|
@ -57,11 +57,11 @@ pub enum Message {
|
||||||
/// advertised network services.
|
/// advertised network services.
|
||||||
///
|
///
|
||||||
/// Q: how does the handshake know the remote peer's services already?
|
/// Q: how does the handshake know the remote peer's services already?
|
||||||
address_recv: (Services, net::SocketAddr),
|
address_recv: (PeerServices, net::SocketAddr),
|
||||||
|
|
||||||
/// The network address of the node sending this message, and its
|
/// The network address of the node sending this message, and its
|
||||||
/// advertised network services.
|
/// advertised network services.
|
||||||
address_from: (Services, net::SocketAddr),
|
address_from: (PeerServices, net::SocketAddr),
|
||||||
|
|
||||||
/// Node random nonce, randomly generated every time a version
|
/// Node random nonce, randomly generated every time a version
|
||||||
/// packet is sent. This nonce is used to detect connections
|
/// packet is sent. This nonce is used to detect connections
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ pub struct Version(pub u32);
|
||||||
// Tower provides utilities for service discovery, so this might go
|
// Tower provides utilities for service discovery, so this might go
|
||||||
// away in the future in favor of that.
|
// away in the future in favor of that.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct Services(pub u64);
|
pub struct PeerServices(pub u64);
|
||||||
|
|
||||||
/// A nonce used in the networking layer to identify messages.
|
/// A nonce used in the networking layer to identify messages.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
|
||||||
|
|
@ -70,13 +70,13 @@ impl ConnectCmd {
|
||||||
|
|
||||||
let version = Message::Version {
|
let version = Message::Version {
|
||||||
version: constants::CURRENT_VERSION,
|
version: constants::CURRENT_VERSION,
|
||||||
services: Services(1),
|
services: PeerServices(1),
|
||||||
timestamp: Utc::now(),
|
timestamp: Utc::now(),
|
||||||
address_recv: (Services(1), self.addr),
|
address_recv: (PeerServices(1), self.addr),
|
||||||
// We just make something up because at this stage the `connect` command
|
// We just make something up because at this stage the `connect` command
|
||||||
// doesn't run a server or anything -- will the zcashd respond on the
|
// doesn't run a server or anything -- will the zcashd respond on the
|
||||||
// same tcp connection or try to open one to the bogus address below?
|
// same tcp connection or try to open one to the bogus address below?
|
||||||
address_from: (Services(1), "127.0.0.1:9000".parse().unwrap()),
|
address_from: (PeerServices(1), "127.0.0.1:9000".parse().unwrap()),
|
||||||
nonce: Nonce(1),
|
nonce: Nonce(1),
|
||||||
user_agent: "Zebra Connect".to_owned(),
|
user_agent: "Zebra Connect".to_owned(),
|
||||||
start_height: BlockHeight(0),
|
start_height: BlockHeight(0),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue