From 73fcecfdcf1cde170fba90499b953b1dd0fc04ee Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 17 Jul 2017 13:04:43 -0500 Subject: [PATCH] A bit of code cleanup and commenting --- include/libp2p/conn/session.h | 11 ++++++++--- include/libp2p/net/multistream.h | 3 +++ net/multistream.c | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/libp2p/conn/session.h b/include/libp2p/conn/session.h index 40ebc4f..8466dc8 100644 --- a/include/libp2p/conn/session.h +++ b/include/libp2p/conn/session.h @@ -16,6 +16,11 @@ struct SessionContext { int port; enum IPTrafficType traffic_type; // once the connection is established + /** + * Note: default_stream should be used in most cases. Often, insecure_stream and secure_stream will be + * the same. This should be re-thought, probably better named, and simplified. Perhaps 1 stream and + * indicators regarding which protocols have been negotiated (i.e. multistream over secio)? + */ struct Stream* insecure_stream; struct Stream* secure_stream; struct Stream* default_stream; @@ -27,9 +32,9 @@ struct SessionContext { char* chosen_hash; unsigned char* shared_key; // a shared key based off of the ephemeral private key size_t shared_key_size; - unsigned char* mac; - size_t mac_size; - // the following items carry state for the sha256 stream cipher. + //unsigned char* mac; + //size_t mac_size; + // the following items carry state for the sha256 stream cipher, and should probably not be touched. size_t aes_encode_nonce_offset; unsigned char aes_encode_stream_block[16]; size_t aes_decode_nonce_offset; diff --git a/include/libp2p/net/multistream.h b/include/libp2p/net/multistream.h index eedbcad..5de01d4 100644 --- a/include/libp2p/net/multistream.h +++ b/include/libp2p/net/multistream.h @@ -43,6 +43,9 @@ struct Stream* libp2p_net_multistream_connect(const char* hostname, int port); /** * Negotiate the multistream protocol by sending and receiving the protocol id. This is a server side function. * Servers should send the protocol ID, and then expect it back. + * NOTE: the SessionContext should already contain the connected stream. If not, use + * libp2p_net_multistream_connect instead of this method. + * * @param session the struct Session, which contains all the context info * @returns true(1) on success, or false(0) */ diff --git a/net/multistream.c b/net/multistream.c index a1eda1b..491ede7 100644 --- a/net/multistream.c +++ b/net/multistream.c @@ -225,6 +225,15 @@ struct Stream* libp2p_net_multistream_connect(const char* hostname, int port) { return stream; } +/** + * Negotiate the multistream protocol by sending and receiving the protocol id. This is a server side function. + * Servers should send the protocol ID, and then expect it back. + * NOTE: the SessionContext should already contain the connected stream. If not, use + * libp2p_net_multistream_connect instead of this method. + * + * @param session the struct Session, which contains all the context info + * @returns true(1) on success, or false(0) + */ int libp2p_net_multistream_negotiate(struct SessionContext* session) { const char* protocolID = "/multistream/1.0.0\n"; unsigned char* results = NULL;