Don't attempt to connect to yourself using secio

yamux
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,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;
}

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) {
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;