45
45
#define IN_KIND_GOSSIP (1)
46
46
#define MAX_IN_LINKS (3)
47
47
48
+ struct fd_snaprd_http_peer {
49
+ char hostname [ 256UL ];
50
+ ulong hostname_len ;
51
+ int is_https ;
52
+ fd_ip4_port_t addr ;
53
+ };
54
+
55
+ typedef struct fd_snaprd_http_peer fd_snaprd_http_peer_t ;
56
+
48
57
struct fd_snaprd_tile {
49
58
fd_ssping_t * ssping ;
50
59
fd_sshttp_t * sshttp ;
@@ -57,7 +66,7 @@ struct fd_snaprd_tile {
57
66
58
67
long diagnostic_deadline_nanos ;
59
68
60
- fd_ip4_port_t addr ;
69
+ fd_sspeer_t peer ;
61
70
62
71
struct {
63
72
ulong write_buffer_pos ;
@@ -95,6 +104,9 @@ struct fd_snaprd_tile {
95
104
uint maximum_download_retry_abort ;
96
105
uint max_full_snapshots_to_keep ;
97
106
uint max_incremental_snapshots_to_keep ;
107
+
108
+ ulong peers_cnt ;
109
+ fd_snaprd_http_peer_t peers [ 16UL ];
98
110
} config ;
99
111
100
112
struct {
@@ -232,8 +244,8 @@ read_http_data( fd_snaprd_tile_t * ctx,
232
244
case FD_SSHTTP_ADVANCE_AGAIN : break ;
233
245
case FD_SSHTTP_ADVANCE_ERROR : {
234
246
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" ,
235
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), fd_ushort_bswap ( ctx -> addr .port ) ));
236
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , now );
247
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), fd_ushort_bswap ( ctx -> peer . addr .port ) ));
248
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer , now );
237
249
fd_stem_publish ( stem , 0UL , FD_SNAPSHOT_MSG_CTRL_RESET_FULL , 0UL , 0UL , 0UL , 0UL , 0UL );
238
250
ctx -> state = FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET ;
239
251
ctx -> deadline_nanos = now ;
@@ -457,8 +469,8 @@ after_credit( fd_snaprd_tile_t * ctx,
457
469
458
470
switch ( ctx -> state ) {
459
471
case FD_SNAPRD_STATE_WAITING_FOR_PEERS : {
460
- fd_ip4_port_t best = fd_ssping_best ( ctx -> ssping );
461
- if ( FD_LIKELY ( best .l ) ) {
472
+ fd_sspeer_t best = fd_ssping_best ( ctx -> ssping );
473
+ if ( FD_LIKELY ( best .addr . l ) ) {
462
474
ctx -> state = FD_SNAPRD_STATE_COLLECTING_PEERS ;
463
475
ctx -> deadline_nanos = now + 500L * 1000L * 1000L ;
464
476
}
@@ -467,8 +479,8 @@ after_credit( fd_snaprd_tile_t * ctx,
467
479
case FD_SNAPRD_STATE_COLLECTING_PEERS : {
468
480
if ( FD_UNLIKELY ( now < ctx -> deadline_nanos ) ) break ;
469
481
470
- fd_ip4_port_t best = fd_ssping_best ( ctx -> ssping );
471
- if ( FD_UNLIKELY ( !best .l ) ) {
482
+ fd_sspeer_t best = fd_ssping_best ( ctx -> ssping );
483
+ if ( FD_UNLIKELY ( !best .addr . l ) ) {
472
484
ctx -> state = FD_SNAPRD_STATE_WAITING_FOR_PEERS ;
473
485
break ;
474
486
}
@@ -479,10 +491,10 @@ after_credit( fd_snaprd_tile_t * ctx,
479
491
ctx -> metrics .full .bytes_total = ctx -> local_in .full_snapshot_size ;
480
492
ctx -> state = FD_SNAPRD_STATE_READING_FULL_FILE ;
481
493
} else {
482
- FD_LOG_NOTICE (( "downloading full snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" , FD_IP4_ADDR_FMT_ARGS ( best .addr ), fd_ushort_bswap ( best .port ) ));
483
- ctx -> addr = best ;
494
+ FD_LOG_NOTICE (( "downloading full snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" , FD_IP4_ADDR_FMT_ARGS ( best .addr . addr ), fd_ushort_bswap ( best . addr .port ) ));
495
+ ctx -> peer = best ;
484
496
ctx -> state = FD_SNAPRD_STATE_READING_FULL_HTTP ;
485
- fd_sshttp_init ( ctx -> sshttp , best , "/snapshot.tar.bz2" , 17UL , now );
497
+ fd_sshttp_init ( ctx -> sshttp , ctx -> peer , "/snapshot.tar.bz2" , 17UL , now );
486
498
}
487
499
break ;
488
500
}
@@ -547,8 +559,8 @@ after_credit( fd_snaprd_tile_t * ctx,
547
559
break ;
548
560
}
549
561
550
- FD_LOG_NOTICE (( "downloading incremental snapshot from http://" FD_IP4_ADDR_FMT ":%hu/incremental-snapshot.tar.bz2" , FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), fd_ushort_bswap ( ctx -> addr .port ) ));
551
- fd_sshttp_init ( ctx -> sshttp , ctx -> addr , "/incremental-snapshot.tar.bz2" , 29UL , fd_log_wallclock () );
562
+ FD_LOG_NOTICE (( "downloading incremental snapshot from http://" FD_IP4_ADDR_FMT ":%hu/incremental-snapshot.tar.bz2" , FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), fd_ushort_bswap ( ctx -> peer . addr .port ) ));
563
+ fd_sshttp_init ( ctx -> sshttp , ctx -> peer , "/incremental-snapshot.tar.bz2" , 29UL , fd_log_wallclock () );
552
564
ctx -> state = FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP ;
553
565
break ;
554
566
case FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET :
@@ -632,12 +644,12 @@ after_frag( fd_snaprd_tile_t * ctx,
632
644
fd_contact_info_t * cur = & ctx -> gossip .ci_table [ msg -> contact_info .idx ];
633
645
fd_ip4_port_t cur_addr = ctx -> gossip .ci_table [ msg -> contact_info .idx ].sockets [ FD_CONTACT_INFO_SOCKET_RPC ];
634
646
if ( cur_addr .l ){
635
- fd_ssping_remove ( ctx -> ssping , cur_addr );
647
+ fd_ssping_remove ( ctx -> ssping , ( fd_sspeer_t ){ . addr = cur_addr , . hostname = NULL , . hostname_len = 0UL } );
636
648
}
637
649
fd_contact_info_t * new = msg -> contact_info .contact_info ;
638
650
fd_ip4_port_t new_addr = new -> sockets [ FD_CONTACT_INFO_SOCKET_RPC ];
639
651
if ( new_addr .l ) {
640
- fd_ssping_add ( ctx -> ssping , new_addr );
652
+ fd_ssping_add ( ctx -> ssping , ( fd_sspeer_t ){ . addr = new_addr , . hostname = NULL , . hostname_len = 0UL } );
641
653
}
642
654
* cur = * new ;
643
655
}
@@ -646,7 +658,7 @@ after_frag( fd_snaprd_tile_t * ctx,
646
658
fd_contact_info_t * cur = & ctx -> gossip .ci_table [ msg -> contact_info_remove .idx ];
647
659
fd_ip4_port_t addr = cur -> sockets [ FD_CONTACT_INFO_SOCKET_RPC ];
648
660
if ( addr .l ) {
649
- fd_ssping_remove ( ctx -> ssping , addr );
661
+ fd_ssping_remove ( ctx -> ssping , ( fd_sspeer_t ){ . addr = addr , . hostname = NULL , . hostname_len = 0UL } );
650
662
}
651
663
}
652
664
break ;
@@ -675,9 +687,9 @@ after_frag( fd_snaprd_tile_t * ctx,
675
687
case FD_SNAPRD_STATE_READING_FULL_HTTP :
676
688
case FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP :
677
689
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" ,
678
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), ctx -> addr .port ));
690
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), ctx -> peer . addr .port ));
679
691
fd_sshttp_cancel ( ctx -> sshttp );
680
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , fd_log_wallclock () );
692
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer , fd_log_wallclock () );
681
693
fd_stem_publish ( stem , 0UL , FD_SNAPSHOT_MSG_CTRL_RESET_FULL , 0UL , 0UL , 0UL , 0UL , 0UL );
682
694
ctx -> state = FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET ;
683
695
break ;
@@ -686,9 +698,9 @@ after_frag( fd_snaprd_tile_t * ctx,
686
698
if ( FD_UNLIKELY ( ctx -> malformed ) ) break ;
687
699
688
700
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/incremental-snapshot.tar.bz2" ,
689
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), ctx -> addr .port ));
701
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), ctx -> peer . addr .port ));
690
702
fd_sshttp_cancel ( ctx -> sshttp );
691
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , fd_log_wallclock () );
703
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer , fd_log_wallclock () );
692
704
/* We would like to transition to FULL_HTTP_RESET, but we
693
705
can't do it just yet, because we have already sent a DONE
694
706
control fragment, and need to wait for acknowledges to come
@@ -862,7 +874,17 @@ unprivileged_init( fd_topo_t * topo,
862
874
}
863
875
}
864
876
865
- for ( ulong i = 0UL ; i < tile -> snaprd .http .peers_cnt ; i ++ ) fd_ssping_add ( ctx -> ssping , tile -> snaprd .http .peers [ i ] );
877
+ ctx -> config .peers_cnt = tile -> snaprd .http .peers_cnt ;
878
+ for ( ulong i = 0UL ; i < tile -> snaprd .http .peers_cnt ; i ++ ) {
879
+ ctx -> config .peers [ i ].addr = tile -> snaprd .http .peers [ i ].addr ;
880
+ fd_memcpy ( ctx -> config .peers [ i ].hostname , tile -> snaprd .http .peers [ i ].hostname , 256UL );
881
+ ctx -> config .peers [ i ].hostname_len = strnlen ( tile -> snaprd .http .peers [ i ].hostname , 256UL );
882
+ }
883
+
884
+ for ( ulong i = 0UL ; i < ctx -> config .peers_cnt ; i ++ ) {
885
+ fd_sspeer_t peer = { .addr = ctx -> config .peers [ i ].addr , .hostname = ctx -> config .peers [ i ].hostname , .hostname_len = ctx -> config .peers [ i ].hostname_len };
886
+ fd_ssping_add ( ctx -> ssping , peer );
887
+ }
866
888
867
889
if ( FD_UNLIKELY ( tile -> out_cnt != 1UL ) ) FD_LOG_ERR (( "tile `" NAME "` has %lu outs, expected 1" , tile -> out_cnt ));
868
890
0 commit comments