use of org.bboxdb.network.packages.response.HelloResponse in project bboxdb by jnidzwetzki.
the class HandshakeHandler method handleRequest.
/**
* Handle the handshake request
*/
@Override
public boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
logger.info("Handshaking with: {}", clientConnectionHandler.clientSocket.getInetAddress());
try {
final HelloRequest heloRequest = HelloRequest.decodeRequest(encodedPackage);
clientConnectionHandler.setConnectionCapabilities(heloRequest.getPeerCapabilities());
final HelloResponse responsePackage = new HelloResponse(packageSequence, NetworkConst.PROTOCOL_VERSION, clientConnectionHandler.getConnectionCapabilities());
clientConnectionHandler.writeResultPackage(responsePackage);
clientConnectionHandler.setConnectionStateToOpen();
return true;
} catch (Exception e) {
logger.warn("Error while reading network package", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
return false;
}
}
Aggregations