Skip to content

Commit 920b7a2

Browse files
committed
Expose socket info in new_session
Fixes: #55 Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
1 parent f07a436 commit 920b7a2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

examples/key_storage.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rsa::BigUint;
99
use sha1::Sha1;
1010
#[cfg(windows)]
1111
use ssh_agent_lib::agent::NamedPipeListener as Listener;
12-
use ssh_agent_lib::agent::Session;
12+
use ssh_agent_lib::agent::{ListeningSocket, Session};
1313
use ssh_agent_lib::error::AgentError;
1414
use ssh_agent_lib::proto::extension::{QueryResponse, RestrictDestination, SessionBind};
1515
use ssh_agent_lib::proto::{
@@ -238,7 +238,10 @@ impl KeyStorageAgent {
238238
}
239239

240240
impl Agent for KeyStorageAgent {
241-
fn new_session(&mut self) -> impl Session {
241+
fn new_session<S>(&mut self, _socket: &S::Stream) -> impl Session
242+
where
243+
S: ListeningSocket + std::fmt::Debug + Send,
244+
{
242245
KeyStorage {
243246
identities: Arc::clone(&self.identities),
244247
}

src/agent.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ where
253253
#[async_trait]
254254
pub trait Agent: 'static + Sync + Send + Sized {
255255
/// Create new session object when a new socket is accepted.
256-
fn new_session(&mut self) -> impl Session;
256+
fn new_session<S>(&mut self, socket: &S::Stream) -> impl Session
257+
where
258+
S: ListeningSocket + fmt::Debug + Send;
257259

258260
/// Listen on a socket waiting for client connections.
259261
async fn listen<S>(mut self, mut socket: S) -> Result<(), AgentError>
@@ -264,7 +266,7 @@ pub trait Agent: 'static + Sync + Send + Sized {
264266
loop {
265267
match socket.accept().await {
266268
Ok(socket) => {
267-
let session = self.new_session();
269+
let session = self.new_session::<S>(&socket);
268270
tokio::spawn(async move {
269271
let adapter = Framed::new(socket, Codec::<Request, Response>::default());
270272
if let Err(e) = handle_socket::<S>(session, adapter).await {
@@ -306,7 +308,10 @@ impl<T> Agent for T
306308
where
307309
T: Default + Session,
308310
{
309-
fn new_session(&mut self) -> impl Session {
311+
fn new_session<S>(&mut self, _socket: &S::Stream) -> impl Session
312+
where
313+
S: ListeningSocket + fmt::Debug + Send,
314+
{
310315
Self::default()
311316
}
312317
}

0 commit comments

Comments
 (0)