Changeset 5391

Show
Ignore:
Timestamp:
03/14/08 17:09:21 (4 months ago)
Author:
morris
Message:

Sync with new socket API

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trackerd/trunk/trackerd/tracker.c

    r5078 r5391  
    4747static wi_array_t                                       *wt_udp_sockets; 
    4848 
    49 static wi_socket_context_t                      *wt_socket_context; 
     49static wi_socket_tls_t                          *wt_socket_tls; 
     50 
     51static wi_rsa_t                                         *wt_private_key; 
    5052 
    5153 
     
    149151 
    150152void wt_tracker_apply_settings(void) { 
     153        wi_x509_t               *certificate; 
     154         
    151155        /* set SSL cipher list */ 
    152156        if(wt_settings.cipher) { 
    153                 if(!wi_socket_context_set_ssl_ciphers(wt_socket_context, wt_settings.cipher)) { 
     157                if(!wi_socket_tls_set_ciphers(wt_socket_tls, wt_settings.cipher)) { 
    154158                        wi_log_err(WI_STR("Could not set SSL cipher list \"%@\""), 
    155159                                wt_settings.cipher); 
     
    159163        /* load SSL certificate */ 
    160164        if(wt_settings.certificate) { 
    161                 if(!wi_socket_context_set_ssl_certificate(wt_socket_context, wt_settings.certificate)) { 
     165                certificate = wi_x509_init_with_pem_file(wi_x509_alloc(), wt_settings.certificate); 
     166                 
     167                if(certificate) { 
     168                        if(!wi_socket_tls_set_certificate(wt_socket_tls, certificate)) 
     169                                wi_log_err(WI_STR("Could not set certificate: %m")); 
     170                 
     171                        wi_release(certificate); 
     172                } else { 
    162173                        wi_log_err(WI_STR("Could not load certificate %@: %m"), 
    163174                                wt_settings.certificate); 
    164175                } 
    165  
    166                 if(!wi_socket_context_set_ssl_privkey(wt_socket_context, wt_settings.certificate)) { 
     176                 
     177                wi_release(wt_private_key); 
     178                wt_private_key = wi_rsa_init_with_pem_file(wi_rsa_alloc(), wt_settings.certificate); 
     179                 
     180                if(wt_private_key) { 
     181                        if(!wi_socket_tls_set_private_key(wt_socket_tls, wt_private_key)) 
     182                                wi_log_err(WI_STR("Could not set private key: %m")); 
     183                } else { 
    167184                        wi_log_err(WI_STR("Could not load private key %@: %m"), 
    168185                                wt_settings.certificate); 
     
    190207        unsigned char   dh1024_g[] = { 0x02 }; 
    191208 
    192         wt_socket_context = wi_socket_context_init(wi_socket_context_alloc()); 
    193          
    194         if(!wi_socket_context_set_ssl_type(wt_socket_context, WI_SOCKET_SSL_SERVER)) 
     209        wt_socket_tls = wi_socket_tls_init(wi_socket_tls_alloc()); 
     210         
     211        if(!wi_socket_tls_set_type(wt_socket_tls, WI_SOCKET_TLS_SERVER)) 
    195212                wi_log_err(WI_STR("Could not set SSL context: %m")); 
    196213         
    197         if(!wi_socket_context_set_ssl_dh(wt_socket_context, dh1024_p, sizeof(dh1024_p), dh1024_g, sizeof(dh1024_g))) 
     214        if(!wi_socket_tls_set_dh(wt_socket_tls, dh1024_p, sizeof(dh1024_p), dh1024_g, sizeof(dh1024_g))) 
    198215                wi_log_err(WI_STR("Could not set anonymous DH key: %m")); 
    199216} 
     
    217234 
    218235                /* accept new client */ 
    219                 socket = wi_socket_accept_multiple(wt_tcp_sockets, wt_socket_context, 30.0, &address); 
     236                socket = wi_socket_accept_multiple(wt_tcp_sockets, 30.0, &address); 
    220237                 
    221238                if(!address) { 
     
    228245                 
    229246                if(!socket) { 
     247                        wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 
     248                         
     249                        goto next; 
     250                } 
     251                 
     252                if(!wi_socket_accept_tls(socket, wt_socket_tls, 30.0)) { 
    230253                        wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 
    231254                         
     
    257280        wi_array_t                      *arguments; 
    258281        wi_address_t            *address; 
    259         wi_string_t                     *ip, *command; 
     282        wi_data_t                       *data; 
     283        wi_string_t                     *ip, *string, *command; 
    260284        wi_time_interval_t      interval; 
    261285        wt_server_t                     *server; 
     
    272296                 
    273297                /* read data */ 
    274                 bytes = wi_socket_recvfrom_multiple(wt_udp_sockets, wt_socket_context, buffer, sizeof(buffer), &address); 
     298                bytes = wi_socket_recvfrom_multiple(wt_udp_sockets, buffer, sizeof(buffer), &address); 
    275299                 
    276300                if(!address) { 
     
    288312                } 
    289313                 
     314                data = wi_rsa_decrypt(wt_private_key, wi_data_with_bytes(buffer, bytes)); 
     315                string = wi_string_with_data(data); 
     316                 
    290317                /* parse command */ 
    291                 wi_parse_wired_command(wi_string_with_cstring(buffer), &command, &arguments); 
    292  
     318                wi_parse_wired_command(string, &command, &arguments); 
     319                 
    293320                if(wi_is_equal(command, WI_STR("UPDATE")) && wi_array_count(arguments) >= 6) { 
    294321                        server = wt_servers_server_with_key(WI_ARRAY(arguments, 0)); 
     
    352379        va_end(ap); 
    353380         
    354         wi_socket_write(client->socket, 0.0, WI_STR("%u %@%c"), n, string, WT_MESSAGE_SEPARATOR); 
     381        wi_socket_write_format(client->socket, 0.0, WI_STR("%u %@%c"), n, string, WT_MESSAGE_SEPARATOR); 
    355382         
    356383        wi_release(string);