Small bugfix to peer copy

This commit is contained in:
John Jones 2017-04-05 20:34:13 -05:00
parent 14209748d6
commit ae2037081c
2 changed files with 6 additions and 1 deletions

View file

@ -109,6 +109,7 @@ struct Libp2pPeer* libp2p_peer_copy(struct Libp2pPeer* in) {
}
memcpy(out->id, in->id, in->id_size);
out->connection_type = in->connection_type;
// loop through the addresses
struct Libp2pLinkedList* current_in = in->addr_head;
struct Libp2pLinkedList* current_out = NULL;
while (current_in != NULL) {
@ -119,8 +120,8 @@ struct Libp2pPeer* libp2p_peer_copy(struct Libp2pPeer* in) {
out->addr_head = copy_item;
} else {
current_out->next = copy_item;
current_out = copy_item;
}
current_out = copy_item;
current_in = current_in->next;
}
out->connection = in->connection;

View file

@ -96,6 +96,10 @@ int libp2p_peerstore_add_peer_entry(struct Peerstore* peerstore, struct PeerEntr
* @returns true(1) on success, otherwise false
*/
int libp2p_peerstore_add_peer(struct Peerstore* peerstore, struct Libp2pPeer* peer) {
// first check to see if it exists. If it does, return TRUE
if (libp2p_peerstore_get_peer_entry(peerstore, peer->id, peer->id_size) != NULL)
return 1;
char peer_id[peer->id_size + 1];
memcpy(peer_id, peer->id, peer->id_size);
peer_id[peer->id_size] = 0;