mirror of
https://github.com/coturn/coturn.git
synced 2025-10-25 13:00:59 +02:00
Use bool over int for the turnutils_uclient program (#1420)
Converts all of the variables in the uclient program that should be bool but weren't. A few other minor adjustments made at the behest of clang-tidy, but this change does not address all of clang-tidy's complaints.
This commit is contained in:
parent
58dc071b46
commit
ad94684b23
@ -1131,7 +1131,7 @@ void print_abs_file_name(const char *msg1, const char *msg2, const char *fn) {
|
||||
}
|
||||
}
|
||||
|
||||
char *find_config_file(const char *config_file, int print_file_name) {
|
||||
char *find_config_file(const char *config_file) {
|
||||
char *full_path_to_config_file = NULL;
|
||||
|
||||
if (config_file && config_file[0]) {
|
||||
@ -1193,7 +1193,7 @@ char *find_config_file(const char *config_file, int print_file_name) {
|
||||
|
||||
if (!full_path_to_config_file) {
|
||||
if (strstr(config_file, "etc/") == config_file) {
|
||||
return find_config_file(config_file + 4, print_file_name);
|
||||
return find_config_file(config_file + 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ wchar_t *_ATW(__in char *pszInBuf, __in int nInSize, __out wchar_t **pszOutBuf,
|
||||
|
||||
////////////////// File search ////////////////////////
|
||||
|
||||
char *find_config_file(const char *config_file, int print_file_name);
|
||||
char *find_config_file(const char *config_file);
|
||||
void set_execdir(void);
|
||||
void print_abs_file_name(const char *msg1, const char *msg2, const char *fn);
|
||||
|
||||
|
||||
@ -2463,7 +2463,7 @@ static void read_config_file(int argc, char **argv, int pass) {
|
||||
FILE *f = NULL;
|
||||
char *full_path_to_config_file = NULL;
|
||||
|
||||
full_path_to_config_file = find_config_file(config_file, pass);
|
||||
full_path_to_config_file = find_config_file(config_file);
|
||||
if (full_path_to_config_file) {
|
||||
f = fopen(full_path_to_config_file, "r");
|
||||
}
|
||||
@ -3418,7 +3418,7 @@ static void adjust_key_file_name(char *fn, const char *file_title, int critical)
|
||||
goto keyerr;
|
||||
} else {
|
||||
|
||||
full_path_to_file = find_config_file(fn, 1);
|
||||
full_path_to_file = find_config_file(fn);
|
||||
{
|
||||
FILE *f = full_path_to_file ? fopen(full_path_to_file, "r") : NULL;
|
||||
if (!f) {
|
||||
|
||||
@ -8,7 +8,13 @@ set(SOURCE_FILES
|
||||
mainuclient.c
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
set(HEADER_FILES
|
||||
uclient.h
|
||||
startuclient.h
|
||||
session.h
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE turnclient)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
|
||||
@ -21,4 +27,4 @@ install(DIRECTORY
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>/
|
||||
DESTINATION DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
COMPONENT Runtime
|
||||
)
|
||||
)
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
#include "apputils.h"
|
||||
#include "ns_turn_utils.h"
|
||||
#include "session.h"
|
||||
#include "stun_buffer.h"
|
||||
#include "uclient.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -48,22 +47,22 @@
|
||||
/////////////// extern definitions /////////////////////
|
||||
|
||||
int clmessage_length = 100;
|
||||
int do_not_use_channel = 0;
|
||||
int c2c = 0;
|
||||
bool do_not_use_channel = false;
|
||||
bool c2c = false;
|
||||
int clnet_verbose = TURN_VERBOSE_NONE;
|
||||
int use_tcp = 0;
|
||||
int use_sctp = 0;
|
||||
int use_secure = 0;
|
||||
int hang_on = 0;
|
||||
bool use_tcp = false;
|
||||
bool use_sctp = false;
|
||||
bool use_secure = false;
|
||||
bool hang_on = false;
|
||||
ioa_addr peer_addr;
|
||||
int no_rtcp = 0;
|
||||
bool no_rtcp = false;
|
||||
int default_address_family = STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_DEFAULT;
|
||||
int dont_fragment = 0;
|
||||
bool dont_fragment = false;
|
||||
uint8_t g_uname[STUN_MAX_USERNAME_SIZE + 1];
|
||||
password_t g_upwd;
|
||||
char g_auth_secret[1025] = "\0";
|
||||
int g_use_auth_secret_with_timestamp = 0;
|
||||
int use_fingerprints = 1;
|
||||
bool g_use_auth_secret_with_timestamp = false;
|
||||
bool use_fingerprints = true;
|
||||
|
||||
static char ca_cert_file[1025] = "";
|
||||
static char cipher_suite[1025] = "";
|
||||
@ -74,26 +73,26 @@ int root_tls_ctx_num = 0;
|
||||
|
||||
uint8_t relay_transport = STUN_ATTRIBUTE_TRANSPORT_UDP_VALUE;
|
||||
unsigned char client_ifname[1025] = "";
|
||||
int passive_tcp = 0;
|
||||
int mandatory_channel_padding = 0;
|
||||
int negative_test = 0;
|
||||
int negative_protocol_test = 0;
|
||||
int dos = 0;
|
||||
int random_disconnect = 0;
|
||||
bool passive_tcp = false;
|
||||
bool mandatory_channel_padding = false;
|
||||
bool negative_test = false;
|
||||
bool negative_protocol_test = false;
|
||||
bool dos = false;
|
||||
bool random_disconnect = false;
|
||||
|
||||
SHATYPE shatype = SHATYPE_DEFAULT;
|
||||
|
||||
int mobility = 0;
|
||||
bool mobility = false;
|
||||
|
||||
int no_permissions = 0;
|
||||
bool no_permissions = false;
|
||||
|
||||
int extra_requests = 0;
|
||||
bool extra_requests = false;
|
||||
|
||||
char origin[STUN_MAX_ORIGIN_SIZE + 1] = "\0";
|
||||
|
||||
band_limit_t bps = 0;
|
||||
|
||||
int dual_allocation = 0;
|
||||
bool dual_allocation = false;
|
||||
|
||||
int oauth = 0;
|
||||
oauth_key okey_array[3];
|
||||
@ -168,7 +167,7 @@ int main(int argc, char **argv) {
|
||||
int peer_port = PEER_DEFAULT_PORT;
|
||||
|
||||
char rest_api_separator = ':';
|
||||
int use_null_cipher = 0;
|
||||
bool use_null_cipher = false;
|
||||
|
||||
#if defined(WINDOWS)
|
||||
|
||||
@ -233,22 +232,22 @@ int main(int argc, char **argv) {
|
||||
STRCPY(origin, optarg);
|
||||
break;
|
||||
case 'B':
|
||||
random_disconnect = 1;
|
||||
random_disconnect = true;
|
||||
break;
|
||||
case 'G':
|
||||
extra_requests = 1;
|
||||
extra_requests = true;
|
||||
break;
|
||||
case 'F':
|
||||
STRCPY(cipher_suite, optarg);
|
||||
break;
|
||||
case 'I':
|
||||
no_permissions = 1;
|
||||
no_permissions = true;
|
||||
break;
|
||||
case 'M':
|
||||
mobility = 1;
|
||||
mobility = true;
|
||||
break;
|
||||
case 'E': {
|
||||
char *fn = find_config_file(optarg, 1);
|
||||
char *fn = find_config_file(optarg);
|
||||
if (!fn) {
|
||||
fprintf(stderr, "ERROR: file %s not found\n", optarg);
|
||||
exit(-1);
|
||||
@ -256,25 +255,25 @@ int main(int argc, char **argv) {
|
||||
STRCPY(ca_cert_file, fn);
|
||||
} break;
|
||||
case 'O':
|
||||
dos = 1;
|
||||
dos = true;
|
||||
break;
|
||||
case 'C':
|
||||
rest_api_separator = *optarg;
|
||||
break;
|
||||
case 'D':
|
||||
mandatory_channel_padding = 1;
|
||||
mandatory_channel_padding = true;
|
||||
break;
|
||||
case 'N':
|
||||
negative_test = 1;
|
||||
negative_test = true;
|
||||
break;
|
||||
case 'R':
|
||||
negative_protocol_test = 1;
|
||||
negative_protocol_test = true;
|
||||
break;
|
||||
case 'z':
|
||||
RTP_PACKET_INTERVAL = atoi(optarg);
|
||||
break;
|
||||
case 'Z':
|
||||
dual_allocation = 1;
|
||||
dual_allocation = true;
|
||||
break;
|
||||
case 'u':
|
||||
STRCPY(g_uname, optarg);
|
||||
@ -283,7 +282,7 @@ int main(int argc, char **argv) {
|
||||
STRCPY(g_upwd, optarg);
|
||||
break;
|
||||
case 'g':
|
||||
dont_fragment = 1;
|
||||
dont_fragment = true;
|
||||
break;
|
||||
case 'd':
|
||||
STRCPY(client_ifname, optarg);
|
||||
@ -298,7 +297,7 @@ int main(int argc, char **argv) {
|
||||
clmessage_length = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
do_not_use_channel = 1;
|
||||
do_not_use_channel = true;
|
||||
break;
|
||||
case 'n':
|
||||
messagenumber = atoi(optarg);
|
||||
@ -319,26 +318,26 @@ int main(int argc, char **argv) {
|
||||
clnet_verbose = TURN_VERBOSE_NORMAL;
|
||||
break;
|
||||
case 'h':
|
||||
hang_on = 1;
|
||||
hang_on = true;
|
||||
break;
|
||||
case 'c':
|
||||
no_rtcp = 1;
|
||||
no_rtcp = true;
|
||||
break;
|
||||
case 'm':
|
||||
mclient = atoi(optarg);
|
||||
break;
|
||||
case 'y':
|
||||
c2c = 1;
|
||||
c2c = true;
|
||||
break;
|
||||
case 't':
|
||||
use_tcp = 1;
|
||||
use_tcp = true;
|
||||
break;
|
||||
case 'b':
|
||||
use_sctp = 1;
|
||||
use_tcp = 1;
|
||||
use_sctp = true;
|
||||
use_tcp = true;
|
||||
break;
|
||||
case 'P':
|
||||
passive_tcp = 1;
|
||||
passive_tcp = true;
|
||||
/* implies 'T': */
|
||||
/* no break */
|
||||
/* Falls through. */
|
||||
@ -346,19 +345,19 @@ int main(int argc, char **argv) {
|
||||
relay_transport = STUN_ATTRIBUTE_TRANSPORT_TCP_VALUE;
|
||||
break;
|
||||
case 'U':
|
||||
use_null_cipher = 1;
|
||||
use_null_cipher = true;
|
||||
/* implies 'S' */
|
||||
/* no break */
|
||||
/* Falls through. */
|
||||
case 'S':
|
||||
use_secure = 1;
|
||||
use_secure = true;
|
||||
break;
|
||||
case 'W':
|
||||
g_use_auth_secret_with_timestamp = 1;
|
||||
g_use_auth_secret_with_timestamp = true;
|
||||
STRCPY(g_auth_secret, optarg);
|
||||
break;
|
||||
case 'i': {
|
||||
char *fn = find_config_file(optarg, 1);
|
||||
char *fn = find_config_file(optarg);
|
||||
if (!fn) {
|
||||
fprintf(stderr, "ERROR: file %s not found\n", optarg);
|
||||
exit(-1);
|
||||
@ -367,7 +366,7 @@ int main(int argc, char **argv) {
|
||||
free(fn);
|
||||
} break;
|
||||
case 'k': {
|
||||
char *fn = find_config_file(optarg, 1);
|
||||
char *fn = find_config_file(optarg);
|
||||
if (!fn) {
|
||||
fprintf(stderr, "ERROR: file %s not found\n", optarg);
|
||||
exit(-1);
|
||||
@ -382,7 +381,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (dual_allocation) {
|
||||
no_rtcp = 1;
|
||||
no_rtcp = true;
|
||||
}
|
||||
|
||||
if (g_use_auth_secret_with_timestamp) {
|
||||
@ -435,11 +434,11 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (is_TCP_relay()) {
|
||||
dont_fragment = 0;
|
||||
no_rtcp = 1;
|
||||
c2c = 1;
|
||||
use_tcp = 1;
|
||||
do_not_use_channel = 1;
|
||||
dont_fragment = false;
|
||||
no_rtcp = true;
|
||||
c2c = true;
|
||||
use_tcp = true;
|
||||
do_not_use_channel = true;
|
||||
}
|
||||
|
||||
if (port == 0) {
|
||||
|
||||
@ -35,12 +35,11 @@
|
||||
#include <event2/event.h>
|
||||
|
||||
#include "ns_turn_ioaddr.h"
|
||||
#include "ns_turn_utils.h"
|
||||
|
||||
#include "apputils.h"
|
||||
#include "stun_buffer.h"
|
||||
|
||||
#include "ns_turn_openssl.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -48,19 +47,17 @@ extern "C" {
|
||||
|
||||
///////// types ////////////
|
||||
|
||||
enum _UR_STATE { UR_STATE_UNKNOWN = 0, UR_STATE_READY, UR_STATE_DONE };
|
||||
|
||||
typedef enum _UR_STATE UR_STATE;
|
||||
typedef enum { UR_STATE_UNKNOWN = 0, UR_STATE_READY, UR_STATE_DONE } UR_STATE;
|
||||
|
||||
//////////////// session info //////////////////////
|
||||
|
||||
typedef struct {
|
||||
/* RFC 6062 */
|
||||
uint32_t cid;
|
||||
uint32_t cid; // https://datatracker.ietf.org/doc/html/rfc6062#section-6.2.1
|
||||
ioa_addr tcp_data_local_addr;
|
||||
ioa_socket_raw tcp_data_fd;
|
||||
SSL *tcp_data_ssl;
|
||||
int tcp_data_bound;
|
||||
bool tcp_data_bound;
|
||||
} app_tcp_conn_info;
|
||||
|
||||
typedef struct {
|
||||
@ -73,30 +70,31 @@ typedef struct {
|
||||
ioa_addr relay_addr;
|
||||
ioa_socket_raw fd;
|
||||
SSL *ssl;
|
||||
int broken;
|
||||
bool broken;
|
||||
uint8_t nonce[STUN_MAX_NONCE_SIZE + 1];
|
||||
uint8_t realm[STUN_MAX_REALM_SIZE + 1];
|
||||
/* oAuth */
|
||||
int oauth;
|
||||
int oauth; // Cannot (yet) be converted to bool, as many functions take an int* instead of bool*, those must be
|
||||
// addressed first.
|
||||
uint8_t server_name[STUN_MAX_SERVER_NAME_SIZE + 1];
|
||||
hmackey_t key;
|
||||
int key_set;
|
||||
int cok;
|
||||
bool key_set;
|
||||
int cok; // presumably means "client oauth key" or something like it? Appears to be used as an index into an array.
|
||||
/* RFC 6062 */
|
||||
app_tcp_conn_info **tcp_conn;
|
||||
size_t tcp_conn_number;
|
||||
int is_peer;
|
||||
bool is_peer;
|
||||
char s_mobile_id[33];
|
||||
} app_ur_conn_info;
|
||||
|
||||
typedef struct {
|
||||
app_ur_conn_info pinfo;
|
||||
UR_STATE state;
|
||||
unsigned int ctime;
|
||||
unsigned int ctime; // assigned to from a uint64_t variable "current time" likely should be a time_t or similar.
|
||||
uint16_t chnum;
|
||||
int wait_cycles;
|
||||
int timer_cycle;
|
||||
int completed;
|
||||
int completed; // A count of the number of connections considered complete.
|
||||
struct event *input_ev;
|
||||
struct event *input_tcp_data_ev;
|
||||
stun_buffer in_buffer;
|
||||
@ -118,7 +116,7 @@ typedef struct {
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
typedef struct _message_info {
|
||||
typedef struct {
|
||||
int msgnum;
|
||||
uint64_t mstime;
|
||||
} message_info;
|
||||
|
||||
@ -89,7 +89,7 @@ static int get_allocate_address_family(ioa_addr *relay_addr) {
|
||||
|
||||
/////////////////////////////////////////
|
||||
|
||||
static SSL *tls_connect(ioa_socket_raw fd, ioa_addr *remote_addr, int *try_again, int connect_cycle) {
|
||||
static SSL *tls_connect(ioa_socket_raw fd, ioa_addr *remote_addr, bool *try_again, int connect_cycle) {
|
||||
|
||||
int ctxtype = (int)(((unsigned long)turn_random()) % root_tls_ctx_num);
|
||||
|
||||
@ -173,7 +173,7 @@ static SSL *tls_connect(ioa_socket_raw fd, ioa_addr *remote_addr, int *try_again
|
||||
if (connect_cycle < MAX_TLS_CYCLES) {
|
||||
if (try_again) {
|
||||
SSL_free(ssl);
|
||||
*try_again = 1;
|
||||
*try_again = true;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -214,7 +214,7 @@ int socket_connect(evutil_socket_t clnet_fd, ioa_addr *remote_addr, int *connect
|
||||
}
|
||||
|
||||
static int clnet_connect(uint16_t clnet_remote_port, const char *remote_address, const unsigned char *ifname,
|
||||
const char *local_address, int verbose, app_ur_conn_info *clnet_info) {
|
||||
const char *local_address, bool verbose, app_ur_conn_info *clnet_info) {
|
||||
|
||||
ioa_addr local_addr;
|
||||
evutil_socket_t clnet_fd;
|
||||
@ -297,7 +297,7 @@ start_socket:
|
||||
}
|
||||
|
||||
if (use_secure) {
|
||||
int try_again = 0;
|
||||
bool try_again = false;
|
||||
clnet_info->ssl = tls_connect(clnet_info->fd, &remote_addr, &try_again, connect_cycle++);
|
||||
if (!clnet_info->ssl) {
|
||||
if (try_again) {
|
||||
@ -354,23 +354,23 @@ void add_origin(stun_buffer *message) {
|
||||
}
|
||||
}
|
||||
|
||||
static int clnet_allocate(int verbose, app_ur_conn_info *clnet_info, ioa_addr *relay_addr, int af, char *turn_addr,
|
||||
static int clnet_allocate(bool verbose, app_ur_conn_info *clnet_info, ioa_addr *relay_addr, int af, char *turn_addr,
|
||||
uint16_t *turn_port) {
|
||||
|
||||
int af_cycle = 0;
|
||||
int reopen_socket = 0;
|
||||
bool reopen_socket = false;
|
||||
|
||||
int allocate_finished;
|
||||
bool allocate_finished;
|
||||
|
||||
stun_buffer request_message, response_message;
|
||||
|
||||
beg_allocate:
|
||||
|
||||
allocate_finished = 0;
|
||||
allocate_finished = false;
|
||||
|
||||
while (!allocate_finished && af_cycle++ < 32) {
|
||||
|
||||
int allocate_sent = 0;
|
||||
bool allocate_sent = false;
|
||||
|
||||
if (reopen_socket && !use_tcp) {
|
||||
socket_closesocket(clnet_info->fd);
|
||||
@ -379,7 +379,7 @@ beg_allocate:
|
||||
clnet_info->lsaddr, verbose, clnet_info) < 0) {
|
||||
exit(-1);
|
||||
}
|
||||
reopen_socket = 0;
|
||||
reopen_socket = false;
|
||||
}
|
||||
|
||||
int af4 = dual_allocation || (af == STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4);
|
||||
@ -387,6 +387,8 @@ beg_allocate:
|
||||
|
||||
uint64_t reservation_token = 0;
|
||||
char *rt = NULL;
|
||||
// TODO: Not a bool, can hold -1.
|
||||
// What is this variable representing?
|
||||
int ep = !no_rtcp && !dual_allocation;
|
||||
|
||||
if (!no_rtcp) {
|
||||
@ -414,7 +416,7 @@ beg_allocate:
|
||||
}
|
||||
|
||||
if (bps) {
|
||||
stun_attr_add_bandwidth_str(request_message.buf, (size_t *)(&(request_message.len)), bps);
|
||||
stun_attr_add_bandwidth_str(request_message.buf, &(request_message.len), bps);
|
||||
}
|
||||
|
||||
if (dont_fragment) {
|
||||
@ -427,7 +429,7 @@ beg_allocate:
|
||||
return -1;
|
||||
}
|
||||
|
||||
stun_attr_add_fingerprint_str(request_message.buf, (size_t *)&(request_message.len));
|
||||
stun_attr_add_fingerprint_str(request_message.buf, &(request_message.len));
|
||||
|
||||
while (!allocate_sent) {
|
||||
|
||||
@ -452,7 +454,7 @@ beg_allocate:
|
||||
|
||||
////////allocate response==>>
|
||||
{
|
||||
int allocate_received = 0;
|
||||
bool allocate_received = false;
|
||||
while (!allocate_received) {
|
||||
|
||||
int len = recv_buffer(clnet_info, &response_message, 1, 0, NULL, &request_message);
|
||||
@ -465,8 +467,8 @@ beg_allocate:
|
||||
int err_code = 0;
|
||||
uint8_t err_msg[129];
|
||||
if (stun_is_success_response(&response_message)) {
|
||||
allocate_received = 1;
|
||||
allocate_finished = 1;
|
||||
allocate_received = true;
|
||||
allocate_finished = true;
|
||||
|
||||
if (clnet_info->nonce[0]) {
|
||||
if (check_integrity(clnet_info, &response_message) < 0) {
|
||||
@ -478,7 +480,7 @@ beg_allocate:
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "success\n");
|
||||
}
|
||||
{
|
||||
int found = 0;
|
||||
bool found = false;
|
||||
|
||||
stun_attr_ref sar = stun_attr_get_first(&response_message);
|
||||
while (sar) {
|
||||
@ -499,14 +501,14 @@ beg_allocate:
|
||||
if (!addr_any(relay_addr)) {
|
||||
if (relay_addr->ss.sa_family == AF_INET) {
|
||||
if (default_address_family != STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6) {
|
||||
found = 1;
|
||||
found = true;
|
||||
addr_cpy(&(clnet_info->relay_addr), relay_addr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (relay_addr->ss.sa_family == AF_INET6) {
|
||||
if (default_address_family == STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6) {
|
||||
found = 1;
|
||||
found = true;
|
||||
addr_cpy(&(clnet_info->relay_addr), relay_addr);
|
||||
break;
|
||||
}
|
||||
@ -533,13 +535,13 @@ beg_allocate:
|
||||
|
||||
read_mobility_ticket(clnet_info, &response_message);
|
||||
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, (size_t)response_message.len, &err_code,
|
||||
err_msg, sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, response_message.len, &err_code, err_msg,
|
||||
sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
clnet_info->server_name, &(clnet_info->oauth))) {
|
||||
goto beg_allocate;
|
||||
} else if (stun_is_error_response(&response_message, &err_code, err_msg, sizeof(err_msg))) {
|
||||
|
||||
allocate_received = 1;
|
||||
allocate_received = true;
|
||||
|
||||
if (err_code == 300) {
|
||||
|
||||
@ -561,13 +563,13 @@ beg_allocate:
|
||||
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "error %d (%s)\n", err_code, (char *)err_msg);
|
||||
if (err_code != 437) {
|
||||
allocate_finished = 1;
|
||||
allocate_finished = true;
|
||||
current_reservation_token = 0;
|
||||
return -1;
|
||||
} else {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "trying allocate again %d...\n", err_code);
|
||||
sleep(1);
|
||||
reopen_socket = 1;
|
||||
reopen_socket = true;
|
||||
}
|
||||
} else {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "unknown allocate response\n");
|
||||
@ -594,7 +596,7 @@ beg_allocate:
|
||||
|
||||
allocate_rtcp = !allocate_rtcp;
|
||||
|
||||
if (1) {
|
||||
if (true) {
|
||||
|
||||
af_cycle = 0;
|
||||
|
||||
@ -603,10 +605,10 @@ beg_allocate:
|
||||
int fd = clnet_info->fd;
|
||||
SSL *ssl = clnet_info->ssl;
|
||||
|
||||
int close_now = (int)(turn_random() % 2);
|
||||
bool close_now = turn_random() % 2;
|
||||
|
||||
if (close_now) {
|
||||
int close_socket = (int)(turn_random() % 2);
|
||||
bool close_socket = (int)(turn_random() % 2);
|
||||
if (ssl && !close_socket) {
|
||||
SSL_shutdown(ssl);
|
||||
SSL_free(ssl);
|
||||
@ -647,7 +649,7 @@ beg_allocate:
|
||||
|
||||
//==>>refresh request, for an example only:
|
||||
{
|
||||
int refresh_sent = 0;
|
||||
bool refresh_sent = false;
|
||||
|
||||
stun_init_request(STUN_METHOD_REFRESH, &request_message);
|
||||
uint32_t lt = htonl(UCLIENT_SESSION_LIFETIME);
|
||||
@ -659,7 +661,10 @@ beg_allocate:
|
||||
}
|
||||
|
||||
if (dual_allocation && !mobility) {
|
||||
int t = ((uint8_t)turn_random()) % 3;
|
||||
// TODO: This could be reworked
|
||||
// it's using t as a tri-state to determine whether to add the requested address family field
|
||||
// it should be two seperate bools for readability purposes though.
|
||||
uint8_t t = ((uint8_t)turn_random()) % 3;
|
||||
if (t) {
|
||||
uint8_t field[4];
|
||||
field[0] = (t == 1) ? (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4
|
||||
@ -677,7 +682,7 @@ beg_allocate:
|
||||
return -1;
|
||||
}
|
||||
|
||||
stun_attr_add_fingerprint_str(request_message.buf, (size_t *)&(request_message.len));
|
||||
stun_attr_add_fingerprint_str(request_message.buf, &(request_message.len));
|
||||
|
||||
while (!refresh_sent) {
|
||||
|
||||
@ -687,7 +692,7 @@ beg_allocate:
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "refresh sent\n");
|
||||
}
|
||||
refresh_sent = 1;
|
||||
refresh_sent = true;
|
||||
|
||||
if (clnet_info->s_mobile_id[0]) {
|
||||
usleep(10000);
|
||||
@ -706,7 +711,7 @@ beg_allocate:
|
||||
|
||||
////////refresh response==>>
|
||||
{
|
||||
int refresh_received = 0;
|
||||
bool refresh_received = false;
|
||||
while (!refresh_received) {
|
||||
|
||||
int len = recv_buffer(clnet_info, &response_message, 1, 0, NULL, &request_message);
|
||||
@ -724,16 +729,16 @@ beg_allocate:
|
||||
uint8_t err_msg[129];
|
||||
if (stun_is_success_response(&response_message)) {
|
||||
read_mobility_ticket(clnet_info, &response_message);
|
||||
refresh_received = 1;
|
||||
refresh_received = true;
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "success\n");
|
||||
}
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, (size_t)response_message.len, &err_code,
|
||||
err_msg, sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, response_message.len, &err_code, err_msg,
|
||||
sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
clnet_info->server_name, &(clnet_info->oauth))) {
|
||||
goto beg_refresh;
|
||||
} else if (stun_is_error_response(&response_message, &err_code, err_msg, sizeof(err_msg))) {
|
||||
refresh_received = 1;
|
||||
refresh_received = true;
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "error %d (%s)\n", err_code, (char *)err_msg);
|
||||
return -1;
|
||||
} else {
|
||||
@ -752,7 +757,7 @@ beg_allocate:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int turn_channel_bind(int verbose, uint16_t *chn, app_ur_conn_info *clnet_info, ioa_addr *peer_addr) {
|
||||
static int turn_channel_bind(bool verbose, uint16_t *chn, app_ur_conn_info *clnet_info, ioa_addr *peer_addr) {
|
||||
|
||||
stun_buffer request_message, response_message;
|
||||
|
||||
@ -770,9 +775,9 @@ beg_bind:
|
||||
return -1;
|
||||
}
|
||||
|
||||
stun_attr_add_fingerprint_str(request_message.buf, (size_t *)&(request_message.len));
|
||||
stun_attr_add_fingerprint_str(request_message.buf, &(request_message.len));
|
||||
|
||||
int cb_sent = 0;
|
||||
bool cb_sent = false;
|
||||
|
||||
while (!cb_sent) {
|
||||
|
||||
@ -781,7 +786,7 @@ beg_bind:
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "channel bind sent\n");
|
||||
}
|
||||
cb_sent = 1;
|
||||
cb_sent = true;
|
||||
} else {
|
||||
perror("send");
|
||||
exit(1);
|
||||
@ -797,7 +802,7 @@ beg_bind:
|
||||
////////channel bind response==>>
|
||||
|
||||
{
|
||||
int cb_received = 0;
|
||||
bool cb_received = false;
|
||||
while (!cb_received) {
|
||||
|
||||
int len = recv_buffer(clnet_info, &response_message, 1, 0, NULL, &request_message);
|
||||
@ -809,7 +814,7 @@ beg_bind:
|
||||
uint8_t err_msg[129];
|
||||
if (stun_is_success_response(&response_message)) {
|
||||
|
||||
cb_received = 1;
|
||||
cb_received = true;
|
||||
|
||||
if (clnet_info->nonce[0]) {
|
||||
if (check_integrity(clnet_info, &response_message) < 0) {
|
||||
@ -820,12 +825,12 @@ beg_bind:
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "success: 0x%x\n", (int)(*chn));
|
||||
}
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, (size_t)response_message.len, &err_code,
|
||||
err_msg, sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, response_message.len, &err_code, err_msg,
|
||||
sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
clnet_info->server_name, &(clnet_info->oauth))) {
|
||||
goto beg_bind;
|
||||
} else if (stun_is_error_response(&response_message, &err_code, err_msg, sizeof(err_msg))) {
|
||||
cb_received = 1;
|
||||
cb_received = true;
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "channel bind: error %d (%s)\n", err_code, (char *)err_msg);
|
||||
return -1;
|
||||
} else {
|
||||
@ -843,7 +848,7 @@ beg_bind:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int turn_create_permission(int verbose, app_ur_conn_info *clnet_info, ioa_addr *peer_addr, int addrnum) {
|
||||
static int turn_create_permission(bool verbose, app_ur_conn_info *clnet_info, ioa_addr *peer_addr, int addrnum) {
|
||||
|
||||
if (no_permissions || (addrnum < 1)) {
|
||||
return 0;
|
||||
@ -859,11 +864,8 @@ static int turn_create_permission(int verbose, app_ur_conn_info *clnet_info, ioa
|
||||
beg_cp:
|
||||
|
||||
stun_init_request(STUN_METHOD_CREATE_PERMISSION, &request_message);
|
||||
{
|
||||
int addrindex;
|
||||
for (addrindex = 0; addrindex < addrnum; ++addrindex) {
|
||||
stun_attr_add_addr(&request_message, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, peer_addr + addrindex);
|
||||
}
|
||||
for (int addrindex = 0; addrindex < addrnum; ++addrindex) {
|
||||
stun_attr_add_addr(&request_message, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, peer_addr + addrindex);
|
||||
}
|
||||
|
||||
add_origin(&request_message);
|
||||
@ -872,9 +874,9 @@ beg_cp:
|
||||
return -1;
|
||||
}
|
||||
|
||||
stun_attr_add_fingerprint_str(request_message.buf, (size_t *)&(request_message.len));
|
||||
stun_attr_add_fingerprint_str(request_message.buf, &(request_message.len));
|
||||
|
||||
int cp_sent = 0;
|
||||
bool cp_sent = false;
|
||||
|
||||
while (!cp_sent) {
|
||||
|
||||
@ -884,7 +886,7 @@ beg_cp:
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "create perm sent: %s\n", saddr);
|
||||
}
|
||||
cp_sent = 1;
|
||||
cp_sent = true;
|
||||
} else {
|
||||
perror("send");
|
||||
exit(1);
|
||||
@ -900,7 +902,7 @@ beg_cp:
|
||||
////////create permission response==>>
|
||||
|
||||
{
|
||||
int cp_received = 0;
|
||||
bool cp_received = false;
|
||||
while (!cp_received) {
|
||||
|
||||
int len = recv_buffer(clnet_info, &response_message, 1, 0, NULL, &request_message);
|
||||
@ -912,7 +914,7 @@ beg_cp:
|
||||
uint8_t err_msg[129];
|
||||
if (stun_is_success_response(&response_message)) {
|
||||
|
||||
cp_received = 1;
|
||||
cp_received = true;
|
||||
|
||||
if (clnet_info->nonce[0]) {
|
||||
if (check_integrity(clnet_info, &response_message) < 0) {
|
||||
@ -923,12 +925,12 @@ beg_cp:
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "success\n");
|
||||
}
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, (size_t)response_message.len, &err_code,
|
||||
err_msg, sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, response_message.len, &err_code, err_msg,
|
||||
sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
clnet_info->server_name, &(clnet_info->oauth))) {
|
||||
goto beg_cp;
|
||||
} else if (stun_is_error_response(&response_message, &err_code, err_msg, sizeof(err_msg))) {
|
||||
cp_received = 1;
|
||||
cp_received = true;
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "create permission error %d (%s)\n", err_code, (char *)err_msg);
|
||||
return -1;
|
||||
} else {
|
||||
@ -946,7 +948,7 @@ beg_cp:
|
||||
}
|
||||
|
||||
int start_connection(uint16_t clnet_remote_port0, const char *remote_address0, const unsigned char *ifname,
|
||||
const char *local_address, int verbose, app_ur_conn_info *clnet_info_probe,
|
||||
const char *local_address, bool verbose, app_ur_conn_info *clnet_info_probe,
|
||||
app_ur_conn_info *clnet_info, uint16_t *chn, app_ur_conn_info *clnet_info_rtcp,
|
||||
uint16_t *chn_rtcp) {
|
||||
|
||||
@ -1044,9 +1046,8 @@ int start_connection(uint16_t clnet_remote_port0, const char *remote_address0, c
|
||||
}
|
||||
ioa_addr arbaddr;
|
||||
make_ioa_addr((const uint8_t *)sarbaddr, 333, &arbaddr);
|
||||
int i;
|
||||
int maxi = (unsigned short)turn_random() % EXTRA_CREATE_PERMS;
|
||||
for (i = 0; i < maxi; i++) {
|
||||
for (int i = 0; i < maxi; i++) {
|
||||
uint16_t chni = 0;
|
||||
int port = (unsigned short)turn_random();
|
||||
if (port < 1024) {
|
||||
@ -1078,9 +1079,8 @@ int start_connection(uint16_t clnet_remote_port0, const char *remote_address0, c
|
||||
}
|
||||
ioa_addr arbaddr[EXTRA_CREATE_PERMS];
|
||||
make_ioa_addr((const uint8_t *)sarbaddr, 333, &arbaddr[0]);
|
||||
int i;
|
||||
int maxi = (unsigned short)turn_random() % EXTRA_CREATE_PERMS;
|
||||
for (i = 0; i < maxi; i++) {
|
||||
for (int i = 0; i < maxi; i++) {
|
||||
if (i > 0) {
|
||||
addr_cpy(&arbaddr[i], &arbaddr[0]);
|
||||
}
|
||||
@ -1095,7 +1095,7 @@ int start_connection(uint16_t clnet_remote_port0, const char *remote_address0, c
|
||||
}
|
||||
} else {
|
||||
|
||||
int before = (turn_random() % 2 == 0);
|
||||
bool const before = turn_random() % 2;
|
||||
|
||||
if (before) {
|
||||
if (turn_create_permission(verbose, clnet_info, &peer_addr, 1) < 0) {
|
||||
@ -1114,14 +1114,13 @@ int start_connection(uint16_t clnet_remote_port0, const char *remote_address0, c
|
||||
|
||||
if (extra_requests) {
|
||||
const char *sarbaddr = "64.56.78.90";
|
||||
if (turn_random() % 2 == 0) {
|
||||
if (turn_random() % 2) {
|
||||
sarbaddr = "2001::172";
|
||||
}
|
||||
ioa_addr arbaddr[EXTRA_CREATE_PERMS];
|
||||
make_ioa_addr((const uint8_t *)sarbaddr, 333, &arbaddr[0]);
|
||||
int i;
|
||||
int maxi = (unsigned short)turn_random() % EXTRA_CREATE_PERMS;
|
||||
for (i = 0; i < maxi; i++) {
|
||||
for (int i = 0; i < maxi; i++) {
|
||||
if (i > 0) {
|
||||
addr_cpy(&arbaddr[i], &arbaddr[0]);
|
||||
}
|
||||
@ -1176,7 +1175,7 @@ int start_connection(uint16_t clnet_remote_port0, const char *remote_address0, c
|
||||
}
|
||||
|
||||
int start_c2c_connection(uint16_t clnet_remote_port0, const char *remote_address0, const unsigned char *ifname,
|
||||
const char *local_address, int verbose, app_ur_conn_info *clnet_info_probe,
|
||||
const char *local_address, bool verbose, app_ur_conn_info *clnet_info_probe,
|
||||
app_ur_conn_info *clnet_info1, uint16_t *chn1, app_ur_conn_info *clnet_info1_rtcp,
|
||||
uint16_t *chn1_rtcp, app_ur_conn_info *clnet_info2, uint16_t *chn2,
|
||||
app_ur_conn_info *clnet_info2_rtcp, uint16_t *chn2_rtcp) {
|
||||
@ -1225,7 +1224,7 @@ int start_c2c_connection(uint16_t clnet_remote_port0, const char *remote_address
|
||||
}
|
||||
|
||||
if (passive_tcp) {
|
||||
clnet_info2->is_peer = 1;
|
||||
clnet_info2->is_peer = true;
|
||||
}
|
||||
|
||||
if (clnet_connect(clnet_remote_port, remote_address, ifname, local_address, verbose, clnet_info2) < 0) {
|
||||
@ -1304,9 +1303,8 @@ int start_c2c_connection(uint16_t clnet_remote_port0, const char *remote_address
|
||||
}
|
||||
ioa_addr arbaddr;
|
||||
make_ioa_addr((const uint8_t *)sarbaddr, 333, &arbaddr);
|
||||
int i;
|
||||
int maxi = (unsigned short)turn_random() % EXTRA_CREATE_PERMS;
|
||||
for (i = 0; i < maxi; i++) {
|
||||
for (int i = 0; i < maxi; i++) {
|
||||
uint16_t chni = 0;
|
||||
int port = (unsigned short)turn_random();
|
||||
if (port < 1024) {
|
||||
@ -1333,9 +1331,8 @@ int start_c2c_connection(uint16_t clnet_remote_port0, const char *remote_address
|
||||
}
|
||||
ioa_addr arbaddr[EXTRA_CREATE_PERMS];
|
||||
make_ioa_addr((const uint8_t *)sarbaddr, 333, &arbaddr[0]);
|
||||
int i;
|
||||
int maxi = (unsigned short)turn_random() % EXTRA_CREATE_PERMS;
|
||||
for (i = 0; i < maxi; i++) {
|
||||
for (int i = 0; i < maxi; i++) {
|
||||
if (i > 0) {
|
||||
addr_cpy(&arbaddr[i], &arbaddr[0]);
|
||||
}
|
||||
@ -1384,9 +1381,8 @@ int start_c2c_connection(uint16_t clnet_remote_port0, const char *remote_address
|
||||
}
|
||||
ioa_addr arbaddr;
|
||||
make_ioa_addr((const uint8_t *)sarbaddr, 333, &arbaddr);
|
||||
int i;
|
||||
int maxi = (unsigned short)turn_random() % EXTRA_CREATE_PERMS;
|
||||
for (i = 0; i < maxi; i++) {
|
||||
for (int i = 0; i < maxi; i++) {
|
||||
addr_set_port(&arbaddr, (unsigned short)turn_random());
|
||||
uint8_t *u = (uint8_t *)&(arbaddr.s4.sin_addr);
|
||||
u[(unsigned short)turn_random() % 4] = u[(unsigned short)turn_random() % 4] + 1;
|
||||
@ -1440,10 +1436,10 @@ int start_c2c_connection(uint16_t clnet_remote_port0, const char *remote_address
|
||||
|
||||
//////////// RFC 6062 ///////////////
|
||||
|
||||
int turn_tcp_connect(int verbose, app_ur_conn_info *clnet_info, ioa_addr *peer_addr) {
|
||||
int turn_tcp_connect(bool verbose, app_ur_conn_info *clnet_info, ioa_addr *peer_addr) {
|
||||
|
||||
{
|
||||
int cp_sent = 0;
|
||||
bool cp_sent = false;
|
||||
|
||||
stun_buffer message;
|
||||
|
||||
@ -1466,7 +1462,7 @@ int turn_tcp_connect(int verbose, app_ur_conn_info *clnet_info, ioa_addr *peer_a
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "tcp connect sent\n");
|
||||
}
|
||||
cp_sent = 1;
|
||||
cp_sent = true;
|
||||
} else {
|
||||
perror("send");
|
||||
exit(1);
|
||||
@ -1499,7 +1495,7 @@ beg_cb:
|
||||
|
||||
stun_attr_add_fingerprint_str(request_message.buf, (size_t *)&(request_message.len));
|
||||
|
||||
int cb_sent = 0;
|
||||
bool cb_sent = false;
|
||||
|
||||
while (!cb_sent) {
|
||||
|
||||
@ -1509,7 +1505,7 @@ beg_cb:
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "connection bind sent\n");
|
||||
}
|
||||
cb_sent = 1;
|
||||
cb_sent = true;
|
||||
} else {
|
||||
if (errorOK) {
|
||||
return 0;
|
||||
@ -1528,7 +1524,7 @@ beg_cb:
|
||||
////////connection bind response==>>
|
||||
|
||||
{
|
||||
int cb_received = 0;
|
||||
bool cb_received = false;
|
||||
while (!cb_received) {
|
||||
|
||||
int len = recv_buffer(clnet_info, &response_message, 1, 1, atc, &request_message);
|
||||
@ -1549,17 +1545,17 @@ beg_cb:
|
||||
if (stun_get_method(&response_message) != STUN_METHOD_CONNECTION_BIND) {
|
||||
continue;
|
||||
}
|
||||
cb_received = 1;
|
||||
cb_received = true;
|
||||
if (verbose) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "success\n");
|
||||
}
|
||||
atc->tcp_data_bound = 1;
|
||||
atc->tcp_data_bound = true;
|
||||
} else if (stun_is_challenge_response_str(response_message.buf, (size_t)response_message.len, &err_code,
|
||||
err_msg, sizeof(err_msg), clnet_info->realm, clnet_info->nonce,
|
||||
clnet_info->server_name, &(clnet_info->oauth))) {
|
||||
goto beg_cb;
|
||||
} else if (stun_is_error_response(&response_message, &err_code, err_msg, sizeof(err_msg))) {
|
||||
cb_received = 1;
|
||||
cb_received = true;
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "connection bind error %d (%s)\n", err_code, (char *)err_msg);
|
||||
return -1;
|
||||
} else {
|
||||
@ -1655,7 +1651,7 @@ again:
|
||||
}
|
||||
|
||||
if (use_secure) {
|
||||
int try_again = 0;
|
||||
bool try_again = false;
|
||||
elem->pinfo.tcp_conn[i]->tcp_data_ssl =
|
||||
tls_connect(elem->pinfo.tcp_conn[i]->tcp_data_fd, &(elem->pinfo.remote_addr), &try_again, connect_cycle++);
|
||||
if (!(elem->pinfo.tcp_conn[i]->tcp_data_ssl)) {
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
#ifndef __STARTCLIENT_TURN__
|
||||
#define __STARTCLIENT_TURN__
|
||||
|
||||
#include "ns_turn_utils.h"
|
||||
#include "session.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -46,17 +45,17 @@ int not_rare_event(void);
|
||||
void add_origin(stun_buffer *message);
|
||||
|
||||
int start_c2c_connection(uint16_t clnet_remote_port, const char *remote_address, const unsigned char *ifname,
|
||||
const char *local_address, int verbose, app_ur_conn_info *clnet_info_probe,
|
||||
const char *local_address, bool verbose, app_ur_conn_info *clnet_info_probe,
|
||||
app_ur_conn_info *clnet_info1, uint16_t *chn1, app_ur_conn_info *clnet_info1_rtcp,
|
||||
uint16_t *chn1_rtcp, app_ur_conn_info *clnet_info2, uint16_t *chn2,
|
||||
app_ur_conn_info *clnet_info2_rtcp, uint16_t *chn2_rtcp);
|
||||
|
||||
int start_connection(uint16_t clnet_remote_port, const char *remote_address, const unsigned char *ifname,
|
||||
const char *local_address, int verbose, app_ur_conn_info *clnet_info_probe,
|
||||
const char *local_address, bool verbose, app_ur_conn_info *clnet_info_probe,
|
||||
app_ur_conn_info *clnet_info, uint16_t *chn, app_ur_conn_info *clnet_info_rtcp,
|
||||
uint16_t *chn_rtcp);
|
||||
|
||||
int turn_tcp_connect(int verbose, app_ur_conn_info *clnet_info, ioa_addr *peer_addr);
|
||||
int turn_tcp_connect(bool verbose, app_ur_conn_info *clnet_info, ioa_addr *peer_addr);
|
||||
|
||||
void tcp_data_connect(app_ur_session *elem, uint32_t cid);
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ static int verbose_packets = 0;
|
||||
|
||||
static size_t current_clients_number = 0;
|
||||
|
||||
static int start_full_timer = 0;
|
||||
static bool start_full_timer = false;
|
||||
static uint32_t tot_messages = 0;
|
||||
static uint32_t tot_send_messages = 0;
|
||||
static uint64_t tot_send_bytes = 0;
|
||||
@ -91,7 +91,7 @@ static uint64_t max_latency = 0;
|
||||
static uint64_t min_jitter = 0xFFFFFFFF;
|
||||
static uint64_t max_jitter = 0;
|
||||
|
||||
static int show_statistics = 0;
|
||||
static bool show_statistics = false;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -107,7 +107,7 @@ static void __turn_getMSTime(void) {
|
||||
start_sec = tp.tv_sec;
|
||||
}
|
||||
if (current_time != (uint64_t)((uint64_t)(tp.tv_sec) - start_sec)) {
|
||||
show_statistics = 1;
|
||||
show_statistics = true;
|
||||
}
|
||||
current_time = (uint64_t)((uint64_t)(tp.tv_sec) - start_sec);
|
||||
current_mstime = (uint64_t)((current_time * 1000) + (tp.tv_nsec / 1000000));
|
||||
@ -137,8 +137,7 @@ static void uc_delete_session_elem_data(app_ur_session *cdi) {
|
||||
EVENT_DEL(cdi->input_ev);
|
||||
EVENT_DEL(cdi->input_tcp_data_ev);
|
||||
if (cdi->pinfo.tcp_conn) {
|
||||
int i = 0;
|
||||
for (i = 0; i < (int)(cdi->pinfo.tcp_conn_number); ++i) {
|
||||
for (int i = 0; i < (int)(cdi->pinfo.tcp_conn_number); ++i) {
|
||||
if (cdi->pinfo.tcp_conn[i]) {
|
||||
if (cdi->pinfo.tcp_conn[i]->tcp_data_ssl && !(cdi->pinfo.broken)) {
|
||||
if (!(SSL_get_shutdown(cdi->pinfo.tcp_conn[i]->tcp_data_ssl) & SSL_SENT_SHUTDOWN)) {
|
||||
@ -191,7 +190,7 @@ static int remove_all_from_ss(app_ur_session *ss) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int data_connection, app_tcp_conn_info *atc) {
|
||||
int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, bool data_connection, app_tcp_conn_info *atc) {
|
||||
|
||||
int rc = 0;
|
||||
int ret = -1;
|
||||
@ -225,7 +224,7 @@ int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int data_con
|
||||
|
||||
if (ssl) {
|
||||
|
||||
int message_sent = 0;
|
||||
bool message_sent = false;
|
||||
while (!message_sent) {
|
||||
|
||||
if (SSL_get_shutdown(ssl)) {
|
||||
@ -242,7 +241,7 @@ int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int data_con
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "buffer sent: size=%d\n", len);
|
||||
}
|
||||
|
||||
message_sent = 1;
|
||||
message_sent = true;
|
||||
ret = len;
|
||||
} else {
|
||||
switch (SSL_get_error(ssl, len)) {
|
||||
@ -272,7 +271,7 @@ int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int data_con
|
||||
}
|
||||
/* Falls through. */
|
||||
default:
|
||||
clnet_info->broken = 1;
|
||||
clnet_info->broken = true;
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Unexpected error while writing!\n");
|
||||
return -1;
|
||||
}
|
||||
@ -281,7 +280,7 @@ int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int data_con
|
||||
|
||||
} else if (fd >= 0) {
|
||||
|
||||
size_t left = (size_t)(message->len);
|
||||
size_t left = message->len;
|
||||
|
||||
while (left > 0) {
|
||||
do {
|
||||
@ -359,7 +358,7 @@ static int wait_fd(int fd, unsigned int cycle) {
|
||||
}
|
||||
}
|
||||
|
||||
int recv_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int sync, int data_connection,
|
||||
int recv_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, bool sync, bool data_connection,
|
||||
app_tcp_conn_info *atc, stun_buffer *request_message) {
|
||||
|
||||
int rc = 0;
|
||||
@ -475,7 +474,7 @@ recv_again:
|
||||
}
|
||||
/* Falls through. */
|
||||
default:
|
||||
clnet_info->broken = 1;
|
||||
clnet_info->broken = true;
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Unexpected error while reading: rc=%d, sslerr=%d\n", rc, sslerr);
|
||||
return -1;
|
||||
}
|
||||
@ -490,7 +489,7 @@ recv_again:
|
||||
|
||||
/* TLS*/
|
||||
|
||||
int message_received = 0;
|
||||
bool message_received = false;
|
||||
int cycle = 0;
|
||||
while (!message_received && cycle++ < 100) {
|
||||
|
||||
@ -511,7 +510,7 @@ recv_again:
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "response received: size=%d\n", rc);
|
||||
}
|
||||
message->len = rc;
|
||||
message_received = 1;
|
||||
message_received = true;
|
||||
|
||||
} else {
|
||||
|
||||
@ -544,7 +543,7 @@ recv_again:
|
||||
}
|
||||
/* Falls through. */
|
||||
default:
|
||||
clnet_info->broken = 1;
|
||||
clnet_info->broken = true;
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Unexpected error while reading: rc=%d, sslerr=%d\n", rc, sslerr);
|
||||
return -1;
|
||||
}
|
||||
@ -675,13 +674,13 @@ static int client_read(app_ur_session *elem, int is_tcp_data, app_tcp_conn_info
|
||||
uint16_t chnumber = 0;
|
||||
|
||||
message_info mi;
|
||||
int miset = 0;
|
||||
bool miset = false;
|
||||
size_t buffers = 1;
|
||||
|
||||
if (is_tcp_data) {
|
||||
if ((int)elem->in_buffer.len == clmessage_length) {
|
||||
memcpy(&mi, (elem->in_buffer.buf), sizeof(message_info));
|
||||
miset = 1;
|
||||
miset = true;
|
||||
} else {
|
||||
/* TODO: make a more clean fix */
|
||||
buffers = (int)elem->in_buffer.len / clmessage_length;
|
||||
@ -731,7 +730,7 @@ static int client_read(app_ur_session *elem, int is_tcp_data, app_tcp_conn_info
|
||||
const uint8_t *data = stun_attr_get_value(sar);
|
||||
|
||||
memcpy(&mi, data, sizeof(message_info));
|
||||
miset = 1;
|
||||
miset = true;
|
||||
}
|
||||
|
||||
} else if (stun_is_success_response(&(elem->in_buffer))) {
|
||||
@ -783,7 +782,7 @@ static int client_read(app_ur_session *elem, int is_tcp_data, app_tcp_conn_info
|
||||
}
|
||||
|
||||
memcpy(&mi, elem->in_buffer.buf + 4, sizeof(message_info));
|
||||
miset = 1;
|
||||
miset = true;
|
||||
applen = elem->in_buffer.len - 4;
|
||||
}
|
||||
} else {
|
||||
@ -1360,9 +1359,8 @@ static void timer_handler(evutil_socket_t fd, short event, void *arg) {
|
||||
__turn_getMSTime();
|
||||
|
||||
if (start_full_timer) {
|
||||
int i = 0;
|
||||
int done = 0;
|
||||
for (i = 0; i < total_clients; ++i) {
|
||||
for (int i = 0; i < total_clients; ++i) {
|
||||
if (elems[i]) {
|
||||
int finished = client_timer_handler(elems[i], &done);
|
||||
if (finished) {
|
||||
@ -1371,7 +1369,7 @@ static void timer_handler(evutil_socket_t fd, short event, void *arg) {
|
||||
}
|
||||
}
|
||||
if (done > 5 && (dos || random_disconnect)) {
|
||||
for (i = 0; i < total_clients; ++i) {
|
||||
for (int i = 0; i < total_clients; ++i) {
|
||||
if (elems[i]) {
|
||||
socket_closesocket(elems[i]->pinfo.fd);
|
||||
elems[i]->pinfo.fd = -1;
|
||||
@ -1414,12 +1412,11 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
|
||||
client_event_base = turn_event_base_new();
|
||||
|
||||
int i = 0;
|
||||
int tot_clients = 0;
|
||||
|
||||
if (c2c) {
|
||||
if (!no_rtcp) {
|
||||
for (i = 0; i < (mclient >> 2); i++) {
|
||||
for (int i = 0; i < (mclient >> 2); i++) {
|
||||
if (!dos) {
|
||||
usleep(SLEEP_INTERVAL);
|
||||
}
|
||||
@ -1429,7 +1426,7 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
tot_clients += 4;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < (mclient >> 1); i++) {
|
||||
for (int i = 0; i < (mclient >> 1); i++) {
|
||||
if (!dos) {
|
||||
usleep(SLEEP_INTERVAL);
|
||||
}
|
||||
@ -1441,7 +1438,7 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
}
|
||||
} else {
|
||||
if (!no_rtcp) {
|
||||
for (i = 0; i < (mclient >> 1); i++) {
|
||||
for (int i = 0; i < (mclient >> 1); i++) {
|
||||
if (!dos) {
|
||||
usleep(SLEEP_INTERVAL);
|
||||
}
|
||||
@ -1451,7 +1448,7 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
tot_clients += 2;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < mclient; i++) {
|
||||
for (int i = 0; i < mclient; i++) {
|
||||
if (!dos) {
|
||||
usleep(SLEEP_INTERVAL);
|
||||
}
|
||||
@ -1479,7 +1476,7 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
|
||||
evtimer_add(ev, &tv);
|
||||
|
||||
for (i = 0; i < total_clients; i++) {
|
||||
for (int i = 0; i < total_clients; i++) {
|
||||
|
||||
if (is_TCP_relay()) {
|
||||
if (passive_tcp) {
|
||||
@ -1488,8 +1485,7 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
socket_connect(elems[i]->pinfo.fd, &(elems[i]->pinfo.remote_addr), &connect_err);
|
||||
}
|
||||
} else {
|
||||
int j = 0;
|
||||
for (j = i + 1; j < total_clients; j++) {
|
||||
for (int j = i + 1; j < total_clients; j++) {
|
||||
if (turn_tcp_connect(clnet_verbose, &(elems[i]->pinfo), &(elems[j]->pinfo.relay_addr)) < 0) {
|
||||
exit(-1);
|
||||
}
|
||||
@ -1508,10 +1504,9 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
if (is_TCP_relay()) {
|
||||
uint64_t connect_wait_start_time = current_time;
|
||||
while (1) {
|
||||
int i = 0;
|
||||
int completed = 0;
|
||||
if (passive_tcp) {
|
||||
for (i = 0; i < total_clients; ++i) {
|
||||
for (int i = 0; i < total_clients; ++i) {
|
||||
if (elems[i]->pinfo.is_peer) {
|
||||
completed += 1;
|
||||
} else if (elems[i]->pinfo.tcp_conn_number > 0 && elems[i]->pinfo.tcp_conn[0]->tcp_data_bound) {
|
||||
@ -1522,9 +1517,8 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < total_clients; ++i) {
|
||||
int j = 0;
|
||||
for (j = 0; j < (int)elems[i]->pinfo.tcp_conn_number; j++) {
|
||||
for (int i = 0; i < total_clients; ++i) {
|
||||
for (int j = 0; j < (int)elems[i]->pinfo.tcp_conn_number; j++) {
|
||||
if (elems[i]->pinfo.tcp_conn[j]->tcp_data_bound) {
|
||||
completed++;
|
||||
}
|
||||
@ -1546,15 +1540,15 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
__turn_getMSTime();
|
||||
stime = current_time;
|
||||
|
||||
for (i = 0; i < total_clients; i++) {
|
||||
for (int i = 0; i < total_clients; i++) {
|
||||
elems[i]->to_send_timems = current_mstime + 1000 + ((uint32_t)turn_random()) % 5000;
|
||||
}
|
||||
|
||||
tot_messages = elems[0]->tot_msgnum * total_clients;
|
||||
|
||||
start_full_timer = 1;
|
||||
start_full_timer = true;
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
|
||||
run_events(1);
|
||||
|
||||
@ -1568,7 +1562,7 @@ void start_mclient(const char *remote_address, int port, const unsigned char *if
|
||||
"%s: msz=%d, tot_send_msgs=%lu, tot_recv_msgs=%lu, tot_send_bytes ~ %llu, tot_recv_bytes ~ %llu\n",
|
||||
__FUNCTION__, msz, (unsigned long)tot_send_messages, (unsigned long)tot_recv_messages,
|
||||
(unsigned long long)tot_send_bytes, (unsigned long long)tot_recv_bytes);
|
||||
show_statistics = 0;
|
||||
show_statistics = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1653,7 +1647,7 @@ int add_integrity(app_ur_conn_info *clnet_info, stun_buffer *message) {
|
||||
(const uint8_t *)etoken.token, (int)etoken.size);
|
||||
|
||||
memcpy(clnet_info->key, otoken.enc_block.mac_key, otoken.enc_block.key_length);
|
||||
clnet_info->key_set = 1;
|
||||
clnet_info->key_set = true;
|
||||
}
|
||||
|
||||
if (stun_attr_add_integrity_by_key_str(message->buf, (size_t *)&(message->len), (uint8_t *)okey_array[cok].kid,
|
||||
|
||||
@ -31,12 +31,9 @@
|
||||
#ifndef __UCLIENT_ECHO__
|
||||
#define __UCLIENT_ECHO__
|
||||
|
||||
#include "ns_turn_utils.h"
|
||||
#include "session.h"
|
||||
#include "stun_buffer.h"
|
||||
|
||||
#include "ns_turn_openssl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -47,42 +44,42 @@ extern "C" {
|
||||
#define STARTING_TCP_RELAY_TIME (30)
|
||||
|
||||
extern int clmessage_length;
|
||||
extern int do_not_use_channel;
|
||||
extern bool do_not_use_channel;
|
||||
extern int clnet_verbose;
|
||||
extern int use_tcp;
|
||||
extern int use_sctp;
|
||||
extern int use_secure;
|
||||
extern bool use_tcp;
|
||||
extern bool use_sctp;
|
||||
extern bool use_secure;
|
||||
extern char cert_file[1025];
|
||||
extern char pkey_file[1025];
|
||||
extern int hang_on;
|
||||
extern int c2c;
|
||||
extern bool hang_on;
|
||||
extern bool c2c;
|
||||
extern ioa_addr peer_addr;
|
||||
extern int no_rtcp;
|
||||
extern bool no_rtcp;
|
||||
extern int default_address_family;
|
||||
extern int dont_fragment;
|
||||
extern bool dont_fragment;
|
||||
extern uint8_t g_uname[STUN_MAX_USERNAME_SIZE + 1];
|
||||
extern password_t g_upwd;
|
||||
extern char g_auth_secret[1025];
|
||||
extern int g_use_auth_secret_with_timestamp;
|
||||
extern int use_fingerprints;
|
||||
extern bool g_use_auth_secret_with_timestamp;
|
||||
extern bool use_fingerprints;
|
||||
extern SSL_CTX *root_tls_ctx[32];
|
||||
extern int root_tls_ctx_num;
|
||||
extern int RTP_PACKET_INTERVAL;
|
||||
extern uint8_t relay_transport;
|
||||
extern unsigned char client_ifname[1025];
|
||||
extern struct event_base *client_event_base;
|
||||
extern int passive_tcp;
|
||||
extern int mandatory_channel_padding;
|
||||
extern int negative_test;
|
||||
extern int negative_protocol_test;
|
||||
extern int dos;
|
||||
extern int random_disconnect;
|
||||
extern bool passive_tcp;
|
||||
extern bool mandatory_channel_padding;
|
||||
extern bool negative_test;
|
||||
extern bool negative_protocol_test;
|
||||
extern bool dos;
|
||||
extern bool random_disconnect;
|
||||
extern SHATYPE shatype;
|
||||
extern int mobility;
|
||||
extern int no_permissions;
|
||||
extern int extra_requests;
|
||||
extern bool mobility;
|
||||
extern bool no_permissions;
|
||||
extern bool extra_requests;
|
||||
extern band_limit_t bps;
|
||||
extern int dual_allocation;
|
||||
extern bool dual_allocation;
|
||||
|
||||
extern char origin[STUN_MAX_ORIGIN_SIZE + 1];
|
||||
|
||||
@ -97,8 +94,8 @@ extern oauth_key okey_array[3];
|
||||
void start_mclient(const char *remote_address, int port, const unsigned char *ifname, const char *local_address,
|
||||
int messagenumber, int mclient);
|
||||
|
||||
int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int data_connection, app_tcp_conn_info *atc);
|
||||
int recv_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, int sync, int data_connection,
|
||||
int send_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, bool data_connection, app_tcp_conn_info *atc);
|
||||
int recv_buffer(app_ur_conn_info *clnet_info, stun_buffer *message, bool sync, bool data_connection,
|
||||
app_tcp_conn_info *atc, stun_buffer *request_message);
|
||||
|
||||
void client_input_handler(evutil_socket_t fd, short what, void *arg);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user