Added utility functions to multiaddress
Parsing of typical IP addresses is now easier
This commit is contained in:
parent
f494344b15
commit
93c4988f90
7 changed files with 21 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,3 +10,5 @@
|
|||
* @returns nothing useful
|
||||
*/
|
||||
void *ipfs_bootstrap_swarm(void* param);
|
||||
|
||||
void *ipfs_bootstrap_routing(void* param);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue