diff --git a/routing/dht_protocol.c b/routing/dht_protocol.c index c512af2..d9811f7 100644 --- a/routing/dht_protocol.c +++ b/routing/dht_protocol.c @@ -574,14 +574,16 @@ int libp2p_routing_dht_send_message_nearest_x(const struct RsaPrivateKey* privat if (entry == NULL) break; struct Libp2pPeer* remote_peer = entry->peer; - // connect (if not connected) - if (libp2p_peer_connect(private_key, remote_peer, peerstore, datastore, 5)) { - // send message - if (libp2p_routing_dht_send_message(remote_peer->sessionContext, msg)) - numSent++; + if (!remote_peer->is_local) { + // connect (if not connected) + if (libp2p_peer_connect(private_key, remote_peer, peerstore, datastore, 5)) { + // send message + if (libp2p_routing_dht_send_message(remote_peer->sessionContext, msg)) + numSent++; + } + if (numSent >= numToSend) + break; } - if (numSent >= numToSend) - break; // grab next entry llpeer_entry = llpeer_entry->next; } diff --git a/secio/secio.c b/secio/secio.c index 7fcaf0a..6ae5066 100644 --- a/secio/secio.c +++ b/secio/secio.c @@ -572,6 +572,10 @@ int libp2p_secio_unencrypted_write(struct SessionContext* session, unsigned char int libp2p_secio_unencrypted_read(struct SessionContext* session, unsigned char** results, size_t* results_size, int timeout_secs) { uint32_t buffer_size; + if (session == NULL || session->insecure_stream == NULL || session->insecure_stream->socket_descriptor == NULL) { + libp2p_logger_error("secio", "Attempted unencrypted read on invalid session.\n"); + return 0; + } // first read the 4 byte integer char* size = (char*)&buffer_size; int left = 4;