コード例 #1
0
        public void Test()
        {
            SimulationTransportAddress.Enable();
            SimulationTransportAddressOther.Enable();
            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 taso = TransportAddressFactory.CreateInstance("b.so://234580");

            Assert.AreEqual(taso.ToString(), "b.so://234580", "Simulation string");
            Assert.AreEqual((taso as SimulationTransportAddressOther).ID, 234580, "Simulation id");
            Assert.AreEqual(TransportAddress.TAType.SO, taso.TransportAddressType, "Simulation ta type");

            Assert.AreNotEqual(taso, tas, "TAs not equal");
            Assert.AreNotEqual(taso.TransportAddressType, tas.TransportAddressType, "Type not equal");

            var tas1 = TransportAddressFactory.CreateInstance("b.s://-234581");

            Assert.AreEqual(-234581, (tas1 as SimulationTransportAddress).ID);
            var tas2 = (tas as SimulationTransportAddress).Invert();

            Assert.AreEqual(tas1, tas2, "Invert equal");
        }
コード例 #2
0
        public void Test()
        {
            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);

            RelayTransportAddress tun_ta = (RelayTransportAddress)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")));

            RelayTransportAddress test_ta = new RelayTransportAddress(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)");
        }
コード例 #3
0
        /*
         * Implements the EdgeListener function to
         * create edges of this type.
         */
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            if (!IsStarted)
            {
                // it should return null and not throw an exception
                // for graceful disconnect and preventing others to
                // connect to us after we've disconnected.
                ecb(false, null, new EdgeException("Not started"));
                return;
            }
            else if (ta.TransportAddressType != this.TAType)
            {
                //Can't make an edge of this type
                ecb(false, null, new EdgeException("Can't make edge of this type"));
                return;
            }
            else if (_ta_auth.Authorize(ta) == TAAuthorizer.Decision.Deny)
            {
                //Not authorized.  Can't make this edge:
                ecb(false, null, new EdgeException(ta.ToString() + " is not authorized"));
                return;
            }

            int remote_id      = ((SimulationTransportAddress)ta).ID;
            int real_remote_id = (remote_id >= 0) ? remote_id : ~remote_id;

            //Outbound edge:
            int delay = 0;

            if (_use_delay)
            {
                if (LatencyMap != null)
                {
                    int local  = LocalID % LatencyMap.Count;
                    int remote = real_remote_id % LatencyMap.Count;
                    delay = LatencyMap[local][remote] / 1000;
                }
                else
                {
                    delay = 100;
                }
            }

            SimulationEdge se_l = new SimulationEdge(this, LocalID, remote_id, false, delay, _ta_type);

            if (real_remote_id == remote_id)
            {
                CreateRemoteEdge(se_l);
            }
            ecb(true, se_l, null);
        }
コード例 #4
0
ファイル: UdpEdgeListener.cs プロジェクト: johnynek/brunet
    /**
     * Implements the EdgeListener function to 
     * create edges of this type.
     */
    public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
    {
      Edge e = null;
      try {
      if( !IsStarted )
      {
	throw new EdgeException("UdpEdgeListener is not started");
      }
      else if( ta.TransportAddressType != this.TAType ) {
	throw new EdgeException(ta.TransportAddressType.ToString()
				+ " is not my type: " + this.TAType.ToString() );
      }
      else if( _ta_auth.Authorize(ta) == TAAuthorizer.Decision.Deny ) {
        //Too bad.  Can't make this edge:
	throw new EdgeException( ta.ToString() + " is not authorized");
      }
      else {
        IPAddress first_ip = ((IPTransportAddress) ta).GetIPAddress();
        IPEndPoint end = new IPEndPoint(first_ip, ((IPTransportAddress) ta).Port);
        /* We have to keep our mapping of end point to edges up to date */
        lock( _id_ht ) {
          //Get a random ID for this edge:
          int id;
          do {
            id = _rand.Next();
	    //Make sure we don't have negative ids
            if( id < 0 ) { id = ~id; }
          } while( _id_ht.Contains(id) || id == 0 );
          e = new UdpEdge(this, false, end, _local_ep, id, 0);
          _id_ht[id] = e;
        }
        NatDataPoint dp = new NewEdgePoint(DateTime.UtcNow, e);
        Interlocked.Exchange<NatHistory>(ref _nat_hist, _nat_hist + dp);
        Interlocked.Exchange<IEnumerable>(ref _nat_tas, new NatTAs( _tas, _nat_hist ));

        /* Tell me when you close so I can clean up the table */
        e.CloseEvent += this.CloseHandler;
        ecb(true, e, null);
      }
      } catch(Exception ex) {
        if( e != null ) {
          //Clean up the edge
          CloseHandler(e, null);
        }
	ecb(false, null, ex);
      }
    }
コード例 #5
0
ファイル: EdgeTester.cs プロジェクト: tristion/brunet
        public static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: edgetester.exe " +
                                  "[client|server] [tcp|udp|function] port " +
                                  "localhost|qubit|cantor|starsky|behnam|kupka)");
                return;
            }

            if (args.Length >= 5)
            {
                delay = Int32.Parse(args[4]);
            }

            EdgeFactory ef   = new EdgeFactory();
            int         port = System.Int16.Parse(args[2]);

            _threads = ArrayList.Synchronized(new ArrayList());
            EdgeListener el = null;

            if (args[1] == "function")
            {
                //This is a special case, it only works in one thread
                el            = new FunctionEdgeListener(port);
                el.EdgeEvent += new EventHandler(HandleEdge);
                //Start listening:
                el.Start();
                ef.AddListener(el);
                el.CreateEdgeTo(
                    TransportAddressFactory.CreateInstance("brunet.function://localhost:" + port),
                    ClientLoop);
            }
            else if (args[0] == "server")
            {
                if (args[1] == "tcp")
                {
                    el = new TcpEdgeListener(port);
                }
                else if (args[1] == "udp")
                {
                    el = new UdpEdgeListener(port);
                }
                else
                {
                    el = null;
                }
                el.EdgeEvent += new EventHandler(HandleEdge);
//Start listening:
                el.Start();
                _el = el;
                Console.WriteLine("Press Q to quit");
                Console.ReadLine();
                el.Stop();
            }
            else if (args[0] == "client")
            {
                TransportAddress ta = null;
                if (args[1] == "tcp")
                {
                    el = new TcpEdgeListener(port + 1);
                }
                else if (args[1] == "udp")
                {
                    el = new UdpEdgeListener(port + 1);
                }
                else
                {
                    el = null;
                }
                ef.AddListener(el);
                _el = el;
                string uri = "brunet." + args[1] + "://" + NameToIP(args[3]) + ":" + port;
                ta = TransportAddressFactory.CreateInstance(uri);
                System.Console.WriteLine("Making edge to {0}\n", ta.ToString());
                el.Start();
                ef.CreateEdgeTo(ta, ClientLoop);
            }
        }
コード例 #6
0
    /*
     * Implements the EdgeListener function to 
     * create edges of this type.
     */
    public override void CreateEdgeTo(TransportAddress ta,
                                      EdgeCreationCallback ecb)
    {
      if( !IsStarted )
      {
        // it should return null and not throw an exception
        // for graceful disconnect and preventing others to
        // connect to us after we've disconnected.
        ecb(false, null, new EdgeException("Not started"));
        return;
      }

#if FUNCTION_DEBUG
      foreach (TransportAddress local_ta in LocalTAs) {
	Console.Error.WriteLine("Create edge local: {0} <-> remote {1}.", local_ta, ta);
      }
#endif

      if( ta.TransportAddressType != this.TAType ) {
        //Can't make an edge of this type
#if FUNCTION_DEBUG
	Console.Error.WriteLine("Can't make edge of this type.");
#endif
        ecb(false, null, new EdgeException("Can't make edge of this type"));
	return;
      }
      
      if( _ta_auth.Authorize(ta) == TAAuthorizer.Decision.Deny ) {
        //Not authorized.  Can't make this edge:
#if FUNCTION_DEBUG
	Console.Error.WriteLine("Can't make edge. Remote TA {0} is not authorized locally.", ta);
#endif
        ecb(false, null,
            new EdgeException( ta.ToString() + " is not authorized") );
	return;
      }
      
      int remote_id = ((IPTransportAddress) ta).Port;
      //Get the edgelistener: 

      //Outbound edge:
      FunctionEdge fe_l = new FunctionEdge(this, _listener_id,
					   remote_id, false);
      lock( _listener_map ) { 
	FunctionEdgeListener remote
	  = (FunctionEdgeListener) _listener_map[remote_id];
	if( remote != null ) {
	  //
	  // Make sure that the remote listener does not deny 
	  // our TAs.
	  //

	  foreach (TransportAddress ta_local in LocalTAs) {
	    if (remote.TAAuth.Authorize(ta_local) == TAAuthorizer.Decision.Deny ) {
	      //Not authorized.  Can't make this edge:
#if FUNCTION_DEBUG
	      Console.Error.WriteLine("Can't make edge. local TA {0} is not authorized remotely by {1}.", ta_local, ta);
#endif
	      ecb(false, null,
		  new EdgeException( ta_local.ToString() + " is not authorized by remote node.") );
	      return;
	    }
	  }

	  FunctionEdge fe_r = new FunctionEdge(remote, remote_id,
					       _listener_id, true);
	  fe_l.Partner = fe_r;
	  fe_r.Partner = fe_l;
	  remote.SendEdgeEvent(fe_r);
	}
	else {
	  //There is no other edge, for now, we use "udp-like"
	  //behavior of just making an edge that goes nowhere.
	}
        ecb(true, fe_l, null);
      }
    }