Skip to content

Commit

Permalink
Remove ClientInfo as argument from Session
Browse files Browse the repository at this point in the history
Signed-off-by: James Spencer <[email protected]>
  • Loading branch information
jcspencer committed Apr 27, 2024
1 parent b57fb7d commit 9b5703b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 5 additions & 2 deletions examples/key_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,14 @@ impl KeyStorageAgent {
}

impl Agent for KeyStorageAgent {
fn new_session<S>(&mut self, _socket: &S::Stream, client_info: &S::ClientInfo) -> impl Session
fn new_session<S>(&mut self, socket: &S::Stream) -> impl Session
where
S: ListeningSocket + std::fmt::Debug + Send,
{
println!("New connection from client: {:?}", client_info);
if let Ok(client_info) = S::client_info(socket) {
println!("New connection from client: {:?}", client_info);
}

KeyStorage {
identities: Arc::clone(&self.identities),
}
Expand Down
7 changes: 3 additions & 4 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ where
#[async_trait]
pub trait Agent: 'static + Sync + Send + Sized {
/// Create new session object when a new socket is accepted.
fn new_session<S>(&mut self, socket: &S::Stream, client_info: &S::ClientInfo) -> impl Session
fn new_session<S>(&mut self, socket: &S::Stream) -> impl Session
where
S: ListeningSocket + fmt::Debug + Send;

Expand All @@ -206,8 +206,7 @@ pub trait Agent: 'static + Sync + Send + Sized {
loop {
match socket.accept().await {
Ok(socket) => {
let client_info = S::client_info(&socket)?;
let session = self.new_session::<S>(&socket, &client_info);
let session = self.new_session::<S>(&socket);
tokio::spawn(async move {
let adapter = Framed::new(socket, Codec::<Request, Response>::default());
if let Err(e) = handle_socket::<S>(session, adapter).await {
Expand Down Expand Up @@ -249,7 +248,7 @@ impl<T> Agent for T
where
T: Default + Session,
{
fn new_session<S>(&mut self, _socket: &S::Stream, _client_info: &S::ClientInfo) -> impl Session
fn new_session<S>(&mut self, _socket: &S::Stream) -> impl Session
where
S: ListeningSocket + fmt::Debug + Send,
{
Expand Down

0 comments on commit 9b5703b

Please sign in to comment.