Pipeline.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package protocols;
  2. import java.util.Arrays;
  3. import communication.Communication;
  4. import crypto.Crypto;
  5. import exceptions.NoSuchPartyException;
  6. import oram.Metadata;
  7. import oram.Tree;
  8. import oram.Tuple;
  9. import protocols.struct.OutAccess;
  10. import protocols.struct.Party;
  11. import protocols.struct.PreData;
  12. import util.Timer;
  13. import util.Util;
  14. public class Pipeline extends Thread {
  15. private Communication con1;
  16. private Communication con2;
  17. private Party party;
  18. private PreData[] predata;
  19. private Tree OTi;
  20. private int h;
  21. private Timer timer;
  22. private Metadata md;
  23. private int treeIndex;
  24. private byte[] Li;
  25. private OutAccess outaccess;
  26. public Pipeline(Communication con1, Communication con2, Party party, PreData[] predata, Tree OTi, int h,
  27. Timer timer, Metadata md, int treeIndex, byte[] Li, OutAccess outaccess) {
  28. this.con1 = con1;
  29. this.con2 = con2;
  30. this.party = party;
  31. this.predata = predata;
  32. this.OTi = OTi;
  33. this.h = h;
  34. this.timer = timer;
  35. this.md = md;
  36. this.treeIndex = treeIndex;
  37. this.Li = Li;
  38. this.outaccess = outaccess;
  39. }
  40. public void runE(PreData[] predata, Tree OTi, int h, Timer timer) {
  41. // 1st eviction
  42. Access access = new Access(con1, con2);
  43. Reshuffle reshuffle = new Reshuffle(con1, con2);
  44. PostProcessT postprocesst = new PostProcessT(con1, con2);
  45. UpdateRoot updateroot = new UpdateRoot(con1, con2);
  46. Eviction eviction = new Eviction(con1, con2);
  47. Tuple[] path = reshuffle.runE(predata[0], outaccess.E_P, OTi.getTreeIndex() == 0, timer);
  48. Tuple Ti = postprocesst.runE(predata[0], outaccess.E_Ti, OTi.getTreeIndex() == h - 1, timer);
  49. Tuple[] root = Arrays.copyOfRange(path, 0, OTi.getStashSize());
  50. root = updateroot.runE(predata[0], OTi.getTreeIndex() == 0, outaccess.Li, root, Ti, timer);
  51. System.arraycopy(root, 0, path, 0, root.length);
  52. eviction.runE(predata[0], OTi.getTreeIndex() == 0, outaccess.Li,
  53. OTi.getTreeIndex() == 0 ? new Tuple[] { Ti } : path, OTi, timer);
  54. // 2nd eviction
  55. OutAccess outaccess2 = access.runE2(OTi, timer);
  56. Tuple[] path2 = outaccess2.E_P;
  57. Tuple Ti2 = outaccess2.E_Ti;
  58. Tuple[] root2 = Arrays.copyOfRange(path2, 0, OTi.getStashSize());
  59. root2 = updateroot.runE(predata[1], OTi.getTreeIndex() == 0, outaccess2.Li, root2, Ti2, timer);
  60. System.arraycopy(root2, 0, path2, 0, root2.length);
  61. eviction.runE(predata[1], OTi.getTreeIndex() == 0, outaccess2.Li,
  62. OTi.getTreeIndex() == 0 ? new Tuple[] { Ti2 } : path2, OTi, timer);
  63. }
  64. public void runD(PreData predata[], Tree OTi, Timer timer) {
  65. // 1st eviction
  66. Access access = new Access(con1, con2);
  67. Reshuffle reshuffle = new Reshuffle(con1, con2);
  68. PostProcessT postprocesst = new PostProcessT(con1, con2);
  69. UpdateRoot updateroot = new UpdateRoot(con1, con2);
  70. Eviction eviction = new Eviction(con1, con2);
  71. reshuffle.runD();
  72. postprocesst.runD();
  73. updateroot.runD(predata[0], OTi.getTreeIndex() == 0, Li, OTi.getW(), timer);
  74. eviction.runD(predata[0], OTi.getTreeIndex() == 0, Li, OTi, timer);
  75. // 2nd eviction
  76. byte[] Li2 = access.runD2(OTi, timer);
  77. updateroot.runD(predata[1], OTi.getTreeIndex() == 0, Li2, OTi.getW(), timer);
  78. eviction.runD(predata[1], OTi.getTreeIndex() == 0, Li2, OTi, timer);
  79. }
  80. public OutAccess runC(PreData[] predata, Metadata md, int ti, byte[] Li, Timer timer) {
  81. // 1st eviction
  82. Access access = new Access(con1, con2);
  83. Reshuffle reshuffle = new Reshuffle(con1, con2);
  84. PostProcessT postprocesst = new PostProcessT(con1, con2);
  85. UpdateRoot updateroot = new UpdateRoot(con1, con2);
  86. Eviction eviction = new Eviction(con1, con2);
  87. Tuple[] path = reshuffle.runC(predata[0], outaccess.C_P, ti == 0, timer);
  88. Tuple Ti = postprocesst.runC(predata[0], outaccess.C_Ti, Li, outaccess.C_Lip1, outaccess.C_j2,
  89. ti == md.getNumTrees() - 1, timer);
  90. Tuple[] root = Arrays.copyOfRange(path, 0, md.getStashSizeOfTree(ti));
  91. root = updateroot.runC(predata[0], ti == 0, root, Ti, timer);
  92. System.arraycopy(root, 0, path, 0, root.length);
  93. eviction.runC(predata[0], ti == 0, ti == 0 ? new Tuple[] { Ti } : path, md.getLBitsOfTree(ti) + 1,
  94. md.getStashSizeOfTree(ti), md.getW(), timer);
  95. // 2nd eviction
  96. byte[] Li2 = Util.nextBytes(md.getLBytesOfTree(ti), Crypto.sr);
  97. OutAccess outaccess2 = access.runC2(md, ti, Li2, timer);
  98. Tuple[] path2 = outaccess2.C_P;
  99. Tuple Ti2 = outaccess2.C_Ti;
  100. Tuple[] root2 = Arrays.copyOfRange(path2, 0, md.getStashSizeOfTree(ti));
  101. root2 = updateroot.runC(predata[1], ti == 0, root2, Ti2, timer);
  102. System.arraycopy(root2, 0, path2, 0, root2.length);
  103. eviction.runC(predata[1], ti == 0, ti == 0 ? new Tuple[] { Ti2 } : path2, md.getLBitsOfTree(ti) + 1,
  104. md.getStashSizeOfTree(ti), md.getW(), timer);
  105. return outaccess;
  106. }
  107. public void run() {
  108. if (party == Party.Eddie) {
  109. runE(predata, OTi, h, timer);
  110. } else if (party == Party.Debbie) {
  111. runD(predata, OTi, timer);
  112. } else if (party == Party.Charlie) {
  113. runC(predata, md, treeIndex, Li, timer);
  114. } else {
  115. throw new NoSuchPartyException(party + "");
  116. }
  117. }
  118. }