@@ -164,7 +164,7 @@ pub(crate) trait RelayContext {
164164 fn self_location ( & self ) -> & PeerKeyLocation ;
165165
166166 /// Determine whether we should accept the joiner immediately.
167- fn should_accept ( & self , joiner : & PeerKeyLocation ) -> bool ;
167+ fn should_accept ( & self , joiner : & PeerKeyLocation , courtesy : bool ) -> bool ;
168168
169169 /// Choose the next hop for the request, avoiding peers already visited.
170170 fn select_next_hop (
@@ -215,10 +215,11 @@ impl RelayState {
215215 actions. observed_address = Some ( ( self . request . origin . clone ( ) , observed_addr) ) ;
216216 }
217217
218- if !self . accepted_locally && ctx. should_accept ( & self . request . origin ) {
218+ let acceptor = ctx. self_location ( ) . clone ( ) ;
219+ let courtesy = ctx. courtesy_hint ( & acceptor, & self . request . origin ) ;
220+
221+ if !self . accepted_locally && ctx. should_accept ( & self . request . origin , courtesy) {
219222 self . accepted_locally = true ;
220- let acceptor = ctx. self_location ( ) . clone ( ) ;
221- let courtesy = ctx. courtesy_hint ( & acceptor, & self . request . origin ) ;
222223 self . courtesy_hint = courtesy;
223224 actions. accept_response = Some ( ConnectResponse {
224225 acceptor : acceptor. clone ( ) ,
@@ -282,14 +283,14 @@ impl RelayContext for RelayEnv<'_> {
282283 & self . self_location
283284 }
284285
285- fn should_accept ( & self , joiner : & PeerKeyLocation ) -> bool {
286+ fn should_accept ( & self , joiner : & PeerKeyLocation , courtesy : bool ) -> bool {
286287 let location = joiner
287288 . location
288289 . unwrap_or_else ( || Location :: from_address ( & joiner. peer . addr ) ) ;
289290 self . op_manager
290291 . ring
291292 . connection_manager
292- . should_accept ( location, & joiner. peer )
293+ . should_accept ( location, & joiner. peer , courtesy )
293294 }
294295
295296 fn select_next_hop (
@@ -789,7 +790,7 @@ pub(crate) async fn join_ring_request(
789790 if !op_manager
790791 . ring
791792 . connection_manager
792- . should_accept ( location, & gateway. peer )
793+ . should_accept ( location, & gateway. peer , false )
793794 {
794795 return Err ( OpError :: ConnError ( ConnectionError :: UnwantedConnection ) ) ;
795796 }
@@ -1000,7 +1001,7 @@ mod tests {
10001001 & self . self_loc
10011002 }
10021003
1003- fn should_accept ( & self , _joiner : & PeerKeyLocation ) -> bool {
1004+ fn should_accept ( & self , _joiner : & PeerKeyLocation , _courtesy : bool ) -> bool {
10041005 self . accept
10051006 }
10061007
0 commit comments