Using muiltistream protocol to begin secio negotiation

This commit is contained in:
John Jones 2017-08-09 09:46:53 -05:00
parent 4f52a20314
commit 1e7806855d

View file

@ -524,6 +524,7 @@ int libp2p_secio_unencrypted_write(struct SessionContext* session, unsigned char
written += written_this_time; written += written_this_time;
} while (left > 0); } while (left > 0);
num_bytes = written; num_bytes = written;
*/
} // there was something to send } // there was something to send
return num_bytes; return num_bytes;
@ -882,15 +883,14 @@ int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPriva
memcpy(&total[protocol_len], propose_out_bytes, propose_out_size); memcpy(&total[protocol_len], propose_out_bytes, propose_out_size);
// write the Proposal to the stream // write the Proposal to the stream
bytes_written = libp2p_secio_unencrypted_write(local_session, total, protocol_len + propose_out_size); if (!local_session->default_stream->write(local_session, total, protocol_len + propose_out_size))
if (bytes_written < propose_out_size + protocol_len)
goto exit; goto exit;
if (incoming_size > 0) { if (incoming_size > 0) {
propose_in_bytes = (uint8_t*)incoming; propose_in_bytes = (uint8_t*)incoming;
propose_in_size = incoming_size; propose_in_size = incoming_size;
} else { } else {
bytes_written = libp2p_secio_unencrypted_read(local_session, &propose_in_bytes, &propose_in_size, 10); bytes_written = local_session->default_stream->read(local_session, &propose_in_bytes, &propose_in_size, 10);
if (bytes_written <= 0) if (bytes_written <= 0)
goto exit; goto exit;
} }