summaryrefslogtreecommitdiff
path: root/ecp/server/dir.h
blob: dbcbc2e387c91cad86c40ac35e671bf6db2ff19c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#define MAX_DIR_MSG             10
#define MAX_DIR_ITEM            (MAX_DIR_MSG * ECP_MAX_DIR_ITEM_IN_MSG)
#define MAX_DIR_ITEM_DIR        100
#define MAX_REGION              10

#define MAX_VKEY                ((MAX_DIR_ITEM_DIR / 2) + 1)
#define MIN_VKEY_REQ            2       /* minimum number of vkeys required for non directory server */

#define MAX_NODE_ANNOUNCE       100
#define MAX_NODE_REMOVE         100

#define CTYPE_DIR               0x00    /* any node to directory server connection */

#define MTYPE_DIR_ANN           0x00
#define MTYPE_DIR_SHADOW        0x01
#define MTYPE_DIR_ORIGIN_REQ    0x02
#define MTYPE_DIR_ORIGIN_REP    0x03

#define PROC_BLOCK_ALL          0
#define PROC_BLOCK_ANN          1
#define PROC_ALLOW_ALL          2

#define ANN_PERIOD              600     /* announce priod (s); can't exceed 1h */
#define CONN_EXPIRE_TO          60

#define DIR_UFLAG_RECONNECT     0x80

typedef struct DIRNode {
    ECPDirItem dir_item;
    int zombie;
    int verified;
    int ann_local;
    int is_new;
    ecp_ecdh_public_t vkey[MAX_VKEY];
    unsigned short vkey_cnt;
    ECPConnection *conn;
    pthread_mutex_t mutex;
} DIRNode;

typedef struct DIRList {
    struct {
        uint8_t count;
        unsigned char buffer[ECP_MAX_DIR_ITEM_IN_MSG * ECP_SIZE_DIR_ITEM];
    } msg[MAX_DIR_MSG];
    uint8_t msg_count;
} DIRList;

typedef struct DIROnline {
    DIRList list[MAX_REGION];
    uint16_t serial;
} DIROnline;

ssize_t dir_send_online(ECPConnection *conn, uint8_t region);
ssize_t dir_handle_client_msg(struct ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, struct ECP2Buffer *b);

ssize_t dir_send_ann(ECPConnection *conn);
ssize_t dir_send_shadow(ECPConnection *conn);
ssize_t dir_handle_ann(ECPConnection *conn, unsigned char *msg, size_t msg_size);
ssize_t dir_handle_shadow(ECPConnection *conn, unsigned char *msg, size_t msg_size);
ssize_t dir_handle_msg(struct ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, struct ECP2Buffer *b);

void dir_process_item(ECPDirItem *dir_item, ECPSocket *sock, ecp_ecdh_public_t *s_public);
int dir_open_conn(DIRNode *node, ECPSocket *sock);
int dir_create_node(ECPDirItem *dir_item, ECPSocket *sock, DIRNode **node);
void dir_destroy_node(DIRNode *node);

void dir_online_switch(ECPSocket *sock, int inc_serial);
void dir_remove_nodes(DIRNode *remove_node[], int remove_cnt);
void dir_announce_allow(void);
void dir_announce_block(void);
void dit_init_serial(uint16_t serial);
int dir_init_dir_cnt(unsigned int dir_cnt, uint16_t serial);
void dir_announce(ECPSocket *sock, int ann_period);
int dir_start_announce(ECPSocket *sock);
void dir_init_switch(ECPSocket *sock, int init_ann);
int dir_init_ann(ECPSocket *sock, ECPNode *node);
int dir_init(ECPSocket *sock);