Added some debugging information to protocols

yamux
jmjatlanta 2017-08-09 12:08:57 -05:00
parent bff867ae4d
commit a009673969
3 changed files with 17 additions and 7 deletions

View File

@ -18,10 +18,18 @@ const struct Libp2pProtocolHandler* protocol_compare(const unsigned char* incomi
return NULL;
}
/***
* Handle an incoming message
* @param incoming the incoming data
* @param incoming_size the size of the incoming data buffer
* @param session the SessionContext of the incoming connection
* @param handlers a Vector of protocol handlers
* @returns -1 on error, 0 if everything was okay, but the daemon should no longer handle this connection, 1 on success
*/
int libp2p_protocol_marshal(const unsigned char* incoming, size_t incoming_size, struct SessionContext* session, struct Libp2pVector* handlers) {
const struct Libp2pProtocolHandler* handler = protocol_compare(incoming, incoming_size, handlers);
if (handler != NULL) {
return handler->HandleMessage(incoming, incoming_size, session, handler->context);
}
return 0;
return -1;
}

View File

@ -22,9 +22,9 @@ int libp2p_routing_dht_can_handle(const uint8_t* incoming, size_t incoming_size)
if (incoming_size < 8)
return 0;
char* result = strstr((char*)incoming, "/ipfs/kad");
if (result == NULL || result != (char*)incoming)
return 0;
return 1;
if (result != NULL && result == (char*)incoming)
return 1;
return 0;
}
int libp2p_routing_dht_shutdown(void* context) {
@ -33,10 +33,11 @@ int libp2p_routing_dht_shutdown(void* context) {
}
int libp2p_routing_dht_handle_msg(const uint8_t* incoming, size_t incoming_size, struct SessionContext* session_context, void* context) {
libp2p_logger_debug("dht_routing", "Handling incoming dht routing request.\n");
struct DhtContext* ctx = (struct DhtContext*)context;
if (!libp2p_routing_dht_handshake(session_context))
return 0;
return libp2p_routing_dht_handle_message(session_context, ctx->peer_store, ctx->provider_store);
return -1;
return (libp2p_routing_dht_handle_message(session_context, ctx->peer_store, ctx->provider_store) == 0) ? -1 : 1;
}
struct Libp2pProtocolHandler* libp2p_routing_dht_build_protocol_handler(struct Peerstore* peer_store, struct ProviderStore* provider_store) {

View File

@ -57,6 +57,7 @@ int libp2p_secio_can_handle(const uint8_t* incoming, size_t incoming_size) {
* @returns <0 on error, 0 if okay
*/
int libp2p_secio_handle_message(const uint8_t* incoming, size_t incoming_size, struct SessionContext* session_context, void* protocol_context) {
libp2p_logger_debug("secio", "Handling incoming secio message.\n");
struct SecioContext* ctx = (struct SecioContext*)protocol_context;
int retVal = libp2p_secio_handshake(session_context, ctx->private_key, ctx->peer_store);
if (retVal)
@ -79,7 +80,7 @@ int libp2p_secio_shutdown(void* context) {
*/
int libp2p_secio_initiate_handshake(struct SessionContext* session_context, struct RsaPrivateKey* private_key, struct Peerstore* peer_store) {
// send the protocol id first
const unsigned char* protocol = (unsigned char*)"/secio/1.0.0\n";
const unsigned char* protocol = (unsigned char*)"/ipfs/secio/1.0.0\n";
int protocol_len = strlen((char*)protocol);
if (!session_context->default_stream->write(session_context, protocol, protocol_len))
return 0;