Example #1
0
  void ConnectionManager::Inquired(const Response &response)
  {
    QSharedPointer<Edge> edge = response.GetFrom().dynamicCast<Edge>();
    if(!edge) {
      qWarning() << "Received an inquired from a non-Edge: " <<
        response.GetFrom()->ToString();
      return;
    } else if(!edge->Outbound()) {
      qWarning() << "We would never make an inquire call on an" <<
        "incoming edge: " << response.GetFrom()->ToString();
      return;
    }

    QByteArray brem_id = response.GetData().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->Stop("Attempting to connect to ourself");
      emit ConnectionAttemptFailure(addr, "Attempting to connect to ourself");
    }
  }
  void Session::Registered(const Response &response)
  {
    if(Stopped()) {
      return;
    }

    if(response.Successful() && response.GetData().toBool()) {
      qDebug() << GetPrivateIdentity().GetLocalId() << "registered and waiting to go.";
      return;
    }

    if(!_register_event.Stopped()) {
      qDebug() << "Almost started two registration attempts simultaneously!";
      return;
    }

    int delay = 5000;
    if(response.GetErrorType() == Response::Other) {
      delay = 60000;
    }
    qDebug() << "Unable to register due to" << response.GetError() <<
      "Trying again later.";

    Dissent::Utils::TimerCallback *cb =
      new Dissent::Utils::TimerMethod<Session, int>(this, &Session::Register, 0);
    _register_event = Dissent::Utils::Timer::GetInstance().QueueCallback(cb, delay);
  }
  void Session::Challenged(const Response &response)
  {
    if(Stopped()) {
      return;
    }

    if(response.Successful()) {
      QPair<bool, QVariant> auth = _auth->ProcessChallenge(response.GetData());
      if(auth.first) {
        qDebug() << "Sending challenge response";
        SendChallenge(false, auth.second);
        return;
      }

      qDebug() << "Received an invalid challenge, retrying.";
    }

    if(!_register_event.Stopped()) {
      qDebug() << "Almost started two registration attempts simultaneously!";
      return;
    }

    int delay = 5000;
    if(response.GetErrorType() == Response::Other) {
      delay = 60000;
    }
    qDebug() << "Unable to register due to" << response.GetError() <<
      "Trying again later.";

    Dissent::Utils::TimerCallback *cb =
      new Dissent::Utils::TimerMethod<Session, int>(this, &Session::Register, 0);
    _register_event = Dissent::Utils::Timer::GetInstance().QueueCallback(cb, delay);
  }
Example #4
0
  void RpcHandler::HandleResponse(const Response &response)
  {
    int id = response.GetId();
    if(id == 0) {
#ifdef RESPOND_NOTIFICATION
      if(response.GetData().toString() == Request::NotificationType) {
        return;
      }
#endif
      qWarning() << "RpcHandler: Response: No ID, from" <<
        response.GetFrom()->ToString();
      return;
    }

    QSharedPointer<RequestState> state = _requests[id];
    if(!state) {
      if(response.GetData().toString() == Request::NotificationType) {
        return;
      }
      qWarning() << "RpcHandler: Response: No handler for" << id;
      return;
    }

    if(state->GetSender() != response.GetFrom()) {
      qDebug() << "Received a response from a different source than " <<
        "the path the request was sent by.  Sent by:" <<
        state->GetSender()->ToString() << "Received by:" <<
        response.GetFrom()->ToString();
      // Eventually we need to not allow this behavior, but that means making
      // better equality comparator
    }

    state->StopTimer();
    _requests.remove(id);
    state->GetResponseHandler()->RequestComplete(response);
  }
  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);
    }
  }