コード例 #1
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay) :
   this(id, loss_prob, ta_auth, use_delay, TransportAddress.TAType.S,
       new PublicNat(TransportAddressFactory.CreateInstance(
           String.Format("b.{0}://{1}",
           TransportAddress.TATypeToString(TransportAddress.TAType.S), id))))
 {
 }
コード例 #2
0
        /**
         * @param port the port to listen on
         * @param ipList an IEnumerable object of IPAddress objects.
         * @param ta_auth the TAAuthorizer to use for remote nodes
         */
        public TcpEdgeListener(int port, IEnumerable local_config_ips, TAAuthorizer ta_auth)
        {
            _is_started  = 0;
            _listen_sock = new Socket(AddressFamily.InterNetwork,
                                      SocketType.Stream, ProtocolType.Tcp);
            _listen_sock.LingerState = new LingerOption(true, 0);
            IPEndPoint tmp_ep = new IPEndPoint(IPAddress.Any, port);

            _listen_sock.Bind(tmp_ep);
            _local_endpoint = (IPEndPoint)_listen_sock.LocalEndPoint;
            port            = _local_endpoint.Port;
            _count          = 0;

            /**
             * We get all the IPAddresses for this computer
             */
            if (local_config_ips == null)
            {
                _tas = TransportAddressFactory.CreateForLocalHost(TransportAddress.TAType.Tcp, port);
            }
            else
            {
                _tas = TransportAddressFactory.Create(TransportAddress.TAType.Tcp, port, local_config_ips);
            }

            _ta_auth = ta_auth;
            if (_ta_auth == null)
            {
                //Always authorize in this case:
                _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
            }
            _loop = new Thread(this.SelectLoop);
            //This is how we push jobs into the SelectThread
            ActionQueue = new LockFreeQueue <SocketStateAction>();
        }
コード例 #3
0
        public void Test()
        {
            TAAuthorizer     a1 = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
            TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.udp://127.0.0.1:45");

            Assert.IsTrue(a1.IsNotDenied(ta), "constant allow");
            TAAuthorizer a2 = new ConstantAuthorizer(TAAuthorizer.Decision.Deny);

            Assert.IsFalse(a2.IsNotDenied(ta), "constant deny");

            IPAddress    network = IPAddress.Parse("10.128.0.0");
            TAAuthorizer a3      = new NetmaskTAAuthorizer(network, 9,
                                                           TAAuthorizer.Decision.Deny,
                                                           TAAuthorizer.Decision.None);
            TransportAddress ta2 = TransportAddressFactory.CreateInstance("brunet.udp://10.255.255.255:80");

            Assert.AreEqual(a3.Authorize(ta2), TAAuthorizer.Decision.Deny, "Netmask Deny");
            TransportAddress ta3 = TransportAddressFactory.CreateInstance("brunet.udp://10.1.255.255:80");

            Assert.AreEqual(a3.Authorize(ta3), TAAuthorizer.Decision.None, "Netmask None");
            //Here is the series:
            //If Netmask doesn't say no, constant says yes:
            TAAuthorizer[] my_auths = new TAAuthorizer[] { a3, a1 };
            TAAuthorizer   a4       = new SeriesTAAuthorizer(my_auths);

            Assert.AreEqual(a4.Authorize(ta2), TAAuthorizer.Decision.Deny, "Series Deny");
            Assert.AreEqual(a4.Authorize(ta3), TAAuthorizer.Decision.Allow, "Series Allow");
        }
コード例 #4
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay)
 {
   _edges = new Dictionary<Edge, Edge>();
   _use_delay = use_delay;
   _listener_id = id;
   _ploss_prob = loss_prob;
   if (ta_auth == null) {
     _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
   } else {
     _ta_auth = ta_auth;
   }
   _tas = new ArrayList();
   _tas.Add(TransportAddressFactory.CreateInstance("b.s://" + _listener_id));
   _rand = new Random();
 }
コード例 #5
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay)
 {
     _edges       = new Dictionary <Edge, Edge>();
     _use_delay   = use_delay;
     _listener_id = id;
     _ploss_prob  = loss_prob;
     if (ta_auth == null)
     {
         _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
     }
     else
     {
         _ta_auth = ta_auth;
     }
     _tas = new ArrayList();
     _tas.Add(TransportAddressFactory.CreateInstance("b.s://" + _listener_id));
     _rand = new Random();
 }
コード例 #6
0
 public FunctionEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth)
 {
     _listener_id = id;
     _ploss_prob  = loss_prob;
     if (ta_auth == null)
     {
         _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
     }
     else
     {
         _ta_auth = ta_auth;
     }
     _tas = new ArrayList();
     _tas.Add(TransportAddressFactory.CreateInstance("brunet.function://localhost:" +
                                                     _listener_id.ToString()));
     _queue        = new BC.LFBlockingQueue <FQEntry>();
     _queue_thread = new Thread(new ThreadStart(StartQueueProcessing));
 }
コード例 #7
0
        /**
         * @param port the local port to bind to
         * @param local_tas an IEnumerable object which gives the list of local
         * IPs.  This is consulted every time LocalTAs is accessed, so it can
         * change as new interfaces are added
         * @param ta_auth the TAAuthorizer for packets incoming
         */
        public UdpEdgeListener(int port, IEnumerable local_config_ips, TAAuthorizer ta_auth)
        {
            _s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, Int32.MaxValue);
            _s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, Int32.MaxValue);
            ipep = new IPEndPoint(IPAddress.Any, port);
            _s.Bind(ipep);
            _port = port = ((IPEndPoint)(_s.LocalEndPoint)).Port;

            /**
             * We get all the IPAddresses for this computer
             */
            if (local_config_ips == null)
            {
                _tas = TransportAddressFactory.CreateForLocalHost(TransportAddress.TAType.Udp, _port);
            }
            else
            {
                _tas = TransportAddressFactory.Create(TransportAddress.TAType.Udp, _port, local_config_ips);
            }
            _nat_hist = null;
            _nat_tas  = new NatTAs(_tas, _nat_hist);
            _ta_auth  = ta_auth;
            if (_ta_auth == null)
            {
                //Always authorize in this case:
                _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
            }
            //We start out expecting around 30 edges with
            //a load factor of 0.15 (to make edge lookup fast)
            _id_ht        = new Hashtable(30, 0.15f);
            _remote_id_ht = new Hashtable();
            _sync         = new object();
            _running      = 0;
            _isstarted    = 0;
            ///@todo, we need a system for using the cryographic RNG
            _rand                     = new Random();
            _send_handler             = this;
            _listen_finished_event    = new ManualResetEvent(false);
            _listen_thread            = new Thread(ListenThread);
            _send_thread              = new Thread(SendThread);
            _send_thread.IsBackground = true;
            _send_queue               = new LFBlockingQueue <UdpMessage>();
        }
コード例 #8
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay)
 {
     _edges       = new Hashtable();
     _use_delay   = use_delay;
     _sync        = new object();
     _ba          = new BufferAllocator(Int16.MaxValue);
     _listener_id = id;
     _ploss_prob  = loss_prob;
     if (ta_auth == null)
     {
         _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
     }
     else
     {
         _ta_auth = ta_auth;
     }
     _tas = new ArrayList();
     _tas.Add(TransportAddressFactory.CreateInstance("b.s://" + _listener_id));
     _rand = new Random();
 }
コード例 #9
0
 public CloseDeniedAction(TcpEdgeListener el, TAAuthorizer taa)
 {
     TAA = taa;
     EL  = el;
 }
コード例 #10
0
ファイル: UdpEdgeListener.cs プロジェクト: bakriy/brunet
 /**
  * @param port the local port to bind to
  * @param local_tas an IEnumerable object which gives the list of local
  * IPs.  This is consulted every time LocalTAs is accessed, so it can
  * change as new interfaces are added
  * @param ta_auth the TAAuthorizer for packets incoming
  */
 public UdpEdgeListener(int port, IEnumerable local_config_ips, TAAuthorizer ta_auth)
 {
   _s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
   ipep = new IPEndPoint(IPAddress.Any, port);
   _s.Bind(ipep);
   _port = port = ((IPEndPoint) (_s.LocalEndPoint)).Port;
   /**
    * We get all the IPAddresses for this computer
    */
   if( local_config_ips == null ) {
     _tas = TransportAddressFactory.CreateForLocalHost(TransportAddress.TAType.Udp, _port);
   }
   else {
     _tas = TransportAddressFactory.Create(TransportAddress.TAType.Udp, _port, local_config_ips);
   }
   _nat_hist = null;
   _nat_tas = new NatTAs( _tas, _nat_hist );
   _ta_auth = ta_auth;
   if( _ta_auth == null ) {
     //Always authorize in this case:
     _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
   }
   //We start out expecting around 30 edges with
   //a load factor of 0.15 (to make edge lookup fast)
   _id_ht = new Hashtable(30, 0.15f);
   _remote_id_ht = new Hashtable();
   _sync = new object();
   _running = 0;
   _isstarted = 0;
   ///@todo, we need a system for using the cryographic RNG
   _rand = new Random();
   _send_handler = this;
   _listen_finished_event = new ManualResetEvent(false);
   _listen_thread = new Thread(ListenThread);
   _send_thread = new Thread(SendThread);
   _send_thread.IsBackground = true;
   _send_queue = new LFBlockingQueue<UdpMessage>();
 }
コード例 #11
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay)
 {
   _edges = new Hashtable();
   _use_delay = use_delay;
   _sync = new object();
   _ba = new BufferAllocator(Int16.MaxValue);
   _listener_id = id;
   _ploss_prob = loss_prob;
   if (ta_auth == null) {
     _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
   } else {
     _ta_auth = ta_auth;
   }
   _tas = new ArrayList();
   _tas.Add(TransportAddressFactory.CreateInstance("b.s://" + _listener_id));
   _rand = new Random();
 }
コード例 #12
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth) :
   this(id, loss_prob, ta_auth, false) {}
コード例 #13
0
    public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth,
        bool use_delay, TransportAddress.TAType type, INat nat)
    {
      _edges = new Dictionary<Edge, Edge>();
      _use_delay = use_delay;
      LocalID = id;
      _ploss_prob = loss_prob;
      if (ta_auth == null) {
        _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
      } else {
        _ta_auth = ta_auth;
      }
      _ta_type = type;

      Nat = nat;
      _is_started = false;
    }
コード例 #14
0
ファイル: TAAuthorizer.cs プロジェクト: johnynek/brunet
 /**
  * Given an IPAddress the first bit_c bits of the primary
  * TransportAddress IPAddress have to match to get the given
  * result
  * @param nw the Network we want to match
  * @param bit_c the number of initial bits of the network that must match.
  * @param on_match what happens when there is a match
  * @param on_mismatch what happens when there is a match
  *
  * Examples:
  * <ul>
  * <li>If you want to deny a certain netmask, but say nothing about another
  * use (Deny, None).</li>
  * <li>If you want to allow a certain netmask and deny all others:
  * use (Allow, Deny).  Note this mode could not be used in Series</li>
  * </ul> 
  * 
  */
 public NetmaskTAAuthorizer(IPAddress nw, int bit_c,
                                  TAAuthorizer.Decision on_match,
                                  TAAuthorizer.Decision on_mismatch) {
   _nw_bytes = nw.GetAddressBytes();
   _bit_c = bit_c;
   _result_on_match = on_match;
   _result_on_mismatch = on_mismatch;
 }
コード例 #15
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth) :
     this(id, loss_prob, ta_auth, false)
 {
 }
コード例 #16
0
ファイル: TcpEdgeListener.cs プロジェクト: pstjuste/brunet
 public CloseDeniedAction(TcpEdgeListener el, TAAuthorizer taa) {
   TAA = taa;
   EL = el;
 }
コード例 #17
0
ファイル: TcpEdgeListener.cs プロジェクト: pstjuste/brunet
    /**
     * @param port the port to listen on
     * @param ipList an IEnumerable object of IPAddress objects.
     * @param ta_auth the TAAuthorizer to use for remote nodes
     */
    public TcpEdgeListener(int port, IEnumerable local_config_ips, TAAuthorizer ta_auth)
    {
      _is_started = 0;
      _listen_sock = new Socket(AddressFamily.InterNetwork,
                                SocketType.Stream, ProtocolType.Tcp);
      _listen_sock.LingerState = new LingerOption (true, 0);
      IPEndPoint tmp_ep = new IPEndPoint(IPAddress.Any, port);
      _listen_sock.Bind(tmp_ep);
      _local_endpoint = (IPEndPoint) _listen_sock.LocalEndPoint;
      port = _local_endpoint.Port;
      _count = 0;
      /**
       * We get all the IPAddresses for this computer
       */
      if( local_config_ips == null ) {
        _tas = TransportAddressFactory.CreateForLocalHost(TransportAddress.TAType.Tcp, port);
      }
      else {
        _tas = TransportAddressFactory.Create(TransportAddress.TAType.Tcp, port, local_config_ips);
      }

      _ta_auth = ta_auth;
      if( _ta_auth == null ) {
        //Always authorize in this case:
        _ta_auth = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
      }
      _loop = new Thread( this.SelectLoop );
      //This is how we push jobs into the SelectThread
      ActionQueue = new LockFreeQueue<SocketStateAction>();
    }
コード例 #18
0
ファイル: TAAuthorizer.cs プロジェクト: johnynek/brunet
 public TATypeAuthorizer(TransportAddress.TAType[] list,
                                  TAAuthorizer.Decision on_match,
                                  TAAuthorizer.Decision on_mismatch) {
   _on_match = on_match;
   _on_mismatch = on_mismatch;
   _match_table = new Dictionary<TransportAddress.TAType, bool>();
   foreach(TransportAddress.TAType tatype in list) {
     _match_table[tatype] = true;
   }
 }
コード例 #19
0
ファイル: TAAuthorizer.cs プロジェクト: johnynek/brunet
 public ConstantAuthorizer(TAAuthorizer.Decision d) {
   _dec = d;
 }
コード例 #20
0
ファイル: TAAuthorizer.cs プロジェクト: johnynek/brunet
 public void Test() {
   TAAuthorizer a1 = new ConstantAuthorizer(TAAuthorizer.Decision.Allow);
   TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.udp://127.0.0.1:45");
   Assert.IsTrue( a1.IsNotDenied( ta ), "constant allow");
   TAAuthorizer a2 = new ConstantAuthorizer(TAAuthorizer.Decision.Deny);
   Assert.IsFalse( a2.IsNotDenied( ta ), "constant deny");
   
   IPAddress network = IPAddress.Parse("10.128.0.0");
   TAAuthorizer a3 = new NetmaskTAAuthorizer(network, 9,
                                             TAAuthorizer.Decision.Deny,
                                             TAAuthorizer.Decision.None);
   TransportAddress ta2 = TransportAddressFactory.CreateInstance("brunet.udp://10.255.255.255:80");
   Assert.AreEqual(a3.Authorize(ta2), TAAuthorizer.Decision.Deny, "Netmask Deny");
   TransportAddress ta3 = TransportAddressFactory.CreateInstance("brunet.udp://10.1.255.255:80");
   Assert.AreEqual(a3.Authorize(ta3), TAAuthorizer.Decision.None, "Netmask None");
   //Here is the series:
   //If Netmask doesn't say no, constant says yes:
   TAAuthorizer[] my_auths = new TAAuthorizer[]{ a3, a1 };
   TAAuthorizer a4 = new SeriesTAAuthorizer(my_auths);
   Assert.AreEqual(a4.Authorize(ta2), TAAuthorizer.Decision.Deny, "Series Deny");
   Assert.AreEqual(a4.Authorize(ta3), TAAuthorizer.Decision.Allow, "Series Allow");
 }