journalio working, needs tuning
This commit is contained in:
parent
f0d82129ab
commit
eecfea4f78
7 changed files with 29 additions and 5 deletions
|
@ -37,6 +37,7 @@ struct SessionContext* libp2p_session_context_new() {
|
|||
context->shared_key = NULL;
|
||||
context->shared_key_size = 0;
|
||||
context->traffic_type = TCP;
|
||||
context->last_comm_epoch = 0;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ struct SessionContext {
|
|||
struct StretchedKey* remote_stretched_key;
|
||||
unsigned char* remote_ephemeral_public_key;
|
||||
size_t remote_ephemeral_public_key_size;
|
||||
unsigned long long last_comm_epoch;
|
||||
};
|
||||
|
||||
/***
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef base58_h
|
||||
#define base58_h
|
||||
|
||||
#include <stddef.h>
|
||||
/**
|
||||
* convert a base58 encoded string into a binary array
|
||||
* @param base58 the base58 encoded string
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "libp2p/os/utils.h"
|
||||
#include "libp2p/net/p2pnet.h"
|
||||
#include "libp2p/record/message.h"
|
||||
#include "libp2p/secio/secio.h"
|
||||
|
@ -107,6 +109,7 @@ int libp2p_net_multistream_write(void* stream_context, const unsigned char* data
|
|||
}
|
||||
// then send the actual data
|
||||
num_bytes += socket_write(sd, (char*)data, data_length, 0);
|
||||
session_context->last_comm_epoch = os_utils_gmtime();
|
||||
} else {
|
||||
// write using secio
|
||||
num_bytes = stream->write(stream_context, buffer, data_length + varint_size);
|
||||
|
@ -186,6 +189,7 @@ int libp2p_net_multistream_read(void* stream_context, unsigned char** results, s
|
|||
return 0;
|
||||
memcpy(*results, buffer, num_bytes_requested);
|
||||
*results_size = num_bytes_requested;
|
||||
session_context->last_comm_epoch = os_utils_gmtime();
|
||||
} else { // use secio instead of raw read/writes
|
||||
unsigned char* read_from_stream;
|
||||
size_t size_read_from_stream;
|
||||
|
@ -213,6 +217,7 @@ int libp2p_net_multistream_read(void* stream_context, unsigned char** results, s
|
|||
return 0;
|
||||
}
|
||||
memcpy(*results, &buffer[left], num_bytes_requested);
|
||||
session_context->last_comm_epoch = os_utils_gmtime();
|
||||
}
|
||||
|
||||
return num_bytes_requested;
|
||||
|
|
|
@ -30,12 +30,20 @@ const struct Libp2pProtocolHandler* protocol_compare(const unsigned char* incomi
|
|||
*/
|
||||
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);
|
||||
char str[incoming_size + 1];
|
||||
memcpy(str, incoming, incoming_size);
|
||||
str[incoming_size] = 0;
|
||||
for(int i = 0; i < incoming_size; i++) {
|
||||
if (str[i] == '\n') {
|
||||
str[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handler == NULL) {
|
||||
char str[incoming_size + 1];
|
||||
memcpy(str, incoming, incoming_size);
|
||||
str[incoming_size] = 0;
|
||||
libp2p_logger_error("protocol", "Unable to find handler for %s.\n", str);
|
||||
return -1;
|
||||
} else {
|
||||
libp2p_logger_debug("protocol", "Found handler for %s.\n", str);
|
||||
}
|
||||
//TODO: strip off the protocol?
|
||||
return handler->HandleMessage(incoming, incoming_size, session, handler->context);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libp2p/crypto/encoding/base58.h"
|
||||
#include "libp2p/net/stream.h"
|
||||
#include "libp2p/routing/dht_protocol.h"
|
||||
#include "libp2p/record/message.h"
|
||||
|
@ -175,7 +176,14 @@ int libp2p_routing_dht_handle_get_providers(struct SessionContext* session, stru
|
|||
}
|
||||
}
|
||||
} else {
|
||||
libp2p_logger_debug("dht_protocol", "I cannot provide a provider for this key.\n");
|
||||
size_t b58_size = 100;
|
||||
uint8_t *b58key = (uint8_t *) malloc(b58_size);
|
||||
if (!libp2p_crypto_encoding_base58_encode((unsigned char*)message->key, message->key_size, (unsigned char**)&b58key, &b58_size)) {
|
||||
libp2p_logger_debug("dht_protocol", "I cannot provide a provider for this key.\n");
|
||||
} else {
|
||||
libp2p_logger_debug("dht_protocol", "I cannot provide a provider for the key %s.\n", b58key);
|
||||
}
|
||||
free(b58key);
|
||||
}
|
||||
if (peer_id != NULL)
|
||||
free(peer_id);
|
||||
|
|
|
@ -54,7 +54,7 @@ int libp2p_secio_can_handle(const uint8_t* incoming, size_t incoming_size) {
|
|||
* @param incoming_size the size of the incoming buffer
|
||||
* @param session_context who is attempting to connect
|
||||
* @param protocol_context a SecioContext that contains the needed information
|
||||
* @returns <0 on error, 0 if okay
|
||||
* @returns <0 on error, 0 if okay (does not allow daemon to continue looping)
|
||||
*/
|
||||
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");
|
||||
|
|
Loading…
Reference in a new issue