diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 12 | ||||
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 41 | ||||
-rw-r--r-- | testing/Lossless_UDP_testserver.c | 14 | ||||
-rw-r--r-- | testing/toxic/chat.c | 2 | ||||
-rw-r--r-- | testing/toxic/main.c | 4 | ||||
-rw-r--r-- | testing/toxic/prompt.c | 2 | ||||
-rw-r--r-- | testing/toxic/windows.c | 46 |
7 files changed, 65 insertions, 56 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index a9575fd5..8ab9157e 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -48,7 +48,7 @@ | |||
48 | 48 | ||
49 | #define PORT 33445 | 49 | #define PORT 33445 |
50 | 50 | ||
51 | void print_clientlist(DHT * dht) | 51 | void print_clientlist(DHT *dht) |
52 | { | 52 | { |
53 | uint32_t i, j; | 53 | uint32_t i, j; |
54 | IP_Port p_ip; | 54 | IP_Port p_ip; |
@@ -71,7 +71,7 @@ void print_clientlist(DHT * dht) | |||
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | void print_friendlist(DHT * dht) | 74 | void print_friendlist(DHT *dht) |
75 | { | 75 | { |
76 | uint32_t i, j, k; | 76 | uint32_t i, j, k; |
77 | IP_Port p_ip; | 77 | IP_Port p_ip; |
@@ -104,7 +104,7 @@ void print_friendlist(DHT * dht) | |||
104 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); | 104 | printf("\nIP: %u.%u.%u.%u:%u", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
105 | printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp); | 105 | printf("\nTimestamp: %llu", (long long unsigned int) dht->friends_list[k].client_list[i].timestamp); |
106 | printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged); | 106 | printf("\nLast pinged: %llu\n", (long long unsigned int) dht->friends_list[k].client_list[i].last_pinged); |
107 | p_ip =dht->friends_list[k].client_list[i].ret_ip_port; | 107 | p_ip = dht->friends_list[k].client_list[i].ret_ip_port; |
108 | printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); | 108 | printf("ret IP: %u.%u.%u.%u:%u\n", p_ip.ip.c[0], p_ip.ip.c[1], p_ip.ip.c[2], p_ip.ip.c[3], ntohs(p_ip.port)); |
109 | printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp); | 109 | printf("Timestamp: %llu\n", (long long unsigned int)dht->friends_list[k].client_list[i].ret_timestamp); |
110 | } | 110 | } |
@@ -134,9 +134,10 @@ int main(int argc, char *argv[]) | |||
134 | /* bind to ip 0.0.0.0:PORT */ | 134 | /* bind to ip 0.0.0.0:PORT */ |
135 | IP ip; | 135 | IP ip; |
136 | ip.i = 0; | 136 | ip.i = 0; |
137 | 137 | ||
138 | DHT * dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); | 138 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); |
139 | init_cryptopackets(dht); | 139 | init_cryptopackets(dht); |
140 | |||
140 | if (argc < 4) { | 141 | if (argc < 4) { |
141 | printf("usage %s ip port public_key\n", argv[0]); | 142 | printf("usage %s ip port public_key\n", argv[0]); |
142 | exit(0); | 143 | exit(0); |
@@ -198,5 +199,6 @@ int main(int argc, char *argv[]) | |||
198 | print_friendlist(dht); | 199 | print_friendlist(dht); |
199 | c_sleep(300); | 200 | c_sleep(300); |
200 | } | 201 | } |
202 | |||
201 | return 0; | 203 | return 0; |
202 | } | 204 | } |
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 0218de4f..09e9e0a3 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -124,25 +124,25 @@ void printconnection(int connection_id) | |||
124 | /*run doLossless_UDP(); */ | 124 | /*run doLossless_UDP(); */ |
125 | //void Lossless_UDP() | 125 | //void Lossless_UDP() |
126 | //{ | 126 | //{ |
127 | /* IP_Port ip_port; | 127 | /* IP_Port ip_port; |
128 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 128 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
129 | uint32_t length; | 129 | uint32_t length; |
130 | while (receivepacket(&ip_port, data, &length) != -1) { | 130 | while (receivepacket(&ip_port, data, &length) != -1) { |
131 | printf("packet with length: %u\n", length); */ | 131 | printf("packet with length: %u\n", length); */ |
132 | /* if(rand() % 3 != 1)//add packet loss | 132 | /* if(rand() % 3 != 1)//add packet loss |
133 | { */ | 133 | { */ |
134 | /* | 134 | /* |
135 | if (LosslessUDP_handlepacket(data, length, ip_port)) | 135 | if (LosslessUDP_handlepacket(data, length, ip_port)) |
136 | printpacket(data, length, ip_port); | 136 | printpacket(data, length, ip_port); |
137 | else | 137 | else |
138 | printf("Received handled packet with length: %u\n", length); //printconnection(0); */ | 138 | printf("Received handled packet with length: %u\n", length); //printconnection(0); */ |
139 | 139 | ||
140 | /* } */ | 140 | /* } */ |
141 | /* }*/ | 141 | /* }*/ |
142 | 142 | ||
143 | //networking_poll(); | 143 | //networking_poll(); |
144 | 144 | ||
145 | //doLossless_UDP(); | 145 | //doLossless_UDP(); |
146 | 146 | ||
147 | //} | 147 | //} |
148 | 148 | ||
@@ -166,7 +166,7 @@ int main(int argc, char *argv[]) | |||
166 | /* bind to ip 0.0.0.0:PORT */ | 166 | /* bind to ip 0.0.0.0:PORT */ |
167 | IP ip; | 167 | IP ip; |
168 | ip.i = 0; | 168 | ip.i = 0; |
169 | Lossless_UDP * ludp = new_lossless_udp(new_networking(ip, PORT)); | 169 | Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); |
170 | perror("Initialization"); | 170 | perror("Initialization"); |
171 | IP_Port serverip; | 171 | IP_Port serverip; |
172 | serverip.ip.i = inet_addr(argv[1]); | 172 | serverip.ip.i = inet_addr(argv[1]); |
@@ -203,6 +203,7 @@ int main(int argc, char *argv[]) | |||
203 | /* printconnection(connection); */ | 203 | /* printconnection(connection); */ |
204 | networking_poll(ludp->net); | 204 | networking_poll(ludp->net); |
205 | do_lossless_udp(ludp); | 205 | do_lossless_udp(ludp); |
206 | |||
206 | if (is_connected(ludp, connection) == 3) { | 207 | if (is_connected(ludp, connection) == 3) { |
207 | 208 | ||
208 | if (write_packet(ludp, connection, buffer, read)) { | 209 | if (write_packet(ludp, connection, buffer, read)) { |
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index c3212888..a82b787a 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c | |||
@@ -124,20 +124,20 @@ void printconnection(int connection_id) | |||
124 | // uint8_t data[MAX_UDP_PACKET_SIZE]; | 124 | // uint8_t data[MAX_UDP_PACKET_SIZE]; |
125 | // uint32_t length; | 125 | // uint32_t length; |
126 | // while (receivepacket(&ip_port, data, &length) != -1) { | 126 | // while (receivepacket(&ip_port, data, &length) != -1) { |
127 | //if(rand() % 3 != 1)//add packet loss | 127 | //if(rand() % 3 != 1)//add packet loss |
128 | //{ | 128 | //{ |
129 | // if (LosslessUDP_handlepacket(data, length, ip_port)) { | 129 | // if (LosslessUDP_handlepacket(data, length, ip_port)) { |
130 | // printpacket(data, length, ip_port); | 130 | // printpacket(data, length, ip_port); |
131 | // } else { | 131 | // } else { |
132 | //printconnection(0); | 132 | //printconnection(0); |
133 | // printf("Received handled packet with length: %u\n", length); | 133 | // printf("Received handled packet with length: %u\n", length); |
134 | // } | 134 | // } |
135 | //} | 135 | //} |
136 | // } | 136 | // } |
137 | 137 | ||
138 | // networking_poll(); | 138 | // networking_poll(); |
139 | 139 | ||
140 | //doLossless_UDP(); | 140 | //doLossless_UDP(); |
141 | //} | 141 | //} |
142 | 142 | ||
143 | 143 | ||
@@ -161,7 +161,7 @@ int main(int argc, char *argv[]) | |||
161 | //bind to ip 0.0.0.0:PORT | 161 | //bind to ip 0.0.0.0:PORT |
162 | IP ip; | 162 | IP ip; |
163 | ip.i = 0; | 163 | ip.i = 0; |
164 | Lossless_UDP * ludp = new_lossless_udp(new_networking(ip, PORT)); | 164 | Lossless_UDP *ludp = new_lossless_udp(new_networking(ip, PORT)); |
165 | perror("Initialization"); | 165 | perror("Initialization"); |
166 | 166 | ||
167 | int connection; | 167 | int connection; |
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index d3e68ec6..c7979843 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -123,7 +123,7 @@ static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint1 | |||
123 | 123 | ||
124 | status[len - 1] = '\0'; | 124 | status[len - 1] = '\0'; |
125 | fix_name(status); | 125 | fix_name(status); |
126 | 126 | ||
127 | wattron(ctx->history, COLOR_PAIR(3)); | 127 | wattron(ctx->history, COLOR_PAIR(3)); |
128 | wprintw(ctx->history, "* Your partner changed status to '%s'\n", status); | 128 | wprintw(ctx->history, "* Your partner changed status to '%s'\n", status); |
129 | wattroff(ctx->history, COLOR_PAIR(3)); | 129 | wattroff(ctx->history, COLOR_PAIR(3)); |
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 6f6c9db4..e5525e94 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -93,7 +93,7 @@ static Messenger *init_tox() | |||
93 | int init_connection(Messenger *m) | 93 | int init_connection(Messenger *m) |
94 | { | 94 | { |
95 | FILE *fp = NULL; | 95 | FILE *fp = NULL; |
96 | 96 | ||
97 | if (DHT_isconnected(m->dht)) | 97 | if (DHT_isconnected(m->dht)) |
98 | return 0; | 98 | return 0; |
99 | 99 | ||
@@ -297,7 +297,7 @@ int main(int argc, char *argv[]) | |||
297 | strcpy(DATA_FILE, user_config_dir); | 297 | strcpy(DATA_FILE, user_config_dir); |
298 | strcat(DATA_FILE, CONFIGDIR); | 298 | strcat(DATA_FILE, CONFIGDIR); |
299 | strcat(DATA_FILE, "data"); | 299 | strcat(DATA_FILE, "data"); |
300 | 300 | ||
301 | SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); | 301 | SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); |
302 | strcpy(SRVLIST_FILE, user_config_dir); | 302 | strcpy(SRVLIST_FILE, user_config_dir); |
303 | strcat(SRVLIST_FILE, CONFIGDIR); | 303 | strcat(SRVLIST_FILE, CONFIGDIR); |
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index 12f8a201..e194a90e 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c | |||
@@ -365,7 +365,9 @@ static void execute(ToxWindow *self, Messenger *m, char *u_cmd) | |||
365 | cmd[i] = '\0'; | 365 | cmd[i] = '\0'; |
366 | 366 | ||
367 | int j = i; | 367 | int j = i; |
368 | |||
368 | while (++j < MAX_STR_SIZE && isspace(cmd[j])); | 369 | while (++j < MAX_STR_SIZE && isspace(cmd[j])); |
370 | |||
369 | i = j - 1; | 371 | i = j - 1; |
370 | 372 | ||
371 | numargs++; | 373 | numargs++; |
diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c index de924329..8fdf4e19 100644 --- a/testing/toxic/windows.c +++ b/testing/toxic/windows.c | |||
@@ -88,23 +88,25 @@ int add_window(Messenger *m, ToxWindow w) | |||
88 | { | 88 | { |
89 | if (LINES < 2) | 89 | if (LINES < 2) |
90 | return -1; | 90 | return -1; |
91 | 91 | ||
92 | int i; | 92 | int i; |
93 | for(i = 0; i < MAX_WINDOWS_NUM; i++) { | 93 | |
94 | if (windows[i].window) | 94 | for (i = 0; i < MAX_WINDOWS_NUM; i++) { |
95 | if (windows[i].window) | ||
95 | continue; | 96 | continue; |
96 | 97 | ||
97 | w.window = newwin(LINES - 2, COLS, 0, 0); | 98 | w.window = newwin(LINES - 2, COLS, 0, 0); |
99 | |||
98 | if (w.window == NULL) | 100 | if (w.window == NULL) |
99 | return -1; | 101 | return -1; |
100 | 102 | ||
101 | windows[i] = w; | 103 | windows[i] = w; |
102 | w.onInit(&w, m); | 104 | w.onInit(&w, m); |
103 | 105 | ||
104 | active_window = windows+i; | 106 | active_window = windows + i; |
105 | return i; | 107 | return i; |
106 | } | 108 | } |
107 | 109 | ||
108 | return -1; | 110 | return -1; |
109 | } | 111 | } |
110 | 112 | ||
@@ -113,8 +115,10 @@ void del_window(ToxWindow *w) | |||
113 | { | 115 | { |
114 | active_window = windows; // Go to prompt screen | 116 | active_window = windows; // Go to prompt screen |
115 | delwin(w->window); | 117 | delwin(w->window); |
118 | |||
116 | if (w->x) | 119 | if (w->x) |
117 | free(w->x); | 120 | free(w->x); |
121 | |||
118 | w->window = NULL; | 122 | w->window = NULL; |
119 | memset(w, 0, sizeof(ToxWindow)); | 123 | memset(w, 0, sizeof(ToxWindow)); |
120 | clear(); | 124 | clear(); |
@@ -124,19 +128,19 @@ void del_window(ToxWindow *w) | |||
124 | /* Shows next window when tab or back-tab is pressed */ | 128 | /* Shows next window when tab or back-tab is pressed */ |
125 | void set_next_window(int ch) | 129 | void set_next_window(int ch) |
126 | { | 130 | { |
127 | ToxWindow *end = windows+MAX_WINDOWS_NUM-1; | 131 | ToxWindow *end = windows + MAX_WINDOWS_NUM - 1; |
128 | ToxWindow *inf = active_window; | 132 | ToxWindow *inf = active_window; |
129 | while(true) { | 133 | |
134 | while (true) { | ||
130 | if (ch == '\t') { | 135 | if (ch == '\t') { |
131 | if (++active_window > end) | 136 | if (++active_window > end) |
132 | active_window = windows; | 137 | active_window = windows; |
133 | } else | 138 | } else if (--active_window < windows) |
134 | if (--active_window < windows) | 139 | active_window = end; |
135 | active_window = end; | 140 | |
136 | |||
137 | if (active_window->window) | 141 | if (active_window->window) |
138 | return; | 142 | return; |
139 | 143 | ||
140 | if (active_window == inf) { // infinite loop check | 144 | if (active_window == inf) { // infinite loop check |
141 | endwin(); | 145 | endwin(); |
142 | exit(2); | 146 | exit(2); |
@@ -148,14 +152,14 @@ void set_active_window(int index) | |||
148 | { | 152 | { |
149 | if (index < 0 || index >= MAX_WINDOWS_NUM) | 153 | if (index < 0 || index >= MAX_WINDOWS_NUM) |
150 | return; | 154 | return; |
151 | 155 | ||
152 | active_window = windows+index; | 156 | active_window = windows + index; |
153 | } | 157 | } |
154 | 158 | ||
155 | ToxWindow *init_windows() | 159 | ToxWindow *init_windows() |
156 | { | 160 | { |
157 | int n_prompt = add_window(m, new_prompt()); | 161 | int n_prompt = add_window(m, new_prompt()); |
158 | 162 | ||
159 | if (n_prompt == -1 | 163 | if (n_prompt == -1 |
160 | || add_window(m, new_friendlist()) == -1 | 164 | || add_window(m, new_friendlist()) == -1 |
161 | || add_window(m, new_dhtstatus()) == -1) { | 165 | || add_window(m, new_dhtstatus()) == -1) { |
@@ -166,7 +170,7 @@ ToxWindow *init_windows() | |||
166 | 170 | ||
167 | prompt = &windows[n_prompt]; | 171 | prompt = &windows[n_prompt]; |
168 | active_window = prompt; | 172 | active_window = prompt; |
169 | 173 | ||
170 | return prompt; | 174 | return prompt; |
171 | } | 175 | } |
172 | 176 | ||
@@ -189,7 +193,7 @@ static void draw_bar() | |||
189 | 193 | ||
190 | for (i = 0; i < (MAX_WINDOWS_NUM); ++i) { | 194 | for (i = 0; i < (MAX_WINDOWS_NUM); ++i) { |
191 | if (windows[i].window) { | 195 | if (windows[i].window) { |
192 | if (windows+i == active_window) | 196 | if (windows + i == active_window) |
193 | attron(A_BOLD); | 197 | attron(A_BOLD); |
194 | 198 | ||
195 | odd = (odd + 1) % blinkrate; | 199 | odd = (odd + 1) % blinkrate; |
@@ -197,13 +201,13 @@ static void draw_bar() | |||
197 | if (windows[i].blink && (odd < (blinkrate / 2))) | 201 | if (windows[i].blink && (odd < (blinkrate / 2))) |
198 | attron(COLOR_PAIR(3)); | 202 | attron(COLOR_PAIR(3)); |
199 | 203 | ||
200 | clrtoeol(); | 204 | clrtoeol(); |
201 | printw(" %s", windows[i].title); | 205 | printw(" %s", windows[i].title); |
202 | 206 | ||
203 | if (windows[i].blink && (odd < (blinkrate / 2))) | 207 | if (windows[i].blink && (odd < (blinkrate / 2))) |
204 | attroff(COLOR_PAIR(3)); | 208 | attroff(COLOR_PAIR(3)); |
205 | 209 | ||
206 | if (windows+i == active_window) { | 210 | if (windows + i == active_window) { |
207 | attroff(A_BOLD); | 211 | attroff(A_BOLD); |
208 | } | 212 | } |
209 | } | 213 | } |