Changeset 5392
- Timestamp:
- 03/14/08 17:09:28 (6 months ago)
- Files:
-
- wired/trunk/wired/server.c (modified) (13 diffs)
- wired/trunk/wired/trackers.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wired/trunk/wired/server.c
r5345 r5392 62 62 static wi_array_t *wd_transfer_sockets; 63 63 64 static wi_socket_ context_t *wd_control_socket_context;65 static wi_socket_ context_t *wd_transfer_socket_context;64 static wi_socket_tls_t *wd_control_socket_tls; 65 static wi_socket_tls_t *wd_transfer_socket_tls; 66 66 67 67 wi_string_t *wd_banner; … … 174 174 void wd_server_apply_settings(void) { 175 175 wi_data_t *data; 176 wi_rsa_t *private_key; 177 wi_x509_t *certificate; 176 178 177 179 /* reload banner */ … … 200 202 /* set SSL cipher list */ 201 203 if(wd_settings.controlcipher) { 202 if(!wi_socket_ context_set_ssl_ciphers(wd_control_socket_context, wd_settings.controlcipher)) {204 if(!wi_socket_tls_set_ciphers(wd_control_socket_tls, wd_settings.controlcipher)) { 203 205 wi_log_err(WI_STR("Could not set SSL cipher list \"%@\": %m"), 204 206 wd_settings.controlcipher); … … 207 209 208 210 if(wd_settings.transfercipher) { 209 if(!wi_socket_ context_set_ssl_ciphers(wd_transfer_socket_context, wd_settings.transfercipher)) {211 if(!wi_socket_tls_set_ciphers(wd_transfer_socket_tls, wd_settings.transfercipher)) { 210 212 wi_log_err(WI_STR("Could not set SSL cipher list \"%@\": %m"), 211 213 wd_settings.transfercipher); … … 215 217 /* load SSL certificate */ 216 218 if(wd_settings.certificate) { 217 if(!wi_socket_context_set_ssl_certificate(wd_control_socket_context, wd_settings.certificate) || 218 !wi_socket_context_set_ssl_certificate(wd_transfer_socket_context, wd_settings.certificate)) { 219 certificate = wi_x509_init_with_pem_file(wi_x509_alloc(), wd_settings.certificate); 220 221 if(certificate) { 222 if(!wi_socket_tls_set_certificate(wd_control_socket_tls, certificate) || 223 !wi_socket_tls_set_certificate(wd_transfer_socket_tls, certificate)) { 224 wi_log_err(WI_STR("Could not set certificate: %m")); 225 } 226 227 wi_release(certificate); 228 } else { 219 229 wi_log_err(WI_STR("Could not load certificate %@: %m"), 230 wd_settings.certificate); 231 } 232 233 private_key = wi_rsa_init_with_pem_file(wi_rsa_alloc(), wd_settings.certificate); 234 235 if(private_key) { 236 if(!wi_socket_tls_set_private_key(wd_control_socket_tls, private_key) || 237 !wi_socket_tls_set_private_key(wd_transfer_socket_tls, private_key)) { 238 wi_log_err(WI_STR("Could not set private key: %m")); 239 } 240 241 wi_release(private_key); 242 } else { 243 wi_log_err(WI_STR("Could not load private key %@: %m"), 220 244 wd_settings.certificate); 221 245 } … … 264 288 unsigned char dh1024_g[] = { 0x02 }; 265 289 266 wd_control_socket_ context = wi_socket_context_init(wi_socket_context_alloc());267 wd_transfer_socket_ context = wi_socket_context_init(wi_socket_context_alloc());268 269 if(!wi_socket_ context_set_ssl_type(wd_control_socket_context, WI_SOCKET_SSL_SERVER) ||270 !wi_socket_ context_set_ssl_type(wd_transfer_socket_context, WI_SOCKET_SSL_SERVER))271 wi_log_err(WI_STR("Could not set SSL context: %m"));272 273 if(!wi_socket_ context_set_ssl_dh(wd_control_socket_context, dh1024_p, sizeof(dh1024_p), dh1024_g, sizeof(dh1024_g)) ||274 !wi_socket_ context_set_ssl_dh(wd_transfer_socket_context, dh1024_p, sizeof(dh1024_p), dh1024_g, sizeof(dh1024_g)))290 wd_control_socket_tls = wi_socket_tls_init(wi_socket_tls_alloc()); 291 wd_transfer_socket_tls = wi_socket_tls_init(wi_socket_tls_alloc()); 292 293 if(!wi_socket_tls_set_type(wd_control_socket_tls, WI_SOCKET_TLS_SERVER) || 294 !wi_socket_tls_set_type(wd_transfer_socket_tls, WI_SOCKET_TLS_SERVER)) 295 wi_log_err(WI_STR("Could not set SSL tls: %m")); 296 297 if(!wi_socket_tls_set_dh(wd_control_socket_tls, dh1024_p, sizeof(dh1024_p), dh1024_g, sizeof(dh1024_g)) || 298 !wi_socket_tls_set_dh(wd_transfer_socket_tls, dh1024_p, sizeof(dh1024_p), dh1024_g, sizeof(dh1024_g))) 275 299 wi_log_err(WI_STR("Could not set anonymous DH key: %m")); 276 300 } … … 328 352 329 353 /* accept new user */ 330 socket = wi_socket_accept_multiple(wd_control_sockets, wd_control_socket_context,30.0, &address);354 socket = wi_socket_accept_multiple(wd_control_sockets, 30.0, &address); 331 355 332 356 if(!address) { … … 339 363 340 364 if(!socket) { 365 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 366 367 continue; 368 } 369 370 if(!wi_socket_accept_tls(socket, wd_control_socket_tls, 30.0)) { 341 371 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 342 372 … … 374 404 375 405 /* accept new connection */ 376 socket = wi_socket_accept_multiple(wd_transfer_sockets, wd_transfer_socket_context,30.0, &address);406 socket = wi_socket_accept_multiple(wd_transfer_sockets, 30.0, &address); 377 407 378 408 if(!address) { … … 385 415 386 416 if(!socket) { 417 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 418 419 continue; 420 } 421 422 if(!wi_socket_accept_tls(socket, wd_transfer_socket_tls, 30.0)) { 387 423 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 388 424 … … 437 473 438 474 wd_user_lock_socket(user); 439 wi_socket_write (wd_user_socket(user), 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR);475 wi_socket_write_format(wd_user_socket(user), 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR); 440 476 wd_user_unlock_socket(user); 441 477 … … 471 507 va_end(ap); 472 508 473 wi_socket_write (socket, 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR);509 wi_socket_write_format(socket, 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR); 474 510 475 511 wi_release(string); … … 498 534 if(wd_user_state(user) == WD_USER_LOGGED_IN) { 499 535 wd_user_lock_socket(user); 500 wi_socket_write (wd_user_socket(user), 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR);536 wi_socket_write_format(wd_user_socket(user), 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR); 501 537 wd_user_unlock_socket(user); 502 538 } wired/trunk/wired/trackers.c
r5147 r5392 50 50 wi_boolean_t active; 51 51 52 wi_socket_context_t *context; 52 wi_rsa_t *public_key; 53 wi_socket_tls_t *tls; 53 54 wi_socket_t *socket; 54 55 wi_address_t *address; … … 142 143 } 143 144 144 tracker-> context = wi_socket_context_init(wi_socket_context_alloc());145 146 if(!wi_socket_ context_set_ssl_type(tracker->context, WI_SOCKET_SSL_CLIENT)) {145 tracker->tls = wi_socket_tls_init(wi_socket_tls_alloc()); 146 147 if(!wi_socket_tls_set_type(tracker->tls, WI_SOCKET_TLS_CLIENT)) { 147 148 wi_log_warn(WI_STR("Could not set SSL context: %m")); 148 149 149 150 continue; 151 } 152 153 if(wd_settings.controlcipher) { 154 if(!wi_socket_tls_set_ciphers(tracker->tls, wd_settings.controlcipher)) { 155 wi_log_err(WI_STR("Could not set SSL cipher list \"%@\": %m"), 156 wd_settings.controlcipher); 157 158 continue; 159 } 150 160 } 151 161 … … 214 224 wd_tracker_t *tracker = instance; 215 225 216 wi_release(tracker-> context);226 wi_release(tracker->tls); 217 227 218 228 wi_release(tracker->addresses); … … 324 334 wi_array_t *arguments; 325 335 wi_string_t *ip, *string; 326 void *key;327 336 uint32_t message; 328 337 wi_boolean_t fatal = false; … … 350 359 } 351 360 352 if(!wi_socket_connect(tracker->socket, tracker->context, 30.0)) { 361 if(!wi_socket_connect(tracker->socket, 30.0)) { 362 wi_log_err(WI_STR("Could not connect to tracker %@: %m"), 363 tracker->host); 364 365 continue; 366 } 367 368 if(!wi_socket_connect_tls(tracker->socket, tracker->tls, 30.0)) { 353 369 wi_log_err(WI_STR("Could not connect to tracker %@: %m"), 354 370 tracker->host); … … 398 414 tracker->key = wi_retain(WI_ARRAY(arguments, 0)); 399 415 400 key = wi_socket_ssl_pubkey(tracker->socket);401 402 if(! key) {416 tracker->public_key = wi_retain(wi_socket_ssl_public_key(tracker->socket)); 417 418 if(!tracker->public_key) { 403 419 wi_log_err(WI_STR("Could not get public key from the tracker %@: %m"), 404 420 tracker->host); … … 407 423 } 408 424 409 wi_socket_context_set_ssl_pubkey(tracker->context, key);410 411 425 wi_log_info(WI_STR("Registered with the tracker %@"), 412 426 tracker->host); … … 425 439 static void wd_tracker_update(wd_tracker_t *tracker) { 426 440 wi_socket_t *socket; 441 wi_data_t *data; 442 wi_string_t *string; 427 443 wi_integer_t bytes; 428 444 uint32_t guest, download; … … 440 456 } 441 457 442 bytes = wi_socket_sendto(socket, tracker->context, WI_STR("UPDATE %#@%c%u%c%u%c%u%c%u%c%llu%c"), 443 tracker->key, WD_FIELD_SEPARATOR, 444 wd_current_users, WD_FIELD_SEPARATOR, 445 guest, WD_FIELD_SEPARATOR, 446 download, WD_FIELD_SEPARATOR, 447 wd_files_unique_count, WD_FIELD_SEPARATOR, 448 wd_files_unique_size, WD_MESSAGE_SEPARATOR); 458 459 string = wi_string_with_format(WI_STR("UPDATE %#@%c%u%c%u%c%u%c%u%c%llu%c"), 460 tracker->key, WD_FIELD_SEPARATOR, 461 wd_current_users, WD_FIELD_SEPARATOR, 462 guest, WD_FIELD_SEPARATOR, 463 download, WD_FIELD_SEPARATOR, 464 wd_files_unique_count, WD_FIELD_SEPARATOR, 465 wd_files_unique_size, WD_MESSAGE_SEPARATOR); 466 467 data = wi_rsa_encrypt(tracker->public_key, wi_string_data(string)); 468 469 bytes = wi_socket_sendto_data(socket, data); 449 470 450 471 if(bytes < 0) { … … 493 514 va_end(ap); 494 515 495 bytes = wi_socket_write (tracker->socket, 30.0, WI_STR("%@%c"), string, WD_MESSAGE_SEPARATOR);516 bytes = wi_socket_write_format(tracker->socket, 30.0, WI_STR("%@%c"), string, WD_MESSAGE_SEPARATOR); 496 517 497 518 if(bytes <= 0) {
