@@ -49,7 +49,7 @@ struct fd_snaprd_tile {
49
49
ulong ack_cnt ;
50
50
int peer_selection ;
51
51
52
- fd_ip4_port_t addr ;
52
+ fd_sspeer_t peer ;
53
53
54
54
struct {
55
55
ulong write_buffer_pos ;
@@ -73,6 +73,13 @@ struct fd_snaprd_tile {
73
73
char incremental_snapshot_path [ PATH_MAX ];
74
74
} local_in ;
75
75
76
+ struct {
77
+ char full_path [ PATH_MAX ];
78
+ ulong full_len ;
79
+ char incremental_path [ PATH_MAX ];
80
+ ulong incremental_len ;
81
+ } http ;
82
+
76
83
struct {
77
84
char path [ PATH_MAX ];
78
85
int do_download ;
@@ -204,8 +211,8 @@ read_http_data( fd_snaprd_tile_t * ctx,
204
211
case FD_SSHTTP_ADVANCE_AGAIN : break ;
205
212
case FD_SSHTTP_ADVANCE_ERROR : {
206
213
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" ,
207
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), ctx -> addr .port ));
208
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , now );
214
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), ctx -> peer . addr .port ));
215
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer . addr , now );
209
216
fd_stem_publish ( stem , 0UL , FD_SNAPSHOT_MSG_CTRL_RESET_FULL , 0UL , 0UL , 0UL , 0UL , 0UL );
210
217
ctx -> state = FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET ;
211
218
ctx -> deadline_nanos = now ;
@@ -319,16 +326,13 @@ drain_buffer( fd_snaprd_tile_t * ctx ) {
319
326
static void
320
327
rename_snapshots ( fd_snaprd_tile_t * ctx ) {
321
328
if ( FD_UNLIKELY ( -1 == ctx -> local_out .dir_fd ) ) return ;
322
- char const * full_snapshot_name ;
323
- char const * incremental_snapshot_name ;
324
- fd_sshttp_snapshot_names ( ctx -> sshttp , & full_snapshot_name , & incremental_snapshot_name );
325
329
326
330
if ( FD_LIKELY ( -1 != ctx -> local_out .full_snapshot_fd ) ) {
327
- if ( FD_UNLIKELY ( -1 == renameat ( ctx -> local_out .dir_fd , "snapshot.tar.bz2-partial" , ctx -> local_out .dir_fd , full_snapshot_name ) ) )
331
+ if ( FD_UNLIKELY ( -1 == renameat ( ctx -> local_out .dir_fd , "snapshot.tar.bz2-partial" , ctx -> local_out .dir_fd , ctx -> http . full_path ) ) )
328
332
FD_LOG_ERR (( "renameat() failed (%i-%s)" , errno , fd_io_strerror ( errno ) ));
329
333
}
330
334
if ( FD_LIKELY ( -1 != ctx -> local_out .incremental_snapshot_fd ) ) {
331
- if ( FD_UNLIKELY ( -1 == renameat ( ctx -> local_out .dir_fd , "incremental-snapshot.tar.bz2-partial" , ctx -> local_out .dir_fd , incremental_snapshot_name ) ) )
335
+ if ( FD_UNLIKELY ( -1 == renameat ( ctx -> local_out .dir_fd , "incremental-snapshot.tar.bz2-partial" , ctx -> local_out .dir_fd , ctx -> http . incremental_path ) ) )
332
336
FD_LOG_ERR (( "renameat() failed (%i-%s)" , errno , fd_io_strerror ( errno ) ));
333
337
}
334
338
}
@@ -357,8 +361,8 @@ after_credit( fd_snaprd_tile_t * ctx,
357
361
358
362
switch ( ctx -> state ) {
359
363
case FD_SNAPRD_STATE_WAITING_FOR_PEERS : {
360
- fd_ip4_port_t best = fd_ssping_best ( ctx -> ssping );
361
- if ( FD_LIKELY ( best .l ) ) {
364
+ fd_sspeer_t best = fd_ssping_best ( ctx -> ssping );
365
+ if ( FD_LIKELY ( best .addr . l ) ) {
362
366
ctx -> state = FD_SNAPRD_STATE_COLLECTING_PEERS ;
363
367
ctx -> deadline_nanos = now + 500L * 1000L * 1000L ;
364
368
}
@@ -367,8 +371,8 @@ after_credit( fd_snaprd_tile_t * ctx,
367
371
case FD_SNAPRD_STATE_COLLECTING_PEERS : {
368
372
if ( FD_UNLIKELY ( now < ctx -> deadline_nanos ) ) break ;
369
373
370
- fd_ip4_port_t best = fd_ssping_best ( ctx -> ssping );
371
- if ( FD_UNLIKELY ( !best .l ) ) {
374
+ fd_sspeer_t best = fd_ssping_best ( ctx -> ssping );
375
+ if ( FD_UNLIKELY ( !best .addr . l ) ) {
372
376
ctx -> state = FD_SNAPRD_STATE_WAITING_FOR_PEERS ;
373
377
break ;
374
378
}
@@ -378,10 +382,19 @@ after_credit( fd_snaprd_tile_t * ctx,
378
382
FD_LOG_NOTICE (( "loading full snapshot from local file `%s`" , ctx -> local_in .full_snapshot_path ));
379
383
ctx -> state = FD_SNAPRD_STATE_READING_FULL_FILE ;
380
384
} else {
381
- FD_LOG_NOTICE (( "downloading full snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" , FD_IP4_ADDR_FMT_ARGS ( best .addr ), best .port ));
382
- ctx -> addr = best ;
385
+ char path [ PATH_MAX ];
386
+ char encoded_full_hash [ FD_BASE58_ENCODED_32_SZ ];
387
+ char encoded_incremental_hash [ FD_BASE58_ENCODED_32_SZ ];
388
+ fd_base58_encode_32 ( best .snapshot_info -> full .hash , NULL , encoded_full_hash );
389
+ fd_base58_encode_32 ( best .snapshot_info -> incremental .hash , NULL , encoded_incremental_hash );
390
+ FD_TEST ( fd_cstr_printf_check ( ctx -> http .full_path , PATH_MAX , & ctx -> http .full_len , "snapshot-%lu-%s.tar.zst" , best .snapshot_info -> full .slot , encoded_full_hash ) );
391
+ FD_TEST ( fd_cstr_printf_check ( ctx -> http .incremental_path , PATH_MAX , & ctx -> http .incremental_len , "incremental-snapshot-%lu-%lu-%s.tar.zst" , best .snapshot_info -> incremental .base_slot , best .snapshot_info -> incremental .slot , encoded_incremental_hash ) );
392
+ FD_TEST ( fd_cstr_printf_check ( path , PATH_MAX , NULL , "/%s" , ctx -> http .full_path ) );
393
+
394
+ FD_LOG_NOTICE (( "downloading full snapshot from http://" FD_IP4_ADDR_FMT ":%hu/%s" , FD_IP4_ADDR_FMT_ARGS ( best .addr .addr ), best .addr .port , ctx -> http .full_path ));
395
+ ctx -> peer = best ;
383
396
ctx -> state = FD_SNAPRD_STATE_READING_FULL_HTTP ;
384
- fd_sshttp_init ( ctx -> sshttp , best , "/snapshot.tar.bz2" , 17UL , now );
397
+ fd_sshttp_init ( ctx -> sshttp , best . addr , path , ctx -> http . full_len + 1UL , now );
385
398
}
386
399
break ;
387
400
}
@@ -445,8 +458,10 @@ after_credit( fd_snaprd_tile_t * ctx,
445
458
break ;
446
459
}
447
460
448
- 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 ), ctx -> addr .port ));
449
- fd_sshttp_init ( ctx -> sshttp , ctx -> addr , "/incremental-snapshot.tar.bz2" , 29UL , fd_log_wallclock () );
461
+ char path [ PATH_MAX ];
462
+ FD_TEST ( fd_cstr_printf_check ( path , PATH_MAX , NULL , "/%s" , ctx -> http .incremental_path ) );
463
+ FD_LOG_NOTICE (( "downloading incremental snapshot from http://" FD_IP4_ADDR_FMT ":%hu/%s" , FD_IP4_ADDR_FMT_ARGS ( ctx -> peer .addr .addr ), ctx -> peer .addr .port , path ));
464
+ fd_sshttp_init ( ctx -> sshttp , ctx -> peer .addr , path , ctx -> http .incremental_len + 1UL , fd_log_wallclock () );
450
465
ctx -> state = FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP ;
451
466
break ;
452
467
case FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET :
@@ -508,18 +523,18 @@ after_frag( fd_snaprd_tile_t * ctx,
508
523
case FD_SNAPRD_STATE_READING_FULL_HTTP :
509
524
case FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP :
510
525
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" ,
511
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), ctx -> addr .port ));
526
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), ctx -> peer . addr .port ));
512
527
fd_sshttp_cancel ( ctx -> sshttp );
513
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , fd_log_wallclock () );
528
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer . addr , fd_log_wallclock () );
514
529
fd_stem_publish ( stem , 0UL , FD_SNAPSHOT_MSG_CTRL_RESET_FULL , 0UL , 0UL , 0UL , 0UL , 0UL );
515
530
ctx -> state = FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET ;
516
531
break ;
517
532
case FD_SNAPRD_STATE_FLUSHING_FULL_HTTP :
518
533
case FD_SNAPRD_STATE_FLUSHING_INCREMENTAL_HTTP :
519
534
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" ,
520
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), ctx -> addr .port ));
535
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), ctx -> peer . addr .port ));
521
536
fd_sshttp_cancel ( ctx -> sshttp );
522
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , fd_log_wallclock () );
537
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer . addr , fd_log_wallclock () );
523
538
/* We would like to transition to FULL_HTTP_RESET, but we can't
524
539
do it just yet, because we have already sent a DONE control
525
540
fragment, and need to wait for acknowledges to come back
0 commit comments