Example #1
0
        public override int Run(string[] remainingArguments)
        {
            CreateNode();
            switch(remainingArguments[0]){
            case "join":{
                var port = remainingArguments[1].Convert<int>();
                node.Connect(Environment.MachineName, port);
                dht = node.New<IDht>("System.Dht");
                dht.Join(new ActorId(remainingArguments[2] + ".localhost/System.Dht"));
            }break;

            case "put":{
                dht.Put(remainingArguments[1], remainingArguments[2]);
            }break;
            case "get":{
                Console.WriteLine(dht.Get(remainingArguments[1]));
            }break;
            }

            //			var dht = node.Proxy.New<IDht>();
            //			// join node
            //			dht.Put(new Resource("abc"), "def");
            //			Console.WriteLine("found " + dht.Get(new Resource("abc")));
            return 0;
        }
Example #2
0
        public static DHCPConfig GetDhcpConfig(IDht dht, string ipop_namespace)
        {
            byte[]      ns_key  = Encoding.UTF8.GetBytes("dhcp:" + ipop_namespace);
            Hashtable[] results = dht.Get(ns_key);

            if (results.Length == 0)
            {
                throw new Exception("Namespace does not exist: " + ipop_namespace);
            }

            string result = Encoding.UTF8.GetString((byte[])results[0]["value"]);

            XmlSerializer serializer   = new XmlSerializer(typeof(DHCPConfig));
            TextReader    stringReader = new StringReader(result);
            DHCPConfig    dhcp_config  = (DHCPConfig)serializer.Deserialize(stringReader);

            if (!ipop_namespace.Equals(dhcp_config.Namespace))
            {
                throw new Exception(String.Format("Namespace mismatch, expected {0}, got {1}",
                                                  ipop_namespace, dhcp_config.Namespace));
            }
            return(dhcp_config);
        }
Example #3
0
        /**
         * <summary>Called during LookUp to perform translation from hostname to IP.
         * If an entry isn't in cache, we can try to get it from the Dht.  Throws
         * an exception if the name is invalid and returns null if no name is found.
         * </summary>
         * <param name="name">The name to lookup</param>
         * <returns>The IP Address or null if none exists for the name.  If the name
         * is invalid, it will throw an exception.</returns>
         */
        public override String AddressLookUp(String name)
        {
            if (!name.EndsWith(DomainName))
            {
                throw new Exception("Invalid Dns name: " + name);
            }
            String ip = (String)dns_a[name];

            if (ip == null)
            {
                try {
                    ip = Encoding.UTF8.GetString((byte[])_dht.Get(Encoding.UTF8.GetBytes(_ipop_namespace + "." + name))[0]["value"]);
                    if (ip != null)
                    {
                        lock (_sync) {
                            dns_a[name] = ip;
                            dns_ptr[ip] = name;
                        }
                    }
                }
                catch {}
            }
            return(ip);
        }
Example #4
0
    public static DHCPConfig GetDhcpConfig(IDht dht, string ipop_namespace) {
      byte[] ns_key = Encoding.UTF8.GetBytes("dhcp:" + ipop_namespace);
      Hashtable[] results = dht.Get(ns_key);

      if(results.Length == 0) {
        throw new Exception("Namespace does not exist: " + ipop_namespace);
      }

      string result = Encoding.UTF8.GetString((byte[]) results[0]["value"]);

      XmlSerializer serializer = new XmlSerializer(typeof(DHCPConfig));
      TextReader stringReader = new StringReader(result);
      DHCPConfig dhcp_config = (DHCPConfig) serializer.Deserialize(stringReader);
      if(!ipop_namespace.Equals(dhcp_config.Namespace)) {
        throw new Exception(String.Format("Namespace mismatch, expected {0}, got {1}",
              ipop_namespace, dhcp_config.Namespace));
      }
      return dhcp_config;
    }