mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 02:55:15 +00:00
Improved latency for traffic initiated from server
This commit is contained in:
parent
5776562339
commit
3fc9eaeaa3
@ -5,6 +5,12 @@ iodine - http://code.kryo.se/iodine
|
||||
|
||||
CHANGES:
|
||||
|
||||
2008-xx-xx: 0.x.x
|
||||
- Delayed sending responses in server to improve latency. Pings from
|
||||
server to client are now always fast instead of cycling from
|
||||
fast to 1000 ms.
|
||||
- The server now replies to all received queries.
|
||||
|
||||
2008-08-06: 0.4.2 "Opened Zone"
|
||||
- Applied a few small patches from Maxim Bourmistrov and Gregor Herrmann
|
||||
- Applied a patch for not creating and configuring the tun interface,
|
||||
|
@ -107,6 +107,13 @@ tunnel_tun(int tun_fd, int dns_fd)
|
||||
if (users[userid].outpacket.len == 0) {
|
||||
memcpy(users[userid].outpacket.data, out, outlen);
|
||||
users[userid].outpacket.len = outlen;
|
||||
if (users[userid].q.id != 0) {
|
||||
/* If delayed response is kept, send reply immediately */
|
||||
write_dns(dns_fd, &(users[userid].q), users[userid].outpacket.data, users[userid].outpacket.len);
|
||||
users[userid].outpacket.len = 0;
|
||||
users[userid].q.id = 0;
|
||||
return 0;
|
||||
}
|
||||
return outlen;
|
||||
} else {
|
||||
return 0;
|
||||
@ -252,6 +259,12 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q)
|
||||
write_dns(dns_fd, q, "BADIP", 5);
|
||||
return; /* illegal id */
|
||||
}
|
||||
if (users[userid].q.id != 0) {
|
||||
/* If delayed response is kept, send empty reply before overwriting */
|
||||
write_dns(dns_fd, &(users[userid].q), users[userid].outpacket.data, users[userid].outpacket.len);
|
||||
users[userid].outpacket.len = 0;
|
||||
users[userid].q.id = 0;
|
||||
}
|
||||
memcpy(&(users[userid].q), q, sizeof(struct query));
|
||||
users[userid].last_pkt = time(NULL);
|
||||
} else if(in[0] == 'Z' || in[0] == 'z') {
|
||||
@ -285,6 +298,12 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q)
|
||||
users[userid].encoder);
|
||||
|
||||
users[userid].last_pkt = time(NULL);
|
||||
if (users[userid].q.id != 0) {
|
||||
/* If delayed response is kept, send empty reply before overwriting */
|
||||
write_dns(dns_fd, &(users[userid].q), users[userid].outpacket.data, users[userid].outpacket.len);
|
||||
users[userid].outpacket.len = 0;
|
||||
users[userid].q.id = 0;
|
||||
}
|
||||
memcpy(&(users[userid].q), q, sizeof(struct query));
|
||||
memcpy(users[userid].inpacket.data + users[userid].inpacket.offset, unpacked, read);
|
||||
users[userid].inpacket.len += read;
|
||||
@ -353,16 +372,10 @@ tunnel(int tun_fd, int dns_fd)
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
while (running) {
|
||||
if (users_waiting_on_reply()) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 5000;
|
||||
} else {
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
}
|
||||
|
||||
FD_ZERO(&fds);
|
||||
/* TODO : use some kind of packet queue */
|
||||
@ -379,15 +392,6 @@ tunnel(int tun_fd, int dns_fd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (i==0) {
|
||||
for (j = 0; j < USERS; j++) {
|
||||
if (users[j].q.id != 0) {
|
||||
write_dns(dns_fd, &(users[j].q), users[j].outpacket.data, users[j].outpacket.len);
|
||||
users[j].outpacket.len = 0;
|
||||
users[j].q.id = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(FD_ISSET(tun_fd, &fds)) {
|
||||
tunnel_tun(tun_fd, dns_fd);
|
||||
continue;
|
||||
@ -397,7 +401,6 @@ tunnel(int tun_fd, int dns_fd)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
17
src/user.c
17
src/user.c
@ -53,23 +53,6 @@ init_users(in_addr_t my_ip)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
users_waiting_on_reply()
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
ret = 0;
|
||||
for (i = 0; i < USERS; i++) {
|
||||
if (users[i].active && users[i].last_pkt + 60 > time(NULL) &&
|
||||
users[i].q.id != 0) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
find_user_by_ip(uint32_t ip)
|
||||
{
|
||||
|
@ -35,7 +35,6 @@ struct user {
|
||||
extern struct user users[USERS];
|
||||
|
||||
void init_users(in_addr_t);
|
||||
int users_waiting_on_reply();
|
||||
int find_user_by_ip(uint32_t);
|
||||
int all_users_waiting_to_send();
|
||||
int find_available_user();
|
||||
|
24
tests/user.c
24
tests/user.c
@ -46,29 +46,6 @@ START_TEST(test_init_users)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_users_waiting)
|
||||
{
|
||||
in_addr_t ip;
|
||||
|
||||
ip = inet_addr("127.0.0.1");
|
||||
init_users(ip);
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
users[3].active = 1;
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
users[3].last_pkt = time(NULL);
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
users[3].q.id = 1;
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 1);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_find_user_by_ip)
|
||||
{
|
||||
in_addr_t ip;
|
||||
@ -153,7 +130,6 @@ test_user_create_tests()
|
||||
|
||||
tc = tcase_create("User");
|
||||
tcase_add_test(tc, test_init_users);
|
||||
tcase_add_test(tc, test_users_waiting);
|
||||
tcase_add_test(tc, test_find_user_by_ip);
|
||||
tcase_add_test(tc, test_all_users_waiting_to_send);
|
||||
tcase_add_test(tc, test_find_available_user);
|
||||
|
Loading…
Reference in New Issue
Block a user