A bit of code cleanup and commenting
This commit is contained in:
parent
a10c7ef5e9
commit
73fcecfdcf
3 changed files with 20 additions and 3 deletions
|
@ -16,6 +16,11 @@ struct SessionContext {
|
||||||
int port;
|
int port;
|
||||||
enum IPTrafficType traffic_type;
|
enum IPTrafficType traffic_type;
|
||||||
// once the connection is established
|
// 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* insecure_stream;
|
||||||
struct Stream* secure_stream;
|
struct Stream* secure_stream;
|
||||||
struct Stream* default_stream;
|
struct Stream* default_stream;
|
||||||
|
@ -27,9 +32,9 @@ struct SessionContext {
|
||||||
char* chosen_hash;
|
char* chosen_hash;
|
||||||
unsigned char* shared_key; // a shared key based off of the ephemeral private key
|
unsigned char* shared_key; // a shared key based off of the ephemeral private key
|
||||||
size_t shared_key_size;
|
size_t shared_key_size;
|
||||||
unsigned char* mac;
|
//unsigned char* mac;
|
||||||
size_t mac_size;
|
//size_t mac_size;
|
||||||
// the following items carry state for the sha256 stream cipher.
|
// the following items carry state for the sha256 stream cipher, and should probably not be touched.
|
||||||
size_t aes_encode_nonce_offset;
|
size_t aes_encode_nonce_offset;
|
||||||
unsigned char aes_encode_stream_block[16];
|
unsigned char aes_encode_stream_block[16];
|
||||||
size_t aes_decode_nonce_offset;
|
size_t aes_decode_nonce_offset;
|
||||||
|
|
|
@ -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.
|
* 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.
|
* 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
|
* @param session the struct Session, which contains all the context info
|
||||||
* @returns true(1) on success, or false(0)
|
* @returns true(1) on success, or false(0)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -225,6 +225,15 @@ struct Stream* libp2p_net_multistream_connect(const char* hostname, int port) {
|
||||||
return stream;
|
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) {
|
int libp2p_net_multistream_negotiate(struct SessionContext* session) {
|
||||||
const char* protocolID = "/multistream/1.0.0\n";
|
const char* protocolID = "/multistream/1.0.0\n";
|
||||||
unsigned char* results = NULL;
|
unsigned char* results = NULL;
|
||||||
|
|
Loading…
Reference in a new issue