diff --git a/core/bootstrap.c b/core/bootstrap.c index 39f85d2..8f13279 100644 --- a/core/bootstrap.c +++ b/core/bootstrap.c @@ -1,5 +1,6 @@ #include "libp2p/peer/peer.h" +#include "ipfs/routing/routing.h" #include "ipfs/core/ipfs_node.h" #include "ipfs/thirdparty/ipfsaddr/ipfs_addr.h" #include "multiaddr/multiaddr.h" @@ -38,6 +39,6 @@ void *ipfs_bootstrap_swarm(void* param) { */ void *ipfs_bootstrap_routing(void* param) { struct IpfsNode* local_node = (struct IpfsNode*)param; - local_node->routing = ipfs_routing_new_kademlia(local_node, local_node->identity->private_key, NULL); + local_node->routing = ipfs_routing_new_kademlia(local_node, &local_node->identity->private_key, NULL); return NULL; } diff --git a/importer/resolver.c b/importer/resolver.c index 51dcc7c..e35a71c 100644 --- a/importer/resolver.c +++ b/importer/resolver.c @@ -9,7 +9,7 @@ #include "ipfs/repo/fsrepo/fs_repo.h" #include "libp2p/net/multistream.h" #include "libp2p/record/message.h" -#include "libp2p/utils/multiaddress.h" +#include "multiaddr/multiaddr.h" /** * return the next chunk of a path @@ -127,8 +127,8 @@ struct Node* ipfs_resolver_remote_get(const char* path, struct Node* from, const // connect to the peer struct MultiAddress* address = peer->addr_head->item; char* ip; - int port; - libp2p_utils_multiaddress_parse_ip4_tcp(address, &ip, &port); + int port = multiaddress_get_ip_port(address); + multiaddress_get_ip_address(address, &ip); struct Stream* stream = libp2p_net_multistream_connect(ip, port); free(ip); // build the request diff --git a/include/ipfs/core/bootstrap.h b/include/ipfs/core/bootstrap.h index c7a5e1d..66270d3 100644 --- a/include/ipfs/core/bootstrap.h +++ b/include/ipfs/core/bootstrap.h @@ -10,3 +10,5 @@ * @returns nothing useful */ void *ipfs_bootstrap_swarm(void* param); + +void *ipfs_bootstrap_routing(void* param); diff --git a/include/ipfs/core/ipfs_node.h b/include/ipfs/core/ipfs_node.h index 97bbb92..7d190f4 100644 --- a/include/ipfs/core/ipfs_node.h +++ b/include/ipfs/core/ipfs_node.h @@ -11,7 +11,7 @@ struct IpfsNode { struct Identity* identity; struct FSRepo* repo; struct Peerstore* peerstore; - struct Routing* routing; + struct s_ipfs_routing* routing; //struct Pinner pinning; // an interface //struct Mount** mounts; // TODO: Add more here diff --git a/routing/Makefile b/routing/Makefile index fd7de81..a23111e 100644 --- a/routing/Makefile +++ b/routing/Makefile @@ -7,7 +7,7 @@ endif LFLAGS = DEPS = -OBJS = offline.o online.o +OBJS = offline.o online.o k_routing.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/routing/k_routing.c b/routing/k_routing.c index 3d179c7..9fe99f1 100644 --- a/routing/k_routing.c +++ b/routing/k_routing.c @@ -1,4 +1,5 @@ #include "ipfs/routing/routing.h" +#include "libp2p/routing/kademlia.h" /** * Routing using Kademlia and DHT @@ -13,8 +14,8 @@ * @param value_size the size of the value * @returns 0 on success, otherwise -1 */ -int ipfs_routing_kademlia_put_value(struct s_ipfs_routing routing, char* key, size_t key_size, void* value, size_t value_size) { - +int ipfs_routing_kademlia_put_value(struct s_ipfs_routing* routing, char* key, size_t key_size, void* value, size_t value_size) { + return 0; } /** @@ -25,27 +26,29 @@ int ipfs_routing_kademlia_put_value(struct s_ipfs_routing routing, char* key, si * @param 4 a place to store the value * @param 5 the size of the value */ -int ipfs_routing_kademlia_get_value(struct s_ipfs_routing*, char*, size_t, void**, size_t*) { +int ipfs_routing_kademlia_get_value(struct s_ipfs_routing* routing, char* key, size_t key_size, void** value, size_t* value_size) { return 0; } /** * Find a provider */ -int ipfs_routing_kademlia_find_providers(struct s_ipfs_routing*, char*, size_t, void*, size_t*) { +int ipfs_routing_kademlia_find_providers(struct s_ipfs_routing* routing, char* param1, size_t param2, void* param3, size_t* param4) { return 0; } /** * Find a peer */ -int ipfs_routing_kademlia_find_peer(struct s_ipfs_routing*, char*, size_t, void*, size_t*) { +int ipfs_routing_kademlia_find_peer(struct s_ipfs_routing* routing, char* param1, size_t param2, void* param3, size_t* param4) { return 0; } -int ipfs_routing_kademlia_provide(struct s_ipfs_routing*, char*) { +int ipfs_routing_kademlia_provide(struct s_ipfs_routing* routing, char* param1) { return 0; } +// declared here so as to have the code in 1 place +int ipfs_routing_online_ping(struct s_ipfs_routing*, struct Libp2pMessage*); /** * Ping this instance */ @@ -53,7 +56,7 @@ int ipfs_routing_kademlia_ping(struct s_ipfs_routing* routing, struct Libp2pMess return ipfs_routing_online_ping(routing, message); } -int ipfs_routing_kademlia_bootstrap(struct s_ipfs_routing*) { +int ipfs_routing_kademlia_bootstrap(struct s_ipfs_routing* routing) { return 0; } @@ -72,7 +75,7 @@ struct s_ipfs_routing* ipfs_routing_new_kademlia(struct IpfsNode* local_node, st routing->Bootstrap = ipfs_routing_kademlia_bootstrap; } // connect to nodes and listen for connections - struct MultiAddress* address = multiaddresss_new_from_string(local_node->repo->config->addresses->api); + struct MultiAddress* address = multiaddress_new_from_string(local_node->repo->config->addresses->api); if (multiaddress_is_ip(address)) { int port = multiaddress_get_ip_port(address); int family = multiaddress_get_ip_family(address); diff --git a/test/Makefile b/test/Makefile index 791d054..5fc0535 100644 --- a/test/Makefile +++ b/test/Makefile @@ -24,6 +24,7 @@ OBJS = testit.o test_helper.o \ ../repo/config/addresses.o ../repo/config/swarm.o ../repo/config/peer.o \ ../routing/offline.o \ ../routing/online.o \ + ../routing/k_routing.o \ ../thirdparty/ipfsaddr/ipfs_addr.o \ ../unixfs/unixfs.o \ ../../c-protobuf/protobuf.o ../../c-protobuf/varint.o