changeset 60:14222beab95b

fix
author KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
date Thu, 27 Jan 2022 18:05:42 +0900
parents c4f8630b7822
children 1a42115e51bb
files topology/HostMessage.cs topology/manager/ConfigWaiter.cs topology/manager/CreateHash.cs topology/manager/CreateTreeTopology.cs topology/manager/IncomingHosts.cs topology/manager/RecordTopology.cs topology/manager/SearchHostName.cs topology/manager/TopologyFinish.cs topology/node/PrepareToClose.cs
diffstat 9 files changed, 218 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/topology/HostMessage.cs	Thu Jan 27 01:19:51 2022 +0900
+++ b/topology/HostMessage.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -4,7 +4,7 @@
 
 
 namespace Christie_net.topology {
-    public class HostMessage /*: Cloneable*/ {
+    public class HostMessage /*: Cloneable*/ { 
         private String hostName = "";
     private int port ;
     private String nodeName; // this is nodeName which have these IP and port.
@@ -18,12 +18,20 @@
     public HostMessage() {}
 
     public void setLocalHostAndPort(int port){
-        try {
-            hostName = InetAddress.getLocalHost().getHostAddress();
+        
+        hostName = Dns.GetHostName();
+        hostName = Dns.GetHostAddresses(hostName).ToString();
+        this.port = port;
+        /*
+        try
+        {
+            hostName = Dns.GetHostName();
+            hostName = Dns.GetHostAddresses(hostName).ToString();
             this.port = port;
         } catch (UnknownHostException e) {
             e.printStackTrace();
         }
+        */
     }
 
     public void setHostAndPort(HostMessage hostMessage) {
--- a/topology/manager/ConfigWaiter.cs	Thu Jan 27 01:19:51 2022 +0900
+++ b/topology/manager/ConfigWaiter.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using Christie_net.daemon;
+using Christie_net.annotation;
+using Christie_net.codegear;
+using Christie_net.topology;
+
+
+namespace Christie_net.topology.manager {
+
+    public class ConfigWaiter : CodeGear {
+        [Peek] public LinkedList<String> waiterNodeNames;
+        [Take] public Message _DONEMESSAGE;
+        [Take] public int nodeNum;
+        
+        public ConfigWaiter() {
+        }
+
+        public override void Run(CodeGearManager cgm) {
+            nodeNum--;
+            if (nodeNum == 0) {
+                GetLocalDgm().Put("_STARTMESSAGE", new Message());
+                foreach (String nodeName in waiterNodeNames) GetDgm(nodeName).Put("_STARTMESSAGE", new Message());
+                GetLocalDgm().Put("startTime", CurrentTimeMillis());
+                GetLocalDgm().Put("running", true);
+
+                return;
+            }
+
+            cgm.Setup(new ConfigWaiter());
+            GetLocalDgm().Put("nodeNum", nodeNum);
+        }
+        private static readonly DateTime Jan1st1970 = new DateTime
+            (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+        public static long CurrentTimeMillis()
+        {
+            return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/topology/manager/CreateHash.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -0,0 +1,98 @@
+using System;
+using System.Text;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Collections.Generic;
+using Christie_net.daemon;
+using Christie_net.annotation;
+using Christie_net.codegear;
+using Christie_net.topology;
+
+
+namespace Christie_net.topology.manager {
+
+    public class CreateHash : CodeGear
+    {
+        [Take] public String orderHash;
+        [Peek] public LinkedList<String> createdList;
+
+        public CreateHash()
+        {
+        }
+
+        public override void Run(CodeGearManager cgm)
+        {
+            Boolean checkNewStr = false;
+            String raw = null;
+
+            while (!checkNewStr)
+            {
+                //raw = RandomStringUtils.randomAscii(10);
+                raw = RandomString();
+                // checking raw String has already created
+                int count = 0;
+                foreach (String str in createdList)
+                {
+                    if (raw.Equals(str)) break;
+                    count++;
+                }
+
+                if (count == createdList.Count) checkNewStr = true;
+            }
+
+            createdList.AddLast(raw);
+            
+            /*
+            try
+            {
+                // convert to MD5
+                String MD5 = convertMD5(raw);
+
+                GetLocalDgm().Put("MD5", MD5);
+            }
+            
+            catch (NoSuchAlgorithmException e)
+            {
+                System.out.println("cannot convert MD5");
+
+            }
+            */
+
+            cgm.Setup(new CreateHash());
+        }
+        
+        
+        private static Random random = new Random();
+        
+        public static string RandomString(int length = 10)
+        {
+            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+            return new string(Enumerable.Repeat(chars, length)
+                .Select(s => s[random.Next(s.Length)]).ToArray());
+        }
+
+
+        private String convertMD5(String raw) /*throws NoSuchAlgorithmException*/
+        {
+            
+            MessageDiges md = MessageDiges.getInstance("MD5");
+            md.update(raw.GetBytes());
+            byte[] hash = md.digest();
+            
+            
+            StringBuilder builder = new StringBuilder();
+            foreach (byte aHash in hash)
+            {
+                if ((0xff & aHash) < 0x10)
+                {
+                    builder.Append("0" + Integer.ToHexString((0xff & aHash)));
+                }
+                else
+                {
+                    builder.Append(Integer.toHexString((0xff & aHash)));
+                }
+            }
+            return builder.ToString();
+        }
+    }
+}
--- a/topology/manager/CreateTreeTopology.cs	Thu Jan 27 01:19:51 2022 +0900
+++ b/topology/manager/CreateTreeTopology.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -34,12 +34,12 @@
         GetDgm(nodeName).Put("topoDG", topoDG);
         GetDgm(nodeName).Put("cookie", MD5);
 
-        absCookieTable.put(MD5, nodeName);
-        GetLocalDgm().Put("absCookieTable", absCookieTable);
+        //absCookieTable.put(MD5, nodeName);
+        //GetLocalDgm().Put("absCookieTable", absCookieTable);
 
         GetLocalDgm().Put("hostCount", hostCount + 1);
         newHost.setAlive(true);
-        nameTable.put(nodeName, newHost);
+        nameTable.Add(nodeName, newHost);
         parentManager.register(nodeName);
 
         if (hostCount == 0) {
@@ -47,7 +47,7 @@
         } else {
             // put parent information own
             String parentNodeName = parentManager.getMyParent();
-            HostMessage parentHost = nameTable.get(parentNodeName).clone();
+            HostMessage parentHost = nameTable[parentNodeName];
 
 
             // 相手からhostNameとportはもらっているので, nodeの情報だけ与えれば良い.
@@ -71,11 +71,17 @@
         //getDGM(nodeName).put("remoteNodeInfo", new HostMessage());
         GetDgm(nodeName).Put("_CONNECTIONMESSAGE", new Message());
         GetDgm(nodeName).Put("_STARTMESSAGE", new Message());
-        GetLocalDgm().Put("startTime", System.currentTimeMillis());
+        GetLocalDgm().Put("startTime", CurrentTimeMillis());
 
         cgm.Setup(new CreateTreeTopology());
 
+        }
 
+        private static readonly DateTime Jan1st1970 = new DateTime
+            (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+        public static long CurrentTimeMillis()
+        {
+            return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
         }
     }
 }
\ No newline at end of file
--- a/topology/manager/IncomingHosts.cs	Thu Jan 27 01:19:51 2022 +0900
+++ b/topology/manager/IncomingHosts.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -1,8 +1,10 @@
 using System;
+using System.Net.Sockets;
 using System.Collections.Generic;
 using Christie_net.annotation;
 using Christie_net.codegear;
 using Christie_net.topology.manager;
+using Microsoft.VisualBasic;
 
 namespace Christie_net.topology.manager {
 
@@ -30,12 +32,12 @@
                             newHost.getHostName(),
                             newHost.getPort());
 
-        absCookieTable.put(MD5, nodeName);
+        absCookieTable.Add(MD5, nodeName);
         GetLocalDgm().Put("absCookieTable", absCookieTable);
 
-        GetDgm(nodeName).put("cookie", MD5);
+        GetDgm(nodeName).Put("cookie", MD5);
 
-        LinkedList<HostMessage> nodeInfoList = resultParse.get(nodeName);
+        LinkedList<HostMessage> nodeInfoList = resultParse[nodeName];
         Put(nodeName, "connectNodeNum", nodeInfoList.Count);
         if(nodeInfoList.Count == 0) Put(nodeName,"_CONNECTIONMESSAGE", new Message());
 
@@ -55,10 +57,10 @@
             if (!topology.ContainsKey(nodeInfoNodeName)) {
                 connections = new LinkedList<HostMessage>();
             } else {
-                connections = topology.get(nodeInfoNodeName);
+                connections = topology[nodeInfoNodeName];
             }
-            connections.add(nodeInfo);
-            topology.put(nodeInfoNodeName, connections);
+            connections.AddLast(nodeInfo);
+            topology.Add(nodeInfoNodeName, connections);
         }
 
         GetLocalDgm().Put("topology", topology);
@@ -66,11 +68,11 @@
 
         if (nodeNames.isEmpty()) {//文字列が空かどうかの判定
             // configuration finish
-            foreach (String key in resultParse.keySet()) {//キーの取得
+            foreach (String key in resultParse.Keys) {//キーの取得
                 topoDG.setNodeName(key);
                 GetDgm(key).Put("topoDG", topoDG);
                 if(topology.ContainsKey(key)){
-                    LinkedList<HostMessage> connections = topology.get(key);
+                    LinkedList<HostMessage> connections = topology[key];
                     foreach(HostMessage connection in connections) {
                         Put(key, "remoteNodeInfo", connection);
                     }
--- a/topology/manager/RecordTopology.cs	Thu Jan 27 01:19:51 2022 +0900
+++ b/topology/manager/RecordTopology.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -20,10 +20,10 @@
             if (!topology.ContainsKey(nodeName)) {
                 connections = new LinkedList<HostMessage>();
             } else {
-                connections = topology.get(nodeName);
+                connections = topology[nodeName];
             }
-            connections.add(nodeInfo);
-            topology.put(nodeName, connections);
+            connections.AddLast(nodeInfo);
+            topology.Add(nodeName, connections);
 
             GetLocalDgm().Put("topology", topology);
 
--- a/topology/manager/SearchHostName.cs	Thu Jan 27 01:19:51 2022 +0900
+++ b/topology/manager/SearchHostName.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -40,7 +40,7 @@
                 }
 
 
-                LinkedList<HostMessage> hostList = topology.get(nodeName);
+                LinkedList<HostMessage> hostList = topology[nodeName];
                 foreach (HostMessage host in hostList)
                 {
                     GetLocalDgm().Put(nodeName, host);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/topology/manager/TopologyFinish.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using Christie_net.daemon;
+using Christie_net.annotation;
+using Christie_net.codegear;
+using Christie_net.topology;
+
+
+namespace Christie_net.topology.manager {
+
+    public class TopologyFinish : CodeGear {
+        [Take] public Message FINISHMESSAGE;
+        [Take] public TopologyManagerConfig topologyManagerConfig;
+        [Take] public long startTime;
+        
+        public TopologyFinish() {
+        }
+
+        public override void Run(CodeGearManager cgm) {
+            if (topologyManagerConfig.showTime) {
+                Console.WriteLine("TopologymanagerTime = " + (CurrentTimeMillis() - startTime));
+            }
+
+
+            foreach(String dgm in cgm.GetDgmList().Keys){
+                GetDgm(dgm).Put("_CLOSEMESSEAGE", new Message());
+                GetDgm(dgm).Shutdown();
+            }
+
+            GetLocalDgm().Finish();
+        }
+        
+        
+        private static readonly DateTime Jan1st1970 = new DateTime
+            (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+        public static long CurrentTimeMillis()
+        {
+            return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
+        }
+        
+    }
+}
\ No newline at end of file
--- a/topology/node/PrepareToClose.cs	Thu Jan 27 01:19:51 2022 +0900
+++ b/topology/node/PrepareToClose.cs	Thu Jan 27 18:05:42 2022 +0900
@@ -21,8 +21,8 @@
 
         public override void Run(CodeGearManager cgm) {
             List<String> _CLIST = topoDG.getConnectionList();
-            for(String dgmName: _CLIST){
-                GetDgm(dgmName).shutdown();
+            foreach(String dgmName in _CLIST){
+                GetDgm(dgmName).Shutdown();
                 //_CLIST.remove(dgmName);
             }