Ejemplo n.º 1
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;
    }
  }
Ejemplo n.º 2
0
  void ConnectionManager::Inquire(RpcRequest &request)
  {
    Dissent::Messaging::ISender *from = request.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 should never receive an inquire call on an outbound edge: " << from->ToString();
      return;
    }

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

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

    Id rem_id(brem_id);

    QVariantMap response;
    response["peer_id"] = _local_id.GetByteArray();
    request.Respond(response);

    QString saddr = request.GetMessage()["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->Close("Attempting to connect to ourself");
    }
  }