diff --git a/core/Makefile b/core/Makefile index a9548c1..637c0ba 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1,5 +1,10 @@ CC = gcc CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-protobuf -Wall + +ifdef DEBUG +CFLAGS += -g3 +endif + LFLAGS = DEPS = builder.h ipfs_node.h OBJS = builder.o daemon.o null.o ping.o diff --git a/core/daemon.c b/core/daemon.c index 86ba2bb..6d432a6 100644 --- a/core/daemon.c +++ b/core/daemon.c @@ -4,8 +4,10 @@ #include #include #include "libp2p/net/p2pnet.h" +#include "libp2p/peer/peerstore.h" #include "ipfs/core/daemon.h" #include "ipfs/core/ipfs_node.h" +#include "ipfs/repo/fsrepo/fs_repo.h" int ipfs_daemon (int argc, char **argv) { @@ -15,12 +17,23 @@ int ipfs_daemon (int argc, char **argv) fprintf(stderr, "Initializing daemon...\n"); + // read the configuration + struct FSRepo* fs_repo; + if (!ipfs_repo_fsrepo_new(NULL, NULL, &fs_repo)) + return 0; + + // open the repository and read the file + if (!ipfs_repo_fsrepo_open(fs_repo)) { + ipfs_repo_fsrepo_free(fs_repo); + return 0; + } + // create a new IpfsNode struct IpfsNode local_node; local_node.mode = MODE_ONLINE; - //local_node.peerstore = ipfs_peerstore_new(); - //local_node.repo = fsrepo; - //local_node.peer_id = peer_id; + local_node.peerstore = libp2p_peerstore_new(); + local_node.repo = fs_repo; + local_node.identity = fs_repo->config->identity; // Set null router param listen_param.ipv4 = 0; // ip 0.0.0.0, all interfaces diff --git a/core/null.c b/core/null.c index 2864304..3b3efa4 100644 --- a/core/null.c +++ b/core/null.c @@ -68,6 +68,7 @@ void *ipfs_null_listen (void *ptr) if (connection_param) { connection_param->socket = s; connection_param->count = &count; + connection_param->local_node = listen_param->local_node; // Create pthread for ipfs_null_connection. if (pthread_create(&pth_connection, NULL, ipfs_null_connection, connection_param)) { fprintf(stderr, "Error creating thread for connection %d\n", count); diff --git a/include/ipfs/core/daemon.h b/include/ipfs/core/daemon.h index 8a32b9d..265b256 100644 --- a/include/ipfs/core/daemon.h +++ b/include/ipfs/core/daemon.h @@ -8,6 +8,7 @@ struct null_connection_params { int socket; int *count; + struct IpfsNode* local_node; }; struct null_listen_params { diff --git a/include/ipfs/core/ipfs_node.h b/include/ipfs/core/ipfs_node.h index dd9cfca..9a878bd 100644 --- a/include/ipfs/core/ipfs_node.h +++ b/include/ipfs/core/ipfs_node.h @@ -4,11 +4,10 @@ enum NodeMode { MODE_OFFLINE, MODE_ONLINE }; struct IpfsNode { enum NodeMode mode; - //struct PeerId identity; + struct Identity* identity; struct FSRepo* repo; struct Peerstore* peerstore; //struct Pinner pinning; // an interface //struct Mount** mounts; - //struct PrivKey* private_key; // TODO: Add more here }; diff --git a/repo/config/identity.c b/repo/config/identity.c index 03be46b..7c12c94 100644 --- a/repo/config/identity.c +++ b/repo/config/identity.c @@ -93,8 +93,14 @@ int repo_config_identity_build_private_key(struct Identity* identity, const char if (retVal == 0) return 0; + // now we have a protobuf'd struct PrivateKey. Unprotobuf it + struct PrivateKey* priv_key; + if (!libp2p_crypto_private_key_protobuf_decode(decoded, decoded_size, &priv_key)) + return 0; + // now convert DER to RsaPrivateKey - retVal = libp2p_crypto_encoding_x509_der_to_private_key(decoded, decoded_size, &identity->private_key); + retVal = libp2p_crypto_encoding_x509_der_to_private_key(priv_key->data, priv_key->data_size, &identity->private_key); + libp2p_crypto_private_key_free(priv_key); if (retVal == 0) return 0;