瀏覽代碼

20240407

master
MEUNIER Thibaud 1 年之前
父節點
當前提交
8f949be152
共有 2 個檔案被更改,包括 16 行新增66 行删除
  1. +1
    -1
      Makefile
  2. +15
    -65
      src/spy2.c

+ 1
- 1
Makefile 查看文件

@ -27,7 +27,7 @@ $(BINDIR)/read_block : $(OBJDIR)/read_block.o
read_block : $(BINDIR)/read_block
$(BINDIR)/btcspy : $(OBJDIR)/spy .o $(OBJDIR)/daemonize.o
$(BINDIR)/btcspy : $(OBJDIR)/spy 2 .o $(OBJDIR)/daemonize.o
$(CC) -o $@ $^ $(LDFLAGS)
btcspy : $(BINDIR)/btcspy

+ 15
- 65
src/spy2.c 查看文件

@ -15,8 +15,6 @@
#include <btc/memory.h>
#include <btc/tx.h>
#include <daemonize.h>
/*
* Les variables globales
*/
@ -26,33 +24,10 @@ FILE* blockchain_fd = NULL;
/*
* 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)
{
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
* 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];
uint32_t read_height[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)
{
/*
* On se sert du haut d ela pile comme point de départ
*/
int outlen;
node->nodegroup->log_write_cb("STATUS : Setting requested hash with %s\n", buffer[19]);
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;
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->state |= NODE_HEADERSYNC;
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;
if (blockchain_fd != NULL)
fflush(blockchain_fd);
// TRES TRES SALE ...
exit(0);
}
}
}
@ -736,38 +718,6 @@ int main(int ac, char** av)
*/
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
*/

Loading…
取消
儲存