heck yeah tests
This commit is contained in:
BIN
A4/src/cascade
BIN
A4/src/cascade
Binary file not shown.
@ -23,7 +23,12 @@ char my_ip[IP_LEN];
|
||||
char my_port[PORT_LEN];
|
||||
|
||||
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.
|
||||
@ -249,6 +254,8 @@ csc_file_t* csc_parse_file(const char* sourcefile)
|
||||
outputfile[strlen(sourcefile)-8] = '\0';
|
||||
casc_file_data->outputfile = 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->blocksize = be64toh(*((unsigned long long*)&header[24]));
|
||||
@ -618,7 +625,7 @@ void server_mt() {
|
||||
request->peer_address = peer_address;
|
||||
request->rio = rio;
|
||||
request->socket = new_socket;
|
||||
|
||||
|
||||
pthread_create(&request_handler, NULL, service_block_request, (void*)request);
|
||||
//pthread_join(&request_handler, NULL);
|
||||
}
|
||||
@ -685,7 +692,11 @@ void client_mt(void* arg) {
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
fprintf(stderr, ">> File %s does not exist\n", cascade_file);
|
||||
@ -702,11 +713,18 @@ void start_peer(char* cascade_file){
|
||||
pthread_t client;
|
||||
|
||||
|
||||
// subscribe to peer
|
||||
casc_file->peercount = send_tracker_request(&(casc_file->peers), casc_file->cascadehash, 2);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
pthread_create(&client, NULL, client_mt, (void*)casc_file);
|
||||
if (!casc_file->completed){
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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]);
|
||||
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_port, PORT_LEN, argv[3]);
|
||||
snprintf(my_ip, IP_LEN, argv[4]);
|
||||
snprintf(my_port, PORT_LEN, argv[5]);
|
||||
|
||||
download_only = (memcmp(argv[6], "d", 1) == 0);
|
||||
|
||||
char cas_str[strlen(argv[1])];
|
||||
snprintf(cas_str, strlen(argv[1])+1, argv[1]);
|
||||
char delim[] = ":";
|
||||
@ -771,14 +796,24 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
pthread_t server;
|
||||
pthread_create(&server, NULL, server_mt, NULL);
|
||||
if (!download_only) {
|
||||
pthread_create(&server, NULL, server_mt, NULL);
|
||||
}
|
||||
|
||||
for (int j=0; j<casc_count; j++)
|
||||
{
|
||||
start_peer(cascade_files[j]);
|
||||
}
|
||||
|
||||
pthread_join(server, NULL);
|
||||
for (int j=0; j<client_amount; j++) {
|
||||
pthread_join(*clients[j], NULL);
|
||||
}
|
||||
|
||||
if (!download_only) {
|
||||
pthread_join(server, NULL);
|
||||
} else {
|
||||
printf("Fully downloaded all files\n");
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#ifndef 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 HEADER_SIZE 16
|
||||
#define MESSAGE_SIZE 54
|
||||
|
BIN
A4/testing/peer1/cascade
Executable file
BIN
A4/testing/peer1/cascade
Executable file
Binary file not shown.
124456
A4/testing/peer1/shakespeare.100kib.txt
Normal file
124456
A4/testing/peer1/shakespeare.100kib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer1/shakespeare.100kib.txt.cascade
Normal file
BIN
A4/testing/peer1/shakespeare.100kib.txt.cascade
Normal file
Binary file not shown.
124456
A4/testing/peer1/shakespeare.10kib.txt
Normal file
124456
A4/testing/peer1/shakespeare.10kib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer1/shakespeare.10kib.txt.cascade
Normal file
BIN
A4/testing/peer1/shakespeare.10kib.txt.cascade
Normal file
Binary file not shown.
124456
A4/testing/peer1/shakespeare.10mib.txt
Normal file
124456
A4/testing/peer1/shakespeare.10mib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer1/shakespeare.10mib.txt.cascade
Normal file
BIN
A4/testing/peer1/shakespeare.10mib.txt.cascade
Normal file
Binary file not shown.
124456
A4/testing/peer1/shakespeare.1kib.txt
Normal file
124456
A4/testing/peer1/shakespeare.1kib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer1/shakespeare.1kib.txt.cascade
Normal file
BIN
A4/testing/peer1/shakespeare.1kib.txt.cascade
Normal file
Binary file not shown.
124456
A4/testing/peer1/shakespeare.1mib.txt
Normal file
124456
A4/testing/peer1/shakespeare.1mib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer1/shakespeare.1mib.txt.cascade
Normal file
BIN
A4/testing/peer1/shakespeare.1mib.txt.cascade
Normal file
Binary file not shown.
BIN
A4/testing/peer2/cascade
Executable file
BIN
A4/testing/peer2/cascade
Executable file
Binary file not shown.
124456
A4/testing/peer2/shakespeare.100kib.txt
Normal file
124456
A4/testing/peer2/shakespeare.100kib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer2/shakespeare.100kib.txt.cascade
Normal file
BIN
A4/testing/peer2/shakespeare.100kib.txt.cascade
Normal file
Binary file not shown.
90551
A4/testing/peer2/shakespeare.10kib.txt
Normal file
90551
A4/testing/peer2/shakespeare.10kib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer2/shakespeare.10kib.txt.cascade
Normal file
BIN
A4/testing/peer2/shakespeare.10kib.txt.cascade
Normal file
Binary file not shown.
0
A4/testing/peer2/shakespeare.10mib.txt
Normal file
0
A4/testing/peer2/shakespeare.10mib.txt
Normal file
BIN
A4/testing/peer2/shakespeare.10mib.txt.cascade
Normal file
BIN
A4/testing/peer2/shakespeare.10mib.txt.cascade
Normal file
Binary file not shown.
124456
A4/testing/peer2/shakespeare.1kib.txt
Normal file
124456
A4/testing/peer2/shakespeare.1kib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer2/shakespeare.1kib.txt.cascade
Normal file
BIN
A4/testing/peer2/shakespeare.1kib.txt.cascade
Normal file
Binary file not shown.
119485
A4/testing/peer2/shakespeare.1mib.txt
Normal file
119485
A4/testing/peer2/shakespeare.1mib.txt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
A4/testing/peer2/shakespeare.1mib.txt.cascade
Normal file
BIN
A4/testing/peer2/shakespeare.1mib.txt.cascade
Normal file
Binary file not shown.
13
A4/testing/test.sh
Executable file
13
A4/testing/test.sh
Executable file
@ -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