@@ -74,12 +74,6 @@ use session::Session;
74
74
// seconds).
75
75
const BANNED_NODES_CHECK : u64 = 300 ; // Check every 5 minutes.
76
76
77
- // The one-time session timeout.
78
- const ONE_TIME_SESSION_TIMEOUT : u64 = 30 ;
79
-
80
- // The maximum number of established one-time sessions to maintain.
81
- const ONE_TIME_SESSION_CACHE_CAPACITY : usize = 100 ;
82
-
83
77
/// Messages sent from the application layer to `Handler`.
84
78
#[ derive( Debug , Clone , PartialEq ) ]
85
79
#[ allow( clippy:: large_enum_variant) ]
@@ -216,8 +210,6 @@ pub struct Handler {
216
210
active_challenges : HashMapDelay < NodeAddress , Challenge > ,
217
211
/// Established sessions with peers.
218
212
sessions : LruTimeCache < NodeAddress , Session > ,
219
- /// Established sessions with peers for a specific request, stored just one per node.
220
- one_time_sessions : LruTimeCache < NodeAddress , ( RequestId , Session ) > ,
221
213
/// The channel to receive messages from the application layer.
222
214
service_recv : mpsc:: UnboundedReceiver < HandlerIn > ,
223
215
/// The channel to send messages to the application layer.
@@ -308,10 +300,6 @@ impl Handler {
308
300
config. session_timeout ,
309
301
Some ( config. session_cache_capacity ) ,
310
302
) ,
311
- one_time_sessions : LruTimeCache :: new (
312
- Duration :: from_secs ( ONE_TIME_SESSION_TIMEOUT ) ,
313
- Some ( ONE_TIME_SESSION_CACHE_CAPACITY ) ,
314
- ) ,
315
303
active_challenges : HashMapDelay :: new ( config. request_timeout ) ,
316
304
service_recv,
317
305
service_send,
@@ -549,9 +537,6 @@ impl Handler {
549
537
// Check for an established session
550
538
let packet = if let Some ( session) = self . sessions . get_mut ( & node_address) {
551
539
session. encrypt_message :: < P > ( self . node_id , & response. encode ( ) )
552
- } else if let Some ( mut session) = self . remove_one_time_session ( & node_address, & response. id )
553
- {
554
- session. encrypt_message :: < P > ( self . node_id , & response. encode ( ) )
555
540
} else {
556
541
// Either the session is being established or has expired. We simply drop the
557
542
// response in this case.
@@ -847,7 +832,7 @@ impl Handler {
847
832
ephem_pubkey,
848
833
enr_record,
849
834
) {
850
- Ok ( ( mut session, enr) ) => {
835
+ Ok ( ( session, enr) ) => {
851
836
// Remove the expected response for the challenge.
852
837
self . remove_expected_response ( node_address. socket_addr ) ;
853
838
// Receiving an AuthResponse must give us an up-to-date view of the node ENR.
@@ -868,28 +853,17 @@ impl Handler {
868
853
{
869
854
warn ! ( error = %e, "Failed to inform of established session" )
870
855
}
871
- // When (re-)establishing a session from an outgoing challenge, we do not need
872
- // to filter out this request from active requests, so we do not pass
873
- // the message nonce on to `new_session`.
874
- self . new_session :: < P > ( node_address. clone ( ) , session, None )
875
- . await ;
876
- self . handle_message (
877
- node_address. clone ( ) ,
878
- message_nonce,
879
- message,
880
- authenticated_data,
881
- )
882
- . await ;
883
856
} else {
884
- // IP's or NodeAddress don't match. Drop the session.
857
+ // IP's or NodeAddress don't match.
858
+ //
859
+ // We still handle the request, but we do not add the ENR to our routing
860
+ // table or consider the ENR valid.
885
861
warn ! (
886
862
udp4_socket = ?enr. udp4_socket( ) ,
887
863
udp6_socket = ?enr. udp6_socket( ) ,
888
864
expected = %node_address,
889
865
"Session has invalid ENR" ,
890
866
) ;
891
- self . fail_session ( & node_address, RequestError :: InvalidRemoteEnr , true )
892
- . await ;
893
867
894
868
// The ENR doesn't verify. Notify application.
895
869
self . notify_unverifiable_enr (
@@ -898,39 +872,20 @@ impl Handler {
898
872
node_address. node_id ,
899
873
)
900
874
. await ;
901
-
902
- // Respond to PING request even if the ENR or NodeAddress don't match
903
- // so that the source node can notice its external IP address has been changed.
904
- let maybe_ping_request = match session. decrypt_message (
905
- message_nonce,
906
- message,
907
- authenticated_data,
908
- ) {
909
- Ok ( m) => match Message :: decode ( & m) {
910
- Ok ( Message :: Request ( request) ) if request. msg_type ( ) == 1 => {
911
- Some ( request)
912
- }
913
- _ => None ,
914
- } ,
915
- _ => None ,
916
- } ;
917
- if let Some ( request) = maybe_ping_request {
918
- debug ! (
919
- %node_address,
920
- "Responding to a PING request using a one-time session." ,
921
- ) ;
922
- self . one_time_sessions
923
- . insert ( node_address. clone ( ) , ( request. id . clone ( ) , session) ) ;
924
- if let Err ( e) = self
925
- . service_send
926
- . send ( HandlerOut :: Request ( node_address. clone ( ) , Box :: new ( request) ) )
927
- . await
928
- {
929
- warn ! ( error = %e, "Failed to report request to application" ) ;
930
- self . one_time_sessions . remove ( & node_address) ;
931
- }
932
- }
933
875
}
876
+
877
+ // When (re-)establishing a session from an outgoing challenge, we do not need
878
+ // to filter out this request from active requests, so we do not pass
879
+ // the message nonce on to `new_session`.
880
+ self . new_session :: < P > ( node_address. clone ( ) , session, None )
881
+ . await ;
882
+ self . handle_message (
883
+ node_address. clone ( ) ,
884
+ message_nonce,
885
+ message,
886
+ authenticated_data,
887
+ )
888
+ . await ;
934
889
}
935
890
Err ( Error :: InvalidChallengeSignature ( challenge) ) => {
936
891
warn ! (
@@ -1294,24 +1249,6 @@ impl Handler {
1294
1249
}
1295
1250
}
1296
1251
1297
- /// Remove one-time session by the given NodeAddress and RequestId if exists.
1298
- fn remove_one_time_session (
1299
- & mut self ,
1300
- node_address : & NodeAddress ,
1301
- request_id : & RequestId ,
1302
- ) -> Option < Session > {
1303
- match self . one_time_sessions . peek ( node_address) {
1304
- Some ( ( id, _) ) if id == request_id => {
1305
- let ( _, session) = self
1306
- . one_time_sessions
1307
- . remove ( node_address)
1308
- . expect ( "one-time session must exist" ) ;
1309
- Some ( session)
1310
- }
1311
- _ => None ,
1312
- }
1313
- }
1314
-
1315
1252
/// A request has failed.
1316
1253
async fn fail_request (
1317
1254
& mut self ,
0 commit comments