Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* Copyright (C) Telefonica 2015
* All rights reserved.
*
* Telefonica Proprietary Information.
*
* Contains proprietary/trade secret information which is the property of
* Telefonica and must not be made available to, or copied or used by
* anyone outside Telefonica without its written authorization.
*
* Authors:
* Matteo Varvello <matteo.varvello@telefonica.com> et al.
*
* Description:
* An SSL/SPP client that connects to an SSL/SPP through a bunch of
* proxies.
*/
#include <stdbool.h> // to support boolean
#include "common.h" // common library between client and server
#include <pthread.h> // thread support
#define KEYFILE "client.pem" // client certificate
#define PASSWORD "password" // unused now
//#define DEBUG // verbose logging
#define CONNECT_TIMEOUT 5 // socket connection timeout
#define MAX_CONC_CLIENT 100 // max concurrent clients
static char *host=HOST;
static int port=PORT;
static int require_server_auth = 1;
static int clientID=0;
// -- Moved up here just because of thread
static SSL *ssl; // SSL instance
static int plain_socket;
static char *proto = "ssl"; // protocol to use (ssl ; spp)
static int stats=0; // Report byte statistics boolean
static int sizeCheck;
static ExperimentInfo *experiment_info; // for printing stats at the end
static int lines = 0; // number of lines in action file
static long fSize = 0;
//nagle stuff
static int disable_nagle = 0;
// allow acces to number of slices also for SSL
static int slices_len = 0; // number of slices
// Thread syncronization variables
static int done = 0;
static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
static bool running = true;
// Thread sync functions
pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m);
pthread_cond_signal(pthread_cond_t *c);
// thread exit
void thr_exit() {
pthread_mutex_lock(&m);
done = 1;
pthread_cond_signal(&c);
pthread_mutex_unlock(&m);
}
// Join
void thr_join() {
pthread_mutex_lock(&m);
while (done == 0){
pthread_cond_wait(&c, &m);
}
pthread_mutex_unlock(&m);
}
// function to plot statistics
void print_stats(SSL *s);
// Compute the size of a file to be served
int calculate_file_size(char *filename){
FILE *fp;
int sz = 0;
// Open file
fp = fopen(filename,"r");
// Check for errors while opening file
if(fp == NULL){
printf("Error while opening file %s.\r\n", filename);
exit(-1);
}
// Seek to the end of the file and ask for position
fseek(fp, 0L, SEEK_END);
sz = ftell(fp);
//fseek(fp, 0L, SEEK_SET);
// Close file
fclose (fp);
// Return file size
#ifdef DEBUG
printf ("[DEBUG] File requested is <<%s>> with size <<%d bytes>>\n", filename, sz);
#endif
return sz;
}
// Read counter of number of proxies in the provided list
int read_proxy_count(char *file_name){
FILE *fp; // pointer to file
int N; // number of proxies
char line [128]; // maximum size of line to read from
// Open file for reading
fp = fopen(file_name,"r");
// CHheck for errors while opening file
if( fp == NULL ){
printf("Error while opening file %s.\r\n", file_name);
exit(-1);
}
// Read first line of file
fgets ( line, sizeof line, fp );
// Convert char into integer
N = atoi(line);
#ifdef DEBUG
printf("[DEBUG] Expected number of proxies is: %d\r\n", N);
#endif
// Close file
fclose(fp);
return N;
}
// Function to read a proxy list from file and populate array of proxies
void read_proxy_list(char *file_name, SPP_PROXY **proxies){
FILE *fp; // pointer to file
int count = 0; // simple counters
bool firstLine = 1; // flag for first line in file
char line [128]; // maximum size of line to read from
// Open file for reading
fp = fopen(file_name,"r");
// Check for errors while opening file
if( fp == NULL ){
printf("Error while opening file %s.\r\n", file_name);
exit(-1);
}
// Read file line-by-line
while ( fgets ( line, sizeof line, fp ) != NULL ) {
// Remove trailing newline (NOTE: strtoK is not thread safe)
strtok(line, "\n");
// Handle first line as a special case
if (firstLine){
firstLine = 0;
continue;
}
// Generate a proxy from IP address just read
char *newLine;
newLine = (char *)malloc(strlen(line)+1);
strcpy(newLine, line);
proxies[count] = SPP_generate_proxy(ssl, newLine);
count++;
}
// Close file
fclose(fp);
}
// Print proxy list
void print_proxy_list(SPP_PROXY **proxies, int N){
int i;
if (N == 1){
printf("[DEBUG] There is %d available proxy (the final server):\r\n", N);
}else{
printf("[DEBUG] There are %d available proxies:\r\n", N);
}
for (i = 0; i < N; i++){
printf("\t[PROXY] Proxy %d with address %s\r\n", i, proxies[i]->address);
}
}
/*
// Timeout for connect
static int sTimeout = 0;
Loading
Loading full blame…