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:
Henry de Valence 2019-09-30 11:40:44 -07:00 committed by Deirdre Connolly
parent 47513b1ae7
commit 9603a29399
5 changed files with 14 additions and 14 deletions

View File

@ -10,7 +10,7 @@ use zebra_chain::serialization::{
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.
///
@ -23,7 +23,7 @@ pub struct MetaAddr {
/// The peer's address.
pub addr: SocketAddr,
/// The services advertised by the peer.
pub services: Services,
pub services: PeerServices,
/// When the peer was last seen.
pub last_seen: DateTime<Utc>,
}
@ -41,7 +41,7 @@ impl ZcashDeserialize for MetaAddr {
fn zcash_deserialize<R: Read>(mut reader: R) -> Result<Self, SerializationError> {
Ok(MetaAddr {
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()?,
})
}

View File

@ -341,14 +341,14 @@ impl Codec {
fn read_version<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
Ok(Message::Version {
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),
address_recv: (
Services(reader.read_u64::<LittleEndian>()?),
PeerServices(reader.read_u64::<LittleEndian>()?),
reader.read_socket_addr()?,
),
address_from: (
Services(reader.read_u64::<LittleEndian>()?),
PeerServices(reader.read_u64::<LittleEndian>()?),
reader.read_socket_addr()?,
),
nonce: Nonce(reader.read_u64::<LittleEndian>()?),
@ -505,7 +505,7 @@ mod tests {
#[test]
fn version_message_round_trip() {
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let services = Services(0x1);
let services = PeerServices(0x1);
let timestamp = Utc.timestamp(1568000000, 0);
let rt = Runtime::new().unwrap();

View File

@ -48,7 +48,7 @@ pub enum Message {
version: Version,
/// The network services advertised by the sender.
services: Services,
services: PeerServices,
/// The time when the version message was sent.
timestamp: DateTime<Utc>,
@ -57,11 +57,11 @@ pub enum Message {
/// advertised network services.
///
/// 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
/// advertised network services.
address_from: (Services, net::SocketAddr),
address_from: (PeerServices, net::SocketAddr),
/// Node random nonce, randomly generated every time a version
/// packet is sent. This nonce is used to detect connections

View File

@ -12,7 +12,7 @@ pub struct Version(pub u32);
// Tower provides utilities for service discovery, so this might go
// away in the future in favor of that.
#[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.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]

View File

@ -70,13 +70,13 @@ impl ConnectCmd {
let version = Message::Version {
version: constants::CURRENT_VERSION,
services: Services(1),
services: PeerServices(1),
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
// 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?
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),
user_agent: "Zebra Connect".to_owned(),
start_height: BlockHeight(0),