Skip to content

Commit

Permalink
connection: Make it more clear that the addr is the peer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbuesch committed Nov 15, 2024
1 parent c6f6e50 commit 794c838
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion letmeind/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async fn async_main(opts: Arc<Opts>) -> ah::Result<()> {
let conf = conf.read().await;
let mut proto = Protocol::new(conn, &conf, &opts.rundir);
if let Err(e) = proto.run().await {
eprintln!("Client '{}' ERROR: {}", proto.addr().ip(), e);
eprintln!("Client '{}' ERROR: {}", proto.peer_addr().ip(), e);
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions letmeind/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl<'a, C: ConnectionOps> Protocol<'a, C> {
}
}

pub fn addr(&self) -> SocketAddr {
self.conn.addr()
pub fn peer_addr(&self) -> SocketAddr {
self.conn.peer_addr()
}

async fn recv_msg(&mut self, expect_operation: Operation) -> ah::Result<Message> {
Expand Down Expand Up @@ -223,7 +223,7 @@ impl<'a, C: ConnectionOps> Protocol<'a, C> {

// Send an open-port request to letmeinfwd.
assert_eq!(self.auth_state, AuthState::ChallengeResponseAuth);
if let Err(e) = fw.open_port(self.addr().ip(), port_type, *port).await {
if let Err(e) = fw.open_port(self.peer_addr().ip(), port_type, *port).await {
let _ = self.send_go_away().await;
return Err(err!("letmeinfwd firewall open: {e}"));
}
Expand Down
12 changes: 6 additions & 6 deletions letmeind/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ use std::net::SocketAddr;
use tokio::net::{TcpListener, TcpStream};

pub trait ConnectionOps {
fn addr(&self) -> SocketAddr;
fn peer_addr(&self) -> SocketAddr;
async fn recv_msg(&mut self) -> ah::Result<Option<Message>>;
async fn send_msg(&mut self, msg: &Message) -> ah::Result<()>;
}

pub struct Connection {
stream: TcpStream,
addr: SocketAddr,
peer_addr: SocketAddr,
}

impl Connection {
fn new(stream: TcpStream, addr: SocketAddr) -> ah::Result<Self> {
Ok(Self { stream, addr })
fn new(stream: TcpStream, peer_addr: SocketAddr) -> ah::Result<Self> {
Ok(Self { stream, peer_addr })
}
}

impl ConnectionOps for Connection {
fn addr(&self) -> SocketAddr {
self.addr
fn peer_addr(&self) -> SocketAddr {
self.peer_addr
}

async fn recv_msg(&mut self) -> ah::Result<Option<Message>> {
Expand Down

0 comments on commit 794c838

Please sign in to comment.