Rework code. Buffering was not a good idea
This commit is contained in:
parent
a84560c76b
commit
b6e31d7bdc
10 changed files with 83 additions and 14 deletions
|
@ -10,7 +10,7 @@ RUN mkdir out && \
|
||||||
ninja
|
ninja
|
||||||
|
|
||||||
FROM fedora:29
|
FROM fedora:29
|
||||||
RUN dnf install -y glib2 tor
|
RUN dnf install -y glib2 tor valgrind
|
||||||
WORKDIR /home/donar
|
WORKDIR /home/donar
|
||||||
RUN mkdir /home/donar/shared && mkdir /home/donar/res && chown -R 1000 /home/donar
|
RUN mkdir /home/donar/shared && mkdir /home/donar/res && chown -R 1000 /home/donar
|
||||||
USER 1000
|
USER 1000
|
||||||
|
|
|
@ -25,14 +25,22 @@ mkdir -p ./{xp1-shared,xp1-res}
|
||||||
sudo chown -R 1000 ./{xp1-shared,xp1-res}
|
sudo chown -R 1000 ./{xp1-shared,xp1-res}
|
||||||
|
|
||||||
sudo docker run -t -i \
|
sudo docker run -t -i \
|
||||||
|
--privileged \
|
||||||
-v `pwd`/xp1-shared:/home/donar/shared \
|
-v `pwd`/xp1-shared:/home/donar/shared \
|
||||||
registry.gitlab.inria.fr/qdufour/donar \
|
registry.gitlab.inria.fr/qdufour/donar \
|
||||||
xp1-server
|
xp1-server
|
||||||
|
|
||||||
sudo docker run -t -i \
|
sudo docker run -t -i \
|
||||||
|
--privileged \
|
||||||
-v `pwd`/xp1-res:/home/donar/res \
|
-v `pwd`/xp1-res:/home/donar/res \
|
||||||
-v `pwd`/xp1-shared:/home/donar/shared \
|
-v `pwd`/xp1-shared:/home/donar/shared \
|
||||||
registry.gitlab.inria.fr/qdufour/donar \
|
registry.gitlab.inria.fr/qdufour/donar \
|
||||||
xp1-client 1000 100 100
|
xp1-client 1000 100 100
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Run an XP instance
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo ./scripts/xp1 1000 100 100
|
||||||
|
```
|
||||||
|
|
34
scripts/xp1
Executable file
34
scripts/xp1
Executable file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Create workdir
|
||||||
|
XP_FOLDER=`mktemp -d -p . xp1-XXXXXXXXXXXXXXXX`
|
||||||
|
mkdir -p $XP_FOLDER
|
||||||
|
cd $XP_FOLDER
|
||||||
|
|
||||||
|
# Create folders
|
||||||
|
mkdir -p ./{shared,log,res}
|
||||||
|
chown -R 1000 ./{shared,log,res}
|
||||||
|
|
||||||
|
# Run server
|
||||||
|
docker run \
|
||||||
|
--privileged \
|
||||||
|
--rm \
|
||||||
|
-v `pwd`/shared:/home/donar/shared \
|
||||||
|
-v `pwd`/log:/home/donar/log \
|
||||||
|
registry.gitlab.inria.fr/qdufour/donar \
|
||||||
|
xp1-server &
|
||||||
|
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
# Run client
|
||||||
|
docker run \
|
||||||
|
--privileged \
|
||||||
|
--rm \
|
||||||
|
-v `pwd`/res:/home/donar/res \
|
||||||
|
-v `pwd`/shared:/home/donar/shared \
|
||||||
|
-v `pwd`/log:/home/donar/log \
|
||||||
|
registry.gitlab.inria.fr/qdufour/donar \
|
||||||
|
xp1-client $1 $2 $3
|
||||||
|
|
||||||
|
# Kill server
|
||||||
|
kill %1
|
|
@ -1,7 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
tor -f /etc/torrc &
|
mkdir -p ./log
|
||||||
|
tor -f /etc/torrc > ./log/client-tor-stdout.log 2> ./log/client-tor-stderr.log &
|
||||||
sleep 2
|
sleep 2
|
||||||
mkdir -p ./shared
|
mkdir -p ./shared
|
||||||
donar -a naive -c -o ./shared/onion_services.pub -r 9000 &
|
valgrind donar -a naive -c -o ./shared/onion_services.pub -r 9000 > ./log/client-donar-stdout.log 2> ./log/client-donar-stderr.log &
|
||||||
measlat -h 127.13.3.7 -p 9000 # Used to wait for connections
|
sleep 2
|
||||||
measlat -h 127.13.3.7 -p 9000 -c $1 -i $2 -s $3 > `mktemp -p ./res res-XXXXXXXXXXXXXXXX.txt`
|
measlat -h 127.13.3.7 -p 9000 > /dev/null 2>&1 # Used to wait for connections
|
||||||
|
measlat -h 127.13.3.7 -p 9000 -c $1 -i $2 -s $3 > `mktemp -p ./res res-XXXXXXXXXXXXXXXX.txt` 2> ./log/client-measlat-stderr.log
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
tor -f /etc/torrc &
|
mkdir -p ./log
|
||||||
|
tor -f /etc/torrc > ./log/server-tor-stdout.log 2> ./log/server-tor-stderr.log &
|
||||||
sleep 2
|
sleep 2
|
||||||
mkdir -p ./shared
|
mkdir -p ./shared
|
||||||
cd ./shared
|
cd ./shared
|
||||||
pwd
|
pwd
|
||||||
donar -a naive -s -e 9000 &
|
valgrind donar -a naive -s -e 9000 > ../log/server-donar-stdout.log 2> ../log/server-donar-stderr.log &
|
||||||
udpecho -p 9000
|
udpecho -p 9000 > ../log/server-udpecho-stdout.log 2> ../log/server-udpecho-stderr.log
|
||||||
|
|
|
@ -13,6 +13,7 @@ void free_port (void* ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
printf("~ Donar ~\n");
|
printf("~ Donar ~\n");
|
||||||
|
|
||||||
int opt, is_server, is_client, errored;
|
int opt, is_server, is_client, errored;
|
||||||
|
|
|
@ -67,13 +67,20 @@ int configure_tcp_clients(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdin
|
||||||
case SOCKS5_STATE_ACK:
|
case SOCKS5_STATE_ACK:
|
||||||
//@FIXME: We suppose that we will be able to do the whole read at once which is wrong too
|
//@FIXME: We suppose that we will be able to do the whole read at once which is wrong too
|
||||||
err = socks5_reply (fdinfo->fd);
|
err = socks5_reply (fdinfo->fd);
|
||||||
fprintf(stderr, "captured err: %d\n", err);
|
if (err == -SOCKS5_REP_GENERAL_FAILURE || err == -SOCKS5_REP_TTLEXP || err == -SOCKS5_REP_HOSTUNREACH) {
|
||||||
if (err < 0) goto on_socks5_err;
|
fprintf(stderr, "%s is not ready, received %s\n", fdinfo->url, socks5_rep(-err));
|
||||||
|
goto on_socks5_err;
|
||||||
|
} else if (err < 0) {
|
||||||
|
fprintf(stderr, "An other error occured on %s\n", fdinfo->url);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
app_ctx->client_sock[pos].state = SOCKS5_STATE_RDY;
|
app_ctx->client_sock[pos].state = SOCKS5_STATE_RDY;
|
||||||
int sock1, sock2;
|
int sock1, sock2;
|
||||||
sock1 = dup(fdinfo->fd);
|
sock1 = dup(fdinfo->fd);
|
||||||
sock2 = dup(fdinfo->fd);
|
sock2 = dup(fdinfo->fd);
|
||||||
if (sock1 < 0 || sock2 < 0) goto on_socks5_err;
|
if (sock1 < 0 || sock2 < 0) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
void* fdcat = evt_core_rm_fd (ctx, fdinfo->fd);
|
void* fdcat = evt_core_rm_fd (ctx, fdinfo->fd);
|
||||||
if (fdcat == NULL) {
|
if (fdcat == NULL) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -107,10 +114,9 @@ int configure_tcp_clients(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdin
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
on_socks5_err:
|
on_socks5_err:
|
||||||
perror("An error occured while connecting to an Onion Service");
|
//perror("An error occured while connecting to an Onion Service");
|
||||||
app_ctx->client_sock[pos].state = SOCKS5_STATE_ERR;
|
app_ctx->client_sock[pos].state = SOCKS5_STATE_ERR;
|
||||||
evt_core_rm_fd (ctx, fdinfo->fd);
|
evt_core_rm_fd (ctx, fdinfo->fd);
|
||||||
perror("0");
|
|
||||||
sleep(2);
|
sleep(2);
|
||||||
init_tcp_client (app_ctx, pos);
|
init_tcp_client (app_ctx, pos);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -178,7 +178,7 @@ void evt_core_loop(struct evt_core_ctx* ctx) {
|
||||||
if (fdinfo != NULL) {
|
if (fdinfo != NULL) {
|
||||||
if (fdinfo->cat->err_cb != NULL) {
|
if (fdinfo->cat->err_cb != NULL) {
|
||||||
if (fdinfo->cat->err_cb(ctx, fdinfo) == 1) {
|
if (fdinfo->cat->err_cb(ctx, fdinfo) == 1) {
|
||||||
fprintf(stderr, "fd=%d on cat=%s is handled by app\n", err_fd, fdinfo->cat->name);
|
fprintf(stderr, "Error on fd=%d on cat=%s is handled by app, not clearing it\n", err_fd, fdinfo->cat->name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,3 +104,7 @@ int socks5_connect_dns(int sock, char* addr, uint16_t port) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* socks5_rep (enum socks5_rep rep) {
|
||||||
|
return rep_msg[rep];
|
||||||
|
}
|
||||||
|
|
13
src/socks5.h
13
src/socks5.h
|
@ -36,6 +36,18 @@ union socks5_addr {
|
||||||
uint8_t ipv6[16];
|
uint8_t ipv6[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum socks5_rep {
|
||||||
|
SOCKS5_REP_SUCCESS,
|
||||||
|
SOCKS5_REP_GENERAL_FAILURE,
|
||||||
|
SOCKS5_REP_CONOTALLOWED,
|
||||||
|
SOCKS5_REP_NETUNREACH,
|
||||||
|
SOCKS5_REP_HOSTUNREACH,
|
||||||
|
SOCKS5_REP_COREFUSED,
|
||||||
|
SOCKS5_REP_TTLEXP,
|
||||||
|
SOCKS5_REP_CMDNOTSUP,
|
||||||
|
SOCKS5_REP_ADDRNOTSUP
|
||||||
|
};
|
||||||
|
|
||||||
static char* rep_msg[] = {
|
static char* rep_msg[] = {
|
||||||
"Succeeded",
|
"Succeeded",
|
||||||
"General SOCKS server failure",
|
"General SOCKS server failure",
|
||||||
|
@ -87,3 +99,4 @@ int socks5_handshake_syn(int sock);
|
||||||
int socks5_handshake_ack(int sock);
|
int socks5_handshake_ack(int sock);
|
||||||
int socks5_connect_dns(int sock, char* addr, uint16_t port);
|
int socks5_connect_dns(int sock, char* addr, uint16_t port);
|
||||||
int socks5_reply(int sock);
|
int socks5_reply(int sock);
|
||||||
|
char* socks5_rep (enum socks5_rep rep);
|
||||||
|
|
Loading…
Reference in a new issue