This commit is contained in:
Quentin Dufour 2020-01-23 20:44:11 +00:00
commit e0158f1dee
8 changed files with 65 additions and 17 deletions

View file

@ -44,14 +44,17 @@ RUN mkdir out && \
FROM fedora:30 FROM fedora:30
RUN dnf install -y \ RUN dnf install -y \
glib2 \ glib2 \
procps-ng \
valgrind \ valgrind \
nmap-ncat \ nmap-ncat \
psmisc \ psmisc \
libevent \ libevent \
zlib \ zlib \
strace \
openssl \ openssl \
libzstd \ libzstd \
xz-libs \ xz-libs \
moreutils \
gstreamer1 \ gstreamer1 \
gstreamer1-plugins-base \ gstreamer1-plugins-base \
gstreamer1-plugins-good \ gstreamer1-plugins-good \
@ -60,7 +63,7 @@ RUN dnf install -y \
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 0
ENV HOME /home/donar ENV HOME /home/donar
COPY --from=builder /home/donar-build/out/donar /usr/local/bin COPY --from=builder /home/donar-build/out/donar /usr/local/bin
COPY --from=builder /home/donar-build/out/measlat /usr/local/bin COPY --from=builder /home/donar-build/out/measlat /usr/local/bin

View file

@ -5,7 +5,7 @@ cd $5/shared
echo -e 'authenticate ""\nsetevents extended circ circ_minor stream orconn addrmap status_general status_client guard info notice warn err newdesc descchanged ns status_server stream_bw clients_seen hs_desc network_liveness' | \ echo -e 'authenticate ""\nsetevents extended circ circ_minor stream orconn addrmap status_general status_client guard info notice warn err newdesc descchanged ns status_server stream_bw clients_seen hs_desc network_liveness' | \
nc --no-shutdown 127.0.0.1 9051 | \ nc --no-shutdown 127.0.0.1 9051 | \
ts \ ts \
> ../log/server-tor-events-stdout.log 2> ../log/server-tor-events-stderr.log > ../log/server-tor-events-stdout.log 2> ../log/server-tor-events-stderr.log &
donar \ donar \
-a dup2 \ -a dup2 \

View file

@ -4,8 +4,17 @@ cd $6/shared
echo -e 'authenticate ""\nsetevents extended circ circ_minor stream orconn addrmap status_general status_client guard info notice warn err newdesc descchanged ns status_server stream_bw clients_seen hs_desc network_liveness' | \ echo -e 'authenticate ""\nsetevents extended circ circ_minor stream orconn addrmap status_general status_client guard info notice warn err newdesc descchanged ns status_server stream_bw clients_seen hs_desc network_liveness' | \
nc --no-shutdown 127.0.0.1 9051 | \ nc --no-shutdown 127.0.0.1 9051 | \
ts \ ts '<%b %d %H:%M:%.S>' \
> ../log/server-tor-events-stdout.log 2> ../log/server-tor-events-stderr.log > ../log/server-tor-events-stdout.log 2> ../log/server-tor-events-stderr.log &
strace \
-s 800 \
-f \
-e trace=network,epoll_wait,epoll_create,epoll_create1,epoll_ctl,epoll_pwait,close \
-p 1 \
-o /dev/stdout | \
ts '<%b %d %H:%M:%.S>' \
> ../log/server-strace-tor-stdout.log 2> ../log/server-strace-tor-stderr.log &
donar \ donar \
-a lightning \ -a lightning \
@ -16,4 +25,14 @@ donar \
-e 9000 \ -e 9000 \
> ../log/server-donar-stdout.log 2> ../log/server-donar-stderr.log & > ../log/server-donar-stdout.log 2> ../log/server-donar-stderr.log &
sleep 3
strace \
-s 800 \
-f \
-e trace=network,epoll_wait,epoll_create,epoll_create1,epoll_ctl,epoll_pwait,close \
-p `pidof donar` \
-o /dev/stdout | \
ts '<%b %d %H:%M:%.S>' \
> ../log/server-strace-donar-stdout.log 2> ../log/server-strace-donar-stderr.log &
measlat -h 127.0.0.1 -p 9000 -l -c $1 -i $2 -s $3 > ../log/server-measlat-stdout.log 2> ../log/server-measlat-stderr.log measlat -h 127.0.0.1 -p 9000 -l -c $1 -i $2 -s $3 > ../log/server-measlat-stdout.log 2> ../log/server-measlat-stderr.log

View file

@ -101,10 +101,10 @@ int donar_client_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
if (removed == 2) { if (removed == 2) {
fprintf(stdout, "[%s][donar-client] Retriggering socks5 for port %d\n", current_human_datetime (), port); fprintf(stdout, "[%s][donar-client] Retriggering socks5 for port %d\n", current_human_datetime (), port);
init_socks5_client (app_ctx, pos); init_socks5_client (app_ctx, pos);
return 0; return 1;
} else if (removed == 0) { } else if (removed == 0) {
fprintf(stdout, "[%s][donar-client] Socks5 has already been retriggered for port %d\n", current_human_datetime (), port); fprintf(stdout, "[%s][donar-client] Socks5 has already been retriggered for port %d\n", current_human_datetime (), port);
return 0; return 1;
} else { } else {
fprintf(stderr, "[%s][donar-client] We only removed 1 link and not 2 for port %d, strange behaviour, exiting...\n", current_human_datetime (), port); fprintf(stderr, "[%s][donar-client] We only removed 1 link and not 2 for port %d, strange behaviour, exiting...\n", current_human_datetime (), port);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View file

@ -43,6 +43,7 @@ void signal_init(struct evt_core_ctx* evts) {
sigaddset(&mask, SIGINT); sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGQUIT); sigaddset(&mask, SIGQUIT);
sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGPIPE);
if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) { if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) {
perror("sigprocmask"); perror("sigprocmask");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View file

@ -52,9 +52,29 @@ socket_create_err:
} }
struct tor_ctl* ugly_global_tctl; struct tor_ctl* ugly_global_tctl;
int donar_server_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fd) { int donar_server_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
fprintf(stderr, "[%s][donar-server] I am a server, I do nothing with broken streams...\n", current_human_datetime ()); fprintf(stdout, "[%s][donar-server] %s broke\n", current_human_datetime (), fdinfo->url);
tor_ctl_list_onions(ugly_global_tctl);
struct evt_core_fdinfo* fdtarget = NULL;
int port = url_get_port_int (fdinfo->url);
int pos = port - 7500, removed = 0;
char buffer[256];
sprintf(buffer, "tcp:read:127.0.0.1:%d", port);
fdtarget = evt_core_get_from_url (ctx, buffer);
if (fdtarget != NULL) {
evt_core_rm_fd(ctx, fdtarget->fd);
removed++;
}
sprintf(buffer, "tcp:write:127.0.0.1:%d", port);
fdtarget = evt_core_get_from_url (ctx, buffer);
if (fdtarget != NULL) {
evt_core_rm_fd(ctx, fdtarget->fd);
removed++;
}
printf("[%s][donar-server] removed %d links\n", current_human_datetime (), removed);
return 1; return 1;
} }

View file

@ -2,8 +2,11 @@
void free_fdinfo(void* v) { void free_fdinfo(void* v) {
struct evt_core_fdinfo* fdinfo = (struct evt_core_fdinfo*)v; struct evt_core_fdinfo* fdinfo = (struct evt_core_fdinfo*)v;
close(fdinfo->fd); // We close the file descriptor here fprintf(stdout, "[%s][evt_core] Freeing fdinfo url=%s fd=%d\n", current_human_datetime (), fdinfo->url, fdinfo->fd);
//fprintf(stderr, "Freeing fdinfo for %s\n", fdinfo->url); if (close(fdinfo->fd) != 0) { // We close the file descriptor here
fprintf(stderr, "[%s][evt_core] Failed to close fd for url=%s fd=%d. ", current_human_datetime (), fdinfo->url, fdinfo->fd);
perror("Error");
}
if (fdinfo->free_other != NULL) { if (fdinfo->free_other != NULL) {
//fprintf(stderr, "Freeing fdinfo->other for %s\n", fdinfo->url); //fprintf(stderr, "Freeing fdinfo->other for %s\n", fdinfo->url);
fdinfo->free_other(fdinfo->other); fdinfo->free_other(fdinfo->other);
@ -266,7 +269,7 @@ void evt_core_loop(struct evt_core_ctx* ctx) {
timing_fx_start(&tfx_loop); timing_fx_start(&tfx_loop);
if (num_fd == -1) { if (num_fd == -1) {
perror("Failed to epoll_wait"); perror("Failed to epoll_wait");
exit(EXIT_FAILURE); continue;
} }
for (n = 0 ; n < num_fd; n++) { for (n = 0 ; n < num_fd; n++) {
@ -274,8 +277,8 @@ void evt_core_loop(struct evt_core_ctx* ctx) {
if (events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) { if (events[n].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) {
int err_fd = events[n].data.fd; int err_fd = events[n].data.fd;
int evt = events[n].events; int evt = events[n].events;
if (evt & EPOLLRDHUP) fprintf(stderr, "Epoll Read Hup Event.\n"); if (evt & EPOLLRDHUP) fprintf(stderr, "Epoll Read Hup Event fd=%d.\n", err_fd);
if (evt & EPOLLHUP) fprintf(stderr, "Epoll Hup Event.\n"); if (evt & EPOLLHUP) fprintf(stderr, "Epoll Hup Event fd=%d.\n", err_fd);
if (evt & EPOLLERR) { if (evt & EPOLLERR) {
int error = 0; int error = 0;
socklen_t errlen = sizeof(error); socklen_t errlen = sizeof(error);

View file

@ -31,6 +31,8 @@ int main_on_tcp_co(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
sprintf(to_fdinfo.url, "tcp:write:127.0.0.1:%s", port); sprintf(to_fdinfo.url, "tcp:write:127.0.0.1:%s", port);
evt_core_add_fd (ctx, &to_fdinfo); evt_core_add_fd (ctx, &to_fdinfo);
printf("[%s][proxy] Accepted a new connection on port=%s: read_fd=%d, write_fd=%d\n", current_human_datetime (), port, conn_sock1, conn_sock2);
return 0; return 0;
co_error: co_error:
@ -212,7 +214,7 @@ void algo_main_init(struct evt_core_ctx* evt, struct algo_params* ap) {
struct evt_core_cat tcp_read = { struct evt_core_cat tcp_read = {
.name = "tcp-read", .name = "tcp-read",
.flags = EPOLLIN | EPOLLET | EPOLLRDHUP, .flags = EPOLLIN | EPOLLET | EPOLLHUP,
.app_ctx = ctx, .app_ctx = ctx,
.free_app_ctx = algo_main_destroy, .free_app_ctx = algo_main_destroy,
.cb = main_on_tcp_read, .cb = main_on_tcp_read,
@ -223,7 +225,7 @@ void algo_main_init(struct evt_core_ctx* evt, struct algo_params* ap) {
struct evt_core_cat udp_read = { struct evt_core_cat udp_read = {
.name = "udp-read", .name = "udp-read",
.flags = EPOLLIN | EPOLLET | EPOLLRDHUP, .flags = EPOLLIN | EPOLLET,
.app_ctx = ctx, .app_ctx = ctx,
.free_app_ctx = algo_main_destroy, .free_app_ctx = algo_main_destroy,
.cb = main_on_udp_read, .cb = main_on_udp_read,
@ -234,7 +236,7 @@ void algo_main_init(struct evt_core_ctx* evt, struct algo_params* ap) {
struct evt_core_cat tcp_write = { struct evt_core_cat tcp_write = {
.name = "tcp-write", .name = "tcp-write",
.flags = EPOLLOUT | EPOLLET | EPOLLRDHUP, .flags = EPOLLOUT | EPOLLET | EPOLLHUP,
.app_ctx = ctx, .app_ctx = ctx,
.free_app_ctx = algo_main_destroy, .free_app_ctx = algo_main_destroy,
.cb = main_on_tcp_write, .cb = main_on_tcp_write,