Protocol.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. } else {
  61. throw new NoSuchPartyException(party.toString());
  62. }
  63. run(party, md, forest);
  64. }
  65. /*
  66. * This is mostly just testing code and may need to change for the purpose
  67. * of an actual execution
  68. */
  69. public abstract void run(Party party, Metadata md, Forest forest);
  70. }