-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.h
More file actions
57 lines (48 loc) · 1.6 KB
/
node.h
File metadata and controls
57 lines (48 loc) · 1.6 KB
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
#pragma once
/**
* @file node.h
* @brief Node (= server until week 11) definition and related functions
*
* @author Valérian Rousset
*/
#include <netinet/in.h>
#include <openssl/sha.h>
#include <stdlib.h>
#include "error.h"
#include "util.h" // for _unused macro
#include "system.h"
/**
* @brief node data structure
*/
typedef struct{
struct sockaddr_in socket;
size_t node_id;
unsigned char* sha1;
}node_t;
/**
* @brief node initialization function
* @param node node to be initalized (modified)
* @param ip server IP address
* @param port server port
* @param node_id after week 11 (included), specify the server node id in a key ring. Unused before week 11.
* @return some error code
*/
error_code node_init(node_t *node, const char *ip, uint16_t port, size_t _unused node_id);
/**
* @brief all what needs to be done when a node is removed.
* Actually useless (=empty) in the current version of the project, but remains here as a placeholder
* @param node the node that is removed, passed by reference as it might be modified.
*/
void node_end(node_t *node);
/**
* @brief tool function to sort nodes according to their SHA
* @param two nodes to be compared
* @return <0 if first node comes first, 0 if equal and >0 is second node comes first
*/
int node_cmp_sha(const node_t *first, const node_t *second);
/**
* @brief tool function to sort node according to their SERVER address
* @param two nodes to be compared
* @return <0 if server of first node comes first, 0 if equal and >0 is sever of second node comes first
*/
int node_cmp_server_addr(const node_t *first, const node_t *second);