Inheritance: SendException
Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
      }
    }