override public void Start() { base.Start(); _estimated_time_left = DateTime.UtcNow.AddSeconds(1); SimpleTimer.Enqueue(Finished, null, 1000, 0); BH.Subscribe(this, null); _bs = new BroadcastSender(Forwarder as StructuredNode, Forwarders); _bs.Send(Simulator.SimBroadcastPType); }
/// <summary>Revoke a random node from a random node.</summary> public NodeMapping Revoke(bool log) { NodeMapping revoked = Nodes.Values[_rand.Next(0, Nodes.Count)]; NodeMapping revoker = Nodes.Values[_rand.Next(0, Nodes.Count)]; while (revoked != revoker) { revoker = Nodes.Values[_rand.Next(0, Nodes.Count)]; } string username = revoked.Node.Address.ToString().Replace('=', '0'); UserRevocationMessage urm = new UserRevocationMessage(_se_key, username); BroadcastSender bs = new BroadcastSender(revoker.Node as StructuredNode); bs.Send(new CopyList(BroadcastRevocationHandler.PType, urm)); if (log) { Console.WriteLine("Revoked: " + revoked.Node.Address); } return(revoked); }
/// <summary>Revoke a random node from a random node.</summary> public NodeMapping Revoke(bool log) { NodeMapping revoked = Nodes.Values[_rand.Next(0, Nodes.Count)]; NodeMapping revoker = Nodes.Values[_rand.Next(0, Nodes.Count)]; while(revoked != revoker) { revoker = Nodes.Values[_rand.Next(0, Nodes.Count)]; } string username = revoked.Node.Address.ToString().Replace('=', '0'); UserRevocationMessage urm = new UserRevocationMessage(_se_key, username); BroadcastSender bs = new BroadcastSender(revoker.Node as StructuredNode); bs.Send(new CopyList(BroadcastRevocationHandler.PType, urm)); if(log) { Console.WriteLine("Revoked: " + revoked.Node.Address); } return revoked; }
/// <summary>Performs a broadcast from the node at idx using the specified /// amount of forwarders.</summary> public void Broadcast(int idx, int forwarders) { _bcast.Start(); NodeMapping nm = Nodes.Values[idx]; BroadcastSender bs = new BroadcastSender(nm.Node as StructuredNode, forwarders); bs.Send(BroadcastHelper.PType); DateTime start = DateTime.UtcNow; int to_run = (int) ((_bcast.EstimatedTimeLeft - start).Ticks / TimeSpan.TicksPerMillisecond); while(to_run > 0) { SimpleTimer.RunSteps(to_run); to_run = (int) ((_bcast.EstimatedTimeLeft - DateTime.UtcNow).Ticks / TimeSpan.TicksPerMillisecond); } StreamWriter sw = null; if(_parameters.Broadcast >= -1) { FileStream fs = new FileStream(_parameters.Output, FileMode.Append); sw = new StreamWriter(fs); } int slowest = -1; List<int> sent_to = new List<int>(); foreach(BroadcastReceiver br in _bcast.Results) { sent_to.Add(br.SentTo); if(sw != null) { sw.WriteLine(br.SentTo + ", " + br.Hops); } slowest = Math.Max(slowest, br.Hops); } if(sw != null) { sw.Close(); } sent_to.Add(bs.SentTo); double avg = Average(sent_to); double stddev = StandardDeviation(sent_to, avg); Console.WriteLine("Average: {0}, StdDev: {1}", avg, stddev); Console.WriteLine("Hit: {0}, in: {1} ", _bcast.Results.Count, slowest); }