Skip to content

Commit

Permalink
Added handle_server_tcp_fin_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedeer committed Dec 11, 2014
1 parent ea3d59d commit 169a478
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
24 changes: 24 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,30 @@ int handle_server_tcp_frame(protocol_frame *rcvd_frame)
return 0;
}

/* Handle close-tunnel frame recived from the server */
int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame)
{
tunnel *tun=NULL;
int offset = 0;
int connid = rcvd_frame->connid;

HASH_FIND_INT(by_id, &connid, tun);

if(!tun)
{
fprintf(stderr, "Got TCP FIN frame with unknown tunnel ID %d\n", rcvd_frame->connid);
return -1;
}

if(tun->friendnumber != rcvd_frame->friendnumber)
{
fprintf(stderr, "Friend #%d tried to close tunnel while server is #%d\n", rcvd_frame->friendnumber, tun->friendnumber);
return -1;
}

tunnel_delete(tun);
}

/* Main loop for the client */
int do_client_loop(char *tox_id_str)
{
Expand Down
1 change: 1 addition & 0 deletions client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
int handle_pong_frame(protocol_frame *rcvd_frame);
int handle_acktunnel_frame(protocol_frame *rcvd_frame);
int handle_server_tcp_frame(protocol_frame *rcvd_frame);
int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame);
int do_client_loop(char *tox_id_str);
14 changes: 8 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ int handle_client_tcp_frame(protocol_frame *rcvd_frame)
return -1;
}

if(tun->friendnumber != rcvd_frame->friendnumber)
{
fprintf(stderr, "Friend #%d tried to send packet to a tunnel which belongs to #%d\n", rcvd_frame->friendnumber, tun->friendnumber);
return -1;
}

while(offset < rcvd_frame->data_length)
{
int sent_bytes;
Expand All @@ -397,11 +403,6 @@ int handle_client_tcp_frame(protocol_frame *rcvd_frame)
return 0;
}

int handle_server_tcp_fin_frame(protocol_frame *rcvd_frame)
{

}

/* Handle close-tunnel frame received from the client */
int handle_client_tcp_fin_frame(protocol_frame *rcvd_frame)
{
Expand Down Expand Up @@ -506,7 +507,7 @@ int parse_lossless_packet(void *sender_uc, const uint8_t *data, uint32_t len)
frame->packet_type = INT16_AT(data, 2);
frame->connid = INT16_AT(data, 4);
frame->data_length = INT16_AT(data, 6);
frame->data = data + PROTOCOL_BUFFER_OFFSET;
frame->data = (uint8_t *)(data + PROTOCOL_BUFFER_OFFSET);
frame->friendnumber = *((uint32_t*)sender_uc);
printf("Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber);

Expand Down Expand Up @@ -861,6 +862,7 @@ int main(int argc, char *argv[])
}

tox_get_address(tox, tox_id);
memset(tox_printable_id, '\0', sizeof(tox_printable_id));
id_to_string(tox_printable_id, tox_id);
tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2] = '\0';
printf("Using Tox ID: %s\n", tox_printable_id);
Expand Down
2 changes: 2 additions & 0 deletions scripts/tuntox.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Systemd service file

[Unit]
Description=Tuntox - TCP tunnel over Tox protocol
After=network.target
Expand Down

0 comments on commit 169a478

Please sign in to comment.