Testing ipns

This commit is contained in:
John Jones 2017-09-14 16:49:19 -05:00
parent 395c7d94cf
commit fc8fc582b1
8 changed files with 111 additions and 54 deletions

View file

@ -1,38 +1,36 @@
#ifndef IPNS_NAMESYS_PB_H
#define IPNS_NAMESYS_PB_H
#include <stdint.h>
#pragma once
#include <stdint.h>
typedef int32_t IpnsEntry_ValidityType;
typedef int32_t IpnsEntry_ValidityType;
struct ipns_entry {
char *value;
char *signature;
int32_t *validityType;
char *validity;
uint64_t *sequence;
uint64_t *ttl;
struct routingResolver *cache; // cache and eol should be the last items.
struct timespec *eol;
};
struct namesys_pb {
// TODO
struct ipns_entry *IpnsEntry;
};
struct ipns_entry {
char *value;
char *signature;
int32_t *validityType;
char *validity;
uint64_t *sequence;
uint64_t *ttl;
struct routingResolver *cache; // cache and eol should be the last items.
struct timespec *eol;
};
struct namesys_pb {
// TODO
struct ipns_entry *IpnsEntry;
};
// setting an EOL says "this record is valid until..."
const IpnsEntry_ValidityType IpnsEntry_EOL = 0;
// setting an EOL says "this record is valid until..."
const static IpnsEntry_ValidityType IpnsEntry_EOL = 0;
char *IpnsEntry_ValidityType_name[] = {
"EOL",
NULL
};
static char *IpnsEntry_ValidityType_name[] = {
"EOL",
NULL
};
int IpnsEntry_ValidityType_value (char *s);
struct ipns_entry* ipfs_namesys_pb_new_ipns_entry ();
char* ipfs_namesys_pb_get_validity (struct ipns_entry*);
char* ipns_entry_data_for_sig(struct ipns_entry*);
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
int IpnsEntry_ValidityType_value (char *s);
struct ipns_entry* ipfs_namesys_pb_new_ipns_entry ();
char* ipfs_namesys_pb_get_validity (struct ipns_entry*);
char* ipns_entry_data_for_sig(struct ipns_entry*);
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);

View file

@ -1,9 +1,21 @@
#ifndef IPFS_PUBLISHER_H
#define IPFS_PUBLISHER_H
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_select_record (int *idx, struct ipns_entry **recs, char **vals);
// ipns_validate_ipns_record implements ValidatorFunc and verifies that the
// given 'val' is an IpnsEntry and that that entry is valid.
int ipns_validate_ipns_record (char *k, char *val);
#endif // IPFS_PUBLISHER_H
#pragma once
#include "ipfs/cid/cid.h"
#include "ipfs/core/ipfs_node.h"
#include "ipfs/namesys/pb.h"
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_select_record (int *idx, struct ipns_entry **recs, char **vals);
// ipns_validate_ipns_record implements ValidatorFunc and verifies that the
// given 'val' is an IpnsEntry and that that entry is valid.
int ipns_validate_ipns_record (char *k, char *val);
/**
* Store the hash locally, and notify the network
*
* @param local_node the context
* @param cid the hash
* @returns true(1) on success, false(0) otherwise
*/
int ipfs_namesys_publisher_publish(struct IpfsNode* local_node, struct Cid* cid);

View file

@ -7,7 +7,7 @@ endif
LFLAGS =
DEPS =
OBJS = base.o dns.o isdomain.o namesys.o proquint.o
OBJS = base.o dns.o isdomain.o namesys.o proquint.o publisher.o pb.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)

View file

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include "libp2p/routing/dht_protocol.h"
#include "ipfs/util/errs.h"
#include "ipfs/util/time.h"
#include "ipfs/namesys/pb.h"
@ -68,6 +69,7 @@ int ipns_selector_func (int *idx, struct ipns_entry ***recs, char *k, char **val
*/
int ipns_select_record (int *idx, struct ipns_entry **recs, char **vals)
{
/*
int err, i, best_i = -1, best_seq = 0;
struct timespec rt, bestt;
@ -105,6 +107,7 @@ int ipns_select_record (int *idx, struct ipns_entry **recs, char **vals)
return ErrNoRecord;
}
*idx = best_i;
*/
return 0;
}
@ -118,6 +121,7 @@ int ipns_select_record (int *idx, struct ipns_entry **recs, char **vals)
*/
int ipns_validate_ipns_record (char *k, char *val)
{
/*
int err = 0;
struct ipns_entry *entry = ipfs_namesys_pb_new_ipns_entry();
struct timespec ts, now;
@ -142,6 +146,7 @@ int ipns_validate_ipns_record (char *k, char *val)
} else {
return ErrUnrecognizedValidity;
}
*/
return 0;
}
@ -154,7 +159,7 @@ int ipns_validate_ipns_record (char *k, char *val)
* @param to_size where to put the value of from_size in the new structure
* @returns true(1) on success, false(0) otherwise
*/
int ipfs_namesys_copy_bytes(uint8_t* from, int from_size, uint8_t** to, int* to_size) {
int ipfs_namesys_copy_bytes(uint8_t* from, size_t from_size, uint8_t** to, size_t* to_size) {
*to = (uint8_t*) malloc(from_size);
if (*to == NULL) {
return 0;
@ -171,7 +176,7 @@ int ipfs_namesys_copy_bytes(uint8_t* from, int from_size, uint8_t** to, int* to_
* @param cid the hash
* @returns true(1) on success, false(0) otherwise
*/
int ipfs_namesys_publish(struct IpfsNode* local_node, struct Cid* cid) {
int ipfs_namesys_publisher_publish(struct IpfsNode* local_node, struct Cid* cid) {
// store locally
struct DatastoreRecord* record = libp2p_datastore_record_new();
if (record == NULL)
@ -183,7 +188,7 @@ int ipfs_namesys_publish(struct IpfsNode* local_node, struct Cid* cid) {
return 0;
}
// value
if (!ipfs_namesys_copy_bytes(local_node->identity->peer->id, local_node->identity->peer->id_size, &record->value, &record->value_size)) {
if (!ipfs_namesys_copy_bytes((unsigned char*)local_node->identity->peer->id, local_node->identity->peer->id_size, &record->value, &record->value_size)) {
libp2p_datastore_record_free(record);
return 0;
}
@ -201,8 +206,8 @@ int ipfs_namesys_publish(struct IpfsNode* local_node, struct Cid* cid) {
libp2p_message_free(msg);
return 0;
}
msg->provider_peer_head = libp2p_utils_vector_new(1);
libp2p_utils_vector_add(msg->provider_peer_head, local_node->identity->peer);
msg->provider_peer_head = libp2p_utils_linked_list_new();
msg->provider_peer_head->item = local_node->identity->peer;
// msg->Libp2pRecord
msg->record = libp2p_record_new();
if (msg->record == NULL) {
@ -210,22 +215,22 @@ int ipfs_namesys_publish(struct IpfsNode* local_node, struct Cid* cid) {
return 0;
}
// KademliaMessage->Libp2pRecord->author
if (!ipfs_namesys_copy_bytes(local_node->identity->peer->id, local_node->identity->peer->id_size, &msg->record->author, &msg->record->author_size)) {
if (!ipfs_namesys_copy_bytes((unsigned char*)local_node->identity->peer->id, local_node->identity->peer->id_size, (unsigned char**)&msg->record->author, &msg->record->author_size)) {
libp2p_message_free(msg);
return 0;
}
// KademliaMessage->Libp2pRecord->key
if (!ipfs_namesys_copy_bytes(cid->hash, cid->hash_length, &msg->record->key, &msg->record->key_size)) {
if (!ipfs_namesys_copy_bytes(cid->hash, cid->hash_length, (unsigned char**)&msg->record->key, &msg->record->key_size)) {
libp2p_message_free(msg);
return 0;
}
// KademliaMessage->Libp2pRecord->value
if (!ipfs_namesys_copy_bytes(local_node->identity->peer->id, local_node->identity->peer->id_size, &msg->record->value, &msg->record->value_size)) {
if (!ipfs_namesys_copy_bytes((unsigned char*)local_node->identity->peer->id, local_node->identity->peer->id_size, &msg->record->value, &msg->record->value_size)) {
libp2p_message_free(msg);
return 0;
}
int retVal = libp2p_routing_send_message(local_node->identity->peer, local_node->providerstore, msg);
int retVal = libp2p_routing_dht_send_message(local_node->identity->peer, local_node->providerstore, msg);
libp2p_message_free(msg);
return retVal;
}

View file

@ -15,6 +15,8 @@ OBJS = testit.o test_helper.o \
../journal/*.o \
../merkledag/merkledag.o ../merkledag/node.o \
../multibase/multibase.o \
../namesys/pb.o \
../namesys/publisher.o \
../repo/init.o \
../repo/fsrepo/*.o \
../repo/config/*.o \

View file

@ -0,0 +1,37 @@
#include <stdlib.h>
#include "ipfs/cid/cid.h"
#include "ipfs/core/ipfs_node.h"
#include "ipfs/namesys/publisher.h"
int test_namesys_publisher_publish() {
int retVal = 0;
struct IpfsNode* local_node = NULL;
struct Cid* cid = NULL;
char* hash_text = "QmZtAEqmnXMZkwVPKdyMGxUoo35cQMzNhmq6CN3DvgRwAD";
char* repo_path = "/tmp/ipfs_1";
// get a local node
if (!ipfs_node_offline_new(repo_path, &local_node)) {
libp2p_logger_error("test_publisher", "publish: Unable to open ipfs repository.\n");
goto exit;
}
// get a cid
if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hash_text, strlen(hash_text), &cid)) {
libp2p_logger_error("test_publisher", "publish: Unable to convert hash from base58.\n");
goto exit;
}
// attempt to publish
if (!ipfs_namesys_publisher_publish(local_node, cid)) {
libp2p_logger_error("test_publisher", "publish: Unable to publish %s.\n", hash_text);
goto exit;
}
retVal = 1;
exit:
ipfs_node_free(local_node);
ipfs_cid_free(cid);
return retVal;
}

View file

@ -62,7 +62,7 @@ int test_routing_put_value() {
// now "publish" to publisher, and verify that "consumer" receives the message
char* args2[] = {"ipfs" "--config", ipfs_path_publisher, "name", "publish", "QmZtAEqmnXMZkwVPKdyMGxUoo35cQMzNhmq6CN3DvgRwAD" };
ipfs_name_publish(6, args2);
//ipfs_name_publish(6, args2);
// wait for everything to settle in
sleep(3);
@ -70,7 +70,7 @@ int test_routing_put_value() {
// see if we have what we should...
char* args3[] = {"ipfs", "--config", ipfs_path_consumer, "resolve", peer_id_publisher};
char* results = NULL;
ipfs_resolve(5, args3, &results);
//ipfs_resolve(5, args3, &results);
retVal = 1;
exit:

View file

@ -10,6 +10,7 @@
#include "flatfs/test_flatfs.h"
#include "journal/test_journal.h"
#include "merkledag/test_merkledag.h"
#include "namesys/test_publisher.h"
#include "node/test_node.h"
#include "node/test_importer.h"
#include "node/test_resolver.h"
@ -80,6 +81,7 @@ const char* names[] = {
"test_merkledag_get_data",
"test_merkledag_add_node",
"test_merkledag_add_node_with_links",
"test_namesys_publisher_publish",
"test_resolver_get",
"test_routing_find_peer",
"test_routing_provide" /*,
@ -142,6 +144,7 @@ int (*funcs[])(void) = {
test_merkledag_get_data,
test_merkledag_add_node,
test_merkledag_add_node_with_links,
test_namesys_publisher_publish,
test_resolver_get,
test_routing_find_peer,
test_routing_provide /*,