Skip to content

Commit

Permalink
complete send file binary
Browse files Browse the repository at this point in the history
  • Loading branch information
millerjs committed Sep 23, 2013
1 parent d8bc9e4 commit 5f92467
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif

DIR = $(shell pwd)

APP = udtcat #test
APP = udtcat
APPOUT = uc

all: $(APP)
Expand Down
7 changes: 4 additions & 3 deletions src/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <openssl/crypto.h>



#include <time.h>

#include <limits.h>
Expand Down Expand Up @@ -70,7 +69,7 @@ static void threadid_func(CRYPTO_THREADID * id)
CRYPTO_THREADID_set_numeric(id, THREAD_ID);
}

// Setups up the mutual exclusion for OpenSSL

int THREAD_setup(void)
{
pris("Setting up threads");
Expand Down Expand Up @@ -206,15 +205,17 @@ int pass_to_enc_thread(pthread_t crypto_threads[N_CRYPTO_THREADS],

pthread_join_disregard_ESRCH(crypto_threads[*curr_crypto_thread], *curr_crypto_thread);

// Initialize and set thread detached attribute
// ----------- [ Initialize and set thread detached attribute
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

// ----------- [ Setup thread
e_args[*curr_crypto_thread].in = (uchar*) in;
e_args[*curr_crypto_thread].len = len;
e_args[*curr_crypto_thread].ctx = &c->ctx[*curr_crypto_thread];

// ----------- [ Spawn thread
int ret = pthread_create(&crypto_threads[*curr_crypto_thread],
&attr, crypto_update_thread, &e_args[*curr_crypto_thread]);

Expand Down
19 changes: 15 additions & 4 deletions src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ and limitations under the License.
#ifndef CRYPTO_H
#define CRYPTO_H


#define N_CRYPTO_THREADS 16
#define N_CRYPTO_THREADS 8
#define USE_CRYPTO 1


#define PASSPHRASE_SIZE 32
#define HEX_PASSPHRASE_SIZE 64
#define EVP_ENCRYPT 1
#define EVP_DECRYPT 0
#define CTR_MODE 1



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -49,6 +51,8 @@ int THREAD_setup(void);
int THREAD_cleanup(void);
void *enrypt_threaded(void* _args);



using namespace std;

typedef unsigned char uchar;
Expand All @@ -60,14 +64,16 @@ class crypto
unsigned char ivec[ 1024 ];
int direction;


int passphrase_size;
int hex_passphrase_size;
public:

public:
// EVP stuff
int thread_id;
EVP_CIPHER_CTX ctx[N_CRYPTO_THREADS];


crypto(int direc, int len, unsigned char* password, char *encryption_type)
{

Expand Down Expand Up @@ -175,12 +181,14 @@ class crypto
};



typedef struct e_thread_args
{
uchar *in;
int len;
crypto *c;
EVP_CIPHER_CTX *ctx;


} e_thread_args;

Expand All @@ -194,5 +202,8 @@ int pass_to_enc_thread(pthread_t crypto_threads[N_CRYPTO_THREADS],
char* in, int len,
crypto*c);




#endif

102 changes: 102 additions & 0 deletions src/sendfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
function Usage(){
cat <<-ENDOFMESSAGE
$0 [options] ip source destination
options:
-p --port specify port to use [default: 9000]
-u --user specify username for ssh connection [default: current user]
-h --help display this message
ENDOFMESSAGE
exit 1
}

function error(){
echo "$*"
exit 1
}

function argCheck(){
if [ $1 -eq 0 -o "${1:0:1}" = "-" ]; then
error "The ${opt} option requires an argument."
fi
}

function getOpts() {
port=9000
user=`whoami`
verbose=0
argv=()
while [ $# -gt 0 ]
do
opt=$1
shift
case ${opt} in
-p|--port)
argCheck $#
port="$1"
shift;;
-u|--user)
argCheck $#
user="$1"
shift;;
-h|--help)
Usage;;
-v|--verbose)
verbose=1;;
*)
if [ "${opt:0:1}" = "-" ]; then
error "${opt}: unknown option."
fi
argv+=(${opt});;
esac
done
}

getOpts $*

ip="${argv[0]}"
src="${argv[1]}"
dest="${argv[2]}"

if [ "$ip" = "" ]; then
error "Please specify the ip address"
fi
if [ "$src" = "" ]; then
error "Please specify the source file"
fi
if [ "$dest" = "" ]; then
error "Please specify the destination file"
fi

if [ "$verbose" == 1 ]; then
cat <<-ENDOFMESSAGE
Transferring
local file : $src
remote dest : $dest
host : $user@$ip
port : $port
ENDOFMESSAGE
fi


# echo "ssh jmiller@localhost 'uc -l 9000 > /home/jmiller/test2 & echo \$!;'"

if [ "$verbose" == 1 ]; then
echo "Sending... "
fi

./uc $ip $port < $src &
ssh $user@$ip "uc -l $port > $dest"

if [ "$verbose" == 1 ]; then
echo "Done."
fs=`du -h $src`
echo "Original file size : $fs"
fs=`ssh $user@$ip "du -h $dest"`
echo "Transferred file size: $fs"
fi
11 changes: 6 additions & 5 deletions src/udtcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void usage(){
}

void initialize_thread_args(thread_args *args){

args->ip = NULL;
args->port = NULL;
args->blast = 0;
Expand All @@ -48,11 +47,11 @@ void initialize_thread_args(thread_args *args){

int main(int argc, char *argv[]){


int opt;
enum {NONE, SERVER, CLIENT};
int operation = CLIENT;

// ----------- [ Read in options
while ((opt = getopt (argc, argv, "l")) != -1){
switch (opt){
case 'l':
Expand All @@ -68,6 +67,7 @@ int main(int argc, char *argv[]){
thread_args args;
initialize_thread_args(&args);

// ----------- [ Setup ip
if (operation == CLIENT){
if (optind < argc){
if (strcmp(argv[optind], "localhost")){
Expand All @@ -83,22 +83,23 @@ int main(int argc, char *argv[]){
}
}

// ----------- [ Check port input
if (optind < argc){
args.port = strdup(argv[optind++]);
} else {
cerr << "error: Please specify port num." << endl;
exit(1);
}


// ----------- [ Initialize crypto
unsigned char* password = (unsigned char*) "12345";
char* cipher = (char*) "aes-128";

crypto enc(EVP_ENCRYPT, PASSPHRASE_SIZE, password, cipher);
crypto dec(EVP_DECRYPT, PASSPHRASE_SIZE, password, cipher);

args.enc = &enc;
args.dec = &dec;

// ----------- [ Spawn correct process
if (operation == SERVER){
run_server(&args);

Expand Down
33 changes: 16 additions & 17 deletions src/udtcat_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,26 @@ int n_recv_threads = 0;
int last_printed = -1;
pthread_mutex_t lock;

/*
THINGS NEEDED IN APPLICATION TO RUN THE MT SUPPORTED CRYPTO:
pthread_t crypto_threads[N_THREADS];
e_thread_args * e_args;
crypto *c;
int* curr_crypto_thread;
*/

// ----------- [ Things needed in application to run the mt supported crypto
// pthread_t crypto_threads[N_THREADS];
// e_thread_args * e_args;
// crypto *c;
// int* curr_crypto_thread;

void* recvdata(void * _args)
{

// Handle socket
// ----------- [ Handle socket
recv_args * args = (recv_args*)_args;
UDTSOCKET recver = *args->usocket;

// Decryption locals
// ----------- [ Decryption locals
int read_len;
e_thread_args e_args[N_CRYPTO_THREADS];

// ----------- [ Crypto variables
e_thread_args e_args[N_CRYPTO_THREADS];
pthread_t decryption_threads[N_CRYPTO_THREADS];

int decrypt_buf_len = BUFF_SIZE / N_CRYPTO_THREADS;
int len, decrypt_cursor, buffer_cursor, curr_crypto_thread;
decrypt_cursor = buffer_cursor = curr_crypto_thread = 0;
Expand Down Expand Up @@ -96,11 +95,11 @@ void* recvdata(void * _args)

buffer_cursor += len;

// This should never happen
// ----------- [ This should never happen
if (buffer_cursor > BUFF_SIZE)
uc_err("Decryption buffer overflow");

// Decrypt what we've got
// ----------- [ Decrypt what we've got
while (decrypt_cursor+decrypt_buf_len <= buffer_cursor){
pass_to_enc_thread(decryption_threads,
e_args,
Expand All @@ -111,7 +110,7 @@ void* recvdata(void * _args)
decrypt_cursor += decrypt_buf_len;
}

// Write the decrypted buffer and reset
// ----------- [ Write the decrypted buffer and reset
if (decrypt_cursor >= BUFF_SIZE){
join_all_encryption_threads(decryption_threads);
write(fileno(stdout), decrypt_buffer, BUFF_SIZE);
Expand Down Expand Up @@ -206,7 +205,7 @@ void* senddata(void* _args)
if (buffer_cursor > BUFF_SIZE)
uc_err("Encryption buffer overflow");

// Encrypt data
// ----------- [ Encrypt data
while (encrypt_cursor+encrypt_buf_len <= buffer_cursor){
pass_to_enc_thread(encryption_threads,
e_args,
Expand All @@ -217,7 +216,7 @@ void* senddata(void* _args)
encrypt_cursor += encrypt_buf_len;
}

// If full buffer, then send to UDT
// ----------- [ If full buffer, then send to UDT
if (encrypt_cursor >= BUFF_SIZE){
join_all_encryption_threads(encryption_threads);
send_buf(client, encrypt_buffer, buffer_cursor, flags);
Expand All @@ -227,7 +226,7 @@ void* senddata(void* _args)

}

// Finish any remaining buffer data
// ----------- [ Finish any remaining buffer data
if (buffer_cursor > 0){
join_all_encryption_threads(encryption_threads);
crypto_update(encrypt_buffer+encrypt_cursor, buffer_cursor-encrypt_cursor, args->enc);
Expand Down
Binary file modified udt/app/appclient
Binary file not shown.
Binary file modified udt/app/appclient.o
Binary file not shown.
Binary file modified udt/app/appserver
Binary file not shown.
Binary file modified udt/app/appserver.o
Binary file not shown.
Binary file removed udt/app/recvfile
Binary file not shown.
Binary file modified udt/app/recvfile.o
Binary file not shown.
Binary file modified udt/app/sendfile
Binary file not shown.
Binary file modified udt/app/sendfile.o
Binary file not shown.
Binary file removed udt/app/test
Binary file not shown.
Binary file removed udt/app/test.o
Binary file not shown.
2 changes: 1 addition & 1 deletion udt/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ifndef arch
arch = IA32
endif

CCFLAGS = -fPIC -Wall -Wextra -D$(os) -finline-functions -O3 -fno-strict-aliasing #-msse3
CCFLAGS = -fPIC -Wall -Wextra -D$(os) -finline-functions -O3 -fno-strict-aliasing -lpthread -DCUSTOM_CC #-msse3

ifeq ($(arch), IA32)
CCFLAGS += -DIA32
Expand Down
Binary file modified udt/src/api.o
Binary file not shown.
Binary file modified udt/src/buffer.o
Binary file not shown.
Binary file modified udt/src/cache.o
Binary file not shown.
Binary file modified udt/src/ccc.o
Binary file not shown.
Binary file modified udt/src/channel.o
Binary file not shown.
Binary file modified udt/src/common.o
Binary file not shown.
Binary file modified udt/src/core.o
Binary file not shown.
Binary file modified udt/src/epoll.o
Binary file not shown.
Binary file modified udt/src/libudt.a
Binary file not shown.
Binary file modified udt/src/libudt.so
Binary file not shown.
Binary file modified udt/src/list.o
Binary file not shown.
Binary file modified udt/src/md5.o
Binary file not shown.
Binary file modified udt/src/packet.o
Binary file not shown.
Binary file modified udt/src/queue.o
Binary file not shown.
Binary file modified udt/src/window.o
Binary file not shown.

0 comments on commit 5f92467

Please sign in to comment.