int main(int args, char *argv[]){ int option = checkArgs(args, argv); int returnVal = 0; switch (option){ case 1:{ //-review XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = review(top, stdout); mxCleanElem (top); break; } case 2:{ //-cat returnVal = combineFiles(args, argv, stdout); break; } case 3:{ //-keep XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = selects(top, KEEP, argv[2], stdout); mxCleanElem(top); break; } case 4:{ //-discard XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = selects(top, DISCARD, argv[2], stdout); mxCleanElem(top); break; } case 5:{ //-lib XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = libFormat(top, stdout); mxCleanElem(top); break; } case 6:{ //-bib XmElem *top = openXmElemTree( stdin ); if (top == NULL){ return EXIT_FAILURE; } returnVal = bibFormat(top, stdout); mxCleanElem(top); break; } default://invalid command return EXIT_FAILURE; } return returnVal; }
/** * Create Diffie-Hellman parameters and save them to files. * Compute the shared secret and computed key from the received other public key. * Save shared secret and computed key to file. */ bool replyToFirstMessage() { cout << "Reply To First Message" << endl; // Split received file into separate files vector<string> outputFiles; outputFiles.push_back(OTHER_FIRST_MESSAGE_RANDOM_NUMBER); outputFiles.push_back(OTHER_PUBLIC_KEY_FILE_NAME); vector<int> bytesPerFile; bytesPerFile.push_back(RANDOM_NUMBER_SIZE); splitFile(FIRST_MESSAGE_FILE_NAME, outputFiles, bytesPerFile); // Read in received Diffie-Hellman public key from file SecByteBlock otherPublicKey; readFromFile(OTHER_PUBLIC_KEY_FILE_NAME, otherPublicKey); // Read in received random number from file SecByteBlock otherFirstMessageRandomNumber; readFromFile(OTHER_FIRST_MESSAGE_RANDOM_NUMBER, otherFirstMessageRandomNumber); // Prepare Diffie-Hellman parameters SecByteBlock publicKey; SecByteBlock privateKey; generateDiffieHellmanParameters(publicKey, privateKey); // Write public key and private key to files writeToFile(PRIVATE_KEY_FILE_NAME, privateKey); writeToFile(PUBLIC_KEY_FILE_NAME, publicKey); // Compute shared secret SecByteBlock sharedSecret; if (!diffieHellmanSharedSecretAgreement(sharedSecret, otherPublicKey, privateKey)) { cerr << "Security Error in replyToFirstMessage. Diffie-Hellman shared secret could not be agreed to." << endl; return false; } // Compute key from shared secret SecByteBlock key; generateSymmetricKeyFromSharedSecret(key, sharedSecret); // Write shared secret and computed key to file writeToFile(SHARED_SECRET_FILE_NAME, sharedSecret); writeToFile(COMPUTED_KEY_FILE_NAME, key); // Generate random number SecByteBlock firstMessageRandomNumber; generateRandomNumber(firstMessageRandomNumber, RANDOM_NUMBER_SIZE); // Write random number to file writeToFile(FIRST_MESSAGE_RANDOM_NUMBER_FILE_NAME, firstMessageRandomNumber); vector<string> inputFileNames; inputFileNames.push_back(FIRST_MESSAGE_RANDOM_NUMBER_FILE_NAME); inputFileNames.push_back(PUBLIC_KEY_FILE_NAME); combineFiles(inputFileNames, FIRST_MESSAGE_REPLY_FILE_NAME); return true; }
void addAndWeight(TString directory, TString plot, TFile& outputfile, double scalingFactor) { // get the histograms, erase existing at the beginning hists_.clear(); loadingHists(directory+"/"+plot); // normalize to luminosity (and add samples) combineFiles(scalingFactor); // define output plot TH1F* weightedPlot=(TH1F*)hists_[files_.size()]->Clone(); // write output to directory if(outputfile.GetDirectory(directory)==0){ outputfile.mkdir(directory); outputfile.cd(directory); } weightedPlot->Write(plot); std::cout << " " << plot; }
/** * Create Diffie-Hellman parameters and save them to files. */ void firstMessage() { cout << "First Message" << endl; // Prepare Diffie-Hellman parameters SecByteBlock publicKey; SecByteBlock privateKey; generateDiffieHellmanParameters(publicKey, privateKey); // Write public key and private key to files writeToFile(PRIVATE_KEY_FILE_NAME, privateKey); writeToFile(PUBLIC_KEY_FILE_NAME, publicKey); // Generate random number SecByteBlock firstMessageRandomNumber; generateRandomNumber(firstMessageRandomNumber, RANDOM_NUMBER_SIZE); // Write random number to file writeToFile(FIRST_MESSAGE_RANDOM_NUMBER_FILE_NAME, firstMessageRandomNumber); // Combine public key and random number into one file vector<string> inputFiles; inputFiles.push_back(FIRST_MESSAGE_RANDOM_NUMBER_FILE_NAME); inputFiles.push_back(PUBLIC_KEY_FILE_NAME); combineFiles(inputFiles, FIRST_MESSAGE_FILE_NAME); }
int main(int argc, char* argv[]) { int nThread = 10; if (argc < 3) { printf("%s <host> <filename> [thread count, default=10]\n", argv[0]); return 0; } if (argc >= 4) { nThread = atoi(argv[3]); } getLog()->open("fc"); system("mkdir .tmp >/dev/null 2>&1"); //start g_pDM = new DwManager(argv[1], 18110, nThread); g_pDM->setName(argv[2]); if (g_pDM->getSizeFromServer() < 0) { return -1; } printf("start to downlaoding...\n"); //start report pthread_t tid; pthread_create(&tid, NULL, pt_report, NULL); //how many threads? //what is the size for every thread? int threadCount = g_pDM->getThreadCount(); int64 filesize = g_pDM->getFileSize(); int64 pt_len = (filesize + threadCount) / threadCount; printf("----file size: %llu, every thread download: %llu\n", filesize, pt_len); struct pt_dwdata ptdw[THREADCOUNT]; for (int i = 0; i < threadCount; i++) { ptdw[i].number = i; ptdw[i].offset = pt_len * i; ptdw[i].length = pt_len; } ptdw[threadCount - 1].length = filesize % pt_len; for (int i = 0; i < threadCount; i++) { //printf("%d, %d, %d\n", ptdw[i].number, ptdw[i].offset, ptdw[i].length); } //start pthread_t ptid[THREADCOUNT]; for (int i = 0; i < threadCount; i++) { pthread_create(&ptid[i], NULL, pt_download, (void*)&ptdw[i]); } //finished for (int i = 0; i < threadCount; i++) { pthread_join(ptid[i], NULL); } pthread_join(tid, NULL); combineFiles(); system("/bin/rm -rf .tmp"); g_pDM->quit(); return 0; }