Adding network calls to kademlia
This commit is contained in:
parent
59af1c0b9e
commit
96b97ad347
4 changed files with 29 additions and 13 deletions
|
@ -47,11 +47,12 @@ int ipfs_daemon_start(char* repo_path) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// create pthread for the API
|
||||
/*
|
||||
//ipfs_bootstrap_routing(&local_node);
|
||||
if (pthread_create(&work_pths[count_pths++], NULL, ipfs_bootstrap_routing, &local_node)) {
|
||||
fprintf(stderr, "Error creating thread for routing\n");
|
||||
}
|
||||
*/
|
||||
|
||||
fprintf(stderr, "Daemon is ready\n");
|
||||
|
||||
|
|
36
core/null.c
36
core/null.c
|
@ -12,28 +12,33 @@
|
|||
#include "ipfs/core/ipfs_node.h"
|
||||
#include "libp2p/secio/secio.h"
|
||||
#include "libp2p/nodeio/nodeio.h"
|
||||
#include "libp2p/routing/dht_protocol.h"
|
||||
#include "ipfs/merkledag/merkledag.h"
|
||||
#include "ipfs/merkledag/node.h"
|
||||
|
||||
#define BUF_SIZE 4096
|
||||
|
||||
int ipfs_null_requesting_secio(unsigned char* buffer, size_t buffer_size) {
|
||||
if (buffer_size > 5 && strncmp((char*)buffer, "/secio", 6) == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
int ipfs_null_requesting_nodeio(unsigned char* buffer, size_t buffer_size) {
|
||||
if (buffer_size > 5 && strncmp((char*)buffer, "/nodeio", 7) == 0)
|
||||
/***
|
||||
* Compare incoming to see if they are requesting a protocol upgrade
|
||||
* @param incoming the incoming string
|
||||
* @param incoming_size the size of the incoming string
|
||||
* @param test the protocol string to compare it with (i.e. "/secio" or "/nodeio"
|
||||
* @returns true(1) if there was a match, false(0) otherwise
|
||||
*/
|
||||
int protocol_compare(unsigned char* incoming, size_t incoming_size, const char* test) {
|
||||
int test_size = strlen(test);
|
||||
if (incoming_size >= test_size && strncmp((char*)incoming, test, test_size) == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* We've received a connection. Find out what they want
|
||||
*/
|
||||
void *ipfs_null_connection (void *ptr)
|
||||
{
|
||||
struct null_connection_params *connection_param = NULL;
|
||||
struct s_ipfs_routing* routing = NULL;
|
||||
//struct s_ipfs_routing* routing = NULL;
|
||||
|
||||
connection_param = (struct null_connection_params*) ptr;
|
||||
|
||||
|
@ -47,19 +52,19 @@ void *ipfs_null_connection (void *ptr)
|
|||
fprintf(stderr, "Connection %d, count %d\n", connection_param->socket, *(connection_param->count));
|
||||
|
||||
if (libp2p_net_multistream_negotiate(session.insecure_stream)) {
|
||||
routing = ipfs_routing_new_online(connection_param->local_node, &connection_param->local_node->identity->private_key, session.insecure_stream);
|
||||
//routing = ipfs_routing_new_online(connection_param->local_node, &connection_param->local_node->identity->private_key, session.insecure_stream);
|
||||
|
||||
for(;;) {
|
||||
// check if they're looking for an upgrade (i.e. secio)
|
||||
unsigned char* results = NULL;
|
||||
size_t bytes_read;
|
||||
session.default_stream->read(&session, &results, &bytes_read);
|
||||
if (ipfs_null_requesting_secio(results, bytes_read)) {
|
||||
if (protocol_compare(results, bytes_read, "/secio")) {
|
||||
if (!libp2p_secio_handshake(&session, &connection_param->local_node->identity->private_key, 1)) {
|
||||
// rejecting connection
|
||||
break;
|
||||
}
|
||||
} else if (ipfs_null_requesting_nodeio(results, bytes_read)) {
|
||||
} else if (protocol_compare(results, bytes_read, "/nodeio")) {
|
||||
if (!libp2p_nodeio_handshake(&session))
|
||||
break;
|
||||
// loop through file requests
|
||||
|
@ -89,8 +94,16 @@ void *ipfs_null_connection (void *ptr)
|
|||
session.default_stream->write(&session, results, results_size);
|
||||
}
|
||||
}
|
||||
} else if (protocol_compare(results, bytes_read, "/kad/")) {
|
||||
if (!libp2p_routing_dht_handshake(&session))
|
||||
break;
|
||||
// this handles 1 transaction
|
||||
libp2p_routing_dht_handle_message(&session, connection_param->local_node->peerstore, connection_param->local_node->providerstore);
|
||||
}
|
||||
else {
|
||||
// oops there was a problem
|
||||
//TODO: Handle this
|
||||
/*
|
||||
struct Libp2pMessage* msg = NULL;
|
||||
libp2p_message_protobuf_decode(results, bytes_read, &msg);
|
||||
if (msg != NULL) {
|
||||
|
@ -116,6 +129,7 @@ void *ipfs_null_connection (void *ptr)
|
|||
} else {
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define DAEMON_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ipfs/core/ipfs_node.h"
|
||||
|
||||
#define MAX 5
|
||||
#define CONNECTIONS 50
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
CC = gcc
|
||||
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/ -I../../c-protobuf -g3 -Wall -std=c99
|
||||
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -g3 -Wall -std=c99
|
||||
LFLAGS = -L../../c-libp2p -L../../c-multihash -L../../c-multiaddr -lp2p -lm -lmultihash -lmultiaddr -lpthread -lresolv
|
||||
DEPS = cmd/ipfs/test_init.h repo/test_repo_bootstrap_peers.h repo/test_repo_config.h repo/test_repo_identity.h cid/test_cid.h
|
||||
OBJS = main.o \
|
||||
|
|
Loading…
Reference in a new issue