Пример #1
0
        public override bool Equals(object o)
        {
            if (o == this)
            {
                return(true);
            }
            TunnelTransportAddress other = o as TunnelTransportAddress;

            if (other == null)
            {
                return(false);
            }

            bool same = _target.Equals(other._target);

            same &= (_forwarders.Count == other._forwarders.Count);
            if (!same)
            {
                return(false);
            }
            for (int i = 0; i < _forwarders.Count; i++)
            {
                same = _forwarders[i].Equals(other._forwarders[i]);
                if (!same)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        protected static TransportAddress NoCacheCreateInstance(string s)
        {
            string scheme = s.Substring(0, s.IndexOf(":"));
            string t      = scheme.Substring(scheme.IndexOf('.') + 1);
            //Console.Error.WriteLine(t);

            TransportAddress result = null;

            TransportAddress.TAType ta_type = StringToType(t);

            switch (ta_type)
            {
            case TransportAddress.TAType.Tcp:
                result = new IPTransportAddress(s);
                break;

            case TransportAddress.TAType.Udp:
                result = new IPTransportAddress(s);
                break;

            case TransportAddress.TAType.Function:
                result = new IPTransportAddress(s);
                break;

            case TransportAddress.TAType.S:
                result = new SimulationTransportAddress(s);
                break;

            case TransportAddress.TAType.Tls:
                result = new IPTransportAddress(s);
                break;

            case TransportAddress.TAType.TlsTest:
                result = new IPTransportAddress(s);
                break;

            case TransportAddress.TAType.Tunnel:
                result = new TunnelTransportAddress(s);
                break;
            }

            return(result);
        }
Пример #3
0
    protected static TransportAddress NoCacheCreateInstance(string s) {
      string scheme = s.Substring(0, s.IndexOf(":"));
      string t = scheme.Substring(scheme.IndexOf('.') + 1);
      //Console.Error.WriteLine(t);
      
      TransportAddress result = null;
      TransportAddress.TAType ta_type = StringToType(t);
      
      switch(ta_type) {
        case TransportAddress.TAType.Tcp:
          result = new IPTransportAddress(s);
          break;
        case TransportAddress.TAType.Udp:
          result = new IPTransportAddress(s);
          break;
        case TransportAddress.TAType.Function:
          result = new IPTransportAddress(s);
          break;
        case TransportAddress.TAType.S:
          result = new SimulationTransportAddress(s);
          break;
        case TransportAddress.TAType.Tls:
          result = new IPTransportAddress(s);
          break;
        case TransportAddress.TAType.TlsTest:
          result = new IPTransportAddress(s);
          break;
        case TransportAddress.TAType.Tunnel:
          result = new TunnelTransportAddress(s);
          break;
      }

      return result;
    }
Пример #4
0
    public void Test() {
      TransportAddress tas = TransportAddressFactory.CreateInstance("b.s://234580");
      Assert.AreEqual(tas.ToString(), "b.s://234580", "Simulation string");
      Assert.AreEqual((tas as SimulationTransportAddress).ID, 234580, "Simulation id");
      Assert.AreEqual(TransportAddress.TAType.S, tas.TransportAddressType, "Simulation ta type");
      TransportAddress ta1 = TransportAddressFactory.CreateInstance("brunet.udp://10.5.144.69:5000");
      Assert.AreEqual(ta1.ToString(), "brunet.udp://10.5.144.69:5000", "Testing TA parsing");
      
      TransportAddress ta2 = TransportAddressFactory.CreateInstance("brunet.udp://10.5.144.69:5000"); 
      Assert.AreEqual(ta1, ta2, "Testing TA Equals");
      
      string ta_string = "brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM";
      TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM");
      Assert.AreEqual(ta.ToString(), ta_string, "testing tunnel TA parsing");
      //Console.WriteLine(ta);

      TunnelTransportAddress tun_ta = (TunnelTransportAddress) TransportAddressFactory.CreateInstance("brunet.tunnel://OIHZCNNUAXTLLARQIOBNCUWXYNAS62LO/CADSL6GV+CADSL6GU");

      ArrayList fwd = new ArrayList();
      fwd.Add(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A")));
      fwd.Add(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A")));
      
      TunnelTransportAddress test_ta = new TunnelTransportAddress(tun_ta.Target, fwd);
      Assert.AreEqual(tun_ta, test_ta, "testing tunnel TA compression enhancements");
      //Console.WriteLine(tun_ta.ToString());
      //Console.WriteLine(test_ta.ToString());
      Assert.AreEqual(tun_ta.ToString(), test_ta.ToString(), "testing tunnel TA compression enhancements (toString)");

      Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A"))), true, 
          "testing tunnel TA contains forwarder (1)");

      Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A"))), true, 
          "testing tunnel TA contains forwarder (2)");

      
      
      string StrLocalHost = Dns.GetHostName();
      IPHostEntry IPEntry = Dns.GetHostEntry(StrLocalHost);
      TransportAddress local_ta = TransportAddressFactory.CreateInstance("brunet.udp://" +  IPEntry.AddressList[0].ToString() + 
                   ":" + 5000);
      IEnumerable locals = TransportAddressFactory.CreateForLocalHost(TransportAddress.TAType.Udp, 5000);

      bool match = false;
      foreach (TransportAddress test_ta1 in locals) {
        //Console.WriteLine("test_ta: {0}", test_ta1);
        if (test_ta1.Equals(local_ta)) {
          match = true;
        }
      }
      Assert.AreEqual(match, true, "testing local TA matches");
      //testing function TA
      TransportAddress func_ta = TransportAddressFactory.CreateInstance("brunet.function://localhost:3000");
      TransportAddress func_ta2 = TransportAddressFactory.CreateInstance("brunet.function://localhost:3000");
      Assert.AreEqual(func_ta, func_ta2, "equality of instances");
      Assert.IsTrue(func_ta == func_ta2, "reference equality, test of caching");
      Assert.AreEqual(func_ta.ToString(), "brunet.function://localhost:3000", "Testing function TA parsing");
      
    }
Пример #5
0
        public void Test()
        {
            TransportAddress tas = TransportAddressFactory.CreateInstance("b.s://234580");

            Assert.AreEqual(tas.ToString(), "b.s://234580", "Simulation string");
            Assert.AreEqual((tas as SimulationTransportAddress).ID, 234580, "Simulation id");
            Assert.AreEqual(TransportAddress.TAType.S, tas.TransportAddressType, "Simulation ta type");
            TransportAddress ta1 = TransportAddressFactory.CreateInstance("brunet.udp://10.5.144.69:5000");

            Assert.AreEqual(ta1.ToString(), "brunet.udp://10.5.144.69:5000", "Testing TA parsing");

            TransportAddress ta2 = TransportAddressFactory.CreateInstance("brunet.udp://10.5.144.69:5000");

            Assert.AreEqual(ta1, ta2, "Testing TA Equals");

            string           ta_string = "brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM";
            TransportAddress ta        = TransportAddressFactory.CreateInstance("brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM");

            Assert.AreEqual(ta.ToString(), ta_string, "testing tunnel TA parsing");
            //Console.WriteLine(ta);

            TunnelTransportAddress tun_ta = (TunnelTransportAddress)TransportAddressFactory.CreateInstance("brunet.tunnel://OIHZCNNUAXTLLARQIOBNCUWXYNAS62LO/CADSL6GV+CADSL6GU");

            ArrayList fwd = new ArrayList();

            fwd.Add(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A")));
            fwd.Add(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A")));

            TunnelTransportAddress test_ta = new TunnelTransportAddress(tun_ta.Target, fwd);

            Assert.AreEqual(tun_ta, test_ta, "testing tunnel TA compression enhancements");
            //Console.WriteLine(tun_ta.ToString());
            //Console.WriteLine(test_ta.ToString());
            Assert.AreEqual(tun_ta.ToString(), test_ta.ToString(), "testing tunnel TA compression enhancements (toString)");

            Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A"))), true,
                            "testing tunnel TA contains forwarder (1)");

            Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A"))), true,
                            "testing tunnel TA contains forwarder (2)");



            string           StrLocalHost = Dns.GetHostName();
            IPHostEntry      IPEntry      = Dns.GetHostEntry(StrLocalHost);
            TransportAddress local_ta     = TransportAddressFactory.CreateInstance("brunet.udp://" + IPEntry.AddressList[0].ToString() +
                                                                                   ":" + 5000);
            IEnumerable locals = TransportAddressFactory.CreateForLocalHost(TransportAddress.TAType.Udp, 5000);

            bool match = false;

            foreach (TransportAddress test_ta1 in locals)
            {
                //Console.WriteLine("test_ta: {0}", test_ta1);
                if (test_ta1.Equals(local_ta))
                {
                    match = true;
                }
            }
            Assert.AreEqual(match, true, "testing local TA matches");
            //testing function TA
            TransportAddress func_ta  = TransportAddressFactory.CreateInstance("brunet.function://localhost:3000");
            TransportAddress func_ta2 = TransportAddressFactory.CreateInstance("brunet.function://localhost:3000");

            Assert.AreEqual(func_ta, func_ta2, "equality of instances");
            Assert.IsTrue(func_ta == func_ta2, "reference equality, test of caching");
            Assert.AreEqual(func_ta.ToString(), "brunet.function://localhost:3000", "Testing function TA parsing");
        }