@@ -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
}
@@ -358,8 +362,8 @@ after_credit( fd_snaprd_tile_t * ctx,
358
362
359
363
switch ( ctx -> state ) {
360
364
case FD_SNAPRD_STATE_WAITING_FOR_PEERS : {
361
- fd_ip4_port_t best = fd_ssping_best ( ctx -> ssping );
362
- if ( FD_LIKELY ( best .l ) ) {
365
+ fd_sspeer_t best = fd_ssping_best ( ctx -> ssping );
366
+ if ( FD_LIKELY ( best .addr . l ) ) {
363
367
ctx -> state = FD_SNAPRD_STATE_COLLECTING_PEERS ;
364
368
ctx -> deadline_nanos = now + 500L * 1000L * 1000L ;
365
369
}
@@ -368,8 +372,8 @@ after_credit( fd_snaprd_tile_t * ctx,
368
372
case FD_SNAPRD_STATE_COLLECTING_PEERS : {
369
373
if ( FD_UNLIKELY ( now < ctx -> deadline_nanos ) ) break ;
370
374
371
- fd_ip4_port_t best = fd_ssping_best ( ctx -> ssping );
372
- if ( FD_UNLIKELY ( !best .l ) ) {
375
+ fd_sspeer_t best = fd_ssping_best ( ctx -> ssping );
376
+ if ( FD_UNLIKELY ( !best .addr . l ) ) {
373
377
ctx -> state = FD_SNAPRD_STATE_WAITING_FOR_PEERS ;
374
378
break ;
375
379
}
@@ -379,10 +383,19 @@ after_credit( fd_snaprd_tile_t * ctx,
379
383
FD_LOG_NOTICE (( "loading full snapshot from local file `%s`" , ctx -> local_in .full_snapshot_path ));
380
384
ctx -> state = FD_SNAPRD_STATE_READING_FULL_FILE ;
381
385
} else {
382
- 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 ));
383
- ctx -> addr = best ;
386
+ char path [ PATH_MAX ];
387
+ char encoded_full_hash [ FD_BASE58_ENCODED_32_SZ ];
388
+ char encoded_incremental_hash [ FD_BASE58_ENCODED_32_SZ ];
389
+ fd_base58_encode_32 ( best .snapshot_info -> full .hash , NULL , encoded_full_hash );
390
+ fd_base58_encode_32 ( best .snapshot_info -> incremental .hash , NULL , encoded_incremental_hash );
391
+ 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 ) );
392
+ 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 ) );
393
+ FD_TEST ( fd_cstr_printf_check ( path , PATH_MAX , NULL , "/%s" , ctx -> http .full_path ) );
394
+
395
+ 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 ));
396
+ ctx -> peer = best ;
384
397
ctx -> state = FD_SNAPRD_STATE_READING_FULL_HTTP ;
385
- fd_sshttp_init ( ctx -> sshttp , best , "/snapshot.tar.bz2" , 17UL , now );
398
+ fd_sshttp_init ( ctx -> sshttp , best . addr , path , ctx -> http . full_len + 1UL , now );
386
399
}
387
400
break ;
388
401
}
@@ -446,8 +459,10 @@ after_credit( fd_snaprd_tile_t * ctx,
446
459
break ;
447
460
}
448
461
449
- 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 ));
450
- fd_sshttp_init ( ctx -> sshttp , ctx -> addr , "/incremental-snapshot.tar.bz2" , 29UL , fd_log_wallclock () );
462
+ char path [ PATH_MAX ];
463
+ FD_TEST ( fd_cstr_printf_check ( path , PATH_MAX , NULL , "/%s" , ctx -> http .incremental_path ) );
464
+ 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 ));
465
+ fd_sshttp_init ( ctx -> sshttp , ctx -> peer .addr , path , ctx -> http .incremental_len + 1UL , fd_log_wallclock () );
451
466
ctx -> state = FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP ;
452
467
break ;
453
468
case FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET :
@@ -509,18 +524,18 @@ after_frag( fd_snaprd_tile_t * ctx,
509
524
case FD_SNAPRD_STATE_READING_FULL_HTTP :
510
525
case FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP :
511
526
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" ,
512
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), ctx -> addr .port ));
527
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), ctx -> peer . addr .port ));
513
528
fd_sshttp_cancel ( ctx -> sshttp );
514
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , fd_log_wallclock () );
529
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer . addr , fd_log_wallclock () );
515
530
fd_stem_publish ( stem , 0UL , FD_SNAPSHOT_MSG_CTRL_RESET_FULL , 0UL , 0UL , 0UL , 0UL , 0UL );
516
531
ctx -> state = FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET ;
517
532
break ;
518
533
case FD_SNAPRD_STATE_FLUSHING_FULL_HTTP :
519
534
case FD_SNAPRD_STATE_FLUSHING_INCREMENTAL_HTTP :
520
535
FD_LOG_NOTICE (( "error downloading snapshot from http://" FD_IP4_ADDR_FMT ":%hu/snapshot.tar.bz2" ,
521
- FD_IP4_ADDR_FMT_ARGS ( ctx -> addr .addr ), ctx -> addr .port ));
536
+ FD_IP4_ADDR_FMT_ARGS ( ctx -> peer . addr .addr ), ctx -> peer . addr .port ));
522
537
fd_sshttp_cancel ( ctx -> sshttp );
523
- fd_ssping_invalidate ( ctx -> ssping , ctx -> addr , fd_log_wallclock () );
538
+ fd_ssping_invalidate ( ctx -> ssping , ctx -> peer . addr , fd_log_wallclock () );
524
539
/* We would like to transition to FULL_HTTP_RESET, but we can't
525
540
do it just yet, because we have already sent a DONE control
526
541
fragment, and need to wait for acknowledges to come back
0 commit comments