From 7b61c706393f2a23b2adcabc4fdb9fd492312fd3 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 3 Apr 2017 20:54:03 -0500 Subject: [PATCH] added logging to daemon --- core/daemon.c | 12 ++++++++---- core/null.c | 16 +++++++++++++--- include/ipfs/core/daemon.h | 4 +++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core/daemon.c b/core/daemon.c index c0a00ad..a68d2f5 100644 --- a/core/daemon.c +++ b/core/daemon.c @@ -9,13 +9,14 @@ #include "ipfs/core/ipfs_node.h" #include "ipfs/core/bootstrap.h" #include "ipfs/repo/fsrepo/fs_repo.h" +#include "libp2p/utils/logger.h" int ipfs_daemon_start(char* repo_path) { int count_pths = 0; pthread_t work_pths[MAX]; struct IpfsNodeListenParams listen_param; - fprintf(stderr, "Initializing daemon...\n"); + libp2p_logger_info("daemon", "Initializing daemon...\n"); // read the configuration struct FSRepo* fs_repo; @@ -43,7 +44,7 @@ int ipfs_daemon_start(char* repo_path) { // Create pthread for swarm listener. if (pthread_create(&work_pths[count_pths++], NULL, ipfs_null_listen, &listen_param)) { - fprintf(stderr, "Error creating thread for ipfs_null_listen\n"); + libp2p_logger_error("daemon", "Error creating thread for ipfs null listen\n"); return 1; } @@ -54,12 +55,12 @@ int ipfs_daemon_start(char* repo_path) { } */ - fprintf(stderr, "Daemon is ready\n"); + libp2p_logger_info("daemon", "Daemon is ready\n"); // Wait for pthreads to finish. while (count_pths) { if (pthread_join(work_pths[--count_pths], NULL)) { - fprintf(stderr, "Error joining thread\n"); + libp2p_logger_error("daemon", "Error joining thread\n"); return 2; } } @@ -71,5 +72,8 @@ int ipfs_daemon_start(char* repo_path) { int ipfs_daemon (int argc, char **argv) { + libp2p_logger_add_class("peerstore"); + libp2p_logger_add_class("providerstore"); + libp2p_logger_add_class("daemon"); return ipfs_daemon_start(NULL); } diff --git a/core/null.c b/core/null.c index 2c13703..8cea249 100644 --- a/core/null.c +++ b/core/null.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include + #include "libp2p/net/p2pnet.h" #include "libp2p/record/message.h" #include "libp2p/net/multistream.h" @@ -45,10 +48,10 @@ void *ipfs_null_connection (void *ptr) // TODO: when should we exit the for loop and disconnect? struct SessionContext session; - session.insecure_stream = libp2p_net_multistream_stream_new(connection_param->socket); + session.insecure_stream = libp2p_net_multistream_stream_new(connection_param->file_descriptor, connection_param->ip, connection_param->port); session.default_stream = session.insecure_stream; - libp2p_logger_log("null", LOGLEVEL_INFO, "Connection %d, count %d\n", connection_param->socket, *(connection_param->count)); + libp2p_logger_log("null", LOGLEVEL_INFO, "Connection %d, count %d\n", connection_param->file_descriptor, *(connection_param->count)); if (libp2p_net_multistream_negotiate(session.insecure_stream)) { @@ -153,9 +156,16 @@ void *ipfs_null_listen (void *ptr) count++; connection_param = malloc (sizeof (struct null_connection_params)); if (connection_param) { - connection_param->socket = s; + connection_param->file_descriptor = s; connection_param->count = &count; connection_param->local_node = listen_param->local_node; + connection_param->port = listen_param->port; + connection_param->ip = malloc(INET_ADDRSTRLEN); + if (inet_ntop(AF_INET, &(listen_param->ipv4), connection_param->ip, INET_ADDRSTRLEN) == NULL) { + free(connection_param->ip); + connection_param->ip = NULL; + connection_param->port = 0; + } // Create pthread for ipfs_null_connection. if (pthread_create(&pth_connection, NULL, ipfs_null_connection, connection_param)) { libp2p_logger_log("null", LOGLEVEL_DEBUG, "Error creating thread for connection %d\n", count); diff --git a/include/ipfs/core/daemon.h b/include/ipfs/core/daemon.h index fe52452..ca376c0 100644 --- a/include/ipfs/core/daemon.h +++ b/include/ipfs/core/daemon.h @@ -8,8 +8,10 @@ #define CONNECTIONS 50 struct null_connection_params { - int socket; + int file_descriptor; int *count; + char* ip; + int port; struct IpfsNode* local_node; };