Skip to content

Commit e9f0b52

Browse files
committed
rename some items in the auth example
1 parent 9d189e2 commit e9f0b52

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

iroh/examples/auth-middleware.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ async fn main() -> Result<()> {
3434
}
3535

3636
async fn connect_side(remote_addr: EndpointAddr, token: &[u8]) -> Result<()> {
37-
let (auth_middleware, auth_connector) = auth::connect(token.to_vec());
37+
let (auth_middleware, auth_task) = auth::outgoing(token.to_vec());
3838
let endpoint = Endpoint::builder()
3939
.middleware(auth_middleware)
4040
.bind()
4141
.await?;
42-
let _guard = auth_connector.spawn(endpoint.clone());
42+
let _guard = auth_task.spawn(endpoint.clone());
4343
Echo::connect(&endpoint, remote_addr, b"hello there!").await
4444
}
4545

@@ -49,7 +49,7 @@ async fn connect_side_no_auth(remote_addr: EndpointAddr) -> Result<()> {
4949
}
5050

5151
async fn accept_side(token: &[u8]) -> Result<Router> {
52-
let (auth_middleware, auth_protocol) = auth::accept(token.to_vec());
52+
let (auth_middleware, auth_protocol) = auth::incoming(token.to_vec());
5353
let endpoint = Endpoint::builder()
5454
.middleware(auth_middleware)
5555
.bind()
@@ -136,11 +136,11 @@ mod auth {
136136
const CLOSE_ACCEPTED: u32 = 1;
137137
const CLOSE_DENIED: u32 = 403;
138138

139-
/// Connect side: Use this if you want to pre-auth outgoing connections.
140-
pub fn connect(token: Vec<u8>) -> (AuthConnectMiddleware, AuthConnectTask) {
139+
/// Outgoing side: Use this if you want to pre-auth outgoing connections.
140+
pub fn outgoing(token: Vec<u8>) -> (OutgoingAuthMiddleware, OutgoingAuthTask) {
141141
let (tx, rx) = mpsc::channel(16);
142-
let middleware = AuthConnectMiddleware { tx };
143-
let connector = AuthConnectTask {
142+
let middleware = OutgoingAuthMiddleware { tx };
143+
let connector = OutgoingAuthTask {
144144
token,
145145
rx,
146146
allowed_remotes: Default::default(),
@@ -152,11 +152,11 @@ mod auth {
152152

153153
/// Middleware to mount on the endpoint builder.
154154
#[derive(Debug)]
155-
pub struct AuthConnectMiddleware {
155+
pub struct OutgoingAuthMiddleware {
156156
tx: mpsc::Sender<(EndpointId, oneshot::Sender<Result<(), Arc<AnyError>>>)>,
157157
}
158158

159-
impl AuthConnectMiddleware {
159+
impl OutgoingAuthMiddleware {
160160
async fn authenticate(&self, remote_id: EndpointId) -> Result<()> {
161161
let (tx, rx) = oneshot::channel();
162162
self.tx
@@ -169,7 +169,7 @@ mod auth {
169169
}
170170
}
171171

172-
impl Middleware for AuthConnectMiddleware {
172+
impl Middleware for OutgoingAuthMiddleware {
173173
async fn before_connect<'a>(
174174
&'a self,
175175
remote_addr: &'a EndpointAddr,
@@ -191,15 +191,15 @@ mod auth {
191191
}
192192

193193
/// Connector task that initiates pre-auth request. Call [`Self::spawn`] once the endpoint is built.
194-
pub struct AuthConnectTask {
194+
pub struct OutgoingAuthTask {
195195
token: Vec<u8>,
196196
rx: mpsc::Receiver<(EndpointId, oneshot::Sender<Result<(), Arc<AnyError>>>)>,
197197
allowed_remotes: HashSet<EndpointId>,
198198
pending_remotes: HashMap<EndpointId, Vec<oneshot::Sender<Result<(), Arc<AnyError>>>>>,
199199
tasks: JoinSet<(EndpointId, Result<()>)>,
200200
}
201201

202-
impl AuthConnectTask {
202+
impl OutgoingAuthTask {
203203
pub fn spawn(self, endpoint: Endpoint) -> AbortOnDropHandle<()> {
204204
AbortOnDropHandle::new(tokio::spawn(self.run(endpoint)))
205205
}
@@ -278,10 +278,10 @@ mod auth {
278278
}
279279
}
280280

281-
/// Accept side: Use this if you want to only accept connections from peers with successful pre-auth requests.
282-
pub fn accept(token: Vec<u8>) -> (AuthAcceptMiddleware, AuthProtocol) {
281+
/// Incoming side: Use this if you want to only accept connections from peers with successful pre-auth requests.
282+
pub fn incoming(token: Vec<u8>) -> (IncomingAuthMiddleware, AuthProtocol) {
283283
let allowed_remotes: Arc<Mutex<HashSet<EndpointId>>> = Default::default();
284-
let middleware = AuthAcceptMiddleware {
284+
let middleware = IncomingAuthMiddleware {
285285
allowed_remotes: allowed_remotes.clone(),
286286
};
287287
let protocol = AuthProtocol {
@@ -295,11 +295,11 @@ mod auth {
295295
///
296296
/// This will reject incoming connections if the remote did not successfully authenticate before.
297297
#[derive(Debug)]
298-
pub struct AuthAcceptMiddleware {
298+
pub struct IncomingAuthMiddleware {
299299
allowed_remotes: Arc<Mutex<HashSet<EndpointId>>>,
300300
}
301301

302-
impl Middleware for AuthAcceptMiddleware {
302+
impl Middleware for IncomingAuthMiddleware {
303303
async fn after_handshake<'a>(
304304
&'a self,
305305
conn: &'a iroh::endpoint::ConnectionInfo,

0 commit comments

Comments
 (0)