Пример #1
0
 private void RunOnNode(NetworkNodeInfo newNode)
 {
     if (_psoController.CalculationsRunning)
     {
         NetworkNodeManager.StartCalculations(_psoController.RunningParameters, newNode);
     }
 }
Пример #2
0
        public void UpdatePsoNeighborhood(NetworkNodeInfo[] allNetworkNodes,
            NetworkNodeInfo currentNetworkNode)
        {
            //do nothing if there is only current network in collection
            if (allNetworkNodes == null || allNetworkNodes.Length <= 1)
                return;
            var nodes = allNetworkNodes.OrderBy(t => t.Id).ToArray();
            NetworkNodeInfo previous = null, next = null;
            for (int index = 0; index < nodes.Length; index++)
            {
                var node = nodes[index];
                if (node.Id != currentNetworkNode.Id) continue;

                previous = nodes[(index - 1 + nodes.Length) % nodes.Length];
                next = nodes[(index + 1) % nodes.Length];
                break;
            }
            if (previous == null || next == null)
            {
                throw new ArgumentException("allNetworkNodes should include this node itself");
            }
            if (_left.Item1 == null || previous.Id != _left.Item1.Id || !previous.ProxyParticlesAddresses.Contains(_left.Item2.RemoteAddress))
            {
                _left.Item2.UpdateRemoteAddress(previous.ProxyParticlesAddresses[0]);
                _left = new Tuple<NetworkNodeInfo, ProxyManager>(previous, _left.Item2);
            }
            if (_right.Item1 == null || next.Id != _right.Item1.Id || !next.ProxyParticlesAddresses.Contains(_right.Item2.RemoteAddress))
            {
                _right.Item2.UpdateRemoteAddress(next.ProxyParticlesAddresses[next.ProxyParticlesAddresses.Length - 1]);
                _right = new Tuple<NetworkNodeInfo, ProxyManager>(next, _right.Item2);

            }
        }
Пример #3
0
 public NodeService(string tcpAddress, int tcpPort, string pipeName)
     : this()
 {
     Info = new NetworkNodeInfo("net.tcp://" + tcpAddress + ":" + tcpPort + "/NodeService", "net.pipe://" + "127.0.0.1" + "/NodeService/" + pipeName);
     KnownNodes.Add(Info);
     PsoManager = new PsoRingManager(Info.Id);
 }
Пример #4
0
 public NodeService(string tcpAddress, int tcpPort, string pipeName)
     : this()
 {
     Info = new NetworkNodeInfo("net.tcp://" + tcpAddress + ":" + tcpPort + "/NodeService", "net.pipe://" + "127.0.0.1" + "/NodeService/" + pipeName);
     KnownNodes.Add(Info);
     PsoManager = new PsoRingManager(Info.Id);
 }
Пример #5
0
        public void Register(NetworkNodeInfo info)
        {
            var client    = new TcpNodeServiceClient(info);
            var neighbors = client.Register(NodeService.Info);

            NodeService.UpdateNodes(neighbors);
        }
Пример #6
0
 public void Run(PsoParameters psoParameters, NetworkNodeInfo mainNodeInfo)
 {
     _mainNodeInfo = mainNodeInfo;
     if (!_psoController.CalculationsRunning)
     {
         _psoController.Run(psoParameters, PsoRingManager.GetProxyParticles());
     }
 }
Пример #7
0
 public void CalculationsFinished(NetworkNodeInfo source, ParticleState result)
 {
     Debug.WriteLine("{0}: received calculations finish from {1}",Info.Id, source.Id);
     if (RemoteCalculationsFinished != null)
     {
         RemoteCalculationsFinished(new RemoteCalculationsFinishedHandlerArgs(source, result));
     }
 }
Пример #8
0
 public void CalculationsFinished(NetworkNodeInfo source, ParticleState result)
 {
     Debug.WriteLine("{0}: received calculations finish from {1}", Info.Id, source.Id);
     if (RemoteCalculationsFinished != null)
     {
         RemoteCalculationsFinished(new RemoteCalculationsFinishedHandlerArgs(source, result));
     }
 }
Пример #9
0
 public void StartCalculation(PsoParameters parameters, NetworkNodeInfo mainNodeInfo)
 {
     Debug.WriteLine("{0}: starting calculations.", Info.Id);
     if (StartCalculations != null)
     {
         StartCalculations(parameters, mainNodeInfo);
     }
 }
Пример #10
0
 public void Deregister(NetworkNodeInfo brokenNodeInfo)
 {
     try
     {
         Proxy.Deregister(brokenNodeInfo);
     }
     catch
     {
     }
 }
Пример #11
0
 public void StartCalculation(PsoParameters parameters, NetworkNodeInfo mainNodeInfo)
 {
     try
     {
         Proxy.StartCalculation(parameters, mainNodeInfo);
     }
     catch
     {
     }
 }
Пример #12
0
 public void CalculationsFinished(NetworkNodeInfo source, ParticleState result)
 {
     try
     {
         Proxy.CalculationsFinished(source, result);
     }
     catch
     {
         // ignored
     }
 }
Пример #13
0
 public NetworkNodeInfo[] Register(NetworkNodeInfo source)
 {
     try
     {
         return(Proxy.Register(source));
     }
     catch
     {
     }
     return(null);
 }
Пример #14
0
        public void CalculationsFinished(NetworkNodeInfo source, ParticleState result)
        {
            try
            {
                Proxy.CalculationsFinished(source, result);

            }
            catch
            {
                // ignored
            }
        }
Пример #15
0
        public void StartCalculation(PsoParameters parameters, NetworkNodeInfo mainNodeInfo)
        {
            try
            {
                Proxy.StartCalculation(parameters, mainNodeInfo);

            }
            catch
            {

            }
        }
Пример #16
0
        public void Deregister(NetworkNodeInfo brokenNodeInfo)
        {
            try
            {
                Proxy.Deregister(brokenNodeInfo);

            }
            catch
            {

            }
        }
Пример #17
0
        public NetworkNodeInfo[] Register(NetworkNodeInfo source)
        {
            try
            {
                return Proxy.Register(source);
            }
            catch
            {

            }
            return null;
        }
Пример #18
0
        public void StartCalculations(PsoParameters parameters, NetworkNodeInfo target)
        {
            var client = new TcpNodeServiceClient(target);

            try
            {
                client.StartCalculation(parameters, NodeService.Info);
            }
            catch
            {
                Debug.WriteLine("cannot start calculations on {0}", parameters);
            }
        }
Пример #19
0
 private void BroadcastNeighborhoodList(NetworkNodeInfo skipNode = null)
 {
     Debug.WriteLine("{0}: broadcasting neighbors list", Info.Id);
     foreach (var networkNodeInfo in KnownNodes)
     {
         if (networkNodeInfo.Id == Info.Id || (skipNode != null && networkNodeInfo.Id == skipNode.Id))
         {
             continue;
         }
         NodeServiceClient nodeServiceClient = new TcpNodeServiceClient(networkNodeInfo.TcpAddress);
         nodeServiceClient.UpdateNodes(KnownNodes.ToArray());
     }
 }
Пример #20
0
 public NetworkNodeInfo[] Register(NetworkNodeInfo source)
 {
     Debug.WriteLine("{0}: registering new node", Info.Id);
     KnownNodes.Add(source);
     BroadcastNeighborhoodList(source);
     Task.Factory.StartNew(() =>
     {
         if (RegisterNode != null)
         {
             RegisterNode(source);
         }
         if (NeighborhoodChanged != null)
         {
             NeighborhoodChanged(KnownNodes.ToArray(), Info);
         }
     });
     return(KnownNodes.ToArray());
 }
Пример #21
0
        public void Deregister(NetworkNodeInfo brokenNodeInfo)
        {
            var nodes = KnownNodes.Where(n => n.Id == brokenNodeInfo.Id);

            if (!nodes.Any())
            {
                Debug.WriteLine("{0}:  Trying to deregister node {1}, already removed", Info.Id, brokenNodeInfo.Id);
                return;
            }
            Debug.WriteLine("{0}: deregistering node {1}", Info.Id, brokenNodeInfo.Id);
            var node = KnownNodes.First(n => n.Id == brokenNodeInfo.Id);

            KnownNodes.Remove(node);
            BroadcastNeighborhoodList();
            Task.Factory.StartNew(() =>
            {
                if (NeighborhoodChanged != null)
                {
                    NeighborhoodChanged(KnownNodes.ToArray(), Info);
                }
            });
        }
Пример #22
0
        public void UpdatePsoNeighborhood(NetworkNodeInfo[] allNetworkNodes,
                                          NetworkNodeInfo currentNetworkNode)
        {
            //do nothing if there is only current network in collection
            if (allNetworkNodes == null || allNetworkNodes.Length <= 1)
            {
                return;
            }
            var             nodes = allNetworkNodes.OrderBy(t => t.Id).ToArray();
            NetworkNodeInfo previous = null, next = null;

            for (int index = 0; index < nodes.Length; index++)
            {
                var node = nodes[index];
                if (node.Id != currentNetworkNode.Id)
                {
                    continue;
                }

                previous = nodes[(index - 1 + nodes.Length) % nodes.Length];
                next     = nodes[(index + 1) % nodes.Length];
                break;
            }
            if (previous == null || next == null)
            {
                throw new ArgumentException("allNetworkNodes should include this node itself");
            }
            if (_left.Item1 == null || previous.Id != _left.Item1.Id || !previous.ProxyParticlesAddresses.Contains(_left.Item2.RemoteAddress))
            {
                _left.Item2.UpdateRemoteAddress(previous.ProxyParticlesAddresses[0]);
                _left = new Tuple <NetworkNodeInfo, ProxyManager>(previous, _left.Item2);
            }
            if (_right.Item1 == null || next.Id != _right.Item1.Id || !next.ProxyParticlesAddresses.Contains(_right.Item2.RemoteAddress))
            {
                _right.Item2.UpdateRemoteAddress(next.ProxyParticlesAddresses[next.ProxyParticlesAddresses.Length - 1]);
                _right = new Tuple <NetworkNodeInfo, ProxyManager>(next, _right.Item2);
            }
        }
Пример #23
0
 public PipeNodeServiceClient(NetworkNodeInfo nodeInfo)
     : this(nodeInfo.PipeAddress)
 {
 }
Пример #24
0
 public RemoteCalculationsFinishedHandlerArgs(NetworkNodeInfo source, object result)
 {
     Source = source;
     Result = result;
 }
Пример #25
0
 public void Run(PsoParameters psoParameters, NetworkNodeInfo mainNodeInfo)
 {
     _mainNodeInfo = mainNodeInfo;
     if (!_psoController.CalculationsRunning)
     {
         _psoController.Run(psoParameters, PsoRingManager.GetProxyParticles());
     }
 }
Пример #26
0
 private void RunOnNode(NetworkNodeInfo newNode)
 {
     if (_psoController.CalculationsRunning)
     {
         NetworkNodeManager.StartCalculations(_psoController.RunningParameters, newNode);
     }
 }
Пример #27
0
 public void StartCalculation(PsoParameters parameters, NetworkNodeInfo mainNodeInfo)
 {
     Debug.WriteLine("{0}: starting calculations.", Info.Id);
     if (StartCalculations != null) StartCalculations(parameters, mainNodeInfo);
 }
Пример #28
0
 public PipeNodeServiceClient(NetworkNodeInfo nodeInfo)
     : this(nodeInfo.PipeAddress)
 {
 }
Пример #29
0
    public override NetworkNodeInfo GetNodeInfo(int x, int y)
    {
        //Debug.Log("Get node info " + x + " " + y + " " + nodes.GetLength(0) + " " + nodes.GetLength(1));

        NetworkNodeInfo info = new NetworkNodeInfo();

        if (nodes != null && x >= 0 && x < width && y >= 0 && y < height && nodes[x, y] != null)
        {
            info = nodes[x, y];

            if (info.nodeRole >= 0 && info.nodeRole < Library.instance.rolesSpr.Count)
            {
                info.sprite = Library.instance.rolesSpr[info.nodeRole];
            }

            return(info);
        }

        info.nodeType       = GetNodeType(x, y);
        info.nodeRole       = GetNodeRole(x, y);
        info.localAddress   = new Vector2Int(x, y);
        info.globalAddress  = GetGlobalAddress(info.localAddress);
        info.nodeDifficulty = GetNodeDifficulty(x, y);

        int appLevel = GMARandom.Range2D(info.nodeDifficulty * 10, (info.nodeDifficulty + 1) * 10, info.globalAddress.x, info.globalAddress.y);

        if (appLevel < 1)
        {
            appLevel = 1;
        }

        NetworkNodeInfo.AppSettings app = new NetworkNodeInfo.AppSettings();
        app.appName  = "LocalNode";
        app.appLevel = appLevel;
        info.apps.Add(app);

        int xx = info.globalAddress.x + x;
        int yy = info.globalAddress.y + y;

        appLevel = GMARandom.Range2D(appLevel - 1, appLevel + 2, xx, yy);
        if (appLevel == 0)
        {
            appLevel = 1;
        }


        if (info.nodeRole == 1)
        {
            app          = new NetworkNodeInfo.AppSettings();
            app.appName  = "SecurityModule";
            app.appLevel = appLevel;
            info.apps.Add(app);
        }
        else if (info.nodeRole == 4)
        {
            app          = new NetworkNodeInfo.AppSettings();
            app.appName  = "DataStorage";
            app.appLevel = appLevel;
            info.apps.Add(app);
        }
        else if (info.nodeRole == 5)
        {
            app          = new NetworkNodeInfo.AppSettings();
            app.appName  = "PersonalComputer";
            app.appLevel = appLevel;
            info.apps.Add(app);
        }

        if (info.nodeRole >= 0 && info.nodeRole < Library.instance.rolesSpr.Count)
        {
            info.sprite = Library.instance.rolesSpr[info.nodeRole];
        }

        return(info);
    }
Пример #30
0
 public TcpNodeServiceClient(NetworkNodeInfo nodeInfo)
     : this(nodeInfo.TcpAddress)
 {
 }
Пример #31
0
 public void UpdateNodes(NetworkNodeInfo[] nodes)
 {
     foreach (var networkNodeInfo in nodes)
     {
         if (KnownNodes.Contains(networkNodeInfo)) continue;
         Debug.WriteLine("{0}: updating nodes", Info.Id);
         KnownNodes = new List<NetworkNodeInfo>(nodes);
         if (NeighborhoodChanged != null) NeighborhoodChanged(KnownNodes.ToArray(), Info);
     }
 }
Пример #32
0
 private void BroadcastNeighborhoodList(NetworkNodeInfo skipNode = null)
 {
     Debug.WriteLine("{0}: broadcasting neighbors list", Info.Id);
     foreach (var networkNodeInfo in KnownNodes)
     {
         if (networkNodeInfo.Id == Info.Id ||(skipNode != null && networkNodeInfo.Id == skipNode.Id)) continue;
         NodeServiceClient nodeServiceClient = new TcpNodeServiceClient(networkNodeInfo.TcpAddress);
         nodeServiceClient.UpdateNodes(KnownNodes.ToArray());
     }
 }
Пример #33
0
 public TcpNodeServiceClient(NetworkNodeInfo nodeInfo)
     : this(nodeInfo.TcpAddress)
 {
 }
 public RemoteCalculationsFinishedHandlerArgs(NetworkNodeInfo source, object result)
 {
     Source = source;
     Result = result;
 }
Пример #35
0
 public void StartCalculations(PsoParameters parameters, NetworkNodeInfo target)
 {
     var client = new TcpNodeServiceClient(target);
     try
     {
         client.StartCalculation(parameters, NodeService.Info);
     }
     catch
     {
         Debug.WriteLine("cannot start calculations on {0}", parameters);
     }
 }
Пример #36
0
 public void Register(NetworkNodeInfo info)
 {
     var client = new TcpNodeServiceClient(info);
     var neighbors = client.Register(NodeService.Info);
     NodeService.UpdateNodes(neighbors);
 }
Пример #37
0
 public void Deregister(NetworkNodeInfo brokenNodeInfo)
 {
     var nodes = KnownNodes.Where(n => n.Id == brokenNodeInfo.Id);
     if (!nodes.Any())
     {
         Debug.WriteLine("{0}:  Trying to deregister node {1}, already removed", Info.Id, brokenNodeInfo.Id);
         return;
     }
     Debug.WriteLine("{0}: deregistering node {1}", Info.Id, brokenNodeInfo.Id);
     var node = KnownNodes.First(n => n.Id == brokenNodeInfo.Id);
     KnownNodes.Remove(node);
     BroadcastNeighborhoodList();
     Task.Factory.StartNew(() =>
     {
         if (NeighborhoodChanged != null) NeighborhoodChanged(KnownNodes.ToArray(), Info);
     });
 }
Пример #38
0
        public void UpdateNodes(NetworkNodeInfo[] nodes)
        {
            try
            {
                Proxy.UpdateNodes(nodes);
            }
            catch
            {

            }
        }
Пример #39
0
 public NetworkNodeInfo[] Register(NetworkNodeInfo source)
 {
     Debug.WriteLine("{0}: registering new node", Info.Id);
     KnownNodes.Add(source);
     BroadcastNeighborhoodList(source);
     Task.Factory.StartNew(() =>
     {
         if (RegisterNode != null) RegisterNode(source);
         if (NeighborhoodChanged != null) NeighborhoodChanged(KnownNodes.ToArray(), Info);
     });
     return KnownNodes.ToArray();
 }