Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/01/16 10:47:53 (8 years ago)
Author:
thasling
Message:

#2615:
made minor changes

Location:
branches/thasling/DistributedGA/DistributedGA.Core
Files:
6 edited

Legend:

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

    r13957 r13965  
    2929
    3030
    31     public void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacity, int communicationRate) {
     31    public void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacity, double communicationRate) {
    3232      try {
    3333        ownInstance = new PeerInfo() {
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/TestPeerListManager.cs

    r13956 r13965  
    4242
    4343        #endregion
     44
     45        #region IPeerListManager Members
     46
     47        public void Init(PeerInfo source, string contactServerUrl, double communicationRate) {
     48          throw new System.NotImplementedException();
     49        }
     50
     51        #endregion
    4452    }
    4553}
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs

    r13959 r13965  
    2929      bufferedMessagesWrite = new SizedConcurrentQueue<KeyValuePair<PeerInfo, byte[][]>>();
    3030      bufferedMessagesWrite.Limit = bufferedMessagesRead.Limit;
    31       timer = new Timer(1000 * 60); //each 5 minutes
     31      timer = new Timer(1000 * 10); //each 10 seconds
    3232      timer.Elapsed += GenerateSendingTasks;
    3333      timer.Start();
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs

    r13959 r13965  
    2424    private IContactService heartbeatClient;
    2525
    26     private int communicationRate; //how many peers are contacted by this peer in percent
     26    private Random rand;
    2727
    28     public void Init(PeerInfo source, string contactServerUrl, int communicationRate) {
     28    private double communicationRate; //how many peers are contacted by this peer in percent
     29
     30    public void Init(PeerInfo source, string contactServerUrl, double communicationRate) {
    2931      serverString = contactServerUrl;
    3032      this.communicationRate = communicationRate;
    3133      myself = source;
     34      rand = new Random();
     35     
    3236      //Init ChannelFactory and Clients
    3337      var binding = new NetTcpBinding();
     
    4751      try {
    4852        var allPeers = client.GetPeerList(myself); //maybe timout exception...
    49         var peersForMessaging = ChoosePeersForMessaging(allPeers);
    50         //return peersForMessaging;
    51         return allPeers; //TODO: Enable 10% list communication
     53        var peersForMessaging = ChoosePeersForMessaging(ref allPeers);
     54        return peersForMessaging;
    5255      }
    5356      catch { } //if maybe sending failed (because of connection lost, etc.): just ignore
     
    7073
    7174
    72     private List<PeerInfo> ChoosePeersForMessaging(List<PeerInfo> allPeers) {
    73       //communicate with 10% of the network
    74       int noOfPeers = allPeers.Count / (100 / communicationRate);
    75       List<int> indexList = GetRandomItemIndexes(noOfPeers, 0, allPeers.Count - 1);
    76       List<PeerInfo> res = new List<PeerInfo>();
    77       foreach (int index in indexList) {
    78         res.Add(allPeers.ElementAt(index));
     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;
    7980      }
    80       return allPeers;
     81      return allPeers.Take(toTake).ToList(); ;
    8182    }
    82 
    83     private List<int> GetRandomItemIndexes(int noOfItems, int minValue, int maxValue) {
    84       List<int> res = new List<int>();
    85       Random rnd = new Random();
    86       int tmp = -1;
    87       while (res.Count < noOfItems) {
    88         tmp = rnd.Next(minValue, maxValue + 1);
    89         if (!res.Contains(tmp)) {
    90           res.Add(tmp);
    91         }
     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;
    9291      }
    93       return res;
    9492    }
    9593
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs

    r13956 r13965  
    66  public interface IMessageHandler {
    77
    8     void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacty, int communicationRate); //Registers at contract-server
     8    void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacty, double communicationRate);
    99
    1010    void PublishDataToNetwork(byte[][] data);
  • branches/thasling/DistributedGA/DistributedGA.Core/Interface/IPeerListManager.cs

    r13956 r13965  
    66  public interface IPeerListManager {
    77
    8     void Init(PeerInfo source, string contactServerUrl, int communicationRate); //Registers own instance at the contact-server
     8    void Init(PeerInfo source, string contactServerUrl, double communicationRate); //Registers own instance at the contact-server
    99
    1010    List<PeerInfo> GetPeerList(); //Recieves all peers in the network from contact-server
Note: See TracChangeset for help on using the changeset viewer.