~ubuntu-branches/debian/sid/coturn/sid

« back to all changes in this revision

Viewing changes to src/apps/uclient/startuclient.c

  • Committer: Package Import Robot
  • Author(s): Oleg Moskalenko
  • Date: 2014-11-23 00:15:03 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20141123001503-oxzujsbx5ye4ea6i
Tags: 4.3.1.1-1
Sync to 4.3.1.1: SQLite support added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
#define MAX_CONNECT_EFFORTS (77)
45
45
#define DTLS_MAX_CONNECT_TIMEOUT (30)
 
46
#define MAX_TLS_CYCLES (32)
46
47
#define EXTRA_CREATE_PERMS (25)
47
48
 
48
49
static uint64_t current_reservation_token = 0;
76
77
 
77
78
/////////////////////////////////////////
78
79
 
79
 
static SSL* tls_connect(ioa_socket_raw fd, ioa_addr *remote_addr, int *try_again)
 
80
static SSL* tls_connect(ioa_socket_raw fd, ioa_addr *remote_addr, int *try_again, int connect_cycle)
80
81
{
81
82
        int ctxtype = (int)(((unsigned long)random())%root_tls_ctx_num);
82
83
        SSL *ssl;
122
123
                do {
123
124
                        rc = SSL_connect(ssl);
124
125
                } while (rc < 0 && errno == EINTR);
 
126
                int orig_errno = errno;
125
127
                if (rc > 0) {
126
128
                  TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,"%s: client session connected with cipher %s, method=%s\n",__FUNCTION__,
127
129
                                  SSL_get_cipher(ssl),turn_get_ssl_method(ssl,NULL));
136
138
                } else {
137
139
                        TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: cannot connect: rc=%d, ctx=%d\n",
138
140
                                        __FUNCTION__,rc,ctxtype);
 
141
 
139
142
                        switch (SSL_get_error(ssl, rc)) {
140
143
                        case SSL_ERROR_WANT_READ:
141
144
                        case SSL_ERROR_WANT_WRITE:
143
146
                                continue;
144
147
                        default: {
145
148
                                char buf[1025];
146
 
                                TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s (%d)\n",
147
 
                                                ERR_error_string(ERR_get_error(), buf), SSL_get_error(ssl, rc));
148
 
                                if(ctxtype>0) {
 
149
                                TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "errno=%d, err=%d, %s (%d)\n",orig_errno,
 
150
                                                                (int)ERR_get_error(), ERR_error_string(ERR_get_error(), buf), (int)SSL_get_error(ssl, rc));
 
151
                                if(connect_cycle<MAX_TLS_CYCLES) {
149
152
                                        if(try_again) {
 
153
                                                SSL_FREE(ssl);
150
154
                                                *try_again = 1;
151
155
                                                return NULL;
152
156
                                        }
198
202
        ioa_addr local_addr;
199
203
        evutil_socket_t clnet_fd;
200
204
        int connect_err;
 
205
        int connect_cycle = 0;
201
206
 
202
207
        ioa_addr remote_addr;
203
208
 
266
271
 
267
272
        if (use_secure) {
268
273
                int try_again = 0;
269
 
                clnet_info->ssl = tls_connect(clnet_info->fd, &remote_addr,&try_again);
 
274
                clnet_info->ssl = tls_connect(clnet_info->fd, &remote_addr,&try_again,connect_cycle++);
270
275
                if (!clnet_info->ssl) {
271
276
                        if(try_again) {
272
 
                                close(clnet_fd);
273
277
                                goto start_socket;
274
278
                        }
275
279
                        TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: cannot SSL connect to remote addr\n", __FUNCTION__);
1511
1515
void tcp_data_connect(app_ur_session *elem, u32bits cid)
1512
1516
{
1513
1517
        int clnet_fd;
 
1518
        int connect_cycle = 0;
1514
1519
 
1515
1520
        again:
1516
1521
 
1587
1592
 
1588
1593
        if(use_secure) {
1589
1594
                int try_again = 0;
1590
 
                elem->pinfo.tcp_conn[i]->tcp_data_ssl = tls_connect(elem->pinfo.tcp_conn[i]->tcp_data_fd, &(elem->pinfo.remote_addr),&try_again);
 
1595
                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++);
1591
1596
                if(!(elem->pinfo.tcp_conn[i]->tcp_data_ssl)) {
1592
1597
                        if(try_again) {
1593
 
                                close(clnet_fd);
1594
1598
                                --elem->pinfo.tcp_conn_number;
1595
1599
                                goto again;
1596
1600
                        }