summaryrefslogtreecommitdiff
path: root/ecp/src/dir.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-08-31 22:20:15 +0200
committerUros Majstorovic <majstor@majstor.org>2021-08-31 22:20:15 +0200
commit2a33ef2344145e12f1eea96214cdb317857321c1 (patch)
tree1db9ce4e9c227c54595132edbce8adc65dd086ce /ecp/src/dir.c
parent2a46bdf517eb5fcb8ba59c398a32859c6496475d (diff)
directory service added
Diffstat (limited to 'ecp/src/dir.c')
-rw-r--r--ecp/src/dir.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/ecp/src/dir.c b/ecp/src/dir.c
new file mode 100644
index 0000000..81f564e
--- /dev/null
+++ b/ecp/src/dir.c
@@ -0,0 +1,38 @@
+#include "core.h"
+#include "cr.h"
+
+#include "dir.h"
+
+void ecp_dir_parse_item(unsigned char *buf, ECPDirItem *item) {
+ ecp_cr_dh_pub_from_buf(&item->node.public, buf);
+ buf += ECP_ECDH_SIZE_KEY;
+
+ memcpy(&item->node.addr.host, buf, sizeof(item->node.addr));
+ buf += ECP_IPv4_ADDR_SIZE;
+
+ item->node.addr.port = \
+ (buf[0] << 8) | \
+ (buf[1]);
+ buf += sizeof(uint16_t);
+
+ item->capabilities = \
+ (buf[0] << 8) | \
+ (buf[1]);
+ buf += sizeof(uint16_t);
+}
+
+void ecp_dir_serialize_item(unsigned char *buf, ECPDirItem *item) {
+ ecp_cr_dh_pub_to_buf(buf, &item->node.public);
+ buf += ECP_ECDH_SIZE_KEY;
+
+ memcpy(buf, &item->node.addr.host, sizeof(item->node.addr));
+ buf += ECP_IPv4_ADDR_SIZE;
+
+ buf[0] = (item->node.addr.port & 0xFF00) >> 8;
+ buf[1] = (item->node.addr.port & 0x00FF);
+ buf += sizeof(uint16_t);
+
+ buf[0] = (item->capabilities & 0xFF00) >> 8;
+ buf[1] = (item->capabilities & 0x00FF);
+ buf += sizeof(uint16_t);
+}