c-ipfs/test/namesys/test_publisher.h

40 lines
1 KiB
C
Raw Normal View History

2017-09-14 21:49:19 +00:00
#include <stdlib.h>
#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";
pthread_t api_pth = 0;
2017-09-14 21:49:19 +00:00
// get a local node
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:
ipfs_node_free(&api_pth, local_node);
2017-09-14 21:49:19 +00:00
ipfs_cid_free(cid);
return retVal;
}