コード例 #1
0
  void ConnectionManager::HandleEdgeClose()
  {
    Edge *edge = qobject_cast<Edge *>(sender());
    _active_addrs.remove(edge->GetRemoteAddress());
    qDebug() << "Edge closed: " << edge->ToString() << edge->GetStoppedReason();
    if(!_con_tab.RemoveEdge(edge)) {
      qWarning() << "Edge closed but no Edge found in CT:" << edge->ToString();
    }

    QSharedPointer<Connection> con = _con_tab.GetConnection(edge);
    if(con) {
      con = _con_tab.GetConnection(con->GetRemoteId());
      if(con) {
        con->Disconnect();
      }
    }

    if(!Stopped()) {
      return;
    }

    if(_con_tab.GetEdges().count() == 0) {
      emit Disconnected();
    }
  }
コード例 #2
0
  void ConnectionManager::Inquired(RpcRequest &response)
  {
    Dissent::Messaging::ISender *from = response.GetFrom();
    Edge *edge = dynamic_cast<Edge *>(from);
    if(edge == 0) {
      qWarning() << "Received an inquired from a non-Edge: " << from->ToString();
      return;
    } else if(!edge->Outbound()) {
      qWarning() << "We would never make an inquire call on an incoming edge: " << from->ToString();
      return;
    }

    QByteArray brem_id = response.GetMessage()["peer_id"].toByteArray();

    if(brem_id.isEmpty()) {
      qWarning() << "Invalid ConnectionEstablished, no id";
      return;
    }

    Id rem_id(brem_id);


    if(_local_id < rem_id) {
      BindEdge(edge, rem_id);
    } else if(rem_id == _local_id) {
      Address addr = edge->GetRemoteAddress();
      qDebug() << "Attempting to connect to ourself";
      edge->Close("Attempting to connect to ourself");
      emit ConnectionAttemptFailure(addr, "Attempting to connect to ourself");
      return;
    }
  }