public Socket newSocket() throws IOException { // zero means 'bind on any available port.' if (isEncryptedChannel()) { if (Config.getOutboundBindAny()) return SSLFactory.getSocket( DatabaseDescriptor.getServerEncryptionOptions(), endPoint(), DatabaseDescriptor.getSSLStoragePort()); else return SSLFactory.getSocket( DatabaseDescriptor.getServerEncryptionOptions(), endPoint(), DatabaseDescriptor.getSSLStoragePort(), FBUtilities.getLocalAddress(), 0); } else { Socket socket = SocketChannel.open(new InetSocketAddress(endPoint(), DatabaseDescriptor.getStoragePort())) .socket(); if (Config.getOutboundBindAny() && !socket.isBound()) socket.bind(new InetSocketAddress(FBUtilities.getLocalAddress(), 0)); return socket; } }
boolean isEncryptedChannel() { switch (DatabaseDescriptor.getServerEncryptionOptions().internode_encryption) { case none: return false; // if nothing needs to be encrypted then return immediately. case all: break; case dc: if (snitch .getDatacenter(id) .equals(snitch.getDatacenter(FBUtilities.getBroadcastAddress()))) return false; break; case rack: // for rack then check if the DC's are the same. if (snitch.getRack(id).equals(snitch.getRack(FBUtilities.getBroadcastAddress())) && snitch .getDatacenter(id) .equals(snitch.getDatacenter(FBUtilities.getBroadcastAddress()))) return false; break; } return true; }