当前位置: 首页>>代码示例>>C#>>正文


C# TransportAddress.ToString方法代码示例

本文整理汇总了C#中Brunet.Transport.TransportAddress.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# TransportAddress.ToString方法的具体用法?C# TransportAddress.ToString怎么用?C# TransportAddress.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Brunet.Transport.TransportAddress的用法示例。


在下文中一共展示了TransportAddress.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SplitPath

    /** return the base TransportAddress and the path associated with it
     */
    public static TransportAddress SplitPath(TransportAddress ta, out string path) {
      string tas = ta.ToString();
      // Need to be careful of the case ta:////ta:9/
      int init_idx = tas.IndexOf("://") + 3;
      int idx = init_idx;
      int pos = 0;
      bool next = false;
      for(; idx < tas.Length; idx++) {
        if(tas[idx] == '/') {
          if(!next) {
            pos = idx;
          }
        } else {
          next = false;
        }
      }

      if(pos > 0) {
        path = tas.Substring(pos);
        return TransportAddressFactory.CreateInstance(tas.Substring(0, pos));
      } else {
        path = "/";
        return ta;
      }
    }
开发者ID:hseom,项目名称:brunet,代码行数:27,代码来源:PathEdgeListener.cs

示例2: CreateEdgeTo

    /**
     * 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);
      }
    }
开发者ID:bakriy,项目名称:brunet,代码行数:49,代码来源:UdpEdgeListener.cs

示例3: CreateEdgeTo

    /*
     * 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);
    }
开发者ID:bakriy,项目名称:brunet,代码行数:72,代码来源:SimulationEdgeListener.cs

示例4: CreateEdgeTo

    /*
     * 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);
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:43,代码来源:SimulationEdgeListener.cs

示例5: CacheInstance

 protected static TransportAddress CacheInstance(TransportAddress ta) {
   var ta_cache = Interlocked.Exchange<WeakValueTable<string, TransportAddress>>(ref _ta_cache, null);
   if( ta_cache != null ) {
     try {
       var ta2 = ta_cache.GetValue(ta.ToString());
       if(ta.Equals(ta2)) {
         ta = ta2;
       } else {
         ta_cache.Replace(ta.ToString(), ta);
       }
     }
     finally {
       Interlocked.Exchange<WeakValueTable<string, TransportAddress>>(ref _ta_cache, ta_cache);
     }
   }
   return ta;
 }
开发者ID:hseom,项目名称:brunet,代码行数:17,代码来源:TransportAddress.cs

示例6: CreateEdgeTo

    /* //////////////////////////////
     *
     * 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);
      }
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:36,代码来源:TcpEdgeListener.cs


注:本文中的Brunet.Transport.TransportAddress.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。