Minor fixes to yamux and identify protocols

yamux
John Jones 2017-11-23 07:44:42 -05:00
parent e05e02188a
commit 13f51260b2
5 changed files with 27 additions and 2 deletions

View File

@ -329,7 +329,7 @@ int libp2p_identify_shutdown(void* protocol_context) {
struct Libp2pProtocolHandler* libp2p_identify_build_protocol_handler(struct Libp2pVector* handlers) {
struct Libp2pProtocolHandler* handler = libp2p_protocol_handler_new();
if (handler != NULL) {
handler->context = handler;
handler->context = NULL;
handler->CanHandle = libp2p_identify_can_handle;
handler->HandleMessage = libp2p_identify_handle_message;
handler->Shutdown = libp2p_identify_shutdown;

View File

@ -42,6 +42,12 @@ struct Libp2pProtocolHandler {
*/
struct Libp2pProtocolHandler* libp2p_protocol_handler_new();
/***
* Release resources of a protocol handler
* @param handler the handler to free
*/
void libp2p_protocol_handler_free(struct Libp2pProtocolHandler* handler);
/***
* Handle an incoming message
* @param message the incoming message

View File

@ -13,6 +13,10 @@ static const int yamux_default_timeout = 10;
static const char YAMUX_CONTEXT = 'Y';
static const char YAMUX_CHANNEL_CONTEXT = 'C';
struct YamuxProtocolContext {
struct Libp2pVector* protocol_handlers;
};
/***
* Context struct for Yamux
*/

View File

@ -41,6 +41,15 @@ struct Libp2pProtocolHandler* libp2p_protocol_handler_new() {
return h;
}
/***
* Release resources of a protocol handler
* @param handler the handler to free
*/
void libp2p_protocol_handler_free(struct Libp2pProtocolHandler* handler) {
if (handler != NULL)
free(handler);
}
/***
* Handle an incoming message
* @param message the incoming message

View File

@ -163,7 +163,13 @@ int yamux_shutdown(void* protocol_context) {
struct Libp2pProtocolHandler* libp2p_yamux_build_protocol_handler(struct Libp2pVector* handlers) {
struct Libp2pProtocolHandler* handler = libp2p_protocol_handler_new();
if (handler != NULL) {
handler->context = handlers;
struct YamuxProtocolContext* ctx = (struct YamuxProtocolContext*) malloc(sizeof(struct YamuxProtocolContext));
if (ctx == NULL) {
libp2p_protocol_handler_free(handler);
return NULL;
}
ctx->protocol_handlers = handlers;
handler->context = ctx;
handler->CanHandle = yamux_can_handle;
handler->HandleMessage = yamux_handle_message;
handler->Shutdown = yamux_shutdown;