catch (SocketException se)
{
logger.warn("Failed to set send buffer size on internode socket.", se);
}
}
out = new DataOutputStreamPlus(new BufferedOutputStream(socket.getOutputStream(), 4096));
out.writeInt(MessagingService.PROTOCOL_MAGIC);
writeHeader(out, targetVersion, shouldCompressConnection());
out.flush();
DataInputStream in = new DataInputStream(socket.getInputStream());
int maxTargetVersion = handshakeVersion(in);
if (maxTargetVersion == NO_VERSION)
{
// no version is returned, so disconnect an try again: we will either get
// a different target version (targetVersion < MessagingService.VERSION_12)
// or if the same version the handshake will finally succeed
logger.debug("Target max version is {}; no version information yet, will retry", maxTargetVersion);
disconnect();
continue;
}
if (targetVersion > maxTargetVersion)
{
logger.debug("Target max version is {}; will reconnect with that version", maxTargetVersion);
MessagingService.instance().setVersion(poolReference.endPoint(), maxTargetVersion);
disconnect();
return false;
}
if (targetVersion < maxTargetVersion && targetVersion < MessagingService.current_version)
{
logger.trace("Detected higher max version {} (using {}); will reconnect when queued messages are done",
maxTargetVersion, targetVersion);
MessagingService.instance().setVersion(poolReference.endPoint(), Math.min(MessagingService.current_version, maxTargetVersion));
softCloseSocket();
}
out.writeInt(MessagingService.current_version);
CompactEndpointSerializationHelper.serialize(FBUtilities.getBroadcastAddress(), out);
if (shouldCompressConnection())
{
out.flush();
logger.trace("Upgrading OutputStream to be compressed");
if (targetVersion < MessagingService.VERSION_21)
{
// Snappy is buffered, so no need for extra buffering output stream
out = new DataOutputStreamPlus(new SnappyOutputStream(socket.getOutputStream()));
}
else
{
// TODO: custom LZ4 OS that supports BB write methods
LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
Checksum checksum = XXHashFactory.fastestInstance().newStreamingHash32(LZ4_HASH_SEED).asChecksum();
out = new DataOutputStreamPlus(new LZ4BlockOutputStream(socket.getOutputStream(),
1 << 14, // 16k block size
compressor,
checksum,
true)); // no async flushing
}