Minor fixes to yamux and identify protocols
This commit is contained in:
parent
e05e02188a
commit
13f51260b2
5 changed files with 27 additions and 2 deletions
|
@ -329,7 +329,7 @@ int libp2p_identify_shutdown(void* protocol_context) {
|
||||||
struct Libp2pProtocolHandler* libp2p_identify_build_protocol_handler(struct Libp2pVector* handlers) {
|
struct Libp2pProtocolHandler* libp2p_identify_build_protocol_handler(struct Libp2pVector* handlers) {
|
||||||
struct Libp2pProtocolHandler* handler = libp2p_protocol_handler_new();
|
struct Libp2pProtocolHandler* handler = libp2p_protocol_handler_new();
|
||||||
if (handler != NULL) {
|
if (handler != NULL) {
|
||||||
handler->context = handler;
|
handler->context = NULL;
|
||||||
handler->CanHandle = libp2p_identify_can_handle;
|
handler->CanHandle = libp2p_identify_can_handle;
|
||||||
handler->HandleMessage = libp2p_identify_handle_message;
|
handler->HandleMessage = libp2p_identify_handle_message;
|
||||||
handler->Shutdown = libp2p_identify_shutdown;
|
handler->Shutdown = libp2p_identify_shutdown;
|
||||||
|
|
|
@ -42,6 +42,12 @@ struct Libp2pProtocolHandler {
|
||||||
*/
|
*/
|
||||||
struct Libp2pProtocolHandler* libp2p_protocol_handler_new();
|
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
|
* Handle an incoming message
|
||||||
* @param message the incoming message
|
* @param message the incoming message
|
||||||
|
|
|
@ -13,6 +13,10 @@ static const int yamux_default_timeout = 10;
|
||||||
static const char YAMUX_CONTEXT = 'Y';
|
static const char YAMUX_CONTEXT = 'Y';
|
||||||
static const char YAMUX_CHANNEL_CONTEXT = 'C';
|
static const char YAMUX_CHANNEL_CONTEXT = 'C';
|
||||||
|
|
||||||
|
struct YamuxProtocolContext {
|
||||||
|
struct Libp2pVector* protocol_handlers;
|
||||||
|
};
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Context struct for Yamux
|
* Context struct for Yamux
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -41,6 +41,15 @@ struct Libp2pProtocolHandler* libp2p_protocol_handler_new() {
|
||||||
return h;
|
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
|
* Handle an incoming message
|
||||||
* @param message the incoming message
|
* @param message the incoming message
|
||||||
|
|
|
@ -163,7 +163,13 @@ int yamux_shutdown(void* protocol_context) {
|
||||||
struct Libp2pProtocolHandler* libp2p_yamux_build_protocol_handler(struct Libp2pVector* handlers) {
|
struct Libp2pProtocolHandler* libp2p_yamux_build_protocol_handler(struct Libp2pVector* handlers) {
|
||||||
struct Libp2pProtocolHandler* handler = libp2p_protocol_handler_new();
|
struct Libp2pProtocolHandler* handler = libp2p_protocol_handler_new();
|
||||||
if (handler != NULL) {
|
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->CanHandle = yamux_can_handle;
|
||||||
handler->HandleMessage = yamux_handle_message;
|
handler->HandleMessage = yamux_handle_message;
|
||||||
handler->Shutdown = yamux_shutdown;
|
handler->Shutdown = yamux_shutdown;
|
||||||
|
|
Loading…
Reference in a new issue