Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/02/16 15:23:57 (8 years ago)
Author:
thasling
Message:

#2615:
made minor changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs

    r13965 r13982  
    2424    private IContactService heartbeatClient;
    2525
    26     private Random rand;
    2726
    28     private double communicationRate; //how many peers are contacted by this peer in percent
    2927
    30     public void Init(PeerInfo source, string contactServerUrl, double communicationRate) {
     28    public void Init(PeerInfo source, string contactServerUrl) {
    3129      serverString = contactServerUrl;
    32       this.communicationRate = communicationRate;
    3330      myself = source;
    34       rand = new Random();
    35      
     31
    3632      //Init ChannelFactory and Clients
    3733      var binding = new NetTcpBinding();
     
    4339      client.RegisterPeer(source);
    4440      //Start heartbeat timer
    45       timer = new Timer(1000); //each 5 minutes
     41      timer = new Timer(1000 * 20); //each 20 seconds
    4642      timer.Elapsed += SendHeartbeatToServer;
    4743      timer.Start();
     
    5147      try {
    5248        var allPeers = client.GetPeerList(myself); //maybe timout exception...
    53         var peersForMessaging = ChoosePeersForMessaging(ref allPeers);
    54         return peersForMessaging;
     49        return allPeers;
    5550      }
    5651      catch { } //if maybe sending failed (because of connection lost, etc.): just ignore
     
    7267    }
    7368
    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 
    9469    private void SendHeartbeatToServer(object sender, ElapsedEventArgs e) {
    9570      lock (timerLock) {
Note: See TracChangeset for help on using the changeset viewer.