Don't attempt to connect to yourself using secio

This commit is contained in:
John Jones 2017-09-28 13:48:35 -05:00
parent bf1f900716
commit c62253dce0
2 changed files with 13 additions and 7 deletions

View file

@ -574,6 +574,7 @@ int libp2p_routing_dht_send_message_nearest_x(const struct RsaPrivateKey* privat
if (entry == NULL) if (entry == NULL)
break; break;
struct Libp2pPeer* remote_peer = entry->peer; struct Libp2pPeer* remote_peer = entry->peer;
if (!remote_peer->is_local) {
// connect (if not connected) // connect (if not connected)
if (libp2p_peer_connect(private_key, remote_peer, peerstore, datastore, 5)) { if (libp2p_peer_connect(private_key, remote_peer, peerstore, datastore, 5)) {
// send message // send message
@ -582,6 +583,7 @@ int libp2p_routing_dht_send_message_nearest_x(const struct RsaPrivateKey* privat
} }
if (numSent >= numToSend) if (numSent >= numToSend)
break; break;
}
// grab next entry // grab next entry
llpeer_entry = llpeer_entry->next; llpeer_entry = llpeer_entry->next;
} }

View file

@ -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) { int libp2p_secio_unencrypted_read(struct SessionContext* session, unsigned char** results, size_t* results_size, int timeout_secs) {
uint32_t buffer_size; 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 // first read the 4 byte integer
char* size = (char*)&buffer_size; char* size = (char*)&buffer_size;
int left = 4; int left = 4;