Starting to make the daemon more intelligent

This commit is contained in:
John Jones 2017-02-22 10:56:11 -05:00
parent fbd862431c
commit f8e4286740
7 changed files with 98 additions and 8 deletions

View file

@ -5,18 +5,27 @@
#include <pthread.h> #include <pthread.h>
#include "libp2p/net/p2pnet.h" #include "libp2p/net/p2pnet.h"
#include "ipfs/core/daemon.h" #include "ipfs/core/daemon.h"
#include "ipfs/core/ipfs_node.h"
int ipfs_daemon (int argc, char **argv) int ipfs_daemon (int argc, char **argv)
{ {
int count_pths = 0; int count_pths = 0;
pthread_t work_pths[MAX]; pthread_t work_pths[MAX];
struct null_listen_params listen_param; struct IpfsNodeListenParams listen_param;
fprintf(stderr, "Initializing daemon...\n"); fprintf(stderr, "Initializing daemon...\n");
// 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;
// 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
listen_param.port = 4001; listen_param.port = 4001;
listen_param.local_node = &local_node;
// Create pthread for ipfs_null_listen. // Create pthread for ipfs_null_listen.
if (pthread_create(&work_pths[count_pths++], NULL, ipfs_null_listen, &listen_param)) { if (pthread_create(&work_pths[count_pths++], NULL, ipfs_null_listen, &listen_param)) {

37
core/net.c Normal file
View file

@ -0,0 +1,37 @@
#include "ipfs/core/net.h"
/**
* Do a socket accept
* @param listener the listener
* @returns true(1) on success, false(0) otherwise
*/
int ipfs_core_net_accept(struct IpfsListener listener) {
//TODO: Implement this
return 0;
}
/**
* Listen using a particular protocol
* @param node the node
* @param protocol the protocol to use
* @param listener the results
* @returns true(1) on success, false(0) otherwise
*/
int ipfs_core_net_listen(struct IpfsNode* node, char* protocol, struct IpfsListener* listener){
// TODO: Implement this
return 0;
}
/***
* Dial a peer
* @param node this node
* @param peer_id who to dial
* @param protocol the protocol to use
* @param stream the resultant stream
* @returns true(1) on success, otherwise false(0)
*/
int ipsf_core_net_dial(struct IpfsNode* node, char* peer_id, char* protocol, struct Stream* stream) {
//TODO: Implement this
return 0;
}

View file

@ -44,10 +44,10 @@ void *ipfs_null_listen (void *ptr)
{ {
int socketfd, s, count = 0; int socketfd, s, count = 0;
pthread_t pth_connection; pthread_t pth_connection;
struct null_listen_params *listen_param; struct IpfsNodeListenParams *listen_param;
struct null_connection_params *connection_param; struct null_connection_params *connection_param;
listen_param = (struct null_listen_params*) ptr; listen_param = (struct IpfsNodeListenParams*) ptr;
if ((socketfd = socket_listen(socket_tcp4(), &(listen_param->ipv4), &(listen_param->port))) <= 0) { if ((socketfd = socket_listen(socket_tcp4(), &(listen_param->ipv4), &(listen_param->port))) <= 0) {
perror("fail to init null router."); perror("fail to init null router.");

View file

@ -15,6 +15,12 @@
uint16_t port; uint16_t port;
}; };
struct IpfsNodeListenParams {
uint32_t ipv4;
uint16_t port;
struct IpfsNode* local_node;
};
void *ipfs_null_connection (void *ptr); void *ipfs_null_connection (void *ptr);
void *ipfs_null_listen (void *ptr); void *ipfs_null_listen (void *ptr);
int ipfs_daemon (int argc, char **argv); int ipfs_daemon (int argc, char **argv);

View file

@ -1,13 +1,14 @@
#ifndef __CORE_IPFS_NODE_H__ #pragma once
#define __CORE_IPFS_NODE_H__
enum NodeMode { MODE_OFFLINE, MODE_ONLINE };
struct IpfsNode { struct IpfsNode {
enum NodeMode mode;
//struct PeerId identity; //struct PeerId identity;
//struct Repo repo; struct FSRepo* repo;
struct Peerstore* peerstore;
//struct Pinner pinning; // an interface //struct Pinner pinning; // an interface
//struct Mount** mounts; //struct Mount** mounts;
//struct PrivKey* private_key; //struct PrivKey* private_key;
// TODO: Add more here // TODO: Add more here
}; };
#endif /* ipfs_node_h */

35
include/ipfs/core/net.h Normal file
View file

@ -0,0 +1,35 @@
#pragma once
#include "libp2p/net/stream.h"
struct IpfsListener {
char* conCh;
char* protocol;
};
/**
* Do a socket accept
* @param listener the listener
* @param stream the returned stream
* @returns true(1) on success, false(0) otherwise
*/
int ipfs_core_net_accept(struct IpfsListener* listener, struct Stream* stream);
/**
* Listen using a particular protocol
* @param node the node
* @param protocol the protocol to use
* @param listener the results
* @returns true(1) on success, false(0) otherwise
*/
int ipfs_core_net_listen(struct IpfsNode* node, char* protocol, struct IpfsListener* listener);
/***
* Dial a peer
* @param node this node
* @param peer_id who to dial
* @param protocol the protocol to use
* @param stream the resultant stream
* @returns true(1) on success, otherwise false(0)
*/
int ipsf_core_net_dial(struct IpfsNode* node, char* peer_id, char* protocol, struct Stream* stream);

View file

@ -1,6 +1,8 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef __USE_ISOC11
#define __USE_ISOC11 #define __USE_ISOC11
#endif
#include <time.h> #include <time.h>
#include "ipfs/cid/cid.h" #include "ipfs/cid/cid.h"
#include "ipfs/path/path.h" #include "ipfs/path/path.h"