|
|
@ -15,8 +15,6 @@ |
|
|
#include <btc/memory.h>
|
|
|
#include <btc/memory.h>
|
|
|
#include <btc/tx.h>
|
|
|
#include <btc/tx.h>
|
|
|
|
|
|
|
|
|
#include <daemonize.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Les variables globales
|
|
|
* Les variables globales
|
|
|
*/
|
|
|
*/
|
|
|
@ -26,33 +24,10 @@ FILE* blockchain_fd = NULL; |
|
|
/*
|
|
|
/*
|
|
|
* Les outils
|
|
|
* Les outils
|
|
|
*/
|
|
|
*/
|
|
|
static void signal_handler(int sig){
|
|
|
|
|
|
char msg[200];
|
|
|
|
|
|
sprintf(msg,"process %d signal %d trapped\n", getpid(), sig);
|
|
|
|
|
|
log_signal_message(msg);
|
|
|
|
|
|
switch(sig){
|
|
|
|
|
|
case SIGUSR1:
|
|
|
|
|
|
// signal USR1
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SIGUSR2:
|
|
|
|
|
|
// Signal USR2
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SIGHUP:
|
|
|
|
|
|
// Reload conf and reinitialize processus
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SIGINT:
|
|
|
|
|
|
// CTRL+C
|
|
|
|
|
|
case SIGTERM:
|
|
|
|
|
|
// Terminate : kill -15
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static btc_bool file_exist(const char *filename)
|
|
|
static btc_bool file_exist(const char *filename)
|
|
|
{
|
|
|
{
|
|
|
struct stat buffer;
|
|
|
struct stat buffer;
|
|
|
return (stat (filename, &buffer) == 0); |
|
|
|
|
|
|
|
|
return (stat(filename, &buffer) == 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
@ -249,14 +224,14 @@ static void cb_handshake_done(struct btc_node_ *node) |
|
|
* De même, on garde une marge de manoeuvre dans les positions
|
|
|
* De même, on garde une marge de manoeuvre dans les positions
|
|
|
* du fichier
|
|
|
* du fichier
|
|
|
*/
|
|
|
*/
|
|
|
if (node->bestknownheight > cb_handshake_done_bestknownheight)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (blockchain_fd != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
if (blockchain_fd != NULL)
|
|
|
|
|
|
{
|
|
|
/*
|
|
|
/*
|
|
|
* Définir et intialiser un tampon de 20 blocks
|
|
|
|
|
|
|
|
|
* Définir et initialiser un tampon de 20 blocks
|
|
|
|
|
|
* Ca veut dire qu'on considère qu'il n'y a pas de fork
|
|
|
|
|
|
* de plus de 20 blocks
|
|
|
*/
|
|
|
*/
|
|
|
#define MARGE_TAMPON 25
|
|
|
|
|
|
|
|
|
#define MARGE_TAMPON 20 |
|
|
char buffer[MARGE_TAMPON][65];
|
|
|
char buffer[MARGE_TAMPON][65];
|
|
|
uint32_t read_height[MARGE_TAMPON];
|
|
|
uint32_t read_height[MARGE_TAMPON];
|
|
|
fpos_t fpos[MARGE_TAMPON];
|
|
|
fpos_t fpos[MARGE_TAMPON];
|
|
|
@ -284,6 +259,9 @@ static void cb_handshake_done(struct btc_node_ *node) |
|
|
}
|
|
|
}
|
|
|
if (read_height[0] > MARGE_TAMPON)
|
|
|
if (read_height[0] > MARGE_TAMPON)
|
|
|
{
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
* On se sert du haut d ela pile comme point de départ
|
|
|
|
|
|
*/
|
|
|
int outlen;
|
|
|
int outlen;
|
|
|
node->nodegroup->log_write_cb("STATUS : Setting requested hash with %s\n", buffer[19]);
|
|
|
node->nodegroup->log_write_cb("STATUS : Setting requested hash with %s\n", buffer[19]);
|
|
|
utils_reverse_hex(buffer[19], 64);
|
|
|
utils_reverse_hex(buffer[19], 64);
|
|
|
@ -292,8 +270,10 @@ static void cb_handshake_done(struct btc_node_ *node) |
|
|
request_headers_or_blocks_hash_init = true;
|
|
|
request_headers_or_blocks_hash_init = true;
|
|
|
fsetpos(blockchain_fd, fpos+(MARGE_TAMPON-1));
|
|
|
fsetpos(blockchain_fd, fpos+(MARGE_TAMPON-1));
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (node->bestknownheight > cb_handshake_done_bestknownheight)
|
|
|
|
|
|
{
|
|
|
node->nodegroup->log_write_cb("STATUS : starting header sync from node %d\n", node->nodeid);
|
|
|
node->nodegroup->log_write_cb("STATUS : starting header sync from node %d\n", node->nodeid);
|
|
|
node->state |= NODE_HEADERSYNC;
|
|
|
node->state |= NODE_HEADERSYNC;
|
|
|
request_headers_or_blocks(node, false);
|
|
|
request_headers_or_blocks(node, false);
|
|
|
@ -654,6 +634,8 @@ static void cb_post_cmd(struct btc_node_ *node, btc_p2p_msg_hdr *hdr, struct con |
|
|
node->state &= ~NODE_HEADERSYNC;
|
|
|
node->state &= ~NODE_HEADERSYNC;
|
|
|
if (blockchain_fd != NULL)
|
|
|
if (blockchain_fd != NULL)
|
|
|
fflush(blockchain_fd);
|
|
|
fflush(blockchain_fd);
|
|
|
|
|
|
// TRES TRES SALE ...
|
|
|
|
|
|
exit(0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@ -736,38 +718,6 @@ int main(int ac, char** av) |
|
|
*/
|
|
|
*/
|
|
|
if (ac > 1) chdir(av[1]);
|
|
|
if (ac > 1) chdir(av[1]);
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Daemonize
|
|
|
|
|
|
*/
|
|
|
|
|
|
daemonize();
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Trapper les signaux pour fermer correctement le programme
|
|
|
|
|
|
*/
|
|
|
|
|
|
int les_signaux_ign[] = { SIGCHLD, SIGTSTP, SIGTTOU, SIGTTIN };
|
|
|
|
|
|
int les_signaux[] = { SIGHUP, SIGTERM, SIGINT };
|
|
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
|
|
|
|
n = array_len(les_signaux_ign);
|
|
|
|
|
|
for(int i = 0; i < n; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (signal(les_signaux_ign[i],SIG_IGN) == SIG_ERR)
|
|
|
|
|
|
{
|
|
|
|
|
|
printf("\ncan't catch signal %d\n", les_signaux_ign[i]);
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
n = array_len(les_signaux);
|
|
|
|
|
|
for(int i = 0; i < n; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (signal(les_signaux[i],signal_handler) == SIG_ERR)
|
|
|
|
|
|
{
|
|
|
|
|
|
printf("\ncan't catch signal %d\n", les_signaux[i]);
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
* Gestion du fichier de chaine de blocks
|
|
|
* Gestion du fichier de chaine de blocks
|
|
|
*/
|
|
|
*/
|
|
|
|