2017-09-14 21:49:19 +00:00
|
|
|
#include <stdlib.h>
|
2017-09-20 17:39:26 +00:00
|
|
|
#include <pthread.h>
|
2017-09-14 21:49:19 +00:00
|
|
|
|
|
|
|
#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";
|
2017-09-20 16:10:54 +00:00
|
|
|
char* repo_path = "/tmp/ipfs_1/.ipfs";
|
2017-09-20 17:39:26 +00:00
|
|
|
pthread_t api_pth = 0;
|
2017-09-14 21:49:19 +00:00
|
|
|
|
|
|
|
// get a local node
|
2017-09-21 12:51:18 +00:00
|
|
|
if (!ipfs_node_offline_new(repo_path, &local_node)) {
|
2017-09-14 21:49:19 +00:00
|
|
|
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:
|
2017-09-20 17:39:26 +00:00
|
|
|
ipfs_node_free(&api_pth, local_node);
|
2017-09-14 21:49:19 +00:00
|
|
|
ipfs_cid_free(cid);
|
|
|
|
return retVal;
|
|
|
|
}
|