Skip to content

Commit 7240a8b

Browse files
snapshots: add https
1 parent 44b3b42 commit 7240a8b

File tree

7 files changed

+303
-85
lines changed

7 files changed

+303
-85
lines changed

src/app/firedancer/topology.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,17 @@ resolve_address( char const * address,
127127

128128
static int
129129
resolve_peer( char const * peer,
130-
fd_ip4_port_t * ip4_port ) {
130+
char hostname[ static 256UL ],
131+
fd_ip4_port_t * ip4_port,
132+
int * is_https ) {
131133

132134
/* Split host:port */
133135
char const * host_port = peer;
134136
if( FD_LIKELY( strncmp( peer, "http://", 7UL )==0 ) ) {
137+
if( FD_LIKELY( is_https ) ) *is_https = 0;
135138
host_port += 7UL;
136139
} else if( FD_LIKELY( strncmp( peer, "https://", 8UL )==0 ) ) {
140+
if( FD_LIKELY( is_https ) ) *is_https = 1;
137141
host_port += 8UL;
138142
}
139143

@@ -148,7 +152,9 @@ resolve_peer( char const * peer,
148152
FD_LOG_ERR(( "invalid [gossip.entrypoints] entry \"%s\": hostname too long", host_port ));
149153
}
150154
fd_memcpy( fqdn, host_port, fqdn_len );
155+
fd_memcpy( hostname, fqdn, fqdn_len );
151156
fqdn[ fqdn_len ] = '\0';
157+
hostname[ fqdn_len ] = '\0';
152158

153159
/* Parse port number */
154160

@@ -169,7 +175,8 @@ static void
169175
resolve_gossip_entrypoints( config_t * config ) {
170176
ulong entrypoint_cnt = config->gossip.entrypoints_cnt;
171177
for( ulong i=0UL; i<entrypoint_cnt; i++ ) {
172-
if( FD_UNLIKELY( 0==resolve_peer( config->gossip.entrypoints[ i ], &config->gossip.resolved_entrypoints[ i ] ) ) ) {
178+
char hostname[ 256UL ];
179+
if( FD_UNLIKELY( 0==resolve_peer( config->gossip.entrypoints[ i ], hostname, &config->gossip.resolved_entrypoints[ i ], NULL ) ) ) {
173180
FD_LOG_ERR(( "failed to resolve address of [gossip.entrypoints] entry \"%s\"", config->gossip.entrypoints[ i ] ));
174181
}
175182
}
@@ -184,7 +191,10 @@ resolve_snapshot_peers( config_t * config,
184191
for( ulong j=0UL; j<peers_cnt; j++ ) {
185192
if( FD_UNLIKELY( !config->firedancer.snapshots.sources.http.peers[ j ].enabled ) ) continue;
186193

187-
if( FD_UNLIKELY( 0==resolve_peer( config->firedancer.snapshots.sources.http.peers[ j ].url, &tile->snaprd.http.peers[ resolved_peers_cnt ] ) ) ) {
194+
if( FD_UNLIKELY( 0==resolve_peer( config->firedancer.snapshots.sources.http.peers[ j ].url,
195+
tile->snaprd.http.peers[ resolved_peers_cnt ].hostname,
196+
&tile->snaprd.http.peers[ resolved_peers_cnt ].addr,
197+
&tile->snaprd.http.peers[ resolved_peers_cnt ].is_https ) ) ) {
188198
FD_LOG_ERR(( "failed to resolve address of [snapshots.sources.http.peers] entry \"%s\"", config->firedancer.snapshots.sources.http.peers[ j ].url ));
189199
} else {
190200
resolved_peers_cnt++;

src/disco/topo/fd_topo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,12 @@ struct fd_topo_tile {
513513

514514
struct {
515515
ulong peers_cnt;
516-
fd_ip4_port_t peers[ 16UL ];
516+
517+
struct {
518+
fd_ip4_port_t addr;
519+
char hostname[ 256UL ];
520+
int is_https;
521+
} peers[ 16UL ];
517522
} http;
518523

519524
int diagnostics;

src/discof/restore/fd_snaprd_tile.c

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
#define IN_KIND_GOSSIP (1)
4646
#define MAX_IN_LINKS (3)
4747

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+
4857
struct fd_snaprd_tile {
4958
fd_ssping_t * ssping;
5059
fd_sshttp_t * sshttp;
@@ -57,7 +66,7 @@ struct fd_snaprd_tile {
5766

5867
long diagnostic_deadline_nanos;
5968

60-
fd_ip4_port_t addr;
69+
fd_sspeer_t peer;
6170

6271
struct {
6372
ulong write_buffer_pos;
@@ -95,6 +104,9 @@ struct fd_snaprd_tile {
95104
uint maximum_download_retry_abort;
96105
uint max_full_snapshots_to_keep;
97106
uint max_incremental_snapshots_to_keep;
107+
108+
ulong peers_cnt;
109+
fd_snaprd_http_peer_t peers[ 16UL ];
98110
} config;
99111

100112
struct {
@@ -232,8 +244,8 @@ read_http_data( fd_snaprd_tile_t * ctx,
232244
case FD_SSHTTP_ADVANCE_AGAIN: break;
233245
case FD_SSHTTP_ADVANCE_ERROR: {
234246
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 );
237249
fd_stem_publish( stem, 0UL, FD_SNAPSHOT_MSG_CTRL_RESET_FULL, 0UL, 0UL, 0UL, 0UL, 0UL );
238250
ctx->state = FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET;
239251
ctx->deadline_nanos = now;
@@ -457,8 +469,8 @@ after_credit( fd_snaprd_tile_t * ctx,
457469

458470
switch ( ctx->state ) {
459471
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 ) ) {
462474
ctx->state = FD_SNAPRD_STATE_COLLECTING_PEERS;
463475
ctx->deadline_nanos = now+500L*1000L*1000L;
464476
}
@@ -467,8 +479,8 @@ after_credit( fd_snaprd_tile_t * ctx,
467479
case FD_SNAPRD_STATE_COLLECTING_PEERS: {
468480
if( FD_UNLIKELY( now<ctx->deadline_nanos ) ) break;
469481

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 ) ) {
472484
ctx->state = FD_SNAPRD_STATE_WAITING_FOR_PEERS;
473485
break;
474486
}
@@ -479,10 +491,10 @@ after_credit( fd_snaprd_tile_t * ctx,
479491
ctx->metrics.full.bytes_total = ctx->local_in.full_snapshot_size;
480492
ctx->state = FD_SNAPRD_STATE_READING_FULL_FILE;
481493
} 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;
484496
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 );
486498
}
487499
break;
488500
}
@@ -547,8 +559,8 @@ after_credit( fd_snaprd_tile_t * ctx,
547559
break;
548560
}
549561

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() );
552564
ctx->state = FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP;
553565
break;
554566
case FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET:
@@ -632,12 +644,12 @@ after_frag( fd_snaprd_tile_t * ctx,
632644
fd_contact_info_t * cur = &ctx->gossip.ci_table[ msg->contact_info.idx ];
633645
fd_ip4_port_t cur_addr = ctx->gossip.ci_table[ msg->contact_info.idx ].sockets[ FD_CONTACT_INFO_SOCKET_RPC ];
634646
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 } );
636648
}
637649
fd_contact_info_t * new = msg->contact_info.contact_info;
638650
fd_ip4_port_t new_addr = new->sockets[ FD_CONTACT_INFO_SOCKET_RPC ];
639651
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 } );
641653
}
642654
*cur = *new;
643655
}
@@ -646,7 +658,7 @@ after_frag( fd_snaprd_tile_t * ctx,
646658
fd_contact_info_t * cur = &ctx->gossip.ci_table[ msg->contact_info_remove.idx ];
647659
fd_ip4_port_t addr = cur->sockets[ FD_CONTACT_INFO_SOCKET_RPC ];
648660
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 } );
650662
}
651663
}
652664
break;
@@ -675,9 +687,9 @@ after_frag( fd_snaprd_tile_t * ctx,
675687
case FD_SNAPRD_STATE_READING_FULL_HTTP:
676688
case FD_SNAPRD_STATE_READING_INCREMENTAL_HTTP:
677689
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 ));
679691
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() );
681693
fd_stem_publish( stem, 0UL, FD_SNAPSHOT_MSG_CTRL_RESET_FULL, 0UL, 0UL, 0UL, 0UL, 0UL );
682694
ctx->state = FD_SNAPRD_STATE_FLUSHING_FULL_HTTP_RESET;
683695
break;
@@ -686,9 +698,9 @@ after_frag( fd_snaprd_tile_t * ctx,
686698
if( FD_UNLIKELY( ctx->malformed ) ) break;
687699

688700
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 ));
690702
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() );
692704
/* We would like to transition to FULL_HTTP_RESET, but we
693705
can't do it just yet, because we have already sent a DONE
694706
control fragment, and need to wait for acknowledges to come
@@ -862,7 +874,17 @@ unprivileged_init( fd_topo_t * topo,
862874
}
863875
}
864876

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+
}
866888

867889
if( FD_UNLIKELY( tile->out_cnt!=1UL ) ) FD_LOG_ERR(( "tile `" NAME "` has %lu outs, expected 1", tile->out_cnt ));
868890

0 commit comments

Comments
 (0)