2019-02-08 13:28:39 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2019-02-11 21:40:00 +00:00
|
|
|
#include "algo_skel.h"
|
2019-02-11 09:23:38 +00:00
|
|
|
#include "donar_client.h"
|
|
|
|
#include "donar_server.h"
|
2019-02-08 13:28:39 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
printf("~ Donar ~\n");
|
2019-02-11 09:23:38 +00:00
|
|
|
|
|
|
|
int opt, is_server, is_client = 0;
|
|
|
|
while ((opt = getopt(argc, argv, "cs")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 's':
|
|
|
|
is_server = 1;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
is_client = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Usage: %s [-c | -s]\n", argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(is_server ^ is_client)) {
|
|
|
|
fprintf(stderr, "2Usage: %s [-c | -s]\n", argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-02-11 15:23:20 +00:00
|
|
|
if (is_server) {
|
|
|
|
struct donar_server_ctx ctx;
|
2019-02-11 21:40:00 +00:00
|
|
|
struct algo_skel as;
|
|
|
|
algo_naive (&as);
|
|
|
|
donar_server(&ctx, &as);
|
2019-02-11 15:23:20 +00:00
|
|
|
} else if (is_client) {
|
|
|
|
donar_client();
|
|
|
|
}
|
2019-02-11 09:23:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
/*
|
2019-02-08 13:28:39 +00:00
|
|
|
int sock;
|
|
|
|
|
|
|
|
struct tor_os_str tos;
|
2019-02-11 08:53:00 +00:00
|
|
|
tor_os_create (&tos, "onion_services.pub", "onion_services.txt", 10);
|
2019-02-08 16:37:02 +00:00
|
|
|
tor_os_read (&tos);
|
|
|
|
|
|
|
|
int ports[10] = { 7500, 7501, 7502, 7503, 7504, 7505, 7506, 7507, 7508, 7509};
|
|
|
|
int err = 0;
|
|
|
|
struct tor_ctl tctl = {};
|
|
|
|
err = tor_ctl_connect (&tctl, "127.0.0.1", "9051");
|
|
|
|
if (err < 0) {
|
|
|
|
fprintf(stderr, "Unable to open Tor Socket\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
err = tor_ctl_add_onion (&tctl, &tos, ports);
|
|
|
|
if (err != 0) {
|
|
|
|
fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
tor_ctl_close (&tctl);
|
2019-02-08 13:28:39 +00:00
|
|
|
tor_os_free (&tos);
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
fprintf(stderr, "Insufficient arguments\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
sock = create_tcp_client(argv[1], argv[2]);
|
|
|
|
socks5_handshake(sock);
|
|
|
|
socks5_connect_dns(sock, "monip.org", 80);
|
|
|
|
socks5_reply(sock);
|
|
|
|
|
|
|
|
char* req = "GET / HTTP/1.0\r\nHost: monip.org\r\n\r\n";
|
|
|
|
size_t req_len = strlen(req);
|
|
|
|
if (req_len != write(sock, req, req_len)) {
|
|
|
|
fprintf(stderr, "partial/failed write\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
char page[256];
|
|
|
|
size_t nread = 0;
|
|
|
|
while ((nread = read(sock, page, sizeof(char) * 255)) > 0) {
|
|
|
|
//printf("%s\n", nread);
|
|
|
|
fwrite(page, nread, 1, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(sock);
|
|
|
|
exit(EXIT_SUCCESS);
|
2019-02-11 09:23:38 +00:00
|
|
|
*/
|
2019-02-08 13:28:39 +00:00
|
|
|
}
|