sanity check

additional sanity check in peerstore and saving remote peer id when
connecting with secio
This commit is contained in:
jmjatlanta 2017-07-31 15:18:17 -05:00
parent 5406fb29e2
commit 8c1c813643
2 changed files with 4 additions and 4 deletions

View file

@ -151,6 +151,9 @@ int libp2p_peerstore_add_peer(struct Peerstore* peerstore, const struct Libp2pPe
* @returns the PeerEntry struct if found, otherwise NULL
*/
struct PeerEntry* libp2p_peerstore_get_peer_entry(struct Peerstore* peerstore, const unsigned char* peer_id, size_t peer_id_size) {
if (peer_id_size == 0 || peer_id == NULL)
return NULL;
struct Libp2pLinkedList* current = peerstore->head_entry;
while(current != NULL) {
struct Libp2pPeer* peer = ((struct PeerEntry*)current->item)->peer;

View file

@ -782,7 +782,6 @@ int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPriva
struct StretchedKey* k1 = NULL, *k2 = NULL;
struct PrivateKey* priv = NULL;
struct PublicKey pub_key = {0};
char* remote_peer_id = NULL;
//TODO: make sure we're not talking to ourself
@ -879,7 +878,7 @@ int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPriva
if (!libp2p_crypto_public_key_protobuf_decode(propose_in->public_key, propose_in->public_key_size, &public_key))
goto exit;
// generate their peer id
libp2p_crypto_public_key_to_peer_id(public_key, &remote_peer_id);
libp2p_crypto_public_key_to_peer_id(public_key, &local_session->remote_peer_id);
// negotiate encryption parameters NOTE: SelectBest must match, otherwise this won't work
// first determine order
@ -1061,8 +1060,6 @@ int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPriva
free(char_buffer);
if (public_key != NULL)
libp2p_crypto_public_key_free(public_key);
if (remote_peer_id != NULL)
free(remote_peer_id);
if (exchange_out != NULL)
libp2p_secio_exchange_free(exchange_out);
if (exchange_out_protobuf != NULL)