Changeset 13982 for branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs
- Timestamp:
- 07/02/16 15:23:57 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs
r13965 r13982 24 24 private IContactService heartbeatClient; 25 25 26 private Random rand;27 26 28 private double communicationRate; //how many peers are contacted by this peer in percent29 27 30 public void Init(PeerInfo source, string contactServerUrl , double communicationRate) {28 public void Init(PeerInfo source, string contactServerUrl) { 31 29 serverString = contactServerUrl; 32 this.communicationRate = communicationRate;33 30 myself = source; 34 rand = new Random(); 35 31 36 32 //Init ChannelFactory and Clients 37 33 var binding = new NetTcpBinding(); … … 43 39 client.RegisterPeer(source); 44 40 //Start heartbeat timer 45 timer = new Timer(1000 ); //each 5 minutes41 timer = new Timer(1000 * 20); //each 20 seconds 46 42 timer.Elapsed += SendHeartbeatToServer; 47 43 timer.Start(); … … 51 47 try { 52 48 var allPeers = client.GetPeerList(myself); //maybe timout exception... 53 var peersForMessaging = ChoosePeersForMessaging(ref allPeers); 54 return peersForMessaging; 49 return allPeers; 55 50 } 56 51 catch { } //if maybe sending failed (because of connection lost, etc.): just ignore … … 72 67 } 73 68 74 75 private List<PeerInfo> ChoosePeersForMessaging(ref List<PeerInfo> allPeers) {76 Shuffle<PeerInfo>(allPeers);77 int toTake = Convert.ToInt32(allPeers.Count * communicationRate) + 1;78 if (allPeers.Count > 0 && toTake == 0) {79 toTake = 1;80 }81 return allPeers.Take(toTake).ToList(); ;82 }83 private void Shuffle<T>(IList<T> list) {84 int n = list.Count;85 while (n > 1) {86 n--;87 int k = rand.Next(n + 1);88 T value = list[k];89 list[k] = list[n];90 list[n] = value;91 }92 }93 94 69 private void SendHeartbeatToServer(object sender, ElapsedEventArgs e) { 95 70 lock (timerLock) {
Note: See TracChangeset
for help on using the changeset viewer.