@@ -70,10 +70,10 @@ pub(crate) mod handle;
70
70
const LOG_TARGET : & str = "litep2p::transport-manager" ;
71
71
72
72
/// Score for a working address.
73
- const SCORE_DIAL_SUCCESS : i32 = 100i32 ;
73
+ const SCORE_CONNECT_SUCCESS : i32 = 100i32 ;
74
74
75
75
/// Score for a non-working address.
76
- const SCORE_DIAL_FAILURE : i32 = -100i32 ;
76
+ const SCORE_CONNECT_FAILURE : i32 = -100i32 ;
77
77
78
78
/// TODO:
79
79
enum ConnectionEstablishedResult {
@@ -698,7 +698,7 @@ impl TransportManager {
698
698
PeerState :: Dialing { ref mut record } => {
699
699
debug_assert_eq ! ( record. connection_id( ) , & Some ( connection_id) ) ;
700
700
701
- record. update_score ( SCORE_DIAL_FAILURE ) ;
701
+ record. update_score ( SCORE_CONNECT_FAILURE ) ;
702
702
context. addresses . insert ( record. clone ( ) ) ;
703
703
704
704
context. state = PeerState :: Disconnected { dial_record : None } ;
@@ -711,7 +711,7 @@ impl TransportManager {
711
711
record,
712
712
dial_record : Some ( mut dial_record) ,
713
713
} => {
714
- dial_record. update_score ( SCORE_DIAL_FAILURE ) ;
714
+ dial_record. update_score ( SCORE_CONNECT_FAILURE ) ;
715
715
context. addresses . insert ( dial_record) ;
716
716
717
717
context. state = PeerState :: Connected {
@@ -730,7 +730,7 @@ impl TransportManager {
730
730
"dial failed for a disconnected peer" ,
731
731
) ;
732
732
733
- dial_record. update_score ( SCORE_DIAL_FAILURE ) ;
733
+ dial_record. update_score ( SCORE_CONNECT_FAILURE ) ;
734
734
context. addresses . insert ( dial_record) ;
735
735
736
736
Ok ( ( ) )
@@ -914,7 +914,10 @@ impl TransportManager {
914
914
let mut peers = self . peers . write ( ) ;
915
915
match peers. get_mut ( & peer) {
916
916
Some ( context) => match context. state {
917
- PeerState :: Connected { .. } => match context. secondary_connection {
917
+ PeerState :: Connected {
918
+ ref mut dial_record,
919
+ ..
920
+ } => match context. secondary_connection {
918
921
Some ( _) => {
919
922
tracing:: debug!(
920
923
target: LOG_TARGET ,
@@ -932,29 +935,57 @@ impl TransportManager {
932
935
context. addresses . insert ( AddressRecord :: new (
933
936
& peer,
934
937
endpoint. address ( ) . clone ( ) ,
935
- SCORE_DIAL_SUCCESS ,
938
+ SCORE_CONNECT_SUCCESS ,
936
939
None ,
937
940
) )
938
941
}
939
942
940
943
return Ok ( ConnectionEstablishedResult :: Reject ) ;
941
944
}
942
- None => {
943
- tracing:: debug!(
945
+ None => match dial_record. take ( ) {
946
+ Some ( record)
947
+ if record. connection_id ( ) == & Some ( endpoint. connection_id ( ) ) =>
948
+ {
949
+ tracing:: debug!(
950
+ target: LOG_TARGET ,
951
+ ?peer,
952
+ connection_id = ?endpoint. connection_id( ) ,
953
+ address = ?endpoint. address( ) ,
954
+ "dialed connection opened as secondary connection" ,
955
+ ) ;
956
+
957
+ context. secondary_connection = Some ( AddressRecord :: new (
958
+ & peer,
959
+ endpoint. address ( ) . clone ( ) ,
960
+ SCORE_CONNECT_SUCCESS ,
961
+ Some ( endpoint. connection_id ( ) ) ,
962
+ ) ) ;
963
+ }
964
+ None => {
965
+ tracing:: debug!(
966
+ target: LOG_TARGET ,
967
+ ?peer,
968
+ connection_id = ?endpoint. connection_id( ) ,
969
+ address = ?endpoint. address( ) ,
970
+ "secondary connection" ,
971
+ ) ;
972
+
973
+ context. secondary_connection = Some ( AddressRecord :: new (
974
+ & peer,
975
+ endpoint. address ( ) . clone ( ) ,
976
+ SCORE_CONNECT_SUCCESS ,
977
+ Some ( endpoint. connection_id ( ) ) ,
978
+ ) ) ;
979
+ }
980
+ Some ( record) => tracing:: warn!(
944
981
target: LOG_TARGET ,
945
982
?peer,
946
983
connection_id = ?endpoint. connection_id( ) ,
947
984
address = ?endpoint. address( ) ,
948
- "secondary connection" ,
949
- ) ;
950
-
951
- context. secondary_connection = Some ( AddressRecord :: new (
952
- & peer,
953
- endpoint. address ( ) . clone ( ) ,
954
- SCORE_DIAL_SUCCESS ,
955
- Some ( endpoint. connection_id ( ) ) ,
956
- ) ) ;
957
- }
985
+ dial_record = ?record,
986
+ "unknown connection opened as secondary connection, discarding" ,
987
+ ) ,
988
+ } ,
958
989
} ,
959
990
PeerState :: Dialing { ref record, .. } => {
960
991
match record. connection_id ( ) == & Some ( endpoint. connection_id ( ) ) {
@@ -986,7 +1017,7 @@ impl TransportManager {
986
1017
record : AddressRecord :: new (
987
1018
& peer,
988
1019
endpoint. address ( ) . clone ( ) ,
989
- SCORE_DIAL_SUCCESS ,
1020
+ SCORE_CONNECT_SUCCESS ,
990
1021
Some ( endpoint. connection_id ( ) ) ,
991
1022
) ,
992
1023
dial_record : Some ( record. clone ( ) ) ,
@@ -1036,14 +1067,14 @@ impl TransportManager {
1036
1067
1037
1068
let record = match records. remove ( endpoint. address ( ) ) {
1038
1069
Some ( mut record) => {
1039
- record. update_score ( SCORE_DIAL_SUCCESS ) ;
1070
+ record. update_score ( SCORE_CONNECT_SUCCESS ) ;
1040
1071
record. set_connection_id ( endpoint. connection_id ( ) ) ;
1041
1072
record
1042
1073
}
1043
1074
None => AddressRecord :: new (
1044
1075
& peer,
1045
1076
endpoint. address ( ) . clone ( ) ,
1046
- SCORE_DIAL_SUCCESS ,
1077
+ SCORE_CONNECT_SUCCESS ,
1047
1078
Some ( endpoint. connection_id ( ) ) ,
1048
1079
) ,
1049
1080
} ;
@@ -1076,7 +1107,7 @@ impl TransportManager {
1076
1107
AddressRecord :: new (
1077
1108
& peer,
1078
1109
endpoint. address ( ) . clone ( ) ,
1079
- SCORE_DIAL_SUCCESS ,
1110
+ SCORE_CONNECT_SUCCESS ,
1080
1111
Some ( endpoint. connection_id ( ) ) ,
1081
1112
) ,
1082
1113
Some ( dial_record) ,
@@ -1086,7 +1117,7 @@ impl TransportManager {
1086
1117
AddressRecord :: new (
1087
1118
& peer,
1088
1119
endpoint. address ( ) . clone ( ) ,
1089
- SCORE_DIAL_SUCCESS ,
1120
+ SCORE_CONNECT_SUCCESS ,
1090
1121
Some ( endpoint. connection_id ( ) ) ,
1091
1122
) ,
1092
1123
None ,
@@ -1107,7 +1138,7 @@ impl TransportManager {
1107
1138
record : AddressRecord :: new (
1108
1139
& peer,
1109
1140
endpoint. address ( ) . clone ( ) ,
1110
- SCORE_DIAL_SUCCESS ,
1141
+ SCORE_CONNECT_SUCCESS ,
1111
1142
Some ( endpoint. connection_id ( ) ) ,
1112
1143
) ,
1113
1144
dial_record : None ,
@@ -1186,7 +1217,7 @@ impl TransportManager {
1186
1217
// all other address records back to `AddressStore`. and ask
1187
1218
// transport to negotiate the
1188
1219
let mut dial_record = records. remove ( & address) . expect ( "address to exist" ) ;
1189
- dial_record. update_score ( SCORE_DIAL_SUCCESS ) ;
1220
+ dial_record. update_score ( SCORE_CONNECT_SUCCESS ) ;
1190
1221
1191
1222
// negotiate the connection
1192
1223
match self
@@ -1298,7 +1329,7 @@ impl TransportManager {
1298
1329
1299
1330
if transports. is_empty ( ) {
1300
1331
for ( _, mut record) in records {
1301
- record. update_score ( SCORE_DIAL_FAILURE ) ;
1332
+ record. update_score ( SCORE_CONNECT_FAILURE ) ;
1302
1333
context. addresses . insert ( record) ;
1303
1334
}
1304
1335
@@ -2259,7 +2290,7 @@ mod tests {
2259
2290
} => {
2260
2291
let seconary_connection = context. secondary_connection . as_ref ( ) . unwrap ( ) ;
2261
2292
assert_eq ! ( seconary_connection. address( ) , & address2) ;
2262
- assert_eq ! ( seconary_connection. score( ) , SCORE_DIAL_SUCCESS ) ;
2293
+ assert_eq ! ( seconary_connection. score( ) , SCORE_CONNECT_SUCCESS ) ;
2263
2294
}
2264
2295
state => panic ! ( "invalid state: {state:?}" ) ,
2265
2296
}
@@ -2282,7 +2313,7 @@ mod tests {
2282
2313
} => {
2283
2314
let seconary_connection = peer. secondary_connection . as_ref ( ) . unwrap ( ) ;
2284
2315
assert_eq ! ( seconary_connection. address( ) , & address2) ;
2285
- assert_eq ! ( seconary_connection. score( ) , SCORE_DIAL_SUCCESS ) ;
2316
+ assert_eq ! ( seconary_connection. score( ) , SCORE_CONNECT_SUCCESS ) ;
2286
2317
assert ! ( peer. addresses. contains( & address3) ) ;
2287
2318
}
2288
2319
state => panic ! ( "invalid state: {state:?}" ) ,
@@ -2365,7 +2396,7 @@ mod tests {
2365
2396
} => {
2366
2397
let seconary_connection = context. secondary_connection . as_ref ( ) . unwrap ( ) ;
2367
2398
assert_eq ! ( seconary_connection. address( ) , & address2) ;
2368
- assert_eq ! ( seconary_connection. score( ) , SCORE_DIAL_SUCCESS ) ;
2399
+ assert_eq ! ( seconary_connection. score( ) , SCORE_CONNECT_SUCCESS ) ;
2369
2400
}
2370
2401
state => panic ! ( "invalid state: {state:?}" ) ,
2371
2402
}
@@ -2467,7 +2498,7 @@ mod tests {
2467
2498
} => {
2468
2499
let seconary_connection = context. secondary_connection . as_ref ( ) . unwrap ( ) ;
2469
2500
assert_eq ! ( seconary_connection. address( ) , & address2) ;
2470
- assert_eq ! ( seconary_connection. score( ) , SCORE_DIAL_SUCCESS ) ;
2501
+ assert_eq ! ( seconary_connection. score( ) , SCORE_CONNECT_SUCCESS ) ;
2471
2502
}
2472
2503
state => panic ! ( "invalid state: {state:?}" ) ,
2473
2504
}
@@ -2579,7 +2610,7 @@ mod tests {
2579
2610
} => {
2580
2611
let seconary_connection = context. secondary_connection . as_ref ( ) . unwrap ( ) ;
2581
2612
assert_eq ! ( seconary_connection. address( ) , & address2) ;
2582
- assert_eq ! ( seconary_connection. score( ) , SCORE_DIAL_SUCCESS ) ;
2613
+ assert_eq ! ( seconary_connection. score( ) , SCORE_CONNECT_SUCCESS ) ;
2583
2614
}
2584
2615
state => panic ! ( "invalid state: {state:?}" ) ,
2585
2616
}
@@ -2616,7 +2647,7 @@ mod tests {
2616
2647
} => {
2617
2648
let seconary_connection = context. secondary_connection . as_ref ( ) . unwrap ( ) ;
2618
2649
assert_eq ! ( seconary_connection. address( ) , & address2) ;
2619
- assert_eq ! ( seconary_connection. score( ) , SCORE_DIAL_SUCCESS ) ;
2650
+ assert_eq ! ( seconary_connection. score( ) , SCORE_CONNECT_SUCCESS ) ;
2620
2651
}
2621
2652
state => panic ! ( "invalid state: {state:?}" ) ,
2622
2653
}
0 commit comments