From 6adc48c89d60364a78f6d46e1c70c2d23b544fd1 Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Thu, 12 Oct 2017 07:36:37 -0500 Subject: [PATCH 1/2] fixes to secio test --- test/test_secio.h | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/test/test_secio.h b/test/test_secio.h index 2835c9f..19b65a5 100644 --- a/test/test_secio.h +++ b/test/test_secio.h @@ -49,7 +49,7 @@ int test_secio_handshake() { unsigned char final_id[final_id_size]; struct PrivateKey* private_key = NULL; - struct SessionContext secure_session = {0}; + struct SessionContext* secure_session = NULL; struct Peerstore *peerstore = NULL; struct Libp2pPeer* local_peer = NULL; @@ -76,14 +76,19 @@ int test_secio_handshake() { local_peer = libp2p_peer_new(); peerstore = libp2p_peerstore_new(local_peer); + secure_session = libp2p_session_context_new(); //secure_session.host = "www.jmjatlanta.com"; - secure_session.host = "10.211.55.2"; - secure_session.port = 4001; - secure_session.traffic_type = TCP; + secure_session->host = "107.170.104.234"; + secure_session->port = 4001; + secure_session->traffic_type = TCP; // connect to host - secure_session.insecure_stream = libp2p_net_multistream_connect(secure_session.host, secure_session.port); - secure_session.default_stream = secure_session.insecure_stream; - if (*((int*)secure_session.insecure_stream->socket_descriptor) == -1) { + secure_session->insecure_stream = libp2p_net_multistream_connect(secure_session->host, secure_session->port); + if (secure_session->insecure_stream == NULL) { + libp2p_logger_error("test_secio", "Unable to open multistream to server %s port %d.\n", secure_session->host, secure_session->port); + goto exit; + } + secure_session->default_stream = secure_session->insecure_stream; + if (*((int*)secure_session->insecure_stream->socket_descriptor) == -1) { fprintf(stderr, "test_secio_handshake: Unable to get socket descriptor\n"); goto exit; } @@ -91,23 +96,23 @@ int test_secio_handshake() { // attempt to write the protocol, and see what comes back char* protocol = "/secio/1.0.0\n"; int protocol_size = strlen(protocol); - secure_session.insecure_stream->write(&secure_session, (unsigned char*)protocol, protocol_size); + secure_session->insecure_stream->write(secure_session, (unsigned char*)protocol, protocol_size); unsigned char* buffer = NULL; size_t bytes_read = 0; int timeout = 30; - secure_session.insecure_stream->read(&secure_session, &buffer, &bytes_read, timeout); + secure_session->insecure_stream->read(secure_session, &buffer, &bytes_read, timeout); - if (!libp2p_secio_handshake(&secure_session, rsa_private_key, peerstore)) { + if (!libp2p_secio_handshake(secure_session, rsa_private_key, peerstore)) { fprintf(stderr, "test_secio_handshake: Unable to do handshake\n"); - if (secure_session.shared_key != NULL) { + if (secure_session->shared_key != NULL) { fprintf(stdout, "Shared key: "); - for(int i = 0; i < secure_session.shared_key_size; i++) - fprintf(stdout, "%d ", secure_session.shared_key[i]); + for(int i = 0; i < secure_session->shared_key_size; i++) + fprintf(stdout, "%d ", secure_session->shared_key[i]); fprintf(stdout, "\nLocal stretched key: "); - print_stretched_key(secure_session.local_stretched_key); + print_stretched_key(secure_session->local_stretched_key); fprintf(stdout, "\nRemote stretched key: "); - print_stretched_key(secure_session.remote_stretched_key); + print_stretched_key(secure_session->remote_stretched_key); fprintf(stdout, "\n"); } goto exit; @@ -125,13 +130,13 @@ int test_secio_handshake() { */ // now attempt to do something with it... try to negotiate a multistream - if (libp2p_net_multistream_negotiate(&secure_session) == 0) { + if (libp2p_net_multistream_negotiate(secure_session) == 0) { fprintf(stdout, "Unable to negotiate multistream\n"); goto exit; } // now attempt an "ls" - if (libp2p_net_multistream_write(&secure_session, (unsigned char*)"ls\n", 3) == 0) { + if (libp2p_net_multistream_write(secure_session, (unsigned char*)"ls\n", 3) == 0) { fprintf(stdout, "Unable to send ls to multistream\n"); goto exit; } @@ -139,7 +144,7 @@ int test_secio_handshake() { // retrieve the response unsigned char* results; size_t results_size; - if (libp2p_net_multistream_read(&secure_session, &results, &results_size, 30) == 0) { + if (libp2p_net_multistream_read(secure_session, &results, &results_size, 30) == 0) { fprintf(stdout, "Unable to read ls results from multistream\n"); free(results); goto exit; @@ -152,6 +157,9 @@ int test_secio_handshake() { retVal = 1; exit: + if (peerstore != NULL) + libp2p_peerstore_free(peerstore); + /* if (secure_session.insecure_stream != NULL) libp2p_net_multistream_stream_free(secure_session.insecure_stream); if (secure_session.local_stretched_key != NULL) @@ -170,14 +178,13 @@ int test_secio_handshake() { free(secure_session.chosen_hash); if (secure_session.shared_key != NULL) free(secure_session.shared_key); + */ if (private_key != NULL) libp2p_crypto_private_key_free(private_key); if (decode_base64 != NULL) free(decode_base64); if (rsa_private_key != NULL) libp2p_crypto_rsa_rsa_private_key_free(rsa_private_key); - if (peerstore != NULL) - libp2p_peerstore_free(peerstore); return retVal; } From 0666b481d26f1f576e3a9757a018bdfc285e16a8 Mon Sep 17 00:00:00 2001 From: Agorise Date: Mon, 16 Oct 2017 13:53:01 +0300 Subject: [PATCH 2/2] Update LICENSE --- LICENSE | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 42c3bed..ee2accb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2017 BitShares Munich IVS +Copyright (c) 2017 Agorise, IBC. +Contains works from BitShares Munich IVS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal