public override void ReceiveEmail(long fromPseudonym, object message, MessageType type) { if (type == MessageType.JoinRequest) { // Join the protocol. var distCount = distPseudonyms.Count; if (distCount == 1) { SendEmail(distPseudonyms[0], new BridgeJoinMessage(Pseudonym, new Zp(Simulator.Prime, Id)), MessageType.BridgeJoin); } else { // Secret share my id among all distributors var shares = ShamirSharing.Share(new Zp(Simulator.Prime, Id), distCount, Simulator.PolynomialDegree); Debug.Assert(shares.Count == distCount); Debug.Assert(Id == ShamirSharing.Reconstruct(shares, Simulator.PolynomialDegree, Simulator.Prime).Value, "The secret is not reconstructible! There is probably an overflow in polynomial evaluation of the sharing phase in Shamir sharing."); for (int i = 0; i < distCount; i++) { SendEmail(distPseudonyms[i], new BridgeJoinMessage(Pseudonym, shares[i]), MessageType.BridgeJoin); } } } else { throw new Exception("Invalid email received."); } }
//public override void Receive<BrideAssignment>(int fromNode, BrideAssignment message, MessageType type) //{ // throw new NotImplementedException(); //} public override void ReceiveEmail(long fromPseudonym, object message, MessageType type) { if (type == MessageType.UserAssignments) // From a distributor: Here's a list of bridge id share for you. { var assignments = message as List <UserAssignment>; if (distributorPseudonyms.Count == 1) { foreach (var a in assignments) { Bridges.Add(Simulator.GetNode <Bridge>((int)a.BridgeShare.Value)); } } else { foreach (var a in assignments) { if (!BridgeShares.ContainsKey(a.BridgePseudonym)) { BridgeShares[a.BridgePseudonym] = new List <Zp>(); } BridgeShares[a.BridgePseudonym].Add(a.BridgeShare); if (BridgeShares[a.BridgePseudonym].Count == distributorPseudonyms.Count) { // We have enough number of shares to reconstruct the bridge ID int bridgeId = (int)ShamirSharing.Reconstruct(BridgeShares[a.BridgePseudonym], Simulator.PolynomialDegree, Simulator.Prime).Value; Debug.Assert(Simulator.GetNodes <Bridge>().Any(b => b.Id == bridgeId), "Invalid bridge ID reconstructed from shares."); Bridges.Add(Simulator.GetNode <Bridge>(bridgeId)); BridgeShares[a.BridgePseudonym] = null; } } } } else { throw new Exception("Invalid message received."); } }