/** * Closes a connection to the supplied remote address, if it is open. This method is particularly * useful when not using a timeout for remote connections. * * @param remoteAddress the address of the peer socket. * @return <code>true</code> if the connection has been closed and <code>false</code> if there was * nothing to close. * @since 1.7.1 */ public synchronized boolean close(Address remoteAddress) throws IOException { if (logger.isDebugEnabled()) { logger.debug("Closing socket for peer address " + remoteAddress); } SocketEntry entry = (SocketEntry) sockets.remove(remoteAddress); if (entry != null) { synchronized (entry) { entry.getSocket().close(); } logger.info("Socket to " + entry.getPeerAddress() + " closed"); return true; } return false; }
public void sendMessage( UdpAddress targetAddress, byte[] message, TransportStateReference tmStateReference) throws java.io.IOException { InetSocketAddress targetSocketAddress = new InetSocketAddress(targetAddress.getInetAddress(), targetAddress.getPort()); if (logger.isDebugEnabled()) { logger.debug( "Sending message to " + targetAddress + " with length " + message.length + ": " + new OctetString(message).toHexString()); } DatagramSocket s = ensureSocket(); s.send(new DatagramPacket(message, message.length, targetSocketAddress)); }
/** Default constructor, initializes the salt to a random value. */ protected Salt() { byte[] rnd = new byte[8]; try { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); sr.nextBytes(rnd); } catch (NoSuchAlgorithmException nsae) { logger.warn("Could not use SecureRandom. Using Random instead."); Random r = new Random(); r.nextBytes(rnd); } salt = rnd[0]; for (int i = 0; i < 7; i++) { salt = (salt * 256) + ((int) rnd[i]) + 128; } if (logger.isDebugEnabled() == true) { logger.debug("Initialized Salt to " + Long.toHexString(salt) + "."); } }