public override void HandleMessage(int fromId, Msg msg) { if (Stage == 0) { ReceiveShareStage(msg); if (SharesReceived == EvalGate.InputCount) { StartGateEvaluation(); } } else if (Stage == 1) { Debug.Assert(msg.Type == MsgType.SubProtocolCompleted); var completedMsg = (SubProtocolCompletedMsg)msg; CollectGateEvaluation(completedMsg); SendShareStage(); } else if (Stage == 2) { // we loopback any shares that go to me in a different quorum. Debug.Assert(msg is SubProtocolCompletedMsg); SubProtocolCompletedMsg completedMsg = (SubProtocolCompletedMsg)msg; foreach (var loopback in OutputLoopbacksNeeded) { ulong counterpartEvalId = ProtocolIdGenerator.GateEvalIdentifier(loopback.Value.Gate.TopologicalRank); T loopbackVal = (T)completedMsg.Result[loopback.Key]; NetSimulator.Loopback(Me.Id, counterpartEvalId, new LoopbackMsg <T>(loopbackVal, loopback.Value.Port)); } IsCompleted = true; } }
public override void Start() { List <Protocol> evalProtocols = new List <Protocol>(); // we want to start protocols for all of the gates I'm involved with for (int i = 0; i < GateList.Count; i++) { Debug.Assert(GateList[i] is ComputationGate); var evalQuorum = GateQuorumMapping[GateList[i]]; if (evalQuorum == MyQuorum) { ulong evalProtocolId = ProtocolIdGenerator.GateEvalIdentifier(i); evalProtocols.Add(new MultiQuorumGateEvaluation <T>(Me, (ComputationGate)GateList[i], GateQuorumMapping, Circuit, ProtocolFactory, CircuitInputs, Prime, evalProtocolId)); } } if (evalProtocols.Count > 0) { ExecuteSubProtocols(evalProtocols); } else { IsCompleted = true; } }
private void SendShareStage() { List <Protocol> reshareProtocols = new List <Protocol>(); OutputLoopbacksNeeded = new Dictionary <ulong, InputGateAddress>(); for (int i = 0; i < EvalGate.OutputCount; i++) { // figure out where this share is going to InputGateAddress counterpartGateAddr; if (Circuit.OutputConnectionCounterparties.TryGetValue(EvalGate.GetLocalOutputAddress(i), out counterpartGateAddr)) { var counterpartGate = counterpartGateAddr.Gate; var counterpartQuorum = GateQuorumMapping[counterpartGate]; bool needReshare; bool needLoopback; if (counterpartQuorum == EvalQuorum) { needLoopback = true; needReshare = false; } else if (counterpartQuorum.HasMember(Me.Id)) { needLoopback = true; needReshare = true; } else { needLoopback = false; needReshare = true; } if (needLoopback && !needReshare) { // loop a message back to the other protocol ulong counterpartEvalId = ProtocolIdGenerator.GateEvalIdentifier(counterpartGate.TopologicalRank); NetSimulator.Loopback(Me.Id, counterpartEvalId, new LoopbackMsg <T>(OutputShares[i], counterpartGateAddr.Port)); } if (needReshare) { Protocol reshareProtocol = ProtocolFactory.GetResharingProtocol(Me, EvalQuorum, counterpartQuorum, OutputShares[i], counterpartGate.TopologicalRank, counterpartGateAddr.Port); reshareProtocols.Add(reshareProtocol); if (needLoopback) { OutputLoopbacksNeeded[reshareProtocol.ProtocolId] = counterpartGateAddr; } } } else { // this was a circuit output Result[EvalGate.GetLocalOutputAddress(i)] = OutputShares[i]; } } Stage = 2; if (reshareProtocols.Count > 0) { ExecuteSubProtocols(reshareProtocols); } else { IsCompleted = true; } }