covert-bandwidth.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Slitheen - a decoy routing system for censorship resistance
  3. * Copyright (C) 2017 Cecylia Bocovich (cbocovic@uwaterloo.ca)
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * Additional permission under GNU GPL version 3 section 7
  18. *
  19. * If you modify this Program, or any covered work, by linking or combining
  20. * it with the OpenSSL library (or a modified version of that library),
  21. * containing parts covered by the terms of the OpenSSL Licence and the
  22. * SSLeay license, the licensors of this Program grant you additional
  23. * permission to convey the resulting work. Corresponding Source for a
  24. * non-source form of such a combination shall include the source code
  25. * for the parts of the OpenSSL library used as well as that of the covered
  26. * work.
  27. */
  28. var fs = require('fs');
  29. var page = require('webpage').create();
  30. page.settings.resourceTimeout = 50000;
  31. page.onResourceRequested = function(request, network) {
  32. console.log('Request ' + JSON.stringify(request, undefined, 4));
  33. };
  34. page.onResourceReceived = function(response) {
  35. console.log('Receive ' + JSON.stringify(response, undefined, 4));
  36. };
  37. var stream = fs.open('top100.txt', 'r');
  38. function loadpage(){
  39. var line = stream.readLine();
  40. console.log(line);
  41. page.clearMemoryCache();
  42. var t = Date.now();
  43. page.open(line, function(status) {
  44. if(status === "success") {
  45. t = Date.now() - t;
  46. console.log("page load time: "+ t);
  47. fs.write("timing.out", line + ','+ t + '\n', 'a');
  48. } else {
  49. console.log("page load failed");
  50. fs.write("timing.out", line + ','+ '-1\n', 'a');
  51. }
  52. if(!stream.atEnd()){
  53. loadpage();
  54. } else {
  55. phantom.exit();
  56. }
  57. });
  58. }
  59. loadpage();