From e5429a28918840d43b5c7ec25d9440d3ba78d8d3 Mon Sep 17 00:00:00 2001 From: Emil Engler Date: Fri, 21 Oct 2022 13:20:06 +0200 Subject: [PATCH] tor-cell: Rename for_client and for_relay This commit renames the for_client and for_relay functions to from_client and from_relay respectively, in order to indicate their origin, as the term "for" is more likely to indicate a destination, which is not true in that situation. --- crates/tor-cell/src/chancell/msg.rs | 4 ++-- crates/tor-cell/tests/testvec_chanmsg.rs | 10 +++++----- crates/tor-proto/src/channel/handshake.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/tor-cell/src/chancell/msg.rs b/crates/tor-cell/src/chancell/msg.rs index 5349dea35..2515d288f 100644 --- a/crates/tor-cell/src/chancell/msg.rs +++ b/crates/tor-cell/src/chancell/msg.rs @@ -652,7 +652,7 @@ fn take_one_netinfo_addr(r: &mut Reader<'_>) -> Result> { } impl Netinfo { /// Construct a new Netinfo to be sent by a client. - pub fn for_client(their_addr: Option) -> Self { + pub fn from_client(their_addr: Option) -> Self { Netinfo { timestamp: 0, // clients don't report their timestamps. their_addr, @@ -660,7 +660,7 @@ impl Netinfo { } } /// Construct a new Netinfo to be sent by a relay - pub fn for_relay(timestamp: u32, their_addr: Option, my_addrs: V) -> Self + pub fn from_relay(timestamp: u32, their_addr: Option, my_addrs: V) -> Self where V: Into>, { diff --git a/crates/tor-cell/tests/testvec_chanmsg.rs b/crates/tor-cell/tests/testvec_chanmsg.rs index c285be199..f05c39775 100644 --- a/crates/tor-cell/tests/testvec_chanmsg.rs +++ b/crates/tor-cell/tests/testvec_chanmsg.rs @@ -243,14 +243,14 @@ fn test_netinfo() { fbody( cmd, "00000000 04 04 7F000001 00", - &msg::Netinfo::for_client(Some(localhost)).into(), + &msg::Netinfo::from_client(Some(localhost)).into(), ); // example relay netinfo fbody( cmd, "5F6F80E1 04 04 7F000001 01 04 04 7F000001", - &msg::Netinfo::for_relay(0x5f6f80e1, Some(localhost), &[localhost][..]).into(), + &msg::Netinfo::from_relay(0x5f6f80e1, Some(localhost), &[localhost][..]).into(), ); // example ipv6 relay netinfo @@ -261,7 +261,7 @@ fn test_netinfo() { 02 04 04 7F000001 06 10 00000000000000000000000000000001", - &msg::Netinfo::for_relay( + &msg::Netinfo::from_relay( 0x5f6f859c, Some(localhost_v6), &[localhost, localhost_v6][..], @@ -280,14 +280,14 @@ fn test_netinfo() { false, ); let expect: msg::ChanMsg = - msg::Netinfo::for_relay(0x5f6f859c, None, &[localhost_v6][..]).into(); + msg::Netinfo::from_relay(0x5f6f859c, None, &[localhost_v6][..]).into(); assert_eq!(format!("{:?}", netinfo), format!("{:?}", expect)); // Zero-valued their_address are None (hand-generated from above) fbody( cmd, "00000000 04 04 00000000 00", - &msg::Netinfo::for_client(None).into(), + &msg::Netinfo::from_client(None).into(), ); } diff --git a/crates/tor-proto/src/channel/handshake.rs b/crates/tor-proto/src/channel/handshake.rs index 3a1a7e626..9780ce1be 100644 --- a/crates/tor-proto/src/channel/handshake.rs +++ b/crates/tor-proto/src/channel/handshake.rs @@ -577,7 +577,7 @@ impl Verif .as_ref() .and_then(ChannelMethod::declared_peer_addr) .map(SocketAddr::ip); - let netinfo = msg::Netinfo::for_client(peer_ip); + let netinfo = msg::Netinfo::from_client(peer_ip); self.tls .send(netinfo.into()) .await @@ -815,7 +815,7 @@ pub(super) mod test { R: Runtime, { let localhost = std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST); - let netinfo_cell = msg::Netinfo::for_client(Some(localhost)); + let netinfo_cell = msg::Netinfo::from_client(Some(localhost)); let clock_skew = ClockSkew::None; UnverifiedChannel { link_protocol: 4,