namesys: Fixed some compilation errors.
This commit is contained in:
parent
c972852c9a
commit
4cd4750f6f
7 changed files with 41 additions and 24 deletions
|
@ -34,4 +34,5 @@
|
|||
char* ipfs_ipns_entry_get_signature(struct ipns_entry*);
|
||||
int ipfs_namesys_pb_get_value (char**, 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
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
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);
|
||||
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);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "ipfs/cid/cid.h"
|
||||
#include "ipfs/path/path.h"
|
||||
#include "ipfs/namesys/namesys.h"
|
||||
#include "ipfs/dnslink/dnslink.h"
|
||||
|
||||
/*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.";
|
||||
int p1[2], p2[2], r, l, c=2;
|
||||
struct pollfd event[2], *e;
|
||||
DNSResolver dnsr;
|
||||
|
||||
segments = ipfs_path_split_n(name, "/", 2);
|
||||
domain = segments[0];
|
||||
|
@ -68,13 +70,15 @@ int ipfs_dns_resolver_resolve_once (char **path, char *name)
|
|||
return ErrPipe;
|
||||
}
|
||||
|
||||
dnsr.lookupTXT = ipfs_dnslink_resolv_lookupTXT;
|
||||
|
||||
r = fork();
|
||||
switch(r) {
|
||||
case -1:
|
||||
return ErrPipe;
|
||||
case 0: // child
|
||||
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.
|
||||
r = fork();
|
||||
|
@ -93,7 +97,7 @@ int ipfs_dns_resolver_resolve_once (char **path, char *name)
|
|||
strncpy (dnslink, dlprefix, l);
|
||||
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.
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
#include "ipfs/namesys/namesys.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.
|
||||
*
|
||||
* 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.
|
||||
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 p[500];
|
||||
char *ps[] = {"/ipns/", NULL};
|
||||
int err;
|
||||
resolver r;
|
||||
|
||||
r.resolveOnce = ipfs_namesys_resolve_once;
|
||||
|
||||
if (memcmp(name, ipfs_prefix, strlen(ipfs_prefix)) == 0) {
|
||||
ipfs_path_parse(p, name);
|
||||
|
@ -85,7 +86,7 @@ int ipfs_namesys_resolve_n(char **path, char *name, int depth)
|
|||
return err;
|
||||
}
|
||||
|
||||
return ipfs_namesys_resolve(&r, path, name, depth, ps);
|
||||
return ipfs_namesys_resolve(path, name);
|
||||
}
|
||||
|
||||
// ipfs_namesys_resolve_once implements resolver.
|
||||
|
@ -95,14 +96,11 @@ int ipfs_namesys_resolve_once (char **path, char *name)
|
|||
char *ptr = NULL;
|
||||
char **segs;
|
||||
int i, err = 0;
|
||||
struct DNSResolver dnsr;
|
||||
|
||||
if (!name) { // NULL pointer.
|
||||
return ErrNULLPointer;
|
||||
}
|
||||
|
||||
dnsr.lookupTXT = ipfs_dnslink_resolv_lookupTXT;
|
||||
|
||||
if (memcmp (name, ipns_prefix, strlen(ipns_prefix)) == 0) { // prefix missing.
|
||||
i = strlen(name) + sizeof(ipns_prefix);
|
||||
ptr = malloc(i);
|
||||
|
@ -146,8 +144,8 @@ int ipfs_namesys_publish (char *proto, ciPrivKey name, char *value)
|
|||
int i;
|
||||
|
||||
for (i = 0 ; ns[i] ; i++) {
|
||||
if (strcmp(ns[i]->Publisher->protocol, proto)==0) {
|
||||
return ns[i]->Publisher->func(name, value);
|
||||
if (strcmp(ns[i]->publisher->protocol, proto)==0) {
|
||||
return ns[i]->publisher->func(name, value);
|
||||
}
|
||||
}
|
||||
return ErrPublishFailed;
|
||||
|
@ -158,8 +156,8 @@ int ipfs_namesys_publish_with_eol (char *proto, ciPrivKey name, char *value, tim
|
|||
int i;
|
||||
|
||||
for (i = 0 ; ns[i] ; i++) {
|
||||
if (strcmp(ns[i]->Publisher->protocol, proto)==0) {
|
||||
return ns[i]->Publisher->func_eol(name, value, eol);
|
||||
if (strcmp(ns[i]->publisher->protocol, proto)==0) {
|
||||
return ns[i]->publisher->func_eol(name, value, eol);
|
||||
}
|
||||
}
|
||||
return ErrPublishFailed;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "ipfs/namesys/routing.h"
|
||||
#include "ipfs/namesys/pb.h"
|
||||
|
||||
|
|
|
@ -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 err, i, c;
|
||||
int err = 0, i, c;
|
||||
|
||||
if (!idx || !recs || !k || !vals) {
|
||||
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.
|
||||
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 timespec ts, now;
|
||||
|
||||
|
@ -122,4 +122,5 @@ int ipns_validate_ipns_record (char *k, char *val)
|
|||
} else {
|
||||
return ErrUnrecognizedValidity;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,20 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.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/util/time.h"
|
||||
#include "mh/multihash.h"
|
||||
#include "ipfs/namesys/pb.h"
|
||||
#include "ipfs/namesys/namesys.h"
|
||||
#include "ipfs/cid/cid.h"
|
||||
#include "ipfs/path/path.h"
|
||||
|
||||
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) {
|
||||
cache = ientry->cache;
|
||||
if (cache) {
|
||||
timespec_get (&now);
|
||||
timespec_get (&now, TIME_UTC);
|
||||
for (i = 0 ; i < cache->next ; i++) {
|
||||
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))) &&
|
||||
|
@ -43,7 +51,7 @@ void ipfs_routing_cache_set (char *key, char *value, struct ipns_entry *ientry)
|
|||
if (n) {
|
||||
n->key = key;
|
||||
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.
|
||||
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;
|
||||
struct MultiHash hash;
|
||||
char *h, *string, *val;
|
||||
struct libp2p_crypto_pubkey pubkey;
|
||||
char *h, *string, val[8];
|
||||
char pubkey[60];
|
||||
|
||||
if (!path || !name | !prefix) {
|
||||
return ErrInvalidParam;
|
||||
|
@ -114,7 +122,7 @@ int ipfs_namesys_routing_resolve_once (char **path, char *name, int depth, char
|
|||
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) {
|
||||
// name should be a multihash. if it isn't, error out here.
|
||||
//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);
|
||||
if (err) {
|
||||
// Not a multihash, probably a new record
|
||||
err = ipfs_path_parse(path, string);
|
||||
err = ipfs_path_parse(*path, string);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
@ -187,7 +195,7 @@ int ipfs_namesys_routing_resolve_once (char **path, char *name, int depth, char
|
|||
return err;
|
||||
}
|
||||
|
||||
err = ipfs_path_parse_from_cid (path, cid);
|
||||
err = ipfs_path_parse_from_cid (*path, (char*)cid->hash);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue