コード例 #1
0
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            SubringTransportAddress sta = ta as SubringTransportAddress;

            if (sta == null)
            {
                ecb(false, null, new Exception("TA Type is not Subring!"));
            }
            else if (!sta.Namespace.Equals(_shared_node.Realm))
            {
                ecb(false, null, new Exception("Namespace mismatch"));
            }
            else if (sta.Target.Equals(_private_node.Address))
            {
                ecb(false, null, new Exception("You are me!"));
            }
            else
            {
                SubringEdge se = new SubringEdge(_local_ta, sta, false,
                                                 new AHExactSender(_shared_node, sta.Target), _ptype);
                se.CloseEvent += CloseHandler;
                _it.Add(se);
                ecb(true, se, null);
            }
        }
コード例 #2
0
        /* //////////////////////////////
         *
         * Here are all the normal methods of TcpEdgeListener
         *
         * //////////////////////////////
         */


        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            try {
                if (!IsStarted)
                {
                    throw new EdgeException("TcpEdgeListener is not started");
                }
                else if (ta.TransportAddressType != TransportAddress.TAType.Tcp)
                {
                    throw new EdgeException(ta.TransportAddressType.ToString()
                                            + " is not my type: Tcp");
                }
                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
                {
                    //Everything looks good:
                    ArrayList tmp_ips = new ArrayList();
                    tmp_ips.Add(((IPTransportAddress)ta).GetIPAddress());
                    CreationState cs = new CreationState(ecb,
                                                         new Queue(tmp_ips),
                                                         ((IPTransportAddress)ta).Port,
                                                         this);
                    ActionQueue.Enqueue(cs);
                }
            } catch (Exception e) {
                ecb(false, null, e);
            }
        }
コード例 #3
0
        /// <summary>Creates an XmppEdge.</summary>
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            if (_ready == 0)
            {
                ecb(false, null, new Exception("Xmpp is not authenticated"));
            }

            XmppTransportAddress xta = ta as XmppTransportAddress;

            if (xta == null)
            {
                ecb(false, null, new Exception("TA Type is not Xmpp!"));
                return;
            }
            else if (!_xmpp.IsUserOnline(xta.JID))
            {
                ecb(false, null, new Exception("Xmpp user, " + xta.JID + ", is not online."));
                return;
            }

            XmppEdge xe = new XmppEdge(this, _local_ta, xta, false);

            _it.Add(xe);
            xe.CloseEvent += CloseHandler;
            ecb(true, xe, null);
        }
コード例 #4
0
        /**
         * Implements the EdgeListener function to
         * create edges of this type.
         */
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            Edge      e  = null;
            Exception ex = null;

            if (!IsStarted)
            {
                ex = new EdgeException("UdpEdgeListener is not started");
            }
            else if (ta.TransportAddressType != this.TAType)
            {
                ex = new EdgeException(ta.TransportAddressType.ToString()
                                       + " is not my type: " + this.TAType.ToString());
            }
            else if (_ta_auth.Authorize(ta) == TAAuthorizer.Decision.Deny)
            {
                ex = 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));

                try {
                    /* Tell me when you close so I can clean up the table */
                    e.CloseEvent += this.CloseHandler;
                } catch (Exception x) {
                    e  = null;
                    ex = x;
                }
            }

            if (e != null)
            {
                ecb(true, e, null);
            }
            else
            {
                ecb(false, null, ex);
            }
        }
コード例 #5
0
ファイル: TunnelEdgeListener.cs プロジェクト: pcbing/brunet
 public TunnelEdgeCallbackAction(TunnelTransportAddress tta, EdgeCreationCallback ecb)
 {
     TunnelTA  = tta;
     Ecb       = ecb;
     Exception = new WriteOnce <Exception>();
     Success   = new WriteOnce <bool>();
     Edge      = new WriteOnce <Edge>();
 }
コード例 #6
0
 public RelayEdgeCallbackAction(RelayTransportAddress tta, EdgeCreationCallback ecb)
 {
     RelayTA   = tta;
     Ecb       = ecb;
     Exception = new WriteOnce <Exception>();
     Success   = new WriteOnce <bool>();
     Edge      = new WriteOnce <Edge>();
 }
コード例 #7
0
 public CreationState(EdgeCreationCallback ecb,
                      Queue ipq, int port,
                      TcpEdgeListener tel)
 {
     ECB            = ecb;
     IPAddressQueue = ipq;
     Port           = port;
     TEL            = tel;
     Result         = new WriteOnce <object>();
 }
コード例 #8
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);
        }
コード例 #9
0
        /// <summary>Does not immediately create an edge to a remote node, instead,
        /// it tells a timer to wait 5 seconds prior to attempting an edge.</summary>
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            RelayTransportAddress tta = ta as RelayTransportAddress;

            if (tta == null)
            {
                ecb(false, null, new Exception("TA Type is not Relay!"));
            }
            else
            {
                RelayEdgeCallbackAction  teca     = new RelayEdgeCallbackAction(tta, ecb);
                System.Action <DateTime> callback = delegate(DateTime now) {
                    CreateEdgeTo(teca);
                };
                Brunet.Util.FuzzyTimer.Instance.DoAfter(callback, 10000, 0);
            }
        }
コード例 #10
0
    public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
    {
      SubringTransportAddress sta = ta as SubringTransportAddress;

      if(sta == null) {
        ecb(false, null, new Exception("TA Type is not Subring!"));
      } else if(!sta.Namespace.Equals(_shared_node.Realm)) {
        ecb(false, null, new Exception("Namespace mismatch"));
      } else if(sta.Target.Equals(_private_node.Address)) {
        ecb(false, null, new Exception("You are me!"));
      } else {
        SubringEdge se = new SubringEdge(_local_ta, sta, false,
            new AHExactSender(_shared_node, sta.Target), _ptype);
        se.CloseEvent += CloseHandler;
        _it.Add(se);
        ecb(true, se, null);
      }
    }
コード例 #11
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);
    }
コード例 #12
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);
            }
        }
コード例 #13
0
ファイル: TunnelEdgeListener.cs プロジェクト: xujyan/brunet
    /**
     * This method creates an instance of a tunnel edge to a remote node, given its 
     * tunnel transport URI.
     * @param ta TransportAddress to create an edge to
     * @param ecb the EdgeCreationCallback to call when done
     * @throw EdgeException if we try to call this before calling
     * Start.
     */
    public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb) 
    {
      try {
      if (!IsStarted) {
        throw new EdgeException("TunnelEdgeListener not started");
      }
      else if (0 == _running) {
        throw new EdgeException("TunnelEdgeListener not running");
      }
      else if (ta.TransportAddressType != this.TAType) {
	throw new EdgeException(ta.TransportAddressType.ToString()
				+ " is not my type: " + this.TAType.ToString());
      }
      else {
#if TUNNEL_DEBUG
        Console.Error.WriteLine("CreateEdgeTo TunnelEdge to: {0}", ta);
#endif  
        TunnelTransportAddress tun_ta = ta as TunnelTransportAddress;
        ArrayList forwarders = new ArrayList();
        ArrayList forwarding_edges = new ArrayList();
#if TUNNEL_DEBUG
        Console.Error.WriteLine("TunnelEdgeListener: Finding structured connections to tunnel over");
#endif
        IEnumerable struc_cons = _node.ConnectionTable.GetConnections(ConnectionType.Structured);
        if (struc_cons ==  null) {
#if TUNNEL_DEBUG
          Console.Error.WriteLine("List of structured connections is null");
#endif 
        }
#if TUNNEL_DEBUG
        Console.Error.WriteLine("TunnelEdgeListener: Browsing list of structured connections");
#endif
        foreach (Connection con in struc_cons) {
#if TUNNEL_DEBUG
          Console.Error.WriteLine("TunnelEdgeListener: Testing : {0}", con.Address);
#endif
          if (con.Edge.TAType == TransportAddress.TAType.Tunnel) {
#if TUNNEL_DEBUG
            Console.Error.WriteLine("Cannot tunnel over tunnel: " + con.Address.ToString());
#endif
            continue;
          }
          if (!tun_ta.ContainsForwarder(con.Address)) {
#if TUNNEL_DEBUG
            Console.Error.WriteLine("Cannot tunnel over connection: " + con.Address.ToString());
#endif
            continue;
          }
#if TUNNEL_DEBUG
          Console.Error.WriteLine("Can tunnel over connection: " + con.Address.ToString());
#endif
          forwarders.Add(con.Address);
          forwarding_edges.Add(con.Edge);
        }

        if (forwarders.Count < MIN_FORWARDERS) {
          ecb(false, null, new EdgeException("Cannot create edge over TA: " + tun_ta + ", not many forwarders"));
          return;
        }
        tun_ta = new TunnelTransportAddress(tun_ta.Target, forwarders);
        
        //choose a locally unique id
        lock( _sync ) {
          //Get a random ID for this edge:
          int localid;
          int remoteid = 0;
          do {
            localid = _rand.Next();
            //Make sure we don't have negative ids
            if( localid < 0 ) { localid = ~localid; }
          } while( _id_ht.Contains(localid) || localid == 0 );      
          //looks like the new edge is ready
          TunnelEdge e = new TunnelEdge(this, false, _node, tun_ta.Target, forwarders, localid, remoteid);
#if TUNNEL_DEBUG
          Console.Error.WriteLine("Creating an instance of TunnelEdge: {0}", e);
          Console.Error.WriteLine("remoteid: {0}, localid: {1}", remoteid, localid);
#endif      
          _id_ht[localid] = e;
          //we will defer the new edge event for later
          //when we actually get a response
          
          //now build the packet payload
          Packet p = null;
          using(MemoryStream ms = new MemoryStream()) {
            ms.WriteByte((byte) MessageType.EdgeRequest);
            NumberSerializer.WriteInt(localid, ms);
            NumberSerializer.WriteInt(remoteid, ms);
    #if TUNNEL_DEBUG
            Console.Error.WriteLine("Written off type, localid, remoteid");
    #endif
            
            ArrayList args = new ArrayList();
            //add the target address
            byte[] addr_bytes = new byte[Address.MemSize];
            _node.Address.CopyTo(addr_bytes);
            args.Add(addr_bytes.Clone());
    #if TUNNEL_DEBUG
            Console.Error.WriteLine("Added target address");
    #endif
            
            foreach (Address fwd in  forwarders) {
              //add forwarding addresses
              fwd.CopyTo(addr_bytes);
              args.Add(addr_bytes.Clone());
    #if TUNNEL_DEBUG
              Console.Error.WriteLine("Added a forwarding address");
    #endif
    
            }
    #if TUNNEL_DEBUG
            Console.Error.WriteLine("Creating a memory stream holding the payload");
    #endif
            AdrConverter.Serialize(args, ms);
            p = new AHPacket(1, 2, _node.Address, tun_ta.Target, AHPacket.AHOptions.Exact, 
                                 AHPacket.Protocol.Tunneling, ms.ToArray());
          }
#if TUNNEL_DEBUG
          Console.Error.WriteLine("Created a request packet.");
#endif
          EdgeCreationState ecs = new EdgeCreationState(localid, forwarding_edges, p, ecb);
          _ecs_ht[localid] = ecs;

#if TUNNEL_DEBUG
          Console.Error.WriteLine("Created an edge creation state for the tunnel edge: {0}", e);
#endif
        }
      }
      //we will defer this sending to next heartbeat; an artificial delay from out own side
      } catch(Exception e) {
	ecb(false, null, e);
      }
    }
コード例 #14
0
ファイル: XmppEdgeListener.cs プロジェクト: pstjuste/brunet
    /// <summary>Creates an XmppEdge.</summary>
    public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
    {
      if(_ready == 0) {
        ecb(false, null, new Exception("Xmpp is not authenticated"));
      }

      XmppTransportAddress xta = ta as XmppTransportAddress;
      if(xta == null) {
        ecb(false, null, new Exception("TA Type is not Xmpp!"));
        return;
      } else if(!_xmpp.IsUserOnline(xta.JID)) {
        ecb(false, null, new Exception("Xmpp user, " + xta.JID + ", is not online."));
        return;
      }

      XmppEdge xe = new XmppEdge(this, _local_ta, xta, false);
      _it.Add(xe);
      xe.CloseEvent += CloseHandler;
      ecb(true, xe, null);
    }
コード例 #15
0
ファイル: RelayEdgeListener.cs プロジェクト: hseom/brunet-1
 public RelayEdgeCallbackAction(RelayTransportAddress tta, EdgeCreationCallback ecb)
 {
   RelayTA = tta;
   Ecb = ecb;
   Exception = new WriteOnce<Exception>();
   Success = new WriteOnce<bool>();
   Edge = new WriteOnce<Edge>();
 }
コード例 #16
0
ファイル: TunnelEdgeListener.cs プロジェクト: xujyan/brunet
 public EdgeCreationState(int id, IList senders, Packet p, EdgeCreationCallback ecb) {
   Id = id;
   Senders = senders;
   _ecb = ecb;
   RequestPacket = p;
   _r = new Random();
   _attempts = MAX_ATTEMPTS;
   _last_send = DateTime.UtcNow;
   _last_send_lock = new object();
 }
コード例 #17
0
ファイル: UdpEdgeListener.cs プロジェクト: bakriy/brunet
    /**
     * Implements the EdgeListener function to 
     * create edges of this type.
     */
    public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
    {
      Edge e = null;
      Exception ex = null;
      if( !IsStarted ) {
        ex = new EdgeException("UdpEdgeListener is not started");
      } else if( ta.TransportAddressType != this.TAType ) {
        ex = new EdgeException(ta.TransportAddressType.ToString()
            + " is not my type: " + this.TAType.ToString() );
      } else if( _ta_auth.Authorize(ta) == TAAuthorizer.Decision.Deny ) {
        ex = 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 ));

        try {
          /* Tell me when you close so I can clean up the table */
          e.CloseEvent += this.CloseHandler;
        } catch (Exception x) {
          e = null;
          ex = x;
        }
      }

      if(e != null) {
        ecb(true, e, null);
      } else {
        ecb(false, null, ex);
      }
    }
コード例 #18
0
ファイル: TunnelEdgeListener.cs プロジェクト: johnynek/brunet
 public TunnelEdgeCallbackAction(TunnelTransportAddress tta, EdgeCreationCallback ecb)
 {
   TunnelTA = tta;
   Ecb = ecb;
   Exception = new WriteOnce<Exception>();
   Success = new WriteOnce<bool>();
   Edge = new WriteOnce<Edge>();
 }
コード例 #19
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( 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;
      }
      
      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;
      //Get the edgelistener: 

      //Outbound edge:
      int delay = 0;
      if(_use_delay) {
        if(LatencyMap != null) {
          // id != 0, so we reduce all by 1
          delay = LatencyMap[_listener_id][remote_id] / 1000;
        } else {
          delay = 100;
        }
      }

      SimulationEdge se_l = new SimulationEdge(this, _listener_id, remote_id, false, delay);
      AddEdge(se_l);

      SimulationEdgeListener remote = (SimulationEdgeListener) _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:
            ecb(false, null, new EdgeException( ta_local.ToString() + " is not authorized by remote node.") );
            return;
          }
        }

        SimulationEdge se_r = new SimulationEdge(remote, remote_id, _listener_id, true, delay);
        remote.AddEdge(se_r);

        se_l.Partner = se_r;
        se_r.Partner = se_l;
        remote.SendEdgeEvent(se_r);
      } else {
          //There is no other edge, for now, we use "udp-like"
          //behavior of just making an edge that goes nowhere.
      }
      ecb(true, se_l, null);
    }
コード例 #20
0
       /**
        * It is imperative that the ECB be called and not ignored.  Not
        * calling back will leave the system in a stale state as it waits
        * for the CreateEdgeTo to complete.
        * @param ta TransportAddress to create an edge to
        * @param ecb the EdgeCreationCallback to call when done
        * @throw EdgeException if we try to call this before calling
        */
 public abstract void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb);
コード例 #21
0
ファイル: TunnelEdgeListener.cs プロジェクト: johnynek/brunet
 /// <summary>Does not immediately create an edge to a remote node, instead,
 /// it tells a timer to wait 5 seconds prior to attempting an edge.</summary>
 public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
 {
   TunnelTransportAddress tta = ta as TunnelTransportAddress;
   if(tta == null) {
     ecb(false, null, new Exception("TA Type is not Tunnel!"));
   } else {
     TunnelEdgeCallbackAction teca = new TunnelEdgeCallbackAction(tta, ecb);
     System.Action<DateTime> callback = delegate(DateTime now) {
       CreateEdgeTo(teca);
     };
     Brunet.Util.FuzzyTimer.Instance.DoAfter(callback, 10000, 0);
   }
 }
コード例 #22
0
ファイル: TcpEdgeListener.cs プロジェクト: xujyan/brunet
 public CreationState(EdgeCreationCallback ecb,
                      Queue ipq, int port,
                      TcpEdgeListener tel)
 {
   ECB = ecb;
   IPAddressQueue = ipq;
   Port = port;
   TEL = tel;
   Result = new WriteOnce<object>();
 }
コード例 #23
0
ファイル: WrapperEdgeListener.cs プロジェクト: pcbing/brunet
        ///<summary>This wraps the underlying CreateEdgeTo using EdgeCreationWrappers</summary>
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            EdgeCreationWrapper ecw = new EdgeCreationWrapper(ta, ecb, null, this);

            _el.CreateEdgeTo(ta, ecw.Callback);
        }
コード例 #24
0
ファイル: TcpEdgeListener.cs プロジェクト: xujyan/brunet
    /* //////////////////////////////
     *
     * Here are all the normal methods of TcpEdgeListener
     *
     * //////////////////////////////
     */


    public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
    {
      try {
        if( !IsStarted ) {
          throw new EdgeException("TcpEdgeListener is not started");
        }
        else if( ta.TransportAddressType != TransportAddress.TAType.Tcp ) {
	        throw new EdgeException(ta.TransportAddressType.ToString()
				    + " is not my type: Tcp");
        }
        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 {
          //Everything looks good:
	        ArrayList tmp_ips = new ArrayList();
	        tmp_ips.Add(((IPTransportAddress)ta).GetIPAddress());
          CreationState cs = new CreationState(ecb,
                                           new Queue( tmp_ips ),
                                           ((IPTransportAddress) ta).Port,
                                           this);
          ActionQueue.Enqueue(cs);
        }
      } catch(Exception e) {
	      ecb(false, null, e);
      }
    }
コード例 #25
0
 /**
  * It is imperative that the ECB be called and not ignored.  Not
  * calling back will leave the system in a stale state as it waits
  * for the CreateEdgeTo to complete.
  * @param ta TransportAddress to create an edge to
  * @param ecb the EdgeCreationCallback to call when done
  * @throw EdgeException if we try to call this before calling
  */
 public abstract void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb);
コード例 #26
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 (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;
            }

            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;
            //Get the edgelistener:

            //Outbound edge:
            int delay = 0;

            if (_use_delay)
            {
                if (LatencyMap != null)
                {
                    // id != 0, so we reduce all by 1
                    delay = LatencyMap[_listener_id][remote_id] / 1000;
                }
                else
                {
                    lock (_sync) {
                        delay = _rand.Next(10, 250);
                    }
                }
            }

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

            AddEdge(se_l);

            SimulationEdgeListener remote = (SimulationEdgeListener)_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:
                        ecb(false, null, new EdgeException(ta_local.ToString() + " is not authorized by remote node."));
                        return;
                    }
                }

                SimulationEdge se_r = new SimulationEdge(remote, remote_id, _listener_id, true, delay);
                remote.AddEdge(se_r);

                se_l.Partner = se_r;
                se_r.Partner = se_l;
                remote.SendEdgeEvent(se_r);
            }
            else
            {
                //There is no other edge, for now, we use "udp-like"
                //behavior of just making an edge that goes nowhere.
            }
            ecb(true, se_l, null);
        }
コード例 #27
0
ファイル: FunctionEdgeListener.cs プロジェクト: xujyan/brunet
    /*
     * 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);
      }
    }
コード例 #28
0
ファイル: WrapperEdgeListener.cs プロジェクト: hseom/brunet-1
 ///<summary>This wraps the underlying CreateEdgeTo using EdgeCreationWrappers</summary>
 public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb) {
   EdgeCreationWrapper ecw = new EdgeCreationWrapper(ta, ecb, null, this);
   _el.CreateEdgeTo(ta, ecw.Callback);
 }