heck yeah tests
This commit is contained in:
Binary file not shown.
+40
-5
@@ -23,7 +23,12 @@ char my_ip[IP_LEN];
|
|||||||
char my_port[PORT_LEN];
|
char my_port[PORT_LEN];
|
||||||
|
|
||||||
csc_file_t* cascade_files[64];
|
csc_file_t* cascade_files[64];
|
||||||
int cascade_amount;
|
int cascade_amount = 0;
|
||||||
|
|
||||||
|
pthread_t* clients[64];
|
||||||
|
int client_amount = 0;
|
||||||
|
|
||||||
|
int download_only;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Frees global resources that are malloc'ed during peer downloads.
|
* Frees global resources that are malloc'ed during peer downloads.
|
||||||
@@ -249,6 +254,8 @@ csc_file_t* csc_parse_file(const char* sourcefile)
|
|||||||
outputfile[strlen(sourcefile)-8] = '\0';
|
outputfile[strlen(sourcefile)-8] = '\0';
|
||||||
casc_file_data->outputfile = outputfile;
|
casc_file_data->outputfile = outputfile;
|
||||||
printf("Downloading to: %s\n", casc_file_data->outputfile);
|
printf("Downloading to: %s\n", casc_file_data->outputfile);
|
||||||
|
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
casc_file_data->mutex = mutex;
|
||||||
|
|
||||||
casc_file_data->targetsize = be64toh(*((unsigned long long*)&header[16]));
|
casc_file_data->targetsize = be64toh(*((unsigned long long*)&header[16]));
|
||||||
casc_file_data->blocksize = be64toh(*((unsigned long long*)&header[24]));
|
casc_file_data->blocksize = be64toh(*((unsigned long long*)&header[24]));
|
||||||
@@ -685,7 +692,11 @@ void client_mt(void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void start_peer(char* cascade_file){
|
void start_peer(char* cascade_file){
|
||||||
printf("Managing download only for: %s\n", cascade_file);
|
if (download_only) {
|
||||||
|
printf("Starting download only peer for: %s\n", cascade_file);
|
||||||
|
} else {
|
||||||
|
printf("Starting peer for: %s\n", cascade_file);
|
||||||
|
}
|
||||||
if (access(cascade_file, F_OK ) != 0 )
|
if (access(cascade_file, F_OK ) != 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr, ">> File %s does not exist\n", cascade_file);
|
fprintf(stderr, ">> File %s does not exist\n", cascade_file);
|
||||||
@@ -702,11 +713,18 @@ void start_peer(char* cascade_file){
|
|||||||
pthread_t client;
|
pthread_t client;
|
||||||
|
|
||||||
|
|
||||||
// subscribe to peer
|
// subscribe to peer or get peers
|
||||||
|
if (download_only) {
|
||||||
|
casc_file->peercount = send_tracker_request(&(casc_file->peers), casc_file->cascadehash, 1);
|
||||||
|
} else {
|
||||||
casc_file->peercount = send_tracker_request(&(casc_file->peers), casc_file->cascadehash, 2);
|
casc_file->peercount = send_tracker_request(&(casc_file->peers), casc_file->cascadehash, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!casc_file->completed){
|
||||||
pthread_create(&client, NULL, client_mt, (void*)casc_file);
|
pthread_create(&client, NULL, client_mt, (void*)casc_file);
|
||||||
|
clients[client_amount] = &client;
|
||||||
|
client_amount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -716,7 +734,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
if (argc != MAIN_ARGNUM + 1)
|
if (argc != MAIN_ARGNUM + 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s <cascade file(s)> <tracker server ip> <tracker server port> <peer ip> <peer port>.\n", argv[0]);
|
fprintf(stderr, "Usage: %s <cascade file(s)> <tracker server ip> <tracker server port> <peer ip> <peer port> (p|d).\n", argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
else if (!is_valid_ip(argv[2]))
|
else if (!is_valid_ip(argv[2]))
|
||||||
@@ -739,12 +757,19 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, ">> Invalid peer port: %s\n", argv[5]);
|
fprintf(stderr, ">> Invalid peer port: %s\n", argv[5]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
else if (!(memcmp(argv[6], "d", 1) == 0 || memcmp(argv[6], "p", 1) == 0))
|
||||||
|
{
|
||||||
|
fprintf(stderr, ">> Invalid role: '%s'\n", argv[6]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(tracker_ip, IP_LEN, argv[2]);
|
snprintf(tracker_ip, IP_LEN, argv[2]);
|
||||||
snprintf(tracker_port, PORT_LEN, argv[3]);
|
snprintf(tracker_port, PORT_LEN, argv[3]);
|
||||||
snprintf(my_ip, IP_LEN, argv[4]);
|
snprintf(my_ip, IP_LEN, argv[4]);
|
||||||
snprintf(my_port, PORT_LEN, argv[5]);
|
snprintf(my_port, PORT_LEN, argv[5]);
|
||||||
|
|
||||||
|
download_only = (memcmp(argv[6], "d", 1) == 0);
|
||||||
|
|
||||||
char cas_str[strlen(argv[1])];
|
char cas_str[strlen(argv[1])];
|
||||||
snprintf(cas_str, strlen(argv[1])+1, argv[1]);
|
snprintf(cas_str, strlen(argv[1])+1, argv[1]);
|
||||||
char delim[] = ":";
|
char delim[] = ":";
|
||||||
@@ -771,14 +796,24 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pthread_t server;
|
pthread_t server;
|
||||||
|
if (!download_only) {
|
||||||
pthread_create(&server, NULL, server_mt, NULL);
|
pthread_create(&server, NULL, server_mt, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
for (int j=0; j<casc_count; j++)
|
for (int j=0; j<casc_count; j++)
|
||||||
{
|
{
|
||||||
start_peer(cascade_files[j]);
|
start_peer(cascade_files[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int j=0; j<client_amount; j++) {
|
||||||
|
pthread_join(*clients[j], NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!download_only) {
|
||||||
pthread_join(server, NULL);
|
pthread_join(server, NULL);
|
||||||
|
} else {
|
||||||
|
printf("Fully downloaded all files\n");
|
||||||
|
}
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#ifndef CASCADE_H
|
#ifndef CASCADE_H
|
||||||
#define CASCADE_H
|
#define CASCADE_H
|
||||||
#define MAIN_ARGNUM 5 // number of command line arguments to main().
|
#define MAIN_ARGNUM 6 // number of command line arguments to main().
|
||||||
#define BODY_SIZE 38
|
#define BODY_SIZE 38
|
||||||
#define HEADER_SIZE 16
|
#define HEADER_SIZE 16
|
||||||
#define MESSAGE_SIZE 54
|
#define MESSAGE_SIZE 54
|
||||||
|
|||||||
Executable
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Executable
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#! /usr/bin/bash
|
||||||
|
|
||||||
|
# Deletes previously downloaded files from the downloading peer
|
||||||
|
rm ./peer2/*.txt
|
||||||
|
|
||||||
|
# Runs the peer
|
||||||
|
./peer1/cascade ./peer1/shakespeare.1kib.txt.cascade 127.0.0.1 8888 127.0.0.1 5555 p &
|
||||||
|
|
||||||
|
# Runs the downloading client
|
||||||
|
./peer2/cascade ./peer2/shakespeare.1kib.txt.cascade 127.0.0.1 8888 127.0.0.1 5556 d
|
||||||
|
|
||||||
|
# Kills the peer
|
||||||
|
killall cascade
|
||||||
Reference in New Issue
Block a user