Rework code. Buffering was not a good idea

This commit is contained in:
Quentin Dufour 2019-03-06 16:39:39 +01:00
parent a84560c76b
commit b6e31d7bdc
10 changed files with 83 additions and 14 deletions

View file

@ -10,7 +10,7 @@ RUN mkdir out && \
ninja
FROM fedora:29
RUN dnf install -y glib2 tor
RUN dnf install -y glib2 tor valgrind
WORKDIR /home/donar
RUN mkdir /home/donar/shared && mkdir /home/donar/res && chown -R 1000 /home/donar
USER 1000

View file

@ -25,14 +25,22 @@ mkdir -p ./{xp1-shared,xp1-res}
sudo chown -R 1000 ./{xp1-shared,xp1-res}
sudo docker run -t -i \
--privileged \
-v `pwd`/xp1-shared:/home/donar/shared \
registry.gitlab.inria.fr/qdufour/donar \
xp1-server
sudo docker run -t -i \
--privileged \
-v `pwd`/xp1-res:/home/donar/res \
-v `pwd`/xp1-shared:/home/donar/shared \
registry.gitlab.inria.fr/qdufour/donar \
xp1-client 1000 100 100
```
## Run an XP instance
```
sudo ./scripts/xp1 1000 100 100
```

34
scripts/xp1 Executable file
View 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

View file

@ -1,7 +1,9 @@
#!/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
mkdir -p ./shared
donar -a naive -c -o ./shared/onion_services.pub -r 9000 &
measlat -h 127.13.3.7 -p 9000 # 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`
valgrind donar -a naive -c -o ./shared/onion_services.pub -r 9000 > ./log/client-donar-stdout.log 2> ./log/client-donar-stderr.log &
sleep 2
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

View file

@ -1,8 +1,9 @@
#!/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
mkdir -p ./shared
cd ./shared
pwd
donar -a naive -s -e 9000 &
udpecho -p 9000
valgrind donar -a naive -s -e 9000 > ../log/server-donar-stdout.log 2> ../log/server-donar-stderr.log &
udpecho -p 9000 > ../log/server-udpecho-stdout.log 2> ../log/server-udpecho-stderr.log

View file

@ -13,6 +13,7 @@ void free_port (void* ptr) {
}
int main(int argc, char** argv) {
setvbuf(stdout, NULL, _IONBF, 0);
printf("~ Donar ~\n");
int opt, is_server, is_client, errored;

View file

@ -67,13 +67,20 @@ int configure_tcp_clients(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdin
case SOCKS5_STATE_ACK:
//@FIXME: We suppose that we will be able to do the whole read at once which is wrong too
err = socks5_reply (fdinfo->fd);
fprintf(stderr, "captured err: %d\n", err);
if (err < 0) goto on_socks5_err;
if (err == -SOCKS5_REP_GENERAL_FAILURE || err == -SOCKS5_REP_TTLEXP || err == -SOCKS5_REP_HOSTUNREACH) {
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;
int sock1, sock2;
sock1 = 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);
if (fdcat == NULL) {
exit(EXIT_FAILURE);
@ -107,10 +114,9 @@ int configure_tcp_clients(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdin
return 1;
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;
evt_core_rm_fd (ctx, fdinfo->fd);
perror("0");
sleep(2);
init_tcp_client (app_ctx, pos);
return 1;

View file

@ -178,7 +178,7 @@ void evt_core_loop(struct evt_core_ctx* ctx) {
if (fdinfo != NULL) {
if (fdinfo->cat->err_cb != NULL) {
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;
}
}

View file

@ -104,3 +104,7 @@ int socks5_connect_dns(int sock, char* addr, uint16_t port) {
}
return 0;
}
char* socks5_rep (enum socks5_rep rep) {
return rep_msg[rep];
}

View file

@ -36,6 +36,18 @@ union socks5_addr {
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[] = {
"Succeeded",
"General SOCKS server failure",
@ -87,3 +99,4 @@ int socks5_handshake_syn(int sock);
int socks5_handshake_ack(int sock);
int socks5_connect_dns(int sock, char* addr, uint16_t port);
int socks5_reply(int sock);
char* socks5_rep (enum socks5_rep rep);