Line data Source code
1 : #include "../../shared/commands/configure/configure.h"
2 : #include "../../shared/commands/run/run.h" /* initialize_workspaces */
3 : #include "../../shared/fd_config.h" /* config_t */
4 : #include "../../../disco/topo/fd_cpu_topo.h" /* fd_topo_cpus */
5 : #include "../../../disco/topo/fd_topob.h"
6 : #include "../../../disco/net/fd_net_tile.h" /* fd_topos_net_tiles */
7 : #include "../../../util/pod/fd_pod_format.h"
8 : #include "../../../util/net/fd_ip4.h" /* fd_cstr_to_ip4_addr */
9 :
10 : #include <stdio.h> /* printf */
11 : #include <unistd.h> /* isatty */
12 : #include <sys/ioctl.h>
13 :
14 : extern fd_topo_obj_callbacks_t * CALLBACKS[];
15 :
16 : fd_topo_run_tile_t
17 : fdctl_tile_run( fd_topo_tile_t const * tile );
18 :
19 : static void
20 0 : gossip_topo( config_t * config ) {
21 0 : static const ulong tile_to_cpu[ FD_TILE_MAX ] = {0}; /* TODO */
22 :
23 0 : config->layout.net_tile_count = 1;
24 :
25 0 : fd_topo_cpus_t cpus[1];
26 0 : fd_topo_cpus_init( cpus );
27 :
28 : /* Reset topology from scratch */
29 0 : fd_topo_t * topo = &config->topo;
30 0 : fd_topob_new( &config->topo, config->name );
31 0 : topo->max_page_size = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
32 :
33 0 : fd_topob_wksp( topo, "metric" );
34 0 : fd_topob_wksp( topo, "metric_in" );
35 0 : fd_topo_tile_t * metric_tile = fd_topob_tile( topo, "metric", "metric", "metric_in", ULONG_MAX, 0, 0 );
36 0 : if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( config->tiles.metric.prometheus_listen_address, &metric_tile->metric.prometheus_listen_addr ) ) )
37 0 : FD_LOG_ERR(( "failed to parse prometheus listen address `%s`", config->tiles.metric.prometheus_listen_address ));
38 0 : metric_tile->metric.prometheus_listen_port = config->tiles.metric.prometheus_listen_port;
39 :
40 0 : fd_topos_net_tiles( topo, 1UL, &config->net, config->tiles.netlink.max_routes, config->tiles.netlink.max_neighbors, tile_to_cpu );
41 0 : ulong net_tile_id = fd_topo_find_tile( topo, "net", 0UL );
42 0 : if( net_tile_id==ULONG_MAX ) net_tile_id = fd_topo_find_tile( topo, "sock", 0UL );
43 0 : if( FD_UNLIKELY( net_tile_id==ULONG_MAX ) ) FD_LOG_ERR(( "net tile not found" ));
44 0 : fd_topo_tile_t * net_tile = &topo->tiles[ net_tile_id ];
45 0 : net_tile->net.gossip_listen_port = config->gossip.port;
46 :
47 0 : fd_topob_wksp( topo, "gossip" );
48 0 : fd_topo_tile_t * gossip_tile = fd_topob_tile( topo, "gossip", "gossip", "metric_in", 0UL, 0, 0 );
49 :
50 0 : strncpy( gossip_tile->gossip.identity_key_path, config->paths.identity_key, sizeof(gossip_tile->gossip.identity_key_path) );
51 0 : gossip_tile->gossip.gossip_listen_port = config->gossip.port;
52 0 : gossip_tile->gossip.ip_addr = config->net.ip_addr;
53 0 : gossip_tile->gossip.expected_shred_version = config->consensus.expected_shred_version;
54 0 : gossip_tile->gossip.entrypoints_cnt = fd_ulong_min( config->gossip.resolved_entrypoints_cnt, FD_TOPO_GOSSIP_ENTRYPOINTS_MAX );
55 0 : fd_memcpy( gossip_tile->gossip.entrypoints, config->gossip.resolved_entrypoints, gossip_tile->gossip.entrypoints_cnt * sizeof(fd_ip4_port_t) );
56 :
57 0 : if( FD_UNLIKELY( !gossip_tile->gossip.entrypoints_cnt ) ) {
58 0 : FD_LOG_ERR(( "Missing [tiles.gossip.entrypoints]" ));
59 0 : }
60 0 : if( FD_UNLIKELY( !gossip_tile->gossip.expected_shred_version ) ) {
61 0 : FD_LOG_ERR(( "Missing [consensus.expected_shred_version]" ));
62 0 : }
63 :
64 0 : fd_topob_wksp( topo, "sign" );
65 0 : fd_topo_tile_t * sign_tile = fd_topob_tile( topo, "sign", "sign", "metric_in", 0UL, 0, 1 );
66 0 : strncpy( sign_tile->sign.identity_key_path, config->paths.identity_key, sizeof(sign_tile->sign.identity_key_path) );
67 0 : fd_topob_wksp( topo, "gossip_sign" );
68 0 : fd_topob_link( topo, "gossip_sign", "gossip_sign", 128UL, 2048UL, 1UL );
69 0 : fd_topob_tile_in( topo, "sign", 0UL, "metric_in", "gossip_sign", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
70 0 : fd_topob_wksp( topo, "sign_gossip" );
71 0 : fd_topob_link( topo, "sign_gossip", "sign_gossip", 128UL, 64UL, 1UL );
72 0 : fd_topob_tile_out( topo, "sign", 0UL, "sign_gossip", 0UL );
73 :
74 0 : fd_topob_wksp( topo, "gossip_net" );
75 0 : fd_topob_link( topo, "gossip_net", "gossip_net", config->net.ingress_buffer_size, FD_NET_MTU, 1UL );
76 :
77 0 : fd_topos_net_rx_link( topo, "net_gossip", 0UL, config->net.ingress_buffer_size );
78 0 : fd_topob_tile_in( topo, "gossip", 0UL, "metric_in", "net_gossip", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
79 0 : fd_topob_tile_in( topo, "gossip", 0UL, "metric_in", "sign_gossip", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_UNPOLLED );
80 0 : fd_topos_tile_in_net( topo, "metric_in", "gossip_net", 0UL, FD_TOPOB_UNRELIABLE, FD_TOPOB_POLLED );
81 :
82 0 : fd_topob_tile_out( topo, "gossip", 0UL, "gossip_net", 0UL );
83 0 : fd_topob_tile_out( topo, "gossip", 0UL, "gossip_sign", 0UL );
84 :
85 0 : fd_topo_obj_t * poh_shred_obj = fd_topob_obj( topo, "fseq", "gossip" );
86 0 : FD_TEST( fd_pod_insertf_ulong( topo->props, poh_shred_obj->id, "poh_shred" ) );
87 0 : fd_topob_tile_uses( topo, gossip_tile, poh_shred_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
88 :
89 0 : fd_topos_net_tile_finish( topo, 0UL );
90 0 : fd_topob_auto_layout( topo, 0 );
91 0 : topo->agave_affinity_cnt = 0;
92 0 : fd_topob_finish( topo, CALLBACKS );
93 0 : fd_topo_print_log( /* stdout */ 1, topo );
94 0 : }
95 :
96 : static void
97 : gossip_cmd_args( int * pargc FD_PARAM_UNUSED,
98 : char *** pargv FD_PARAM_UNUSED,
99 0 : args_t * args FD_PARAM_UNUSED ) {}
100 :
101 : static void
102 : gossip_cmd_fn( args_t * args FD_PARAM_UNUSED,
103 0 : config_t * config ) {
104 0 : gossip_topo( config );
105 0 : fd_topo_t * topo = &config->topo;
106 :
107 0 : configure_stage( &fd_cfg_stage_sysctl, CONFIGURE_CMD_INIT, config );
108 0 : configure_stage( &fd_cfg_stage_hugetlbfs, CONFIGURE_CMD_INIT, config );
109 0 : configure_stage( &fd_cfg_stage_ethtool_channels, CONFIGURE_CMD_INIT, config );
110 0 : configure_stage( &fd_cfg_stage_ethtool_gro, CONFIGURE_CMD_INIT, config );
111 :
112 0 : initialize_workspaces( config );
113 0 : initialize_stacks( config );
114 0 : if( 0==strcmp( config->net.provider, "xdp" ) ) {
115 0 : fd_topo_install_xdp( topo, config->net.bind_address_parsed );
116 0 : }
117 0 : fd_topo_join_workspaces( topo, FD_SHMEM_JOIN_MODE_READ_WRITE );
118 :
119 : /* FIXME allow running sandboxed/multiprocess */
120 0 : fd_topo_run_single_process( topo, 2, config->uid, config->gid, fdctl_tile_run, NULL );
121 :
122 0 : for(;;) pause();
123 0 : }
124 :
125 : static void
126 : configure_stage_perm( configure_stage_t const * stage,
127 : fd_cap_chk_t * chk,
128 0 : config_t const * config ) {
129 0 : int enabled = !stage->enabled || stage->enabled( config );
130 0 : if( enabled && stage->check( config ).result != CONFIGURE_OK )
131 0 : if( stage->init_perm ) stage->init_perm( chk, config );
132 0 : }
133 :
134 : static void
135 : gossip_cmd_perm( args_t * args FD_PARAM_UNUSED,
136 : fd_cap_chk_t * chk,
137 0 : config_t const * config ) {
138 0 : configure_stage_perm( &fd_cfg_stage_sysctl, chk, config );
139 0 : configure_stage_perm( &fd_cfg_stage_hugetlbfs, chk, config );
140 0 : configure_stage_perm( &fd_cfg_stage_ethtool_channels, chk, config );
141 0 : configure_stage_perm( &fd_cfg_stage_ethtool_gro, chk, config );
142 0 : }
143 :
144 : action_t fd_action_gossip = {
145 : .name = "gossip",
146 : .args = gossip_cmd_args,
147 : .fn = gossip_cmd_fn,
148 : .perm = gossip_cmd_perm,
149 : };
|