Example #1
0
  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());
  }
Example #2
0
  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);
    }
  }
Example #3
0
  void ConnectionManager::Connect(const Request &notification)
  {
    QSharedPointer<Edge> edge = notification.GetFrom().dynamicCast<Edge>();
    if(!edge) {
      qWarning() << "Connection attempt not from an Edge: " <<
        notification.GetFrom()->ToString();
      return;
    }
    
    QByteArray brem_id = notification.GetData().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;
    }

    QSharedPointer<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) {
      qDebug() << "Disconnecting old connection";
      old_con->Disconnect();
    }

    CreateConnection(edge, rem_id);
  }
  void Session::HandlePrepare(const Request &notification)
  {
    if(_prepare_waiting) {
      _prepare_waiting = false;
    }

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

    if(_current_round && !_current_round->Stopped() && _current_round->Started()) {
      _prepare_waiting = true;
      _prepare_notification = notification;
      if(msg.value("interrupt").toBool()) {
        _current_round->Stop("Round interrupted.");
      }
      return;
    }

    QByteArray brid = msg.value("round_id").toByteArray();
    if(brid.isEmpty()) {
      qDebug() << "HandlePrepare: Invalid round id";
      return;
    }

    Id round_id(brid);

    if(msg.contains("group")) {
      QDataStream stream(msg.value("group").toByteArray());
      Group group;
      stream >> group;
      qDebug() << "Prepare contains new group. I am present:" <<
        group.Contains(GetPrivateIdentity().GetLocalId());
      _group_holder->UpdateGroup(group);
    }
Example #5
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);
    }
  }
Example #6
0
  void ConnectionManager::Inquire(const Request &request)
  {
    QSharedPointer<Edge> edge = request.GetFrom().dynamicCast<Edge>();
    if(!edge) {
      qWarning() << "Received an inquired from a non-Edge: " <<
        request.GetFrom()->ToString();
      request.Failed(Response::InvalidMessage, "Received on a non-Edge");
      return;
    } else if(edge->Outbound()) {
      qWarning() << "We should never receive an inquire call on an" <<
        "outbound edge: " << request.GetFrom()->ToString();
      request.Failed(Response::InvalidMessage, "Received on outbound edge");
      return;
    }

    QVariantHash data = request.GetData().toHash();
    if(data.value("version").toInt() != VERSION) {
      qDebug() << "Received an inquired from a different version." <<
        "Expected:" << VERSION << "Found:" << data.value("version");
      request.Failed(Response::InvalidInput, "Invalid version");
      return;
    }

    QByteArray brem_id = data.value("peer_id").toByteArray();

    if(brem_id.isEmpty()) {
      qWarning() << "Invalid Inquire, no id";
      request.Failed(Response::InvalidInput, "No remote id");
      return;
    }

    Id rem_id(brem_id);

    request.Respond(_local_id.GetByteArray());

    QString saddr = data.value("persistent").toString();
    Address addr = AddressFactory::GetInstance().CreateAddress(saddr);
    edge->SetRemotePersistentAddress(addr);

    if(_local_id < rem_id) {
      BindEdge(edge, rem_id);
    } else if(_local_id == rem_id) {
      edge->Stop("Attempting to connect to ourself");
    }
  }
Example #7
0
void RelayForwarder::IncomingData(const Request &notification)
{
    QVariantHash msg = notification.GetData().toHash();

    Id destination = Id(msg.value("to").toString());
    if(destination == Id::Zero()) {
        qWarning() << "Received a forwarded message without a destination.";
        return;
    }

    QStringList been = msg.value("been").toStringList();
    if(destination == _local_id) {
        if(been.size() == 0) {
            qWarning() << "Received a forwarded message without any history.";
            return;
        }

        Id source = Id(been[0]);
        if(source == Id::Zero()) {
            qWarning() << "Received a forwarded message without a valid source.";
        }

        QSharedPointer<ForwardingSender> *psender = _cache.take(source);
        if(!psender || (*psender)->GetReverse().isEmpty()) {
            if(psender) {
                delete psender;
            }
            psender = new QSharedPointer<ForwardingSender>(
                new ForwardingSender(GetSharedPointer(), _local_id, source, been));
        }

        QSharedPointer<ForwardingSender> sender(*psender);
        _cache.insert(source, psender);

        _rpc->HandleData(sender, msg.value("data").toByteArray());
        return;
    }

    QStringList reverse = msg.value("reverse").toStringList();
    QByteArray data = msg.value("data").toByteArray();
    if(reverse.isEmpty() || !Reverse(destination, data, been, reverse)) {
        Forward(destination, data, been);
    }
}
Example #8
0
 void ConnectionManager::HandlePingRequest(const Request &request)
 {
   request.Respond(request.GetData());
 }
Example #9
0
 void SessionEntryTunnel::IncomingData(const Request &request)
 {
   QVariantHash hash = request.GetData().toHash();
   m_tunnel.IncomingData(hash.value("data").toByteArray());
 }