More go compat fixes
This commit is contained in:
parent
f3db50c3ba
commit
48b9647a3c
6 changed files with 29 additions and 24 deletions
|
@ -312,15 +312,6 @@ int ipfs_core_http_process_swarm_connect(struct IpfsNode* local_node, struct Htt
|
||||||
multiaddress_free(ma);
|
multiaddress_free(ma);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// ok, we're good. Start a thread to listen to them, and send stuff back to the user
|
|
||||||
// JMJ Debug - just put a loop here for testing
|
|
||||||
while(1) {
|
|
||||||
int retVal = ipfs_null_listen_and_handle(new_peer->sessionContext->default_stream, local_node->protocol_handlers);
|
|
||||||
if (retVal < 0)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
sleep(1);
|
|
||||||
}
|
|
||||||
*resp = ipfs_core_http_response_new();
|
*resp = ipfs_core_http_response_new();
|
||||||
struct HttpResponse* response = *resp;
|
struct HttpResponse* response = *resp;
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
|
|
|
@ -94,13 +94,14 @@ int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node) {
|
||||||
local_node->repo = fs_repo;
|
local_node->repo = fs_repo;
|
||||||
local_node->identity = fs_repo->config->identity;
|
local_node->identity = fs_repo->config->identity;
|
||||||
local_node->peerstore = libp2p_peerstore_new(local_node->identity->peer);
|
local_node->peerstore = libp2p_peerstore_new(local_node->identity->peer);
|
||||||
local_node->dialer = libp2p_conn_dialer_new(local_node->identity->peer, local_node->peerstore, &local_node->identity->private_key);
|
|
||||||
local_node->providerstore = libp2p_providerstore_new(fs_repo->config->datastore, local_node->identity->peer);
|
local_node->providerstore = libp2p_providerstore_new(fs_repo->config->datastore, local_node->identity->peer);
|
||||||
local_node->blockstore = ipfs_blockstore_new(fs_repo);
|
local_node->blockstore = ipfs_blockstore_new(fs_repo);
|
||||||
local_node->protocol_handlers = ipfs_node_online_build_protocol_handlers(local_node);
|
local_node->protocol_handlers = ipfs_node_online_build_protocol_handlers(local_node);
|
||||||
local_node->mode = MODE_OFFLINE;
|
local_node->mode = MODE_OFFLINE;
|
||||||
local_node->routing = ipfs_routing_new_online(local_node, &fs_repo->config->identity->private_key);
|
local_node->routing = ipfs_routing_new_online(local_node, &fs_repo->config->identity->private_key);
|
||||||
local_node->exchange = ipfs_bitswap_new(local_node);
|
local_node->exchange = ipfs_bitswap_new(local_node);
|
||||||
|
local_node->swarm = libp2p_swarm_new(local_node->protocol_handlers, local_node->repo->config->datastore, local_node->repo->config->filestore);
|
||||||
|
local_node->dialer = libp2p_conn_dialer_new(local_node->identity->peer, local_node->peerstore, &local_node->identity->private_key, local_node->swarm);
|
||||||
|
|
||||||
// fire up the API
|
// fire up the API
|
||||||
api_start(local_node, 10, 5);
|
api_start(local_node, 10, 5);
|
||||||
|
@ -140,13 +141,14 @@ int ipfs_node_offline_new(const char* repo_path, struct IpfsNode** node) {
|
||||||
local_node->repo = fs_repo;
|
local_node->repo = fs_repo;
|
||||||
local_node->identity = fs_repo->config->identity;
|
local_node->identity = fs_repo->config->identity;
|
||||||
local_node->peerstore = libp2p_peerstore_new(local_node->identity->peer);
|
local_node->peerstore = libp2p_peerstore_new(local_node->identity->peer);
|
||||||
local_node->dialer = libp2p_conn_dialer_new(local_node->identity->peer, local_node->peerstore, &local_node->identity->private_key);
|
|
||||||
local_node->providerstore = libp2p_providerstore_new(fs_repo->config->datastore, local_node->identity->peer);
|
local_node->providerstore = libp2p_providerstore_new(fs_repo->config->datastore, local_node->identity->peer);
|
||||||
local_node->blockstore = ipfs_blockstore_new(fs_repo);
|
local_node->blockstore = ipfs_blockstore_new(fs_repo);
|
||||||
local_node->protocol_handlers = ipfs_node_online_build_protocol_handlers(local_node);
|
local_node->protocol_handlers = ipfs_node_online_build_protocol_handlers(local_node);
|
||||||
local_node->mode = MODE_OFFLINE;
|
local_node->mode = MODE_OFFLINE;
|
||||||
local_node->routing = ipfs_routing_new_offline(local_node, &fs_repo->config->identity->private_key);
|
local_node->routing = ipfs_routing_new_offline(local_node, &fs_repo->config->identity->private_key);
|
||||||
local_node->exchange = ipfs_bitswap_new(local_node);
|
local_node->exchange = ipfs_bitswap_new(local_node);
|
||||||
|
local_node->swarm = libp2p_swarm_new(local_node->protocol_handlers, local_node->repo->config->datastore, local_node->repo->config->filestore);
|
||||||
|
local_node->dialer = libp2p_conn_dialer_new(local_node->identity->peer, local_node->peerstore, &local_node->identity->private_key, local_node->swarm);
|
||||||
|
|
||||||
if (api_running(local_node))
|
if (api_running(local_node))
|
||||||
local_node->mode = MODE_API_AVAILABLE;
|
local_node->mode = MODE_API_AVAILABLE;
|
||||||
|
|
31
core/null.c
31
core/null.c
|
@ -18,6 +18,7 @@
|
||||||
#include "libp2p/routing/dht_protocol.h"
|
#include "libp2p/routing/dht_protocol.h"
|
||||||
#include "libp2p/secio/secio.h"
|
#include "libp2p/secio/secio.h"
|
||||||
#include "libp2p/utils/logger.h"
|
#include "libp2p/utils/logger.h"
|
||||||
|
#include "libp2p/swarm/swarm.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/exchange/bitswap/network.h"
|
#include "ipfs/exchange/bitswap/network.h"
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
#include "ipfs/merkledag/node.h"
|
#include "ipfs/merkledag/node.h"
|
||||||
#include "ipfs/routing/routing.h"
|
#include "ipfs/routing/routing.h"
|
||||||
#include "ipfs/util/thread_pool.h"
|
#include "ipfs/util/thread_pool.h"
|
||||||
|
#include "libp2p/swarm/swarm.h"
|
||||||
|
|
||||||
#define BUF_SIZE 4096
|
#define BUF_SIZE 4096
|
||||||
|
|
||||||
|
@ -153,9 +155,8 @@ void* ipfs_null_listen (void *ptr)
|
||||||
{
|
{
|
||||||
null_shutting_down = 0;
|
null_shutting_down = 0;
|
||||||
int socketfd, s, count = 0;
|
int socketfd, s, count = 0;
|
||||||
threadpool thpool = thpool_init(25);
|
//threadpool thpool = thpool_init(25);
|
||||||
struct IpfsNodeListenParams *listen_param;
|
struct IpfsNodeListenParams *listen_param;
|
||||||
struct null_connection_params *connection_param;
|
|
||||||
|
|
||||||
listen_param = (struct IpfsNodeListenParams*) ptr;
|
listen_param = (struct IpfsNodeListenParams*) ptr;
|
||||||
|
|
||||||
|
@ -186,6 +187,10 @@ void* ipfs_null_listen (void *ptr)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add the new connection to the swarm
|
||||||
|
libp2p_swarm_add_connection(listen_param->local_node->swarm, s, listen_param->ipv4, listen_param->port);
|
||||||
|
|
||||||
|
/*
|
||||||
count++;
|
count++;
|
||||||
connection_param = malloc (sizeof (struct null_connection_params));
|
connection_param = malloc (sizeof (struct null_connection_params));
|
||||||
if (connection_param) {
|
if (connection_param) {
|
||||||
|
@ -207,18 +212,20 @@ void* ipfs_null_listen (void *ptr)
|
||||||
// Create pthread for ipfs_null_connection.
|
// Create pthread for ipfs_null_connection.
|
||||||
thpool_add_work(thpool, ipfs_null_connection, connection_param);
|
thpool_add_work(thpool, ipfs_null_connection, connection_param);
|
||||||
}
|
}
|
||||||
} else {
|
*/
|
||||||
// timeout... do maintenance
|
} else {
|
||||||
struct PeerEntry* entry = current_peer_entry->item;
|
// timeout... do maintenance
|
||||||
ipfs_null_do_maintenance(listen_param->local_node, entry->peer);
|
struct PeerEntry* entry = current_peer_entry->item;
|
||||||
if (current_peer_entry != NULL)
|
// JMJ Debugging
|
||||||
current_peer_entry = current_peer_entry->next;
|
//ipfs_null_do_maintenance(listen_param->local_node, entry->peer);
|
||||||
if (current_peer_entry == NULL)
|
if (current_peer_entry != NULL)
|
||||||
current_peer_entry = listen_param->local_node->peerstore->head_entry;
|
current_peer_entry = current_peer_entry->next;
|
||||||
}
|
if (current_peer_entry == NULL)
|
||||||
|
current_peer_entry = listen_param->local_node->peerstore->head_entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thpool_destroy(thpool);
|
//thpool_destroy(thpool);
|
||||||
|
|
||||||
close(socketfd);
|
close(socketfd);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "libp2p/peer/peerstore.h"
|
#include "libp2p/peer/peerstore.h"
|
||||||
#include "libp2p/peer/providerstore.h"
|
#include "libp2p/peer/providerstore.h"
|
||||||
|
#include "libp2p/swarm/swarm.h"
|
||||||
#include "ipfs/blocks/blockstore.h"
|
#include "ipfs/blocks/blockstore.h"
|
||||||
#include "ipfs/exchange/exchange.h"
|
#include "ipfs/exchange/exchange.h"
|
||||||
#include "ipfs/repo/config/identity.h"
|
#include "ipfs/repo/config/identity.h"
|
||||||
|
@ -39,6 +40,7 @@ struct IpfsNode {
|
||||||
struct Libp2pVector* protocol_handlers;
|
struct Libp2pVector* protocol_handlers;
|
||||||
struct ApiContext* api_context;
|
struct ApiContext* api_context;
|
||||||
struct Dialer* dialer;
|
struct Dialer* dialer;
|
||||||
|
struct SwarmContext* swarm;
|
||||||
//struct Pinner pinning; // an interface
|
//struct Pinner pinning; // an interface
|
||||||
//struct Mount** mounts;
|
//struct Mount** mounts;
|
||||||
// TODO: Add more here
|
// TODO: Add more here
|
||||||
|
|
|
@ -19,6 +19,9 @@ int test_compat_go_join_swarm() {
|
||||||
libp2p_logger_add_class("yamux");
|
libp2p_logger_add_class("yamux");
|
||||||
libp2p_logger_add_class("identify");
|
libp2p_logger_add_class("identify");
|
||||||
libp2p_logger_add_class("null");
|
libp2p_logger_add_class("null");
|
||||||
|
libp2p_logger_add_class("multistream");
|
||||||
|
libp2p_logger_add_class("swarm");
|
||||||
|
libp2p_logger_add_class("secio");
|
||||||
|
|
||||||
// Here is the connection information for the GO version:
|
// Here is the connection information for the GO version:
|
||||||
char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA";
|
char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA";
|
||||||
|
|
|
@ -55,7 +55,7 @@ int test_ping() {
|
||||||
remote_peer->addr_head->item = multiaddress_new_from_string("/ip4/192.168.43.234/tcp/4001/");
|
remote_peer->addr_head->item = multiaddress_new_from_string("/ip4/192.168.43.234/tcp/4001/");
|
||||||
|
|
||||||
// connect using a dialer
|
// connect using a dialer
|
||||||
dialer = libp2p_conn_dialer_new(fs_repo->config->identity->peer, NULL, NULL);
|
dialer = libp2p_conn_dialer_new(fs_repo->config->identity->peer, NULL, NULL, NULL);
|
||||||
conn = libp2p_conn_dialer_get_connection(dialer, remote_peer->addr_head->item);
|
conn = libp2p_conn_dialer_get_connection(dialer, remote_peer->addr_head->item);
|
||||||
|
|
||||||
//TODO: Dialer should know the protocol
|
//TODO: Dialer should know the protocol
|
||||||
|
|
Loading…
Reference in a new issue