No longer deleting session context when deleting message

yamux
John Jones 2017-09-28 17:14:37 -05:00
parent 198e5d544a
commit f4dd9b46be
3 changed files with 28 additions and 0 deletions

View File

@ -90,6 +90,29 @@ int libp2p_session_context_free(struct SessionContext* context) {
return 1;
}
/****
* Make a copy of a SessionContext
* @param original the original
* @returns a copy of the original, or NULL on error
*/
struct SessionContext* libp2p_session_context_copy(const struct SessionContext* original) {
struct SessionContext* new_ctx = libp2p_session_context_new();
if (new_ctx != NULL) {
new_ctx->aes_decode_nonce_offset = original->aes_decode_nonce_offset;
memcpy(new_ctx->aes_decode_stream_block, original->aes_decode_stream_block, 16);
new_ctx->aes_encode_nonce_offset = original->aes_encode_nonce_offset;
memcpy(new_ctx->aes_encode_stream_block, original->aes_encode_stream_block, 16);
new_ctx->chosen_cipher = (char*) malloc(strlen(original->chosen_cipher) + 1);
strcpy(new_ctx->chosen_cipher, original->chosen_cipher);
new_ctx->chosen_curve = (char*) malloc(strlen(original->chosen_curve) + 1);
strcpy(new_ctx->chosen_curve, original->chosen_curve);
new_ctx->chosen_hash = (char*) malloc(strlen(original->chosen_hash) + 1);
strcpy(new_ctx->chosen_hash, original->chosen_hash);
// TODO: Copy everything else
}
return new_ctx;
}
int libp2p_session_context_compare_streams(const struct Stream* a, const struct Stream* b) {
if (a == NULL && b == NULL)
return 0;
@ -134,3 +157,4 @@ int libp2p_session_context_compare(const struct SessionContext* a, const struct
total = libp2p_session_context_compare_remote_key(&a->remote_key, &b->remote_key);
return total;
}

View File

@ -83,3 +83,5 @@ int libp2p_session_context_free(struct SessionContext* session);
* @returns 0 if equal, <0 if A wins, >0 if B wins
*/
int libp2p_session_context_compare(const struct SessionContext* a, const struct SessionContext* b);
struct SessionContext* libp2p_session_context_copy(const struct SessionContext* original);

View File

@ -53,6 +53,8 @@ void libp2p_message_free(struct KademliaMessage* in) {
while (current != NULL) {
next = current->next;
struct Libp2pPeer* peer = (struct Libp2pPeer*)current->item;
// don't delete the session context
peer->sessionContext = NULL;
libp2p_peer_free(peer);
current->item = NULL;
libp2p_utils_linked_list_free(current);