File client.c changed (mode: 100644) (index 75d4b0d..58b35d4) |
... |
... |
int handle_server_tcp_frame(protocol_frame *rcvd_frame) |
171 |
171 |
return 0; |
return 0; |
172 |
172 |
} |
} |
173 |
173 |
|
|
|
174 |
|
/* Handle close-tunnel frame recived from the server */ |
|
175 |
|
int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame) |
|
176 |
|
{ |
|
177 |
|
tunnel *tun=NULL; |
|
178 |
|
int offset = 0; |
|
179 |
|
int connid = rcvd_frame->connid; |
|
180 |
|
|
|
181 |
|
HASH_FIND_INT(by_id, &connid, tun); |
|
182 |
|
|
|
183 |
|
if(!tun) |
|
184 |
|
{ |
|
185 |
|
fprintf(stderr, "Got TCP FIN frame with unknown tunnel ID %d\n", rcvd_frame->connid); |
|
186 |
|
return -1; |
|
187 |
|
} |
|
188 |
|
|
|
189 |
|
if(tun->friendnumber != rcvd_frame->friendnumber) |
|
190 |
|
{ |
|
191 |
|
fprintf(stderr, "Friend #%d tried to close tunnel while server is #%d\n", rcvd_frame->friendnumber, tun->friendnumber); |
|
192 |
|
return -1; |
|
193 |
|
} |
|
194 |
|
|
|
195 |
|
tunnel_delete(tun); |
|
196 |
|
} |
|
197 |
|
|
174 |
198 |
/* Main loop for the client */ |
/* Main loop for the client */ |
175 |
199 |
int do_client_loop(char *tox_id_str) |
int do_client_loop(char *tox_id_str) |
176 |
200 |
{ |
{ |
File client.h changed (mode: 100644) (index 7d5e50d..d22c161) |
16 |
16 |
int handle_pong_frame(protocol_frame *rcvd_frame); |
int handle_pong_frame(protocol_frame *rcvd_frame); |
17 |
17 |
int handle_acktunnel_frame(protocol_frame *rcvd_frame); |
int handle_acktunnel_frame(protocol_frame *rcvd_frame); |
18 |
18 |
int handle_server_tcp_frame(protocol_frame *rcvd_frame); |
int handle_server_tcp_frame(protocol_frame *rcvd_frame); |
|
19 |
|
int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame); |
19 |
20 |
int do_client_loop(char *tox_id_str); |
int do_client_loop(char *tox_id_str); |
File main.c changed (mode: 100644) (index bff4620..f564664) |
... |
... |
int handle_client_tcp_frame(protocol_frame *rcvd_frame) |
374 |
374 |
return -1; |
return -1; |
375 |
375 |
} |
} |
376 |
376 |
|
|
|
377 |
|
if(tun->friendnumber != rcvd_frame->friendnumber) |
|
378 |
|
{ |
|
379 |
|
fprintf(stderr, "Friend #%d tried to send packet to a tunnel which belongs to #%d\n", rcvd_frame->friendnumber, tun->friendnumber); |
|
380 |
|
return -1; |
|
381 |
|
} |
|
382 |
|
|
377 |
383 |
while(offset < rcvd_frame->data_length) |
while(offset < rcvd_frame->data_length) |
378 |
384 |
{ |
{ |
379 |
385 |
int sent_bytes; |
int sent_bytes; |
|
... |
... |
int handle_client_tcp_frame(protocol_frame *rcvd_frame) |
397 |
403 |
return 0; |
return 0; |
398 |
404 |
} |
} |
399 |
405 |
|
|
400 |
|
int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame) |
|
401 |
|
{ |
|
402 |
|
|
|
403 |
|
} |
|
404 |
|
|
|
405 |
406 |
/* Handle close-tunnel frame received from the client */ |
/* Handle close-tunnel frame received from the client */ |
406 |
407 |
int handle_client_tcp_fin_frame(protocol_frame *rcvd_frame) |
int handle_client_tcp_fin_frame(protocol_frame *rcvd_frame) |
407 |
408 |
{ |
{ |
|
... |
... |
int parse_lossless_packet(void *sender_uc, const uint8_t *data, uint32_t len) |
506 |
507 |
frame->packet_type = INT16_AT(data, 2); |
frame->packet_type = INT16_AT(data, 2); |
507 |
508 |
frame->connid = INT16_AT(data, 4); |
frame->connid = INT16_AT(data, 4); |
508 |
509 |
frame->data_length = INT16_AT(data, 6); |
frame->data_length = INT16_AT(data, 6); |
509 |
|
frame->data = data + PROTOCOL_BUFFER_OFFSET; |
|
|
510 |
|
frame->data = (uint8_t *)(data + PROTOCOL_BUFFER_OFFSET); |
510 |
511 |
frame->friendnumber = *((uint32_t*)sender_uc); |
frame->friendnumber = *((uint32_t*)sender_uc); |
511 |
512 |
printf("Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber); |
printf("Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber); |
512 |
513 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
861 |
862 |
} |
} |
862 |
863 |
|
|
863 |
864 |
tox_get_address(tox, tox_id); |
tox_get_address(tox, tox_id); |
|
865 |
|
memset(tox_printable_id, '\0', sizeof(tox_printable_id)); |
864 |
866 |
id_to_string(tox_printable_id, tox_id); |
id_to_string(tox_printable_id, tox_id); |
865 |
867 |
tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0'; |
tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0'; |
866 |
868 |
printf("Using Tox ID: %s\n", tox_printable_id); |
printf("Using Tox ID: %s\n", tox_printable_id); |