Protocol.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package protocols;
  2. import communication.Communication;
  3. import crypto.Crypto;
  4. import exceptions.NoSuchPartyException;
  5. import oram.Forest;
  6. import oram.Global;
  7. import oram.Metadata;
  8. import struct.Party;
  9. import util.Bandwidth;
  10. import util.Timer;
  11. public abstract class Protocol {
  12. protected Communication con1;
  13. protected Communication con2;
  14. public Timer timer;
  15. public Bandwidth online_band;
  16. public Bandwidth offline_band;
  17. /*
  18. * Connections are alphabetized so:
  19. *
  20. * For Eddie con1 = debbie con2 = charlie
  21. *
  22. * For Debbie con1 = eddie con2 = charlie
  23. *
  24. * For Charlie con1 = eddie con2 = debbie
  25. */
  26. public Protocol(Communication con1, Communication con2) {
  27. this.con1 = con1;
  28. this.con2 = con2;
  29. timer = new Timer();
  30. online_band = new Bandwidth("Online");
  31. offline_band = new Bandwidth("Offline");
  32. }
  33. private static final boolean ENSURE_SANITY = true;
  34. public boolean ifSanityCheck() {
  35. return ENSURE_SANITY;
  36. }
  37. // Utility function will test for synchrony between the parties.
  38. public void sanityCheck() {
  39. if (ENSURE_SANITY) {
  40. // System.out.println("Sanity check");
  41. con1.write("sanity");
  42. con2.write("sanity");
  43. if (!con1.readString().equals("sanity")) {
  44. System.out.println("Sanity check failed for con1");
  45. }
  46. if (!con2.readString().equals("sanity")) {
  47. System.out.println("Sanity check failed for con2");
  48. }
  49. }
  50. }
  51. public void run(Party party, Metadata md, String forestFile) {
  52. Forest forest = null;
  53. if (party == Party.Eddie) {
  54. if (Global.cheat)
  55. forest = new Forest(md, Crypto.sr);
  56. else if (forestFile == null)
  57. forest = Forest.readFromFile(md.getDefaultSharesName1());
  58. else
  59. forest = Forest.readFromFile(forestFile);
  60. } else if (party == Party.Debbie) {
  61. if (Global.cheat)
  62. forest = new Forest(md, null);
  63. else if (forestFile == null)
  64. forest = Forest.readFromFile(md.getDefaultSharesName2());
  65. else
  66. forest = Forest.readFromFile(forestFile);
  67. } else if (party == Party.Charlie) {
  68. if (Global.cheat)
  69. forest = new Forest(md, null);
  70. } else {
  71. throw new NoSuchPartyException(party.toString());
  72. }
  73. run(party, md, forest);
  74. }
  75. // a simulation using a path instead of building whole tree
  76. public void run(Party party, Metadata md) {
  77. // System.err.println("Check");
  78. assert Global.cheat;
  79. Forest[] forests = new Forest[2];
  80. // Eddie has x1, x2
  81. // Debbie has x1, x3
  82. // Charlie has x2, x3
  83. // only x1 should have content
  84. if (party == Party.Eddie) {
  85. forests[0] = new Forest(md, Crypto.sr);
  86. forests[1] = new Forest(md, null);
  87. } else if (party == Party.Debbie) {
  88. forests[0] = new Forest(md, Crypto.sr);
  89. forests[1] = new Forest(md, null);
  90. } else if (party == Party.Charlie) {
  91. forests[0] = new Forest(md, null);
  92. forests[1] = new Forest(md, null);
  93. } else {
  94. throw new NoSuchPartyException(party.toString());
  95. }
  96. run(party, md, forests);
  97. }
  98. /*
  99. * This is mostly just testing code and may need to change for the purpose of an
  100. * actual execution
  101. */
  102. public abstract void run(Party party, Metadata md, Forest forest);
  103. public abstract void run(Party party, Metadata md, Forest[] forests);
  104. }