//------------------------------------------------------------------------------ bool ClientLogon::handlePacket(Packet * packet) { RakNet::BitStream stream(&packet->data[1], packet->length-1, false); switch (packet->data[0]) { case ID_DISCONNECTION_NOTIFICATION: if (!suicide_scheduled_) { // something is wrong if we are disconnected without // receiving either session key or authorization // failed messages... onConnectFailed("Connection to authentication server closed unexpectedly."); } break; case ID_CONNECTION_REQUEST_ACCEPTED: sendCredentials(packet->systemAddress); break; case ID_CONNECTION_ATTEMPT_FAILED: onConnectFailed("Failed to contact authentication server."); break; case ID_ALREADY_CONNECTED: onConnectFailed("Already connected!?"); break; case ID_NO_FREE_INCOMING_CONNECTIONS: onConnectFailed("Server is busy. Try again in a moment."); break; case ID_CONNECTION_BANNED: onConnectFailed("You have been banned from the authentication server!"); break; case VHPI_VERSION_MISMATCH: onConnectFailed("Client is not up to date."); break; case VHPI_TYPE_MISMATCH: onConnectFailed("Target server is not a valid authentication server."); break; case ID_RSA_PUBLIC_KEY_MISMATCH: onConnectFailed("Our public key stored for the ranking server is out of date."); break; case RPI_SESSION_KEY: onSessionKeyReceived(stream); break; case RPI_AUTHORIZATION_FAILED: onAuthorizationFailed(stream); break; default: return false; } return true; }
SocketCode Socket::connect(UFC32 host, const U32 port) { if (!isValidSocket()) { return InvalidSocket; } struct hostent *he; if ((he = gethostbyname(host)) == NULL) { cout << "Socket::connect(): Failed to convert " << host << " to an IP" << endl; } _mAddr.sin_family = AF_INET; _mAddr.sin_port = htons(port); memcpy(&_mAddr.sin_addr, he->h_addr_list[0], he->h_length); S32 status = ::connect(sObj, (sockaddr *)&_mAddr, sizeof(_mAddr)); if (status == 0) { onConnected(); return Connected; } cout << "Socket::connect(): Failed to connect: " << status << ", errno " << errno << endl; onConnectFailed(); return ConnectionFailed; }
BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture<FaceFixture>) { ControlParameters parameters; parameters.setUri("tcp://127.0.0.1"); Block encodedParameters(parameters.wireEncode()); Name commandName("/localhost/nfd/faces"); commandName.append("create"); commandName.append(encodedParameters); shared_ptr<Interest> command(make_shared<Interest>(commandName)); generateCommand(*command); getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, command->getName(), 408, "unit-test-reason"); onConnectFailed(command->getName(), "unit-test-reason"); BOOST_REQUIRE(didCallbackFire()); BOOST_CHECK_EQUAL(didReceiveNotication(), false); }