Testing ipns
This commit is contained in:
parent
395c7d94cf
commit
fc8fc582b1
8 changed files with 111 additions and 54 deletions
|
@ -1,5 +1,4 @@
|
|||
#ifndef IPNS_NAMESYS_PB_H
|
||||
#define IPNS_NAMESYS_PB_H
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int32_t IpnsEntry_ValidityType;
|
||||
|
@ -20,9 +19,9 @@
|
|||
};
|
||||
|
||||
// setting an EOL says "this record is valid until..."
|
||||
const IpnsEntry_ValidityType IpnsEntry_EOL = 0;
|
||||
const static IpnsEntry_ValidityType IpnsEntry_EOL = 0;
|
||||
|
||||
char *IpnsEntry_ValidityType_name[] = {
|
||||
static char *IpnsEntry_ValidityType_name[] = {
|
||||
"EOL",
|
||||
NULL
|
||||
};
|
||||
|
@ -35,4 +34,3 @@
|
|||
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
|
||||
|
|
|
@ -1,9 +1,21 @@
|
|||
#ifndef IPFS_PUBLISHER_H
|
||||
#define 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);
|
||||
#endif // IPFS_PUBLISHER_H
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 \
|
||||
|
|
37
test/namesys/test_publisher.h
Normal file
37
test/namesys/test_publisher.h
Normal 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;
|
||||
}
|
|
@ -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:
|
||||
|
|
|
@ -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 /*,
|
||||
|
|
Loading…
Reference in a new issue