Skip to content

Commit

Permalink
clean version barring the fact that there is a free() error on close,…
Browse files Browse the repository at this point in the history
… have to look into it
  • Loading branch information
millerjs committed Sep 28, 2013
1 parent 52721b7 commit 33eae55
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 157 deletions.
3 changes: 2 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ DIR = $(shell pwd)
APP = udtcat
APPOUT = uc

all: $(APP)
all: $(APP) sendfile

%.o: %.cpp
$(C++) $(CCFLAGS) $< -c

udtcat: udtcat.o udtcat_threads.o udtcat_server.o udtcat_client.o crypto.o
$(C++) $^ -o $(APPOUT) $(LDFLAGS)
cp $(APPOUT) $(APP)

clean:
rm -f *.o $(APPOUT)
Expand Down
2 changes: 1 addition & 1 deletion src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and limitations under the License.
#ifndef CRYPTO_H
#define CRYPTO_H

#define N_CRYPTO_THREADS 16
#define N_CRYPTO_THREADS 8

#define PASSPHRASE_SIZE 32
#define HEX_PASSPHRASE_SIZE 64
Expand Down
106 changes: 0 additions & 106 deletions src/sendfile

This file was deleted.

48 changes: 24 additions & 24 deletions src/udtcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ int main(int argc, char *argv[]){
initialize_thread_args(&args);
int use_crypto = 0;
int verbose = 0;
char* path_to_password = NULL;
char* password = NULL;
char* path_to_key = NULL;
char* key = NULL;

// ----------- [ Read in options
while ((opt = getopt (argc, argv, "hvnlp:f:")) != -1){
Expand All @@ -84,11 +84,11 @@ int main(int argc, char *argv[]){
break;

case 'p':
password = strdup(optarg);
key = strdup(optarg);
break;

case 'f':
path_to_password = strdup(optarg);
path_to_key = strdup(optarg);
break;

case 'h':
Expand All @@ -103,34 +103,34 @@ int main(int argc, char *argv[]){
}
}

if (use_crypto && (path_to_password && password)){
fprintf(stderr, "error: Please specify either password or password file, not both.\n");
if (use_crypto && (path_to_key && key)){
fprintf(stderr, "error: Please specify either key or key file, not both.\n");
exit(1);
}

if (path_to_password){
FILE*password_file = fopen(path_to_password, "r");
if (!password_file){
fprintf(stderr, "password file: %s.\n", strerror(errno));
if (path_to_key){
FILE*key_file = fopen(path_to_key, "r");
if (!key_file){
fprintf(stderr, "key file: %s.\n", strerror(errno));
exit(1);
}

fseek(password_file, 0, SEEK_END);
long size = ftell(password_file);
fseek(password_file, 0, SEEK_SET);
password = (char*)malloc(size);
fread(password, 1, size, password_file);
fseek(key_file, 0, SEEK_END);
long size = ftell(key_file);
fseek(key_file, 0, SEEK_SET);
key = (char*)malloc(size);
fread(key, 1, size, key_file);

}

if (!use_crypto && password){
fprintf(stderr, "warning: You've specified a password, but you don't have encryption turned on.\nProceeding without encryption.\n");
if (!use_crypto && key){
fprintf(stderr, "warning: You've specified a key, but you don't have encryption turned on.\nProceeding without encryption.\n");
}

if (use_crypto && !password){
if (use_crypto && !key){
fprintf(stderr, "Please either: \n (1) %s\n (2) %s\n (3) %s\n",
"include password in cli [-p password]",
"read on in from file [-f /path/to/password/file]",
"include key in cli [-p key]",
"read on in from file [-f /path/to/key/file]",
"choose not to use encryption, remove [-n]");
exit(1);
}
Expand All @@ -157,9 +157,8 @@ int main(int argc, char *argv[]){
if (use_crypto){

char* cipher = (char*) "aes-128";
crypto enc(EVP_ENCRYPT, PASSPHRASE_SIZE, (unsigned char*)password, cipher);
crypto dec(EVP_DECRYPT, PASSPHRASE_SIZE, (unsigned char*)password, cipher);
memset(password, 0, strlen(password));
crypto enc(EVP_ENCRYPT, PASSPHRASE_SIZE, (unsigned char*)key, cipher);
crypto dec(EVP_DECRYPT, PASSPHRASE_SIZE, (unsigned char*)key, cipher);
args.enc = &enc;
args.dec = &dec;

Expand All @@ -170,7 +169,8 @@ int main(int argc, char *argv[]){

}


if (key)
memset(key, 0, strlen(key));

// ----------- [ Spawn correct process
if (operation == SERVER){
Expand Down
1 change: 1 addition & 0 deletions src/udtcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and limitations under the License.
#include "udtcat_threads.h"
#include "crypto.h"

/* #define BUFF_SIZE 327680 */
#define BUFF_SIZE 67108864

typedef struct rs_args{
Expand Down
9 changes: 4 additions & 5 deletions src/udtcat_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int run_client(thread_args *args)
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;

if (0 != getaddrinfo(NULL, port, &hints, &local)){
cerr << "incorrect network address.\n" << endl;
return 1;
Expand All @@ -85,7 +85,7 @@ int run_client(thread_args *args)
UDT::setsockopt(client, 0, UDT_SNDBUF, &udt_buff, sizeof(int));
UDT::setsockopt(client, 0, UDP_SNDBUF, &udp_buff, sizeof(int));

freeaddrinfo(local);
// freeaddrinfo(local);

if (0 != getaddrinfo(ip, port, &hints, &peer)) {
cerr << "incorrect server/peer address. " << ip << ":" << port << endl;
Expand Down Expand Up @@ -127,7 +127,7 @@ int run_client(thread_args *args)
send_args.verbose = args->verbose;
send_args.c = args->enc;

freeaddrinfo(peer);
// freeaddrinfo(peer);

if (blast) {
CUDPBlast* cchandle = NULL;
Expand All @@ -142,9 +142,8 @@ int run_client(thread_args *args)
void * retval;
pthread_join(sndthread, &retval);

UDT::close(client);

UDT::cleanup();

return 0;
}

6 changes: 1 addition & 5 deletions src/udtcat_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,11 @@ int run_server(thread_args *args){
send_args.verbose = args->verbose;
send_args.c = args->enc;

// pthread_create(&sndthread, NULL, senddata, new UDTSOCKET(recver));
pthread_create(&sndthread, NULL, senddata, &send_args);

pthread_join(sndthread, NULL);

UDT::close(serv);

UDT::cleanup();
freeaddrinfo(res);

return 0;
}

Loading

0 comments on commit 33eae55

Please sign in to comment.