Starting to handle get_value request

This commit is contained in:
John Jones 2017-02-27 12:27:40 -05:00
parent 7a6b138444
commit f1aac5d707
15 changed files with 281 additions and 31 deletions

View file

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-protobuf -Wall
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
ifdef DEBUG
CFLAGS += -g3

View file

@ -9,8 +9,7 @@
#include "ipfs/core/ipfs_node.h"
#include "ipfs/repo/fsrepo/fs_repo.h"
int ipfs_daemon (int argc, char **argv)
{
int ipfs_daemon_start(char* repo_path) {
int count_pths = 0;
pthread_t work_pths[MAX];
struct IpfsNodeListenParams listen_param;
@ -19,7 +18,7 @@ int ipfs_daemon (int argc, char **argv)
// read the configuration
struct FSRepo* fs_repo;
if (!ipfs_repo_fsrepo_new(NULL, NULL, &fs_repo))
if (!ipfs_repo_fsrepo_new(repo_path, NULL, &fs_repo))
return 0;
// open the repository and read the file
@ -58,4 +57,10 @@ int ipfs_daemon (int argc, char **argv)
// All pthreads aborted?
return 0;
}
int ipfs_daemon (int argc, char **argv)
{
return ipfs_daemon_start(NULL);
}

View file

@ -32,7 +32,7 @@ void *ipfs_null_connection (void *ptr)
fprintf(stderr, "Connection %d, count %d\n", connection_param->socket, *(connection_param->count));
if (libp2p_net_multistream_negotiate(stream)) {
routing = ipfs_routing_new_online(connection_param->local_node->repo, &connection_param->local_node->identity->private_key, stream);
routing = ipfs_routing_new_online(connection_param->local_node, &connection_param->local_node->identity->private_key, stream);
for(;;) {
struct Libp2pMessage* msg = libp2p_net_multistream_get_message(stream);
@ -41,9 +41,17 @@ void *ipfs_null_connection (void *ptr)
case (MESSAGE_TYPE_PING):
routing->Ping(routing, msg);
break;
case (MESSAGE_TYPE_GET_VALUE):
routing->GetValue(routing, msg->key, msg->key_size, NULL, NULL);
case (MESSAGE_TYPE_GET_VALUE): {
unsigned char* val;
size_t val_size = 0;
routing->GetValue(routing, msg->key, msg->key_size, (void**)&val, &val_size);
if (val == NULL) {
stream->write(stream, 0, 1);
} else {
stream->write(stream, val, val_size);
}
break;
}
default:
break;
}