Changeset 5391
- Timestamp:
- 03/14/08 17:09:21 (4 months ago)
- Files:
-
- trackerd/trunk/trackerd/tracker.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trackerd/trunk/trackerd/tracker.c
r5078 r5391 47 47 static wi_array_t *wt_udp_sockets; 48 48 49 static wi_socket_context_t *wt_socket_context; 49 static wi_socket_tls_t *wt_socket_tls; 50 51 static wi_rsa_t *wt_private_key; 50 52 51 53 … … 149 151 150 152 void wt_tracker_apply_settings(void) { 153 wi_x509_t *certificate; 154 151 155 /* set SSL cipher list */ 152 156 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)) { 154 158 wi_log_err(WI_STR("Could not set SSL cipher list \"%@\""), 155 159 wt_settings.cipher); … … 159 163 /* load SSL certificate */ 160 164 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 { 162 173 wi_log_err(WI_STR("Could not load certificate %@: %m"), 163 174 wt_settings.certificate); 164 175 } 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 { 167 184 wi_log_err(WI_STR("Could not load private key %@: %m"), 168 185 wt_settings.certificate); … … 190 207 unsigned char dh1024_g[] = { 0x02 }; 191 208 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)) 195 212 wi_log_err(WI_STR("Could not set SSL context: %m")); 196 213 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))) 198 215 wi_log_err(WI_STR("Could not set anonymous DH key: %m")); 199 216 } … … 217 234 218 235 /* 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); 220 237 221 238 if(!address) { … … 228 245 229 246 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)) { 230 253 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 231 254 … … 257 280 wi_array_t *arguments; 258 281 wi_address_t *address; 259 wi_string_t *ip, *command; 282 wi_data_t *data; 283 wi_string_t *ip, *string, *command; 260 284 wi_time_interval_t interval; 261 285 wt_server_t *server; … … 272 296 273 297 /* 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); 275 299 276 300 if(!address) { … … 288 312 } 289 313 314 data = wi_rsa_decrypt(wt_private_key, wi_data_with_bytes(buffer, bytes)); 315 string = wi_string_with_data(data); 316 290 317 /* parse command */ 291 wi_parse_wired_command( wi_string_with_cstring(buffer), &command, &arguments);292 318 wi_parse_wired_command(string, &command, &arguments); 319 293 320 if(wi_is_equal(command, WI_STR("UPDATE")) && wi_array_count(arguments) >= 6) { 294 321 server = wt_servers_server_with_key(WI_ARRAY(arguments, 0)); … … 352 379 va_end(ap); 353 380 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); 355 382 356 383 wi_release(string);
