diff options
Diffstat (limited to 'ecp/src')
-rw-r--r-- | ecp/src/ecp/dir/dir.c | 24 | ||||
-rw-r--r-- | ecp/src/ecp/dir/dir.h | 11 |
2 files changed, 21 insertions, 14 deletions
diff --git a/ecp/src/ecp/dir/dir.c b/ecp/src/ecp/dir/dir.c index d826e24..6258e0e 100644 --- a/ecp/src/ecp/dir/dir.c +++ b/ecp/src/ecp/dir/dir.c @@ -2,10 +2,19 @@ #include <string.h> #include <ecp/core.h> +#include <ecp/tr.h> #include <ecp/cr.h> #include "dir.h" +int ecp_dir_item_eq(ECPDirItem *item1, ECPDirItem *item2) { + if (item1->region != item2->region) return 0; + if (item1->capabilities != item2->capabilities) return 0; + if (!item1->node.key_perma.valid || !item1->node.key_perma.valid) return 0; + if (memcmp(&item1->node.key_perma.public, &item2->node.key_perma.public, sizeof(item1->node.key_perma.public)) != 0) return 0; + return ecp_tr_addr_eq(&item1->node.addr, &item2->node.addr); +} + size_t ecp_dir_item_parse(ECPDirItem *item, unsigned char *buf) { ECPDHPub *key; ecp_tr_addr_t *addr; @@ -31,11 +40,10 @@ size_t ecp_dir_item_parse(ECPDirItem *item, unsigned char *buf) { buf += sizeof(uint16_t); rsize += sizeof(uint16_t); - item->capabilities = \ - ((uint16_t)buf[0] << 8) | \ - ((uint16_t)buf[1]); - buf += sizeof(uint16_t); - rsize += sizeof(uint16_t); + item->region = buf[0]; + item->capabilities = buf[1]; + buf += 2; + rsize += 2; return rsize; } @@ -61,10 +69,10 @@ size_t ecp_dir_item_serialize(ECPDirItem *item, unsigned char *buf) { buf += sizeof(uint16_t); rsize += sizeof(uint16_t); - buf[0] = item->capabilities >> 8; + buf[0] = item->region; buf[1] = item->capabilities; - buf += sizeof(uint16_t); - rsize += sizeof(uint16_t); + buf += 2; + rsize += 2; return rsize; } diff --git a/ecp/src/ecp/dir/dir.h b/ecp/src/ecp/dir/dir.h index b28f801..83b97df 100644 --- a/ecp/src/ecp/dir/dir.h +++ b/ecp/src/ecp/dir/dir.h @@ -1,10 +1,7 @@ #define ECP_SIZE_DIR_ITEM 40 -#define ECP_MTYPE_DIR_UPD 0x00 -#define ECP_MTYPE_DIR_REQ 0x01 -#define ECP_MTYPE_DIR_ANN 0x02 -#define ECP_MTYPE_DIR_REP 0x03 -#define ECP_MTYPE_DIR_SHADOW 0x04 +#define ECP_MTYPE_DIR_REQ 0x00 +#define ECP_MTYPE_DIR_REP 0x01 #define ECP_CTYPE_DIR (0x00 | ECP_CTYPE_FLAG_SYS) @@ -13,9 +10,11 @@ typedef struct ECPDirItem { ECPNode node; - uint16_t capabilities; + uint8_t region; + uint8_t capabilities; } ECPDirItem; +int ecp_dir_item_eq(ECPDirItem *item1, ECPDirItem *item2); size_t ecp_dir_item_parse(ECPDirItem *item, unsigned char *buf); size_t ecp_dir_item_serialize(ECPDirItem *item, unsigned char *buf); |