From ae2037081cca4df9649529b87075663924789add Mon Sep 17 00:00:00 2001 From: John Jones Date: Wed, 5 Apr 2017 20:34:13 -0500 Subject: [PATCH] Small bugfix to peer copy --- peer/peer.c | 3 ++- peer/peerstore.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/peer/peer.c b/peer/peer.c index a2e28d1..4f13f92 100644 --- a/peer/peer.c +++ b/peer/peer.c @@ -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; diff --git a/peer/peerstore.c b/peer/peerstore.c index d136f85..e7e772c 100644 --- a/peer/peerstore.c +++ b/peer/peerstore.c @@ -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;