void client_submit_error(YAAMP_CLIENT *client, YAAMP_JOB *job, int id, const char *message, char *extranonce2, char *ntime, char *nonce) { // if(job->templ->created+2 > time(NULL)) if(job && job->deleted) client_send_result(client, "true"); else { client_send_error(client, id, message); share_add(client, job, false, extranonce2, ntime, nonce, id); client->submit_bad++; // dump_submit_debug(message, client, job, extranonce2, ntime, nonce); } object_unlock(job); }
/*** * share_admin() * Process NET SHARE [ipc$ | admin$] command line (display or add) * * Args: * name - the share * * Returns: * nothing - success * exit(2) - command failed */ VOID share_admin(TCHAR * name) { USHORT err; /* API return status */ TCHAR FAR * pBuffer; // // On NT, the redir doesn't have to be running to use the server // #if !defined(NTENV) start_autostart(txt_SERVICE_REDIR); #endif start_autostart(txt_SERVICE_FILE_SRV); if (err = MNetShareGetInfo(NULL, name, 0, (LPBYTE*)&pBuffer)) { if (err == NERR_NetNameNotFound) { /* must be a new use */ if (! stricmpf(name, ADMIN_DOLLAR)) check_max_uses(); share_add(name, NULL, 0); } else ErrorExit(err); } else { /* Share exists */ if (SwitchList[0]) share_change(name); else share_display_share(name); } NetApiBufferFree(pBuffer); }
int main(void) { /* initialize a memory-only database */ fail_unless(db_init(NULL, NULL) == 0); /* initialize a share */ global_share = share_new("/tmp"); fail_unless(global_share); char *cwd = g_get_current_dir(); fail_unless(share_add(global_share, cwd, TRUE) == 0); free(cwd); hub_t *hub = hub_new(); fail_unless(hub); hub->me = user_new("nick", NULL, NULL, NULL, NULL, 0ULL, hub); fail_unless(hub->me); cc_t *cc = cc_new(-1, hub); fail_unless(cc); fail_unless(cc->state == CC_STATE_MYNICK); /* login a test user on the hub */ user_t *test_user = user_new("foo", NULL, NULL, NULL, NULL, 0ULL, hub); g_hash_table_insert(hub->users, strdup(test_user->nick), test_user); /* fake remote nick of the client connection */ cc->nick = strdup("foo"); /* requesting a non-existent file should fail */ int rc = cc_upload_prepare(cc, "non-existent-file", 0, 0); fail_unless(rc == -1); /* a user with same nick as me requesting a file should fail */ free(cc->nick); cc->nick = strdup("nick"); rc = cc_upload_prepare(cc, "sphubd\\sphubd.c", 0, 0); fail_unless(rc == -1); cc->nick = strdup("foo"); /* cc_upload_prepare should set cc->offset correctly after called */ cc->offset = 4711ULL; rc = cc_upload_prepare(cc, "sphubd\\sphubd.c", 0, 0); fail_unless(rc == 0); fail_unless(cc->offset == 0ULL); fail_unless(cc->bytes_to_transfer == cc->filesize); guint64 ofs = 17; rc = cc_upload_prepare(cc, "sphubd\\sphubd.c", ofs, 0); fail_unless(rc == 0); fail_unless(cc->offset == ofs); fail_unless(cc->bytes_to_transfer == cc->filesize - ofs); /* send commands to a file instead of to a hub */ cc->fd = open("/tmp/client_test.log", O_RDWR|O_CREAT); fail_unless(cc->fd != -1); /* nothing in the download queue yet */ fail_unless(cc_request_download(cc) == -1); /* ok, so add a file to the download queue */ rc = queue_add("bar", "share\\bar-file.zip", 4711ULL, "/tmp/client_test_file.zip", "ABCDEFGHIJKLMNOPQRSTUVWXYZ012"); fail_unless(rc == 0); /* wrong nick in the download queue */ fail_unless(cc_request_download(cc) == -1); /* ok, so add two files to the download queue with correct nick */ rc = queue_add("foo", "share\\foo-file2.zip", 17ULL, "/tmp/client_test_file2.zip", "ABCDEFGHIJKLMNOPQRSTUVWXYZ234"); fail_unless(rc == 0); rc = queue_add("foo", "share\\foo-file.zip", 4711ULL, "/tmp/client_test_file.zip", "ABCDEFGHIJKLMNOPQRSTUVWXYZ012"); fail_unless(rc == 0); fail_unless(cc_request_download(cc) == 0); fail_unless(cc->state == CC_STATE_REQUEST); /* should download foo-file.zip first, because they're sorted by filename */ fail_unless(strcmp(cc->current_queue->target_filename, "/tmp/client_test_file.zip") == 0); cc->has_adcget = TRUE; cc->has_tthf = TRUE; cc_start_download(cc); fail_unless(cc->state == CC_STATE_BUSY); cc_finish_download(cc); /* cc_finish_download should request another file directly if there is one * in the download queue */ fail_unless(cc->state == CC_STATE_REQUEST); fail_unless(strcmp(cc->current_queue->target_filename, "/tmp/client_test_file2.zip") == 0); cc_start_download(cc); fail_unless(cc->state == CC_STATE_BUSY); cc_finish_download(cc); fail_unless(cc->state == CC_STATE_READY); /* nothing more in the download queue */ fail_unless(cc_request_download(cc) == -1); /* zero-sized files are not downloaded (except filelists) */ rc = queue_add("foo", "share\\file3.zip", 0ULL, "/tmp/client_test_file3.zip", "ABCDEFGHIJKLMNOPQRSTUVWXYZ345"); fail_unless(rc == 0); fail_unless(cc_request_download(cc) == -1); /* download a filelist */ cc->has_xmlbzlist = true; rc = queue_add_filelist("foo", false); fail_unless(rc == 0); fail_unless(cc_request_download(cc) == 0); fail_unless(strcmp(cc->current_queue->target_filename, "/tmp/files.xml.foo.bz2") == 0); cc_start_download(cc); fail_unless(cc->state == CC_STATE_BUSY); cc_finish_download(cc); fail_unless(cc->state == CC_STATE_READY); return 0; }
bool client_submit(YAAMP_CLIENT *client, json_value *json_params) { // submit(worker_name, jobid, extranonce2, ntime, nonce): if(json_params->u.array.length<5) { debuglog("%s - %s bad message\n", client->username, client->sock->ip); client->submit_bad++; return false; } // char name[1024]; char extranonce2[32]; char ntime[32]; char nonce[32]; memset(extranonce2, 0, 32); memset(ntime, 0, 32); memset(nonce, 0, 32); int jobid = htoi(json_params->u.array.values[1]->u.string.ptr); strncpy(extranonce2, json_params->u.array.values[2]->u.string.ptr, 31); strncpy(ntime, json_params->u.array.values[3]->u.string.ptr, 31); strncpy(nonce, json_params->u.array.values[4]->u.string.ptr, 31); // debuglog("submit %s %d, %s, %s, %s\n", client->sock->ip, jobid, extranonce2, ntime, nonce); string_lower(extranonce2); string_lower(ntime); string_lower(nonce); YAAMP_JOB *job = (YAAMP_JOB *)object_find(&g_list_job, jobid, true); if(!job) { client_submit_error(client, NULL, 21, "Invalid job id", extranonce2, ntime, nonce); return true; } if(job->deleted) { client_send_result(client, "true"); object_unlock(job); return true; } YAAMP_JOB_TEMPLATE *templ = job->templ; // dump_submit_debug(client, job, extranonce2, ntime, nonce); if(strlen(nonce) != YAAMP_NONCE_SIZE*2) { client_submit_error(client, job, 20, "Invalid nonce size", extranonce2, ntime, nonce); return true; } // if(strcmp(ntime, templ->ntime)) // { // client_submit_error(client, job, 23, "Invalid time rolling", extranonce2, ntime, nonce); // return true; // } YAAMP_SHARE *share = share_find(job->id, extranonce2, ntime, nonce, client->extranonce1); if(share) { client_submit_error(client, job, 22, "Duplicate share", extranonce2, ntime, nonce); return true; } if(strlen(extranonce2) != client->extranonce2size*2) { client_submit_error(client, job, 24, "Invalid extranonce2 size", extranonce2, ntime, nonce); return true; } /////////////////////////////////////////////////////////////////////////////////////////// YAAMP_JOB_VALUES submitvalues; memset(&submitvalues, 0, sizeof(submitvalues)); build_submit_values(&submitvalues, templ, client->extranonce1, extranonce2, ntime, nonce); if(submitvalues.hash_bin[30] || submitvalues.hash_bin[31]) { client_submit_error(client, job, 25, "Invalid share", extranonce2, ntime, nonce); return true; } uint64_t hash_int = get_hash_difficulty(submitvalues.hash_bin); uint64_t user_target = diff_to_target(client->difficulty_actual); uint64_t coin_target = decode_compact(templ->nbits); // debuglog("%016llx actual\n", hash_int); // debuglog("%016llx target\n", user_target); // debuglog("%016llx coin\n", coin_target); if(hash_int > user_target && hash_int > coin_target) { client_submit_error(client, job, 26, "Low difficulty share", extranonce2, ntime, nonce); return true; } if(job->coind) client_do_submit(client, job, &submitvalues, extranonce2, ntime, nonce); else remote_submit(client, job, &submitvalues, extranonce2, ntime, nonce); client_send_result(client, "true"); client_record_difficulty(client); client->submit_bad = 0; share_add(client, job, true, extranonce2, ntime, nonce, 0); object_unlock(job); return true; }