-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdarksync.h
More file actions
145 lines (126 loc) · 3.27 KB
/
darksync.h
File metadata and controls
145 lines (126 loc) · 3.27 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <pthread.h>
#include <time.h>
#include <ncurses.h>
#include <sys/random.h>
#include "aes.h"
#define RPORT 8686
#define SPORT 8687
#define MAXCONN 50
#define MAXMSGLEN 256
#define MAXFILESIZE 8*1000*1000 // 100 MB
//------- Identifiers
#define ACTIVE_NODES_REQ 0xF0
#define DISCONNECT 0xF1
#define STD_MSG 0xF2
#define NODE_RES 0xF3
#define HELLO 0xF4
#define BL_UPD 0xF5
#define F_MSG 0xF6
//------- Structures
// User Input
struct arguments_s{
char* key;
char* node_ip;
char* nickname;
};
typedef struct arguments_s* Arguments;
// Ip linked list
struct ip_list_s{
uint32_t ip;
char nick[20];
struct ip_list_s* next;
};
typedef struct ip_list_s* IP_List;
void IPL_add(uint32_t ip, IP_List* root, char* nickname);
void IPL_print(IP_List root);
void IPL_destroy(IP_List root);
char* IPL_contains(uint32_t ip, IP_List root);
int IPL_remove(uint32_t ip, IP_List* root);
// Message List
struct message_list_s{
char message[MAXMSGLEN];
char nick[20];
uint32_t time;
struct message_list_s* next;
};
typedef struct message_list_s* MSG_List;
void MSG_add(char* message, char* nick, uint32_t time, MSG_List* messages);
void MSG_destroy(MSG_List messages);
void MSG_display(MSG_List messages);
void print_time(uint32_t* time);
void wprint_time(WINDOW* w, uint32_t* time);
// Metadata
struct metadata_s{
int ip_count;
int blacklist_count;
uint32_t my_ip;
int reciever_s;
int sender_s;
char nick[20];
IP_List ip_list;
IP_List blacklist;
MSG_List messages;
unsigned int lock: 2;
unsigned int ipassive: 1;
unsigned int emit_black: 1;
unsigned int keyloaded: 1;
uint8_t key[32];
uint8_t iv[16];
WINDOW* win;
WINDOW* message_board;
WINDOW* messenger;
WINDOW* banner;
WINDOW* status;
WINDOW* message_sender;
struct AES_ctx* encrypt_context;
};
typedef struct metadata_s* Metadata;
struct message_s{
uint8_t identifier;
int size;
uint8_t* message;
};
typedef struct message_s* Message;
//------- encryption
void generate_key_256();
void load_key(char* key, Metadata meta);
int send_message_encrypted(Message m, int socket, Metadata meta);
//------- display
void display(Metadata meta);
void display_mb(MSG_List messages, WINDOW* mb);
//------- blacklist
void load_blacklist(IP_List* root, Metadata meta);
void dump_blacklist(IP_List root);
//------- voids
void print_usage(); // print the usage
void create_directories(); // create the .darkchat and keys if not present
void check_args(); // validate arguments
void print_ip(uint32_t ip); // print in human readable
//------- aux
uint32_t conv_ip(char* ip); // check and convert the ip
//------- socket
int init_socket();
uint32_t get_ip_of_interface(char* interface);
int send_message(Message m, int socket);
//------- threading
void* message_reciever_worker(void* arg);
void* message_sender_worker(void* arg);
//------- locks
void lock(Metadata meta);
void unlock(Metadata meta);
//------- destruction
void destructor(Arguments args, Metadata meta);