File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -251,6 +251,37 @@ where
251251}
252252
253253/// Factory of sessions for the given type of sockets.
254+ ///
255+ /// An agent implementation is automatically created for types which
256+ /// implement [`Session`] and [`Clone`]: new sessions are created by
257+ /// cloning the agent object. This is usually sufficient for the
258+ /// majority of use cases. In case the information about the
259+ /// underlying socket (connection source) is needed the [`Agent`] can
260+ /// be implemented manually.
261+ ///
262+ /// # Examples
263+ ///
264+ /// This example shows how to retrieve the connecting process ID on Unix:
265+ ///
266+ /// ```
267+ /// use ssh_agent_lib::agent::{Agent, Session};
268+ ///
269+ /// #[derive(Debug, Default)]
270+ /// struct AgentSocketInfo;
271+ ///
272+ /// #[cfg(unix)]
273+ /// impl Agent<tokio::net::UnixListener> for AgentSocketInfo {
274+ /// fn new_session(&mut self, socket: &tokio::net::UnixStream) -> impl Session {
275+ /// let _socket_info = format!(
276+ /// "unix: addr: {:?} cred: {:?}",
277+ /// socket.peer_addr().unwrap(),
278+ /// socket.peer_cred().unwrap()
279+ /// );
280+ /// Self
281+ /// }
282+ /// }
283+ /// # impl Session for AgentSocketInfo { }
284+ /// ```
254285pub trait Agent < S > : ' static + Send + Sync
255286where
256287 S : ListeningSocket + fmt:: Debug + Send ,
You can’t perform that action at this time.
0 commit comments