void RepeatingBulkRound::IncomingData(const Request &notification)
  {
    if(Stopped()) {
      qWarning() << "Received a message on a closed session:" << ToString();
      return;
    }

    QSharedPointer<Connections::IOverlaySender> sender =
      notification.GetFrom().dynamicCast<Connections::IOverlaySender>();
    if(!sender) {
      qDebug() << ToString() << " received wayward message from: " <<
        notification.GetFrom()->ToString();
      return;
    }

    const Id &id = sender->GetRemoteId();
    if(!GetGroup().Contains(id)) {
      qDebug() << ToString() << " received wayward message from: " << 
        notification.GetFrom()->ToString();
      return;
    }

    QVariantHash msg = notification.GetData().toHash();

    bool bulk = msg.value("bulk").toBool();
    if(bulk) {
      ProcessData(id, msg.value("data").toByteArray());
    } else {
      _shuffle_round->IncomingData(notification);
    }
  }
  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();
    }
  }
  void ConnectionManager::EdgeCheck(const int &)
  {
    qDebug() << "Checking edges";
    QList<QSharedPointer<Edge> > edges_to_close;
    qint64 now = Utils::Time::GetInstance().MSecsSinceEpoch();
    qint64 check_time = now - EdgeCheckTimeout;
    qint64 close_time = now - EdgeCloseTimeout;

    foreach(const QSharedPointer<Edge> &edge, _con_tab.GetEdges()) {
      qint64 last_msg = edge->GetLastIncomingMessage();
      if(check_time < last_msg) {
        continue;
      } else if(last_msg < close_time) {
        QSharedPointer<Connection> con = _con_tab.GetConnection(edge.data());
        if(con && (con->GetRemoteId() == _local_id)) {
          qDebug() << "Attempted to close loopback connection.";
          continue;
        }
        qDebug() << "Closing edge:" << edge->ToString();
        edge->Stop("Timed out");
      } else {
        QSharedPointer<Messaging::ISender> sender = _con_tab.GetConnection(edge.data());
        if(!sender) {
          sender = edge;
        }
        qDebug() << "Testing:" << sender->ToString();
        _rpc->SendRequest(sender, "CM::Ping", QVariant(), _ping_handler, true);
      }
    }
  }
  void Round::IncomingData(const Request &notification)
  {
    if(Stopped()) {
      qWarning() << "Received a message on a closed session:" << ToString();
      return;
    }
      
    QSharedPointer<Connections::IOverlaySender> sender =
      notification.GetFrom().dynamicCast<Connections::IOverlaySender>();

    if(!sender) {
      qDebug() << ToString() << " received wayward message from: " <<
        notification.GetFrom()->ToString();
      return;
    }

    const Id &id = sender->GetRemoteId();
    if(!_group.Contains(id)) {
      qDebug() << ToString() << " received wayward message from: " <<
        notification.GetFrom()->ToString();
      return;
    }

    ProcessData(id, notification.GetData().toHash().value("data").toByteArray());
  }
Beispiel #5
0
void RelayForwarder::Forward(const Id &to, const QByteArray &data,
                             const QStringList &been)
{
    QHash<int, bool> tested;

    QSharedPointer<Connection> con = _ct.GetConnection(to);
    if(!con || (dynamic_cast<RelayEdge *>(con->GetEdge().data()) != 0)) {
        if(!been.contains(Preferred().ToString())) {
            con = _ct.GetConnection(Preferred());
        }
    }

    if(!con || (dynamic_cast<RelayEdge *>(con->GetEdge().data()) != 0)) {
        const QList<QSharedPointer<Connection> > cons = _ct.GetConnections();

        Dissent::Utils::Random &rand = Dissent::Utils::Random::GetInstance();
        int idx = rand.GetInt(0, cons.size());
        con = cons[idx];
        tested[idx] = true;
        RelayEdge *redge = dynamic_cast<RelayEdge *>(con->GetEdge().data());
        while(been.contains(con->GetRemoteId().ToString()) || (redge != 0)) {
            if(tested.size() == cons.size()) {
                qWarning() << "Packet has been to all of our connections.";
                return;
            }

            idx = rand.GetInt(0, cons.size());
            con = cons[idx];
            redge = dynamic_cast<RelayEdge *>(con->GetEdge().data());
            tested[idx] = true;
        }
    }

    Send(con, to, data, been);
}
Beispiel #6
0
  void BaseBulkRound::IncomingDataSpecial(const Request &notification)
  {
    QVariantHash msg = notification.GetData().toHash();

    if(msg.value("bulk", false).toBool()) {
      QSharedPointer<Connections::IOverlaySender> sender =
        notification.GetFrom().dynamicCast<Connections::IOverlaySender>();
      const Id &id = sender->GetRemoteId();
      ProcessData(id, msg.value("data").toByteArray());
    } else {
      _shuffle_round->IncomingData(notification);
    }
  }
Beispiel #7
0
void RelayForwarder::Send(const QSharedPointer<Connection> &con,
                          const Id &to, const QByteArray &data, const QStringList &been,
                          const QStringList &reverse)
{
    QVariantHash msg;
    msg["to"] = to.ToString();
    msg["data"] = data;
    msg["been"] = been + _base_been;

    if(!reverse.isEmpty()) {
        msg["reverse"] = reverse;
    }

    qDebug() << con->GetLocalId().ToString() << "Forwarding message from" <<
             msg["been"].toStringList().value(0) << "to" << to.ToString() << "via" <<
             con->GetRemoteId().ToString() << "Reverse path" << !reverse.isEmpty();

    _rpc->SendNotification(con, "RF::Data", msg);
}
  void CSConnectionAcquirer::ServerStateResponse(const Response &response)
  {
    QSharedPointer<Connection> con =  response.GetFrom().dynamicCast<Connection>();
    if(!con) {
      qCritical() << "Received an rpc request from a non-connection.";
      return;
    }
    Id remote = con->GetRemoteId();

    QVariantHash msg = response.GetData().toHash();

    QHash<QByteArray, QUrl> id_to_addr;
    QDataStream stream(msg.value("list").toByteArray());
    stream >> id_to_addr;
    int cons = msg.value("connections").toInt();

    if(IsServer()) {
      ServerHandleServerStateResponse(remote, id_to_addr, cons);
    } else {
      ClientHandleServerStateResponse(remote, id_to_addr, cons);
    }
  }