Line data Source code
1 : #ifndef HEADER_fd_src_discof_restore_fd_snapct_tile_h 2 : #define HEADER_fd_src_discof_restore_fd_snapct_tile_h 3 : 4 : #include "../../util/fd_util_base.h" 5 : 6 : /* The snapct tile at a high level is a state machine that downloads 7 : snapshots from the network or reads snapshots from disk and produces 8 : a byte stream that is parsed by downstream snapshot consumer tiles. 9 : The snapct tile gathers the latest SnapshotHashes information from 10 : gossip to decide whether to download snapshots or read local 11 : snapshots from disk. If the snapct tile needs to download a snapshot, 12 : it goes through the process of discovering and selecting elegible 13 : peers from gossip to download from. */ 14 : 15 0 : #define FD_SNAPCT_STATE_INIT ( 0) /* Initialization step, it determines whether to start loading from file or to download */ 16 : 17 0 : #define FD_SNAPCT_STATE_WAITING_FOR_PEERS ( 1) /* Waiting for first peer to arrive from gossip to download from */ 18 0 : #define FD_SNAPCT_STATE_WAITING_FOR_PEERS_INCREMENTAL ( 2) /* Waiting for peers when attempting to download an incremental snapshot */ 19 0 : #define FD_SNAPCT_STATE_COLLECTING_PEERS ( 3) /* First peer arrived, wait a little longer to see if a better one arrives */ 20 0 : #define FD_SNAPCT_STATE_COLLECTING_PEERS_INCREMENTAL ( 4) /* Collecting peers to download an incremental snapshot */ 21 : 22 0 : #define FD_SNAPCT_STATE_READING_FULL_FILE ( 5) /* Full file looks better than peer, reading it from disk */ 23 0 : #define FD_SNAPCT_STATE_FLUSHING_FULL_FILE_FINI ( 6) /* Full file was read ok, signal downstream to finish all pending operations */ 24 0 : #define FD_SNAPCT_STATE_FLUSHING_FULL_FILE_DONE ( 7) /* Full file was read ok, and all other tiles have finished processing it */ 25 0 : #define FD_SNAPCT_STATE_FLUSHING_FULL_FILE_RESET ( 8) /* Resetting to load full snapshot from file again, confirm decompress and inserter are reset too */ 26 : 27 0 : #define FD_SNAPCT_STATE_READING_INCREMENTAL_FILE ( 9) /* Incremental file looks better than peer, reading it from disk */ 28 0 : #define FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_FINI (10) /* Incremental file was read ok, and all other tiles have finished processing it */ 29 0 : #define FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_DONE (11) /* Incremental file was read ok, signal downstream to finish all pending operations */ 30 0 : #define FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_RESET (12) /* Resetting to load incremental snapshot from file again, confirm decompress and inserter are reset too */ 31 : 32 0 : #define FD_SNAPCT_STATE_READING_FULL_HTTP (13) /* Peer was selected, reading full snapshot from HTTP */ 33 0 : #define FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_FINI (14) /* Full snapshot was downloaded ok, and all other tiles have finished processing it */ 34 0 : #define FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_DONE (15) /* Full snapshot was downloaded ok, signal downstream to finish all pending operations */ 35 0 : #define FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_RESET (16) /* Resetting to load full snapshot from HTTP again, confirm decompress and inserter are reset too */ 36 : 37 0 : #define FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP (17) /* Peer was selected, reading incremental snapshot from HTTP */ 38 0 : #define FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_FINI (18) /* Incremental snapshot was downloaded ok, and all other tiles have finished processing it */ 39 0 : #define FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_DONE (19) /* Incremental snapshot was downloaded ok, signal downstream to finish all pending operations */ 40 0 : #define FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_RESET (20) /* Resetting to load incremental snapshot from HTTP again, confirm decompress and inserter are reset too */ 41 : 42 0 : #define FD_SNAPCT_STATE_SHUTDOWN (21) /* The tile is done, and has likely already exited */ 43 : 44 : 45 : 46 : 47 : static inline const char * 48 0 : fd_snapct_state_str( ulong state ) { 49 0 : switch( state ) { 50 0 : case FD_SNAPCT_STATE_INIT: return "init"; 51 0 : case FD_SNAPCT_STATE_WAITING_FOR_PEERS: return "waiting_for_peers"; 52 0 : case FD_SNAPCT_STATE_WAITING_FOR_PEERS_INCREMENTAL: return "waiting_for_peers_incremental"; 53 0 : case FD_SNAPCT_STATE_COLLECTING_PEERS: return "collecting_peers"; 54 0 : case FD_SNAPCT_STATE_COLLECTING_PEERS_INCREMENTAL: return "collecting_peers_incremental"; 55 0 : case FD_SNAPCT_STATE_READING_FULL_FILE: return "reading_full_file"; 56 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_FILE_FINI: return "flushing_full_file_fini"; 57 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_FILE_DONE: return "flushing_full_file_done"; 58 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_FILE_RESET: return "flushing_full_file_reset"; 59 0 : case FD_SNAPCT_STATE_READING_INCREMENTAL_FILE: return "reading_incremental_file"; 60 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_FINI: return "flushing_incremental_file_fini"; 61 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_DONE: return "flushing_incremental_file_done"; 62 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_FILE_RESET: return "flushing_incremental_file_reset"; 63 0 : case FD_SNAPCT_STATE_READING_FULL_HTTP: return "reading_full_http"; 64 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_FINI: return "flushing_full_http_fini"; 65 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_DONE: return "flushing_full_http_done"; 66 0 : case FD_SNAPCT_STATE_FLUSHING_FULL_HTTP_RESET: return "flushing_full_http_reset"; 67 0 : case FD_SNAPCT_STATE_READING_INCREMENTAL_HTTP: return "reading_incremental_http"; 68 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_FINI: return "flushing_incremental_http_fini"; 69 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_DONE: return "flushing_incremental_http_done"; 70 0 : case FD_SNAPCT_STATE_FLUSHING_INCREMENTAL_HTTP_RESET: return "flushing_incremental_http_reset"; 71 0 : case FD_SNAPCT_STATE_SHUTDOWN: return "shutdown"; 72 0 : default: return "unknown"; 73 0 : } 74 0 : } 75 : 76 0 : #define FD_SNAPCT_SNAPSHOT_TYPE_FULL (0) 77 0 : #define FD_SNAPCT_SNAPSHOT_TYPE_INCREMENTAL (1) 78 : 79 : typedef struct { 80 : int type; 81 : int is_download; 82 : char read_path[ PATH_MAX ]; 83 : } fd_snapct_update_t; 84 : 85 : #endif /* HEADER_fd_src_discof_restore_fd_snapct_tile_h */