@@ -16,6 +16,7 @@ use interledger_service::{
16
16
use log:: { debug, error, trace, warn} ;
17
17
use parking_lot:: { Mutex , RwLock } ;
18
18
use ring:: digest:: { digest, SHA256 } ;
19
+ use std:: cmp:: Ordering as StdOrdering ;
19
20
use std:: collections:: HashMap ;
20
21
use std:: {
21
22
cmp:: min,
@@ -185,13 +186,13 @@ where
185
186
pub async fn start_broadcast_interval ( & self , interval : u64 ) -> Result < ( ) , ( ) > {
186
187
self . request_all_routes ( ) . await ?;
187
188
let mut interval = tokio:: time:: interval ( Duration :: from_millis ( interval) ) ;
188
- while let _ = interval. tick ( ) . await {
189
+ loop {
190
+ interval. tick ( ) . await ;
189
191
// ensure we have the latest ILP Address from the store
190
192
self . update_ilp_address ( ) ;
191
193
// Do not consume the result if an error since we want to keep the loop going
192
194
let _ = self . broadcast_routes ( ) . await ;
193
195
}
194
- Ok ( ( ) )
195
196
}
196
197
197
198
fn update_ilp_address ( & self ) {
@@ -424,38 +425,24 @@ where
424
425
{
425
426
tokio:: spawn ( {
426
427
let self_clone = self . clone ( ) ;
427
- async move {
428
- self_clone
429
- . update_best_routes ( Some (
430
- prefixes_updated
431
- . into_iter ( )
432
- . map ( |s| s. to_string ( ) )
433
- . collect ( ) ,
434
- ) )
435
- . await
436
- }
428
+ async move { self_clone. update_best_routes ( Some ( prefixes_updated) ) . await }
437
429
} ) ;
438
430
}
439
431
440
432
#[ cfg( test) ]
441
433
{
442
434
let ilp_address = self . ilp_address . clone ( ) ;
443
- self . update_best_routes ( Some (
444
- prefixes_updated
445
- . into_iter ( )
446
- . map ( |s| s. to_string ( ) )
447
- . collect ( ) ,
448
- ) )
449
- . map_err ( move |_| {
450
- RejectBuilder {
451
- code : ErrorCode :: T00_INTERNAL_ERROR ,
452
- message : b"Error processing route update" ,
453
- data : & [ ] ,
454
- triggered_by : Some ( & ilp_address. read ( ) ) ,
455
- }
456
- . build ( )
457
- } )
458
- . await ?;
435
+ self . update_best_routes ( Some ( prefixes_updated) )
436
+ . map_err ( move |_| {
437
+ RejectBuilder {
438
+ code : ErrorCode :: T00_INTERNAL_ERROR ,
439
+ message : b"Error processing route update" ,
440
+ data : & [ ] ,
441
+ triggered_by : Some ( & ilp_address. read ( ) ) ,
442
+ }
443
+ . build ( )
444
+ } )
445
+ . await ?;
459
446
}
460
447
Ok ( CCP_RESPONSE . clone ( ) )
461
448
}
@@ -476,7 +463,7 @@ where
476
463
let table = table. clone ( ) ;
477
464
let self_clone = self . clone ( ) ;
478
465
async move {
479
- self_clone
466
+ let _ = self_clone
480
467
. send_route_control_request (
481
468
request. from . clone ( ) ,
482
469
table. id ( ) ,
@@ -487,7 +474,8 @@ where
487
474
} ) ;
488
475
489
476
#[ cfg( test) ]
490
- self . send_route_control_request ( request. from . clone ( ) , table. id ( ) , table. epoch ( ) )
477
+ let _ = self
478
+ . send_route_control_request ( request. from . clone ( ) , table. id ( ) , table. epoch ( ) )
491
479
. await ;
492
480
Err ( reject)
493
481
}
@@ -668,7 +656,10 @@ where
668
656
let epoch = forwarding_table. increment_epoch ( ) ;
669
657
forwarding_table_updates. push ( (
670
658
new_routes,
671
- withdrawn_routes. iter ( ) . map ( |s| s. to_string ( ) ) . collect ( ) ,
659
+ withdrawn_routes
660
+ . into_iter ( )
661
+ . map ( |s| s. to_string ( ) )
662
+ . collect ( ) ,
672
663
) ) ;
673
664
debug_assert_eq ! ( epoch as usize + 1 , forwarding_table_updates. len( ) ) ;
674
665
@@ -886,8 +877,8 @@ where
886
877
from_epoch_index,
887
878
to_epoch_index,
888
879
current_epoch_index,
889
- new_routes : new_routes . clone ( ) ,
890
- withdrawn_routes : withdrawn_routes . clone ( ) ,
880
+ new_routes,
881
+ withdrawn_routes,
891
882
speaker : self . ilp_address . read ( ) . clone ( ) ,
892
883
hold_down_time : DEFAULT_ROUTE_EXPIRY_TIME ,
893
884
}
@@ -977,24 +968,27 @@ fn get_best_route_for_prefix<A: CcpRoutingAccount>(
977
968
( account, route) ,
978
969
|( best_account, best_route) , ( account, route) | {
979
970
// Prioritize child > peer > parent
980
- if best_account. routing_relation ( ) > account. routing_relation ( ) {
981
- return ( best_account, best_route) ;
982
- } else if best_account. routing_relation ( ) < account. routing_relation ( ) {
983
- return ( account, route) ;
984
- }
985
-
986
- // Prioritize shortest path
987
- if best_route. path . len ( ) < route. path . len ( ) {
988
- return ( best_account, best_route) ;
989
- } else if best_route. path . len ( ) > route. path . len ( ) {
990
- return ( account, route) ;
991
- }
992
-
993
- // Finally base it on account ID
994
- if best_account. id ( ) . to_string ( ) < account. id ( ) . to_string ( ) {
995
- ( best_account, best_route)
996
- } else {
997
- ( account, route)
971
+ match best_account
972
+ . routing_relation ( )
973
+ . cmp ( & account. routing_relation ( ) )
974
+ {
975
+ StdOrdering :: Greater => ( best_account, best_route) ,
976
+ StdOrdering :: Less => ( account, route) ,
977
+ _ => {
978
+ // Prioritize shortest path
979
+ match best_route. path . len ( ) . cmp ( & route. path . len ( ) ) {
980
+ StdOrdering :: Less => ( best_account, best_route) ,
981
+ StdOrdering :: Greater => ( account, route) ,
982
+ _ => {
983
+ // Finally base it on account ID
984
+ if best_account. id ( ) . to_string ( ) < account. id ( ) . to_string ( ) {
985
+ ( best_account, best_route)
986
+ } else {
987
+ ( account, route)
988
+ }
989
+ }
990
+ }
991
+ }
998
992
}
999
993
} ,
1000
994
) ;
@@ -1063,7 +1057,7 @@ mod ranking_routes {
1063
1057
let mut child = TestAccount :: new( Uuid :: from_slice( & [ 6 ; 16 ] ) . unwrap( ) , "example.child" ) ;
1064
1058
child. relation = RoutingRelation :: Child ;
1065
1059
child_table. add_route(
1066
- child. clone ( ) ,
1060
+ child,
1067
1061
Route {
1068
1062
prefix: "example.d" . to_string( ) ,
1069
1063
path: vec![ "example.one" . to_string( ) ] ,
@@ -1092,7 +1086,7 @@ mod ranking_routes {
1092
1086
} ,
1093
1087
) ;
1094
1088
peer_table_1. add_route(
1095
- peer_1. clone ( ) ,
1089
+ peer_1,
1096
1090
Route {
1097
1091
// This route should be overridden by the configured "example.a" route
1098
1092
prefix: "example.a.sub-prefix" . to_string( ) ,
@@ -1104,7 +1098,7 @@ mod ranking_routes {
1104
1098
let mut peer_table_2 = RoutingTable :: default ( ) ;
1105
1099
let peer_2 = TestAccount :: new( Uuid :: from_slice( & [ 8 ; 16 ] ) . unwrap( ) , "example.peer2" ) ;
1106
1100
peer_table_2. add_route(
1107
- peer_2. clone ( ) ,
1101
+ peer_2,
1108
1102
Route {
1109
1103
prefix: "example.e" . to_string( ) ,
1110
1104
path: vec![ "example.one" . to_string( ) , "example.two" . to_string( ) ] ,
0 commit comments