Beginning of implementation of smarter connections for daemon
This commit is contained in:
parent
f8e4286740
commit
daefe7604f
6 changed files with 31 additions and 6 deletions
|
@ -1,5 +1,10 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-protobuf -Wall
|
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-protobuf -Wall
|
||||||
|
|
||||||
|
ifdef DEBUG
|
||||||
|
CFLAGS += -g3
|
||||||
|
endif
|
||||||
|
|
||||||
LFLAGS =
|
LFLAGS =
|
||||||
DEPS = builder.h ipfs_node.h
|
DEPS = builder.h ipfs_node.h
|
||||||
OBJS = builder.o daemon.o null.o ping.o
|
OBJS = builder.o daemon.o null.o ping.o
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "libp2p/net/p2pnet.h"
|
#include "libp2p/net/p2pnet.h"
|
||||||
|
#include "libp2p/peer/peerstore.h"
|
||||||
#include "ipfs/core/daemon.h"
|
#include "ipfs/core/daemon.h"
|
||||||
#include "ipfs/core/ipfs_node.h"
|
#include "ipfs/core/ipfs_node.h"
|
||||||
|
#include "ipfs/repo/fsrepo/fs_repo.h"
|
||||||
|
|
||||||
int ipfs_daemon (int argc, char **argv)
|
int ipfs_daemon (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -15,12 +17,23 @@ int ipfs_daemon (int argc, char **argv)
|
||||||
|
|
||||||
fprintf(stderr, "Initializing daemon...\n");
|
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
|
// create a new IpfsNode
|
||||||
struct IpfsNode local_node;
|
struct IpfsNode local_node;
|
||||||
local_node.mode = MODE_ONLINE;
|
local_node.mode = MODE_ONLINE;
|
||||||
//local_node.peerstore = ipfs_peerstore_new();
|
local_node.peerstore = libp2p_peerstore_new();
|
||||||
//local_node.repo = fsrepo;
|
local_node.repo = fs_repo;
|
||||||
//local_node.peer_id = peer_id;
|
local_node.identity = fs_repo->config->identity;
|
||||||
|
|
||||||
// Set null router param
|
// Set null router param
|
||||||
listen_param.ipv4 = 0; // ip 0.0.0.0, all interfaces
|
listen_param.ipv4 = 0; // ip 0.0.0.0, all interfaces
|
||||||
|
|
|
@ -68,6 +68,7 @@ void *ipfs_null_listen (void *ptr)
|
||||||
if (connection_param) {
|
if (connection_param) {
|
||||||
connection_param->socket = s;
|
connection_param->socket = s;
|
||||||
connection_param->count = &count;
|
connection_param->count = &count;
|
||||||
|
connection_param->local_node = listen_param->local_node;
|
||||||
// Create pthread for ipfs_null_connection.
|
// Create pthread for ipfs_null_connection.
|
||||||
if (pthread_create(&pth_connection, NULL, ipfs_null_connection, connection_param)) {
|
if (pthread_create(&pth_connection, NULL, ipfs_null_connection, connection_param)) {
|
||||||
fprintf(stderr, "Error creating thread for connection %d\n", count);
|
fprintf(stderr, "Error creating thread for connection %d\n", count);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
struct null_connection_params {
|
struct null_connection_params {
|
||||||
int socket;
|
int socket;
|
||||||
int *count;
|
int *count;
|
||||||
|
struct IpfsNode* local_node;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct null_listen_params {
|
struct null_listen_params {
|
||||||
|
|
|
@ -4,11 +4,10 @@ enum NodeMode { MODE_OFFLINE, MODE_ONLINE };
|
||||||
|
|
||||||
struct IpfsNode {
|
struct IpfsNode {
|
||||||
enum NodeMode mode;
|
enum NodeMode mode;
|
||||||
//struct PeerId identity;
|
struct Identity* identity;
|
||||||
struct FSRepo* repo;
|
struct FSRepo* repo;
|
||||||
struct Peerstore* peerstore;
|
struct Peerstore* peerstore;
|
||||||
//struct Pinner pinning; // an interface
|
//struct Pinner pinning; // an interface
|
||||||
//struct Mount** mounts;
|
//struct Mount** mounts;
|
||||||
//struct PrivKey* private_key;
|
|
||||||
// TODO: Add more here
|
// TODO: Add more here
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,8 +93,14 @@ int repo_config_identity_build_private_key(struct Identity* identity, const char
|
||||||
if (retVal == 0)
|
if (retVal == 0)
|
||||||
return 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
|
// 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)
|
if (retVal == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue