Update new_gossiped_meta_addr to the latest API

This commit is contained in:
teor 2021-05-20 18:22:45 +10:00
parent c7ea1395e7
commit 40d06657b3
1 changed files with 17 additions and 12 deletions

View File

@ -137,17 +137,17 @@ pub struct MetaAddr {
} }
impl MetaAddr { impl MetaAddr {
/// Create a new `MetaAddr` from the deserialized fields in a gossiped /// Create a new gossiped [`MetaAddr`], based on the deserialized fields from
/// peer `Addr` message. /// a gossiped peer [`Addr`] message.
pub fn new_gossiped( pub fn new_gossiped_meta_addr(
addr: &SocketAddr, addr: SocketAddr,
services: &PeerServices, untrusted_services: PeerServices,
last_seen: &DateTime<Utc>, untrusted_last_seen: DateTime<Utc>,
) -> MetaAddr { ) -> MetaAddr {
MetaAddr { MetaAddr {
addr: *addr, addr,
services: *services, services: untrusted_services,
last_seen: *last_seen, last_seen: untrusted_last_seen,
// the state is Zebra-specific, it isn't part of the Zcash network protocol // the state is Zebra-specific, it isn't part of the Zcash network protocol
last_connection_state: NeverAttemptedGossiped, last_connection_state: NeverAttemptedGossiped,
} }
@ -336,11 +336,16 @@ impl ZcashSerialize for MetaAddr {
impl ZcashDeserialize for MetaAddr { 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> {
// This can't panic, because all u32 values are valid `Utc.timestamp`s // This can't panic, because all u32 values are valid `Utc.timestamp`s
let last_seen = Utc.timestamp(reader.read_u32::<LittleEndian>()?.into(), 0); let untrusted_last_seen = Utc.timestamp(reader.read_u32::<LittleEndian>()?.into(), 0);
let services = PeerServices::from_bits_truncate(reader.read_u64::<LittleEndian>()?); let untrusted_services =
PeerServices::from_bits_truncate(reader.read_u64::<LittleEndian>()?);
let addr = reader.read_socket_addr()?; let addr = reader.read_socket_addr()?;
Ok(MetaAddr::new_gossiped(&addr, &services, &last_seen)) Ok(MetaAddr::new_gossiped_meta_addr(
addr,
untrusted_services,
untrusted_last_seen,
))
} }
} }