Small bugfix to peer copy
This commit is contained in:
parent
14209748d6
commit
ae2037081c
2 changed files with 6 additions and 1 deletions
|
@ -109,6 +109,7 @@ struct Libp2pPeer* libp2p_peer_copy(struct Libp2pPeer* in) {
|
||||||
}
|
}
|
||||||
memcpy(out->id, in->id, in->id_size);
|
memcpy(out->id, in->id, in->id_size);
|
||||||
out->connection_type = in->connection_type;
|
out->connection_type = in->connection_type;
|
||||||
|
// loop through the addresses
|
||||||
struct Libp2pLinkedList* current_in = in->addr_head;
|
struct Libp2pLinkedList* current_in = in->addr_head;
|
||||||
struct Libp2pLinkedList* current_out = NULL;
|
struct Libp2pLinkedList* current_out = NULL;
|
||||||
while (current_in != NULL) {
|
while (current_in != NULL) {
|
||||||
|
@ -119,8 +120,8 @@ struct Libp2pPeer* libp2p_peer_copy(struct Libp2pPeer* in) {
|
||||||
out->addr_head = copy_item;
|
out->addr_head = copy_item;
|
||||||
} else {
|
} else {
|
||||||
current_out->next = copy_item;
|
current_out->next = copy_item;
|
||||||
current_out = copy_item;
|
|
||||||
}
|
}
|
||||||
|
current_out = copy_item;
|
||||||
current_in = current_in->next;
|
current_in = current_in->next;
|
||||||
}
|
}
|
||||||
out->connection = in->connection;
|
out->connection = in->connection;
|
||||||
|
|
|
@ -96,6 +96,10 @@ int libp2p_peerstore_add_peer_entry(struct Peerstore* peerstore, struct PeerEntr
|
||||||
* @returns true(1) on success, otherwise false
|
* @returns true(1) on success, otherwise false
|
||||||
*/
|
*/
|
||||||
int libp2p_peerstore_add_peer(struct Peerstore* peerstore, struct Libp2pPeer* peer) {
|
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];
|
char peer_id[peer->id_size + 1];
|
||||||
memcpy(peer_id, peer->id, peer->id_size);
|
memcpy(peer_id, peer->id, peer->id_size);
|
||||||
peer_id[peer->id_size] = 0;
|
peer_id[peer->id_size] = 0;
|
||||||
|
|
Loading…
Reference in a new issue