Reverting back to specific network reads and writes

This commit is contained in:
jmjatlanta 2017-08-09 10:23:24 -05:00
parent 563a89150d
commit 8ff5020088
4 changed files with 13 additions and 17 deletions

View file

@ -21,4 +21,4 @@ struct Libp2pProtocolHandler* libp2p_secio_build_protocol_handler(struct RsaPriv
* @param remote_requested the other side is who asked for the upgrade * @param remote_requested the other side is who asked for the upgrade
* @returns true(1) on success, false(0) otherwise * @returns true(1) on success, false(0) otherwise
*/ */
int libp2p_secio_handshake(struct SessionContext* session, struct RsaPrivateKey* private_key, struct Peerstore* peerstore, const uint8_t* buffer, size_t buffer_size); int libp2p_secio_handshake(struct SessionContext* session, struct RsaPrivateKey* private_key, struct Peerstore* peerstore);

View file

@ -117,7 +117,7 @@ int libp2p_peer_connect(struct RsaPrivateKey* privateKey, struct Libp2pPeer* pee
peer->sessionContext->default_stream = peer->sessionContext->insecure_stream; peer->sessionContext->default_stream = peer->sessionContext->insecure_stream;
peer->connection_type = CONNECTION_TYPE_CONNECTED; peer->connection_type = CONNECTION_TYPE_CONNECTED;
} }
libp2p_secio_handshake(peer->sessionContext, privateKey, peerstore, NULL, 0); libp2p_secio_handshake(peer->sessionContext, privateKey, peerstore);
free(ip); free(ip);
} // is IP } // is IP
now = time(NULL); now = time(NULL);

View file

@ -50,7 +50,7 @@ int libp2p_secio_can_handle(const uint8_t* incoming, size_t incoming_size) {
int libp2p_secio_handle_message(const uint8_t* incoming, size_t incoming_size, struct SessionContext* session_context, void* protocol_context) { int libp2p_secio_handle_message(const uint8_t* incoming, size_t incoming_size, struct SessionContext* session_context, void* protocol_context) {
struct SecioContext* ctx = (struct SecioContext*)protocol_context; struct SecioContext* ctx = (struct SecioContext*)protocol_context;
return libp2p_secio_handshake(session_context, ctx->private_key, ctx->peer_store, incoming, incoming_size); return libp2p_secio_handshake(session_context, ctx->private_key, ctx->peer_store);
} }
int libp2p_secio_shutdown(void* context) { int libp2p_secio_shutdown(void* context) {
@ -802,7 +802,7 @@ struct Propose* libp2p_secio_get_propose_in(const uint8_t* buffer, size_t buffer
* @param remote_requested it is the other side that requested the upgrade to secio * @param remote_requested it is the other side that requested the upgrade to secio
* @returns true(1) on success, false(0) otherwise * @returns true(1) on success, false(0) otherwise
*/ */
int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPrivateKey* private_key, struct Peerstore* peerstore, const uint8_t* incoming, size_t incoming_size) { int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPrivateKey* private_key, struct Peerstore* peerstore) {
int retVal = 0; int retVal = 0;
size_t results_size = 0, bytes_written = 0; size_t results_size = 0, bytes_written = 0;
unsigned char* propose_in_bytes = NULL; // the remote protobuf unsigned char* propose_in_bytes = NULL; // the remote protobuf
@ -886,20 +886,15 @@ int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPriva
libp2p_logger_error("secio", "Sent propose_out, but did not write the correct number of bytes. Should be %d but was %d.\n", propose_out_size, bytes_written); libp2p_logger_error("secio", "Sent propose_out, but did not write the correct number of bytes. Should be %d but was %d.\n", propose_out_size, bytes_written);
} }
if (incoming_size > 0) { // try to get the Propse struct from the remote peer
propose_in_bytes = (uint8_t*)incoming; bytes_written = libp2p_secio_unencrypted_read(local_session, &propose_in_bytes, &propose_in_size, 10);
propose_in_size = incoming_size; if (bytes_written <= 0) {
} else { libp2p_logger_error("secio", "Unable to get the remote's Propose struct.\n");
bytes_written = libp2p_secio_unencrypted_read(local_session, &propose_in_bytes, &propose_in_size, 10); goto exit;
if (bytes_written <= 0)
goto exit;
} }
propose_in = libp2p_secio_get_propose_in(propose_in_bytes, propose_in_size); propose_in = libp2p_secio_get_propose_in(propose_in_bytes, propose_in_size);
if (propose_in == NULL) { if (propose_in == NULL) {
libp2p_logger_error("secio", "Unable to get the remote's Propose struct\n"); libp2p_logger_error("secio", "Unable to un-protobuf the remote's Propose struct\n");
if (incoming_size == 0) {
free(propose_in_bytes);
}
goto exit; goto exit;
} }
@ -1125,7 +1120,8 @@ int libp2p_secio_handshake(struct SessionContext* local_session, struct RsaPriva
libp2p_logger_log("secio", LOGLEVEL_DEBUG, "Handshake complete\n"); libp2p_logger_log("secio", LOGLEVEL_DEBUG, "Handshake complete\n");
exit: exit:
if (propose_in_bytes != NULL)
free(propose_in_bytes);
if (propose_out_bytes != NULL) if (propose_out_bytes != NULL)
free(propose_out_bytes); free(propose_out_bytes);
if (results != NULL) if (results != NULL)

View file

@ -80,7 +80,7 @@ int test_secio_handshake() {
goto exit; goto exit;
} }
if (!libp2p_secio_handshake(&secure_session, rsa_private_key, NULL, NULL, 0)) { if (!libp2p_secio_handshake(&secure_session, rsa_private_key, NULL)) {
fprintf(stderr, "test_secio_handshake: Unable to do handshake\n"); fprintf(stderr, "test_secio_handshake: Unable to do handshake\n");
fprintf(stdout, "Shared key: "); fprintf(stdout, "Shared key: ");
for(int i = 0; i < secure_session.shared_key_size; i++) for(int i = 0; i < secure_session.shared_key_size; i++)