added logging to daemon

This commit is contained in:
John Jones 2017-04-03 20:54:03 -05:00
parent 089d072736
commit 7b61c70639
3 changed files with 24 additions and 8 deletions

View file

@ -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);
}

View file

@ -4,6 +4,9 @@
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#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);

View file

@ -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;
};