namesys: Fixed some compilation errors.

This commit is contained in:
Jose Marcial Vieira Bisneto 2017-02-13 08:52:22 -03:00
parent c972852c9a
commit 4cd4750f6f
7 changed files with 41 additions and 24 deletions

View file

@ -34,4 +34,5 @@
char* ipfs_ipns_entry_get_signature(struct ipns_entry*); char* ipfs_ipns_entry_get_signature(struct ipns_entry*);
int ipfs_namesys_pb_get_value (char**, struct ipns_entry*); int ipfs_namesys_pb_get_value (char**, struct ipns_entry*);
IpnsEntry_ValidityType ipfs_namesys_pb_get_validity_type (struct ipns_entry*); IpnsEntry_ValidityType ipfs_namesys_pb_get_validity_type (struct ipns_entry*);
void ipfs_namesys_ipnsentry_reset (struct ipns_entry *m);
#endif // IPNS_NAMESYS_PB_H #endif // IPNS_NAMESYS_PB_H

View file

@ -19,6 +19,10 @@
struct cacheEntry **data; struct cacheEntry **data;
}; };
struct libp2p_routing_value_store { // dummy declaration, not implemented yet.
void *missing;
};
char* ipfs_routing_cache_get (char *key, struct ipns_entry *ientry); char* ipfs_routing_cache_get (char *key, struct ipns_entry *ientry);
void ipfs_routing_cache_set (char *key, char *value, struct ipns_entry *ientry); void ipfs_routing_cache_set (char *key, char *value, struct ipns_entry *ientry);
struct routingResolver* ipfs_namesys_new_routing_resolver (struct libp2p_routing_value_store *route, int cachesize); struct routingResolver* ipfs_namesys_new_routing_resolver (struct libp2p_routing_value_store *route, int cachesize);

View file

@ -9,6 +9,7 @@
#include "ipfs/cid/cid.h" #include "ipfs/cid/cid.h"
#include "ipfs/path/path.h" #include "ipfs/path/path.h"
#include "ipfs/namesys/namesys.h" #include "ipfs/namesys/namesys.h"
#include "ipfs/dnslink/dnslink.h"
/*type LookupTXTFunc func(name string) (txt []string, err error) /*type LookupTXTFunc func(name string) (txt []string, err error)
@ -53,6 +54,7 @@ int ipfs_dns_resolver_resolve_once (char **path, char *name)
char **segments, *domain, *dnslink, buf[500], dlprefix[] = "_dnslink."; char **segments, *domain, *dnslink, buf[500], dlprefix[] = "_dnslink.";
int p1[2], p2[2], r, l, c=2; int p1[2], p2[2], r, l, c=2;
struct pollfd event[2], *e; struct pollfd event[2], *e;
DNSResolver dnsr;
segments = ipfs_path_split_n(name, "/", 2); segments = ipfs_path_split_n(name, "/", 2);
domain = segments[0]; domain = segments[0];
@ -68,13 +70,15 @@ int ipfs_dns_resolver_resolve_once (char **path, char *name)
return ErrPipe; return ErrPipe;
} }
dnsr.lookupTXT = ipfs_dnslink_resolv_lookupTXT;
r = fork(); r = fork();
switch(r) { switch(r) {
case -1: case -1:
return ErrPipe; return ErrPipe;
case 0: // child case 0: // child
close(p1[STDIN_FILENO]); // we don't need to read at child process. close(p1[STDIN_FILENO]); // we don't need to read at child process.
return ipfs_dns_work_domain (p1[STDOUT_FILENO], r, domain); return ipfs_dns_work_domain (p1[STDOUT_FILENO], &dnsr, domain);
} }
close(p1[STDOUT_FILENO]); // we don't need to write at main process. close(p1[STDOUT_FILENO]); // we don't need to write at main process.
r = fork(); r = fork();
@ -93,7 +97,7 @@ int ipfs_dns_resolver_resolve_once (char **path, char *name)
strncpy (dnslink, dlprefix, l); strncpy (dnslink, dlprefix, l);
strncat (dnslink, domain, l - strlen(dnslink)); strncat (dnslink, domain, l - strlen(dnslink));
return ipfs_dns_work_domain (p2[STDOUT_FILENO], r, dnslink); return ipfs_dns_work_domain (p2[STDOUT_FILENO], &dnsr, dnslink);
} }
close(p2[STDOUT_FILENO]); // we don't need to write at main process. close(p2[STDOUT_FILENO]); // we don't need to write at main process.

View file

@ -6,6 +6,11 @@
#include "ipfs/namesys/namesys.h" #include "ipfs/namesys/namesys.h"
#include "ipfs/dnslink/dnslink.h" #include "ipfs/dnslink/dnslink.h"
#ifndef __USE_ISOC11
extern int timespec_get (struct timespec *__ts, int __base)
__THROW __nonnull ((1));
#endif
/* mpns (a multi-protocol NameSystem) implements generic IPFS naming. /* mpns (a multi-protocol NameSystem) implements generic IPFS naming.
* *
* Uses several Resolvers: * Uses several Resolvers:
@ -32,7 +37,7 @@ func NewNameSystem(r routing.ValueStore, ds ds.Datastore, cachesize int) NameSys
} }
}*/ }*/
const DefaultResolverCacheTTL = 60; const int DefaultResolverCacheTTL = 60;
// ipfs_namesys_resolve implements Resolver. // ipfs_namesys_resolve implements Resolver.
int ipfs_namesys_resolve(char **path, char *name) int ipfs_namesys_resolve(char **path, char *name)
@ -45,11 +50,7 @@ int ipfs_namesys_resolve_n(char **path, char *name, int depth)
{ {
char ipfs_prefix[] = "/ipfs/"; char ipfs_prefix[] = "/ipfs/";
char p[500]; char p[500];
char *ps[] = {"/ipns/", NULL};
int err; int err;
resolver r;
r.resolveOnce = ipfs_namesys_resolve_once;
if (memcmp(name, ipfs_prefix, strlen(ipfs_prefix)) == 0) { if (memcmp(name, ipfs_prefix, strlen(ipfs_prefix)) == 0) {
ipfs_path_parse(p, name); ipfs_path_parse(p, name);
@ -85,7 +86,7 @@ int ipfs_namesys_resolve_n(char **path, char *name, int depth)
return err; return err;
} }
return ipfs_namesys_resolve(&r, path, name, depth, ps); return ipfs_namesys_resolve(path, name);
} }
// ipfs_namesys_resolve_once implements resolver. // ipfs_namesys_resolve_once implements resolver.
@ -95,14 +96,11 @@ int ipfs_namesys_resolve_once (char **path, char *name)
char *ptr = NULL; char *ptr = NULL;
char **segs; char **segs;
int i, err = 0; int i, err = 0;
struct DNSResolver dnsr;
if (!name) { // NULL pointer. if (!name) { // NULL pointer.
return ErrNULLPointer; return ErrNULLPointer;
} }
dnsr.lookupTXT = ipfs_dnslink_resolv_lookupTXT;
if (memcmp (name, ipns_prefix, strlen(ipns_prefix)) == 0) { // prefix missing. if (memcmp (name, ipns_prefix, strlen(ipns_prefix)) == 0) { // prefix missing.
i = strlen(name) + sizeof(ipns_prefix); i = strlen(name) + sizeof(ipns_prefix);
ptr = malloc(i); ptr = malloc(i);
@ -146,8 +144,8 @@ int ipfs_namesys_publish (char *proto, ciPrivKey name, char *value)
int i; int i;
for (i = 0 ; ns[i] ; i++) { for (i = 0 ; ns[i] ; i++) {
if (strcmp(ns[i]->Publisher->protocol, proto)==0) { if (strcmp(ns[i]->publisher->protocol, proto)==0) {
return ns[i]->Publisher->func(name, value); return ns[i]->publisher->func(name, value);
} }
} }
return ErrPublishFailed; return ErrPublishFailed;
@ -158,8 +156,8 @@ int ipfs_namesys_publish_with_eol (char *proto, ciPrivKey name, char *value, tim
int i; int i;
for (i = 0 ; ns[i] ; i++) { for (i = 0 ; ns[i] ; i++) {
if (strcmp(ns[i]->Publisher->protocol, proto)==0) { if (strcmp(ns[i]->publisher->protocol, proto)==0) {
return ns[i]->Publisher->func_eol(name, value, eol); return ns[i]->publisher->func_eol(name, value, eol);
} }
} }
return ErrPublishFailed; return ErrPublishFailed;

View file

@ -1,4 +1,5 @@
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "ipfs/namesys/routing.h" #include "ipfs/namesys/routing.h"
#include "ipfs/namesys/pb.h" #include "ipfs/namesys/pb.h"

View file

@ -27,7 +27,7 @@ char* ipns_entry_data_for_sig (struct ipns_entry *entry)
int ipns_selector_func (int *idx, struct ipns_entry ***recs, char *k, char **vals) int ipns_selector_func (int *idx, struct ipns_entry ***recs, char *k, char **vals)
{ {
int err, i, c; int err = 0, i, c;
if (!idx || !recs || !k || !vals) { if (!idx || !recs || !k || !vals) {
return ErrInvalidParam; return ErrInvalidParam;
@ -98,7 +98,7 @@ int ipns_select_record (int *idx, struct ipns_entry **recs, char **vals)
// given 'val' is an IpnsEntry and that that entry is valid. // given 'val' is an IpnsEntry and that that entry is valid.
int ipns_validate_ipns_record (char *k, char *val) int ipns_validate_ipns_record (char *k, char *val)
{ {
int err; int err = 0;
struct ipns_entry *entry = ipfs_namesys_pb_new_ipns_entry(); struct ipns_entry *entry = ipfs_namesys_pb_new_ipns_entry();
struct timespec ts, now; struct timespec ts, now;
@ -122,4 +122,5 @@ int ipns_validate_ipns_record (char *k, char *val)
} else { } else {
return ErrUnrecognizedValidity; return ErrUnrecognizedValidity;
} }
return 0;
} }

View file

@ -2,12 +2,20 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#ifndef __USE_ISOC11
extern int timespec_get (struct timespec *__ts, int __base)
__THROW __nonnull ((1));
#endif
#ifndef TIME_UTC
# define TIME_UTC 1
#endif
#include "ipfs/namesys/routing.h" #include "ipfs/namesys/routing.h"
#include "ipfs/util/time.h" #include "ipfs/util/time.h"
#include "mh/multihash.h" #include "mh/multihash.h"
#include "ipfs/namesys/pb.h" #include "ipfs/namesys/pb.h"
#include "ipfs/namesys/namesys.h" #include "ipfs/namesys/namesys.h"
#include "ipfs/cid/cid.h" #include "ipfs/cid/cid.h"
#include "ipfs/path/path.h"
char* ipfs_routing_cache_get (char *key, struct ipns_entry *ientry) char* ipfs_routing_cache_get (char *key, struct ipns_entry *ientry)
{ {
@ -18,7 +26,7 @@ char* ipfs_routing_cache_get (char *key, struct ipns_entry *ientry)
if (key && ientry) { if (key && ientry) {
cache = ientry->cache; cache = ientry->cache;
if (cache) { if (cache) {
timespec_get (&now); timespec_get (&now, TIME_UTC);
for (i = 0 ; i < cache->next ; i++) { for (i = 0 ; i < cache->next ; i++) {
if (((now.tv_sec < cache->data[i]->eol.tv_sec || if (((now.tv_sec < cache->data[i]->eol.tv_sec ||
(now.tv_sec == cache->data[i]->eol.tv_sec && now.tv_nsec < cache->data[i]->eol.tv_nsec))) && (now.tv_sec == cache->data[i]->eol.tv_sec && now.tv_nsec < cache->data[i]->eol.tv_nsec))) &&
@ -43,7 +51,7 @@ void ipfs_routing_cache_set (char *key, char *value, struct ipns_entry *ientry)
if (n) { if (n) {
n->key = key; n->key = key;
n->value = value; n->value = value;
timespec_get (&n->eol); // now timespec_get (&n->eol, TIME_UTC); // now
n->eol.tv_sec += DefaultResolverCacheTTL; // sum TTL seconds to time seconds. n->eol.tv_sec += DefaultResolverCacheTTL; // sum TTL seconds to time seconds.
cache->data[cache->next++] = n; cache->data[cache->next++] = n;
} }
@ -98,8 +106,8 @@ int ipfs_namesys_routing_resolve_once (char **path, char *name, int depth, char
{ {
int err, l, s, ok; int err, l, s, ok;
struct MultiHash hash; struct MultiHash hash;
char *h, *string, *val; char *h, *string, val[8];
struct libp2p_crypto_pubkey pubkey; char pubkey[60];
if (!path || !name | !prefix) { if (!path || !name | !prefix) {
return ErrInvalidParam; return ErrInvalidParam;
@ -114,7 +122,7 @@ int ipfs_namesys_routing_resolve_once (char **path, char *name, int depth, char
name += strlen (prefix); // trim prefix. name += strlen (prefix); // trim prefix.
} }
err = libp2p_b58_to_multihash (name, strlen(name), &hash); err = libp2p_b58_to_multihash ((unsigned char*)name, strlen(name), &hash);
if (err) { if (err) {
// name should be a multihash. if it isn't, error out here. // name should be a multihash. if it isn't, error out here.
//log.Warningf("RoutingResolve: bad input hash: [%s]\n", name) //log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
@ -174,7 +182,7 @@ int ipfs_namesys_routing_resolve_once (char **path, char *name, int depth, char
err = libp2p_multihash_from_hex_string(string, strlen(string), &hash); err = libp2p_multihash_from_hex_string(string, strlen(string), &hash);
if (err) { if (err) {
// Not a multihash, probably a new record // Not a multihash, probably a new record
err = ipfs_path_parse(path, string); err = ipfs_path_parse(*path, string);
if (err) { if (err) {
return err; return err;
} }
@ -187,7 +195,7 @@ int ipfs_namesys_routing_resolve_once (char **path, char *name, int depth, char
return err; return err;
} }
err = ipfs_path_parse_from_cid (path, cid); err = ipfs_path_parse_from_cid (*path, (char*)cid->hash);
if (err) { if (err) {
return err; return err;
} }