void *thread_sender(void *arg) { client_info_t *client_info = (client_info_t*) arg; pthread_cond_broadcast(&client_info->peer_signal); printf("enter sender\n"); for(;;) { char str_in[SEND_STR_SIZE], str_out[SEND_STR_SIZE]; task_t task; if (queue_pop(&client_info->context->queue, &task) != 0) { pthread_exit(0); } //printf("take job\n"); sprintf(str_out, SEND_JOB_TMPL, task.pass, 0, 0, client_info->context->hash, client_info->context->alph, task.to, client_info->context->length); printf("write job into str %s\n", str_out); uint32_t length = strlen (str_out); if (write(client_info->i32_connect_FD, &length, sizeof(uint32_t)) == -1) { queue_push(&task, &client_info->context->queue); pthread_exit(0); } //printf("send length\n"); if (write(client_info->i32_connect_FD, str_out, length) == -1) { queue_push(&task, &client_info->context->queue); pthread_exit(0); } printf("send job %s\n", str_out); if (read (client_info->i32_connect_FD, &length, sizeof(uint32_t)) == -1) { queue_push(&task, &client_info->context->queue); pthread_exit(0); } //printf("get result length %d\n", length); if (read (client_info->i32_connect_FD, &str_in, length) == -1) { queue_push(&task, &client_info->context->queue); pthread_exit(0); } printf("get result str %s\n", str_in); int id, check_result; sscanf(str_in, REPORT_RESULT_TMPL, str_out, &id, &id, &check_result); //printf("result = %s\n", str_out); if (check_result != 0) { printf("beda s checkom\n"); client_info->context->complete = !0; queue_cancel(&client_info->context->queue); memcpy(client_info->context->password, str_out, client_info->context->length); unrev(client_info->context); pthread_exit(0); } unrev(client_info->context); //printf("rev %d\n", client_info->context->rev_count); } }
void snr3_run_in_files_cancel(Tsnr3run *s3run) { DEBUG_MSG("snr3_run_in_files_cancel s3run %p\n",s3run); g_atomic_int_set(&s3run->cancelled, 1); if (s3run->findfiles) { findfiles_cancel(s3run->findfiles); } queue_cancel(&s3run->threadqueue, queue_cancel_freefunc, NULL); /* hmm but what if there are still idle callbacks registered ??? the s3run structure can only be free'd after the fw refcount is 0 */ }
void brute_server(context_t *context, task_t *task) { task->from = 0; task->to = context->length - 2; struct sockaddr_in st_sock_addr, peer_addr; socklen_t peer_addr_size = sizeof(struct sockaddr_in); pthread_t thread_id; int i32_socket_FD = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP ); if ( i32_socket_FD == -1 ) { printf("Error in creat desc"); exit( EXIT_FAILURE ); } memset( &st_sock_addr, 0, sizeof( st_sock_addr ) ); st_sock_addr.sin_family = PF_INET; st_sock_addr.sin_port = htons (PORT); st_sock_addr.sin_addr.s_addr = htonl(INADDR_ANY); if ( bind( i32_socket_FD, (struct sockaddr *)&st_sock_addr, sizeof( st_sock_addr ) ) == -1) { printf("Error in bind"); close( i32_socket_FD ); exit( EXIT_FAILURE ); } if ( listen (i32_socket_FD, 10 ) == -1 ) { printf("Error in listen"); close (i32_socket_FD ); exit (EXIT_FAILURE ); } distributor_t distributor; distributor.peer_addr = peer_addr; distributor.peer_addr_size = peer_addr_size; distributor.i32_socket_FD = i32_socket_FD; distributor.context = context; pthread_create(&thread_id, NULL, &client_distributor, &distributor); struct crypt_data data_single; data_single.initialized = 0; brute_iter(context, task, &data_single, &queue_push_transform); pthread_mutex_lock(&context->mutex_sem); if(context->rev_count != 0 && context->complete == 0) pthread_cond_wait(&context->signal_sem, &context->mutex_sem); pthread_mutex_unlock(&context->mutex_sem); queue_cancel(&context->queue); shutdown(i32_socket_FD, SHUT_RDWR); close(i32_socket_FD); }
void brute_multi(context_t *context, task_t *task) { task->from = 0; task->to = context->length - 2; struct crypt_data data_single; data_single.initialized = 0; int i, nProcess = sysconf(_SC_NPROCESSORS_CONF); pthread_t threadIdCons[nProcess]; for(i = 0; i < nProcess; i++) pthread_create (&threadIdCons[i], NULL, &thread_consumer, context); if (context->brute_mode == BM_REC) brute_rec (context, task, 0, &data_single, &queue_push_transform); else brute_iter (context, task, &data_single, &queue_push_transform); pthread_mutex_lock(&context->mutex_sem); if(context->rev_count != 0) pthread_cond_wait(&context->signal_sem, &context->mutex_sem); pthread_mutex_unlock(&context->mutex_sem); queue_cancel(&context->queue); }