A bit of code cleanup and commenting

yamux
John Jones 2017-07-17 13:04:43 -05:00
parent a10c7ef5e9
commit 73fcecfdcf
3 changed files with 20 additions and 3 deletions

View File

@ -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;

View File

@ -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)
*/

View File

@ -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;