2017-04-20 22:56:03 +00:00
|
|
|
#include <stdlib.h>
|
2017-09-20 17:39:26 +00:00
|
|
|
#include <pthread.h>
|
2017-04-20 22:56:03 +00:00
|
|
|
|
|
|
|
#include "../test_helper.h"
|
|
|
|
#include "ipfs/core/ipfs_node.h"
|
|
|
|
|
|
|
|
int test_node_peerstore() {
|
|
|
|
int retVal = 0;
|
|
|
|
const char *repo_path = "/tmp/test1";
|
|
|
|
char* peer_id = NULL;
|
|
|
|
struct IpfsNode *local_node = NULL;
|
|
|
|
struct Libp2pPeer* peer = NULL;
|
|
|
|
|
|
|
|
if (!drop_and_build_repository(repo_path, 4001, NULL, &peer_id))
|
|
|
|
goto exit;
|
|
|
|
|
2017-09-25 13:55:42 +00:00
|
|
|
if (!ipfs_node_online_new(repo_path, &local_node))
|
2017-04-20 22:56:03 +00:00
|
|
|
goto exit;
|
|
|
|
|
|
|
|
// add a peer to the peerstore
|
|
|
|
peer = libp2p_peer_new();
|
|
|
|
if (peer == NULL)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
peer->id_size = strlen(peer_id);
|
|
|
|
peer->id = malloc(peer->id_size);
|
|
|
|
memcpy(peer->id, peer_id, peer->id_size);
|
|
|
|
|
|
|
|
if (!libp2p_peerstore_add_peer(local_node->peerstore, peer))
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
// add a second peer by changing the id a bit
|
|
|
|
char tmp = peer->id[3];
|
|
|
|
char tmp2 = peer->id[4];
|
|
|
|
char tmp3 = peer->id[5];
|
|
|
|
peer->id[3] = tmp2;
|
|
|
|
peer->id[4] = tmp3;
|
|
|
|
peer->id[5] = tmp;
|
|
|
|
|
|
|
|
if (!libp2p_peerstore_add_peer(local_node->peerstore, peer))
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
|
|
|
|
retVal = 1;
|
|
|
|
exit:
|
|
|
|
if (peer_id != NULL)
|
|
|
|
free(peer_id);
|
|
|
|
if (peer != NULL)
|
|
|
|
libp2p_peer_free(peer);
|
|
|
|
if (local_node != NULL)
|
2017-09-25 13:55:42 +00:00
|
|
|
ipfs_node_free(local_node);
|
2017-04-20 22:56:03 +00:00
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|