From c6c2d3c299c60ead311d18050c7110837e220b1e Mon Sep 17 00:00:00 2001 From: t Date: Fri, 10 Jan 2025 02:15:24 +0100 Subject: [PATCH] Experimented with network order --- dht.c | 6 +++++- webserver.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dht.c b/dht.c index b0d1502..836e2f6 100644 --- a/dht.c +++ b/dht.c @@ -11,7 +11,7 @@ void build_lookup_request(lookup_request* lr){ char *lrreq = lr->node_request; - snprintf(lr->node_request, HTTP_MAX_SIZE, "%d|%hd|%d|%s|%d\r\n\r\n", lr->message_type, lr->hash_id, lr->node_id, lr->node_ip, lr->node_port); + snprintf(lr->node_request, HTTP_MAX_SIZE, "%d|%hd|%d|%s|%d\r\n\r\n", lr->message_type, htons(lr->hash_id), lr->node_id, lr->node_ip, lr->node_port); } void lookup_request_init(lookup_request* lr, int message_type, int node_id, char *node_ip, int node_port, uint16_t hash_id, char *node_request) @@ -28,6 +28,10 @@ void lookup_request_init(lookup_request* lr, int message_type, int node_id, char void extract_lookup_request(lookup_request* lr, char* request){ sscanf(request, "%d|%hd|%d|%s|%d\r\n\r\n", &lr->message_type, &lr->hash_id, &lr->node_id, lr->node_ip, &lr->node_port); + // lr->message_type = ntohs(lr->message_type); + lr->hash_id = ntohs(lr->hash_id); + // lr->node_id = ntohs(lr->node_id); + // lr->node_port = ntohs(lr->node_port); } int call_network(lookup_request* lr, char *ip, int port){ diff --git a/webserver.c b/webserver.c index 16353eb..cec5212 100644 --- a/webserver.c +++ b/webserver.c @@ -403,7 +403,7 @@ neighbor check_neighborhood(uint16_t hash) { if ((pre_id == id && suc_id == id) || (id < pre_id && ((hash > pre_id && hash < 65535)) || hash <= id) || (hash > pre_id && hash <= id)) return res; - if ((id < suc_id && hash > id && hash <= suc_id) || (id > suc_id && (hash > id || hash <= suc_id))) + if ((id < suc_id && hash > id && hash <= suc_id) || (hash > id || hash <= suc_id)) return not_res; return dunno;