コード例 #1
0
ファイル: ConnectionOverlord.cs プロジェクト: xujyan/brunet
    /**
     * Connectors just send and receive ConnectToMessages.  They return all responses
     * to the ConnectionOverlord that initiated the ConnectToMessage
     * @return true if we have enough responses for this connector, and should
     * stop listening for more
     */
    virtual public bool HandleCtmResponse(Connector c, ISender return_path, ConnectToMessage resp) {
      /**
       * Time to start linking:
       */

      Linker l = new Linker(_node, resp.Target.Address,
                            resp.Target.Transports,
                            resp.ConnectionType,
                            _node.Address.ToString());
      _node.TaskQueue.Enqueue( l );
      return true;
    }
コード例 #2
0
    /**
     * Connectors just send and receive ConnectToMessages.  They return all responses
     * to the ConnectionOverlord that initiated the ConnectToMessage
     * @return true if we have enough responses for this connector, and should
     * stop listening for more
     */
    virtual public bool HandleCtmResponse(Connector c, ISender return_path, ConnectToMessage resp) {
      /**
       * Time to start linking:
       */

      ICollection transports = resp.Target.Transports;

      if(TAAuth != null) {
        ArrayList trans = new ArrayList();
        foreach(TransportAddress ta in resp.Target.Transports) {
          if(TAAuth.Authorize(ta) != TAAuthorizer.Decision.Deny) {
            trans.Add(ta);
          }
        }
        transports = trans;
      }

      Linker l = new Linker(_node, resp.Target.Address, transports,
          resp.ConnectionType, resp.Token);
      l.FinishEvent += LinkerEndHandler;
      _node.TaskQueue.Enqueue( l );
      return true;
    }
コード例 #3
0
ファイル: ConnectionOverlord.cs プロジェクト: xujyan/brunet
    virtual protected void ConnectTo(Address target, string ConnectionType) {
      ConnectionType mt = Connection.StringToMainType(ConnectionType);
      /*
       * This is an anonymous delegate which is called before
       * the Connector starts.  If it returns true, the Connector
       * will finish immediately without sending an ConnectToMessage
       */
      Linker l = new Linker(_node, target, null, ConnectionType,
          _node.Address.ToString());
      object link_task = l.Task;
      Connector.AbortCheck abort = delegate(Connector c) {
        bool stop = false;
        stop = _node.ConnectionTable.Contains( mt, target );
        if (!stop ) {
          /*
           * Make a linker to get the task.  We won't use
           * this linker.
           * No need in sending a ConnectToMessage if we
           * already have a linker going.
           */
          stop = _node.TaskQueue.HasTask( link_task );
        }
        return stop;
      };
      if (abort(null)) {
        return;
      }

      ConnectToMessage  ctm = new ConnectToMessage(ConnectionType, _node.GetNodeInfo(8),
          _node.Address.ToString());
      ISender send = new AHSender(_node, target, AHPacket.AHOptions.Exact);
      Connector con = new Connector(_node, send, ctm, this);
      con.FinishEvent += ConnectorEndHandler;
      con.AbortIf = abort;
      _node.TaskQueue.Enqueue(con);
    }
コード例 #4
0
 /**
  * When we get ConnectToMessage responses the connector tells us.
  */
 override public bool HandleCtmResponse(Connector c, ISender ret_path,
                                        ConnectToMessage ctm_resp)
 {
   base.HandleCtmResponse(c, ret_path, ctm_resp);
   /**
    * Check this guys neighbors:
    */
   //See if we want more:
   bool got_enough = true;
   object des_o = _connectors[c];
   if( des_o != null ) {
     got_enough = (c.ReceivedCTMs.Count >= (int)des_o);
   }
   return got_enough;
 }
コード例 #5
0
    /**
     * Initiates connection setup. 
     * @param sender the ISender for the Connector to use
     * @param contype the type of connection we want to make
     * @param token the token used for connection messages
     * @param responses the maximum number of ctm response messages to listen
     */
    protected void ConnectTo(ISender sender, string contype, string token, int responses)
    {
      ConnectionType mt = Connection.StringToMainType(contype);
      /*
       * This is an anonymous delegate which is called before
       * the Connector starts.  If it returns true, the Connector
       * will finish immediately without sending an ConnectToMessage
       */
      Connector.AbortCheck abort = null;
      ForwardingSender fs = sender as ForwardingSender;
      if( fs != null ) {
        //In general, we only know the exact node we are trying
        //to reach when we are using a ForwardingSender
        Address target = fs.Destination;
        Linker l = new Linker(_node, target, null, contype, token);
        object linker_task = l.Task;  //This is what we check for
        abort = delegate(Connector c) {
          bool stop = _node.ConnectionTable.Contains( mt, target );
          if (!stop ) {
              /*
               * Make a linker to get the task.  We won't use
               * this linker.
               * No need in sending a ConnectToMessage if we
               * already have a linker going.
               */
            stop = _node.TaskQueue.HasTask( linker_task );
          }
          return stop;
        };
        if ( abort(null) ) {
          return;
        }
      }
      //Send the 4 neighbors closest to this node:
      ArrayList nearest = _node.ConnectionTable.GetNearestTo( (AHAddress)_node.Address, 4);
      NodeInfo[] near_ni = new NodeInfo[nearest.Count];
      int i = 0;
      foreach(Connection cons in nearest) {
        //We don't use the TAs, just the addresses
        near_ni[i] = NodeInfo.CreateInstance(cons.Address);
        i++;
      }
      ConnectToMessage ctm = new ConnectToMessage(contype, _node.GetNodeInfo(8), near_ni, token);

      Connector con = new Connector(_node, sender, ctm, this);
      con.AbortIf = abort;
      //Keep a reference to it does not go out of scope
      lock( _sync ) {
        _connectors[con] = responses;
      }
      con.FinishEvent += new EventHandler(this.ConnectorEndHandler);
      //Start up this Task:
      _node.TaskQueue.Enqueue(con);
    }
コード例 #6
0
 /**
  * When we get ConnectToMessage responses the connector tells us.
  */
 override public bool HandleCtmResponse(Connector c, ISender ret_path,
                                        ConnectToMessage ctm_resp)
 {
   /**
    * Time to start linking:
    */
   
   Linker l = new Linker(_node, ctm_resp.Target.Address,
                         ctm_resp.Target.Transports,
                         ctm_resp.ConnectionType,
                         ctm_resp.Token);
   _node.TaskQueue.Enqueue( l );
   /**
    * Check this guys neighbors:
    */
   /* POB: I don't think this is needed because we also do the 
    * same thing in the ConnectorEndHandler, so why do this twice?
    * In fact, it seems better to wait for all the responses before
    * looking for the closest one
    *
    * commenting this out:
    *
   ConnectionList structs =
       _node.ConnectionTable.GetConnections(ConnectionType.Structured);
   ConnectToNearer(structs, ctm_resp.Target.Address, ctm_resp.Neighbors);
   */
   //See if we want more:
   bool got_enough = true;
   object des_o = _connectors[c];
   if( des_o != null ) {
     got_enough = (c.ReceivedCTMs.Count >= (int)des_o);
   }
   return got_enough;
 }