BitLab 0.1.0
BitLab: A Browser for the Bitcoin P2P Network and Blockchain
|
#include <signal.h>
#include <stdbool.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <pthread.h>
Go to the source code of this file.
Data Structures | |
struct | program_state |
The program state structure used to store the state of the program. More... | |
struct | program_operation |
The program operation structure used to store the operation of the program. More... | |
Macros | |
#define | BITLAB_VERSION "0.1.0" |
#define | PEER_DISCOVERY_DEFAULT_DAEMON false |
#define | PEER_DISCOVERY_DEFAULT_HARDCODED_SEEDS false |
#define | PEER_DISCOVERY_DEFAULT_DNS_LOOKUP true |
Functions | |
void | init_program_state () |
Initialize the program state. | |
void | print_program_state () |
Print the program state. | |
void | set_exit_flag (volatile sig_atomic_t flag) |
Set the exit flag. | |
sig_atomic_t | get_exit_flag () |
Get the exit flag. | |
void | mark_started_with_parameters () |
Mark the program as started with parameters. | |
void | destroy_program_state () |
Destroy the program state. | |
int | init_program_operation () |
Initialize the program operation. | |
void | start_peer_discovery_progress () |
Start the peer discovery progress. | |
void | finish_peer_discovery_progress (bool succeeded) |
Finish the peer discovery progress. | |
bool | set_peer_discovery (bool value) |
Set the peer discovery operation. | |
bool | force_stop_peer_discovery () |
Force stop the peer discovery operation. | |
bool | get_peer_discovery () |
Get the peer discovery operation. | |
bool | get_peer_discovery_in_progress () |
Get the peer discovery in progress state. | |
bool | get_peer_discovery_succeeded () |
Get the peer discovery succeeded state. | |
bool | set_peer_discovery_daemon (bool value) |
Set the peer discovery daemon state. | |
bool | set_peer_discovery_hardcoded_seeds (bool value) |
Set the peer discovery hardcoded seeds state. | |
bool | set_peer_discovery_dns_lookup (bool value) |
Set the peer discovery DNS lookup state. | |
bool | get_peer_discovery_daemon () |
Get the peer discovery daemon state. | |
bool | get_peer_discovery_hardcoded_seeds () |
Get the peer discovery hardcoded seeds state. | |
bool | get_peer_discovery_dns_lookup () |
Get the peer discovery DNS lookup state. | |
bool | set_peer_discovery_dns_domain (const char *domain) |
Set the peer discovery DNS domain. | |
const char * | get_peer_discovery_dns_domain () |
Get the peer discovery DNS domain. | |
void | destroy_program_operation () |
Clear all program operations. | |
int | get_pid () |
Get the program PID. | |
time_t | get_start_time () |
Get the program start time. | |
int | get_elapsed_time () |
Get the elapsed time since the program started. | |
Variables | |
program_state | state |
The program state used to store the state of the program. | |
program_operation | operation |
The program operation used to store all current operations of the program. | |
void destroy_program_operation | ( | ) |
Clear all program operations.
Definition at line 247 of file state.c.
References operation, and program_operation::operation_mutex.
Referenced by run_bitlab().
void destroy_program_state | ( | ) |
Destroy the program state.
Definition at line 95 of file state.c.
References program_state::exit_flag_mutex, and state.
Referenced by run_bitlab().
void finish_peer_discovery_progress | ( | bool | succeeded | ) |
Finish the peer discovery progress.
succeeded | The flag to indicate if the peer discovery operation succeeded. |
Definition at line 117 of file state.c.
References operation, program_operation::operation_mutex, program_operation::peer_discovery_in_progress, and program_operation::peer_discovery_succeeded.
Referenced by handle_peer_discovery().
bool force_stop_peer_discovery | ( | ) |
Force stop the peer discovery operation.
Definition at line 140 of file state.c.
References BITLAB_LOG, log_message(), LOG_WARN, operation, program_operation::operation_mutex, program_operation::peer_discovery, and program_operation::peer_discovery_in_progress.
int get_elapsed_time | ( | ) |
Get the elapsed time since the program started.
Definition at line 262 of file state.c.
References program_state::start_time, and state.
Referenced by print_program_state().
sig_atomic_t get_exit_flag | ( | ) |
Get the exit flag.
Definition at line 80 of file state.c.
References program_state::exit_flag, program_state::exit_flag_mutex, and state.
Referenced by handle_cli(), handle_peer_discovery(), and run_bitlab().
bool get_peer_discovery | ( | ) |
Get the peer discovery operation.
Definition at line 150 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery.
Referenced by cli_peer_discovery(), and handle_peer_discovery().
bool get_peer_discovery_daemon | ( | ) |
Get the peer discovery daemon state.
Definition at line 198 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_daemon.
const char * get_peer_discovery_dns_domain | ( | ) |
Get the peer discovery DNS domain.
Definition at line 239 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_dns_domain.
Referenced by handle_peer_discovery().
bool get_peer_discovery_dns_lookup | ( | ) |
Get the peer discovery DNS lookup state.
Definition at line 214 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_dns_lookup.
Referenced by handle_peer_discovery().
bool get_peer_discovery_hardcoded_seeds | ( | ) |
Get the peer discovery hardcoded seeds state.
Definition at line 206 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_hardcoded_seeds.
Referenced by handle_peer_discovery().
bool get_peer_discovery_in_progress | ( | ) |
Get the peer discovery in progress state.
Definition at line 158 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_in_progress.
Referenced by cli_peer_discovery(), and handle_peer_discovery().
bool get_peer_discovery_succeeded | ( | ) |
Get the peer discovery succeeded state.
Definition at line 166 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_succeeded.
Referenced by cli_peer_discovery(), and handle_peer_discovery().
int get_pid | ( | ) |
Get the program PID.
Definition at line 252 of file state.c.
References program_state::pid, and state.
time_t get_start_time | ( | ) |
Get the program start time.
Definition at line 257 of file state.c.
References program_state::start_time, and state.
int init_program_operation | ( | ) |
Initialize the program operation.
Definition at line 100 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery.
Referenced by run_bitlab().
void init_program_state | ( | ) |
Initialize the program state.
Definition at line 52 of file state.c.
References BITLAB_LOG, program_state::exit_flag, program_state::exit_flag_mutex, log_message(), LOG_WARN, program_state::pid, program_state::start_time, and state.
Referenced by run_bitlab().
void mark_started_with_parameters | ( | ) |
Mark the program as started with parameters.
Definition at line 88 of file state.c.
References program_state::exit_flag_mutex, program_state::started_with_parameters, and state.
Referenced by run_bitlab().
void print_program_state | ( | ) |
Print the program state.
Definition at line 63 of file state.c.
References get_elapsed_time(), guarded_print_line(), program_state::pid, program_state::started_with_parameters, and state.
Referenced by cli_info().
void set_exit_flag | ( | volatile sig_atomic_t | flag | ) |
Set the exit flag.
flag | The flag to set. |
Definition at line 73 of file state.c.
References program_state::exit_flag, program_state::exit_flag_mutex, and state.
Referenced by cli_exit().
bool set_peer_discovery | ( | bool | value | ) |
Set the peer discovery operation.
This function cannot stop the peer discovery operation if it is in progress. Use force_stop_peer_discovery instead.
value | The value to set. |
Definition at line 125 of file state.c.
References BITLAB_LOG, log_message(), LOG_WARN, operation, program_operation::operation_mutex, program_operation::peer_discovery, and program_operation::peer_discovery_in_progress.
Referenced by cli_peer_discovery().
bool set_peer_discovery_daemon | ( | bool | value | ) |
Set the peer discovery daemon state.
value | The value to set. |
Definition at line 174 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_daemon.
Referenced by cli_peer_discovery().
bool set_peer_discovery_dns_domain | ( | const char * | domain | ) |
Set the peer discovery DNS domain.
domain | The domain to set. |
Definition at line 222 of file state.c.
References BITLAB_LOG, LOG_ERROR, log_message(), operation, program_operation::operation_mutex, and program_operation::peer_discovery_dns_domain.
Referenced by cli_peer_discovery().
bool set_peer_discovery_dns_lookup | ( | bool | value | ) |
Set the peer discovery DNS lookup state.
value | The value to set. |
Definition at line 190 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_dns_lookup.
Referenced by cli_peer_discovery().
bool set_peer_discovery_hardcoded_seeds | ( | bool | value | ) |
Set the peer discovery hardcoded seeds state.
value | The value to set. |
Definition at line 182 of file state.c.
References operation, program_operation::operation_mutex, and program_operation::peer_discovery_hardcoded_seeds.
Referenced by cli_peer_discovery().
void start_peer_discovery_progress | ( | ) |
Start the peer discovery progress.
This function only starts the progress if the peer discovery operation is set.
Definition at line 107 of file state.c.
References BITLAB_LOG, log_message(), LOG_WARN, operation, program_operation::operation_mutex, program_operation::peer_discovery, and program_operation::peer_discovery_in_progress.
Referenced by handle_peer_discovery().
|
extern |
The program operation used to store all current operations of the program.
The program operation used to store all current operations of the program.
Only accessible in state.c directly, otherwise functions should be used.
peer_discovery | The peer discovery operation of the program. |
peer_discovery_in_progress | The peer discovery operation in progress. |
peer_discovery_succeeded | The peer discovery operation succeeded. |
peer_discovery_daemon | The peer discovery operation as a daemon. |
peer_discovery_hardcoded_seeds | The peer discovery operation with hardcoded seeds. |
peer_discovery_dns_lookup | The peer discovery operation with DNS lookup. |
peer_discovery_dns_domain | The peer discovery DNS domain field for custom DNS lookup. |
mutex | The mutex to protect the operation. |
Definition at line 40 of file state.c.
Referenced by cli_info(), destroy_program_operation(), finish_peer_discovery_progress(), force_stop_peer_discovery(), get_peer_discovery(), get_peer_discovery_daemon(), get_peer_discovery_dns_domain(), get_peer_discovery_dns_lookup(), get_peer_discovery_hardcoded_seeds(), get_peer_discovery_in_progress(), get_peer_discovery_succeeded(), init_program_operation(), run_bitlab(), set_peer_discovery(), set_peer_discovery_daemon(), set_peer_discovery_dns_domain(), set_peer_discovery_dns_lookup(), set_peer_discovery_hardcoded_seeds(), and start_peer_discovery_progress().
|
extern |
The program state used to store the state of the program.
The program state used to store the state of the program.
Only accessible in state.c directly, otherwise functions should be used.
pid | The process ID of the program. |
start_time | The start time of the program. |
started_with_parameters | The flag to indicate if the program started with CLI parameters. |
exit_flag | The exit flag of the program. |
exit_flag_mutex | The mutex to protect the exit flag. |
Definition at line 19 of file state.c.
Referenced by cli_command_generator(), destroy_program_state(), get_elapsed_time(), get_exit_flag(), get_pid(), get_start_time(), init_program_state(), mark_started_with_parameters(), print_program_state(), run_bitlab(), and set_exit_flag().