Protocol.java 2.8 KB

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