Exemplo n.º 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();
    }
  }
Exemplo n.º 2
0
  void ConnectionManager::HandleEdgeClose(const QString &reason)
  {
    Edge *edge = qobject_cast<Edge *>(sender());
    qDebug() << "Edge closed: " << edge->ToString() << reason;
    if(!_con_tab.RemoveEdge(edge)) {
      qWarning() << "Edge closed but no Edge found in CT:" << edge->ToString();
    }

    Connection *con = _con_tab.GetConnection(edge);
    if(con != 0) {
      con = _con_tab.GetConnection(con->GetRemoteId());
      if(con != 0) {
        con->Disconnect();
      }
    }

    if(!_closed) {
      return;
    }

    if(_con_tab.GetEdges().count() == 0) {
      emit Disconnected();
    }
  }
Exemplo n.º 3
0
  void ConnectionManager::Connect(RpcRequest &notification)
  {
    Edge *edge = dynamic_cast<Edge *>(notification.GetFrom());
    if(edge == 0) {
      qWarning() << "Connection attempt not from an Edge: " << notification.GetFrom()->ToString();
      return;
    }
    
    QByteArray brem_id = notification.GetMessage()["peer_id"].toByteArray();

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

    Id rem_id(brem_id);
    if(_local_id < rem_id) {
      qWarning() << "We should be sending CM::Connect, not the remote side.";
      return;
    }

    Connection *old_con = _con_tab.GetConnection(rem_id);
    // XXX if there is an old connection and the node doesn't want it, we need
    // to close it
    if(old_con != 0) {
      qDebug() << "Disconnecting old connection";
      old_con->Disconnect();
    }

    QSharedPointer<Edge> pedge = _con_tab.GetEdge(edge);
    if(pedge.isNull()) {
      qCritical() << "An edge attempted to create a connection, but there "
       "is no record of it" << edge->ToString();
      return;
    }

    CreateConnection(pedge, rem_id);
  }