use of jgnash.util.EncryptionManager in project jgnash by ccavanaugh.
the class AttachmentTransferClient method connectToServer.
/**
* Starts the connection with the lock server.
*
* @param host remote host
* @param port connection port
* @param password connection password
* @return {@code true} if successful
*/
boolean connectToServer(final String host, final int port, final char[] password) {
boolean result = false;
// If a password has been specified, create an EncryptionManager
if (password != null && password.length > 0) {
encryptionManager = new EncryptionManager(password);
}
final Bootstrap bootstrap = new Bootstrap();
eventLoopGroup = new NioEventLoopGroup();
transferHandler = new NettyTransferHandler(tempDirectory, encryptionManager);
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class).handler(new Initializer()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, ConnectionFactory.getConnectionTimeout() * 1000).option(ChannelOption.SO_KEEPALIVE, true);
try {
// Start the connection attempt.
channel = bootstrap.connect(host, port).sync().channel();
result = true;
logger.info("Connection made with File Transfer Server");
} catch (final InterruptedException e) {
logger.log(Level.SEVERE, "Failed to connect to the File Transfer Server", e);
disconnectFromServer();
}
return result;
}
use of jgnash.util.EncryptionManager in project jgnash by ccavanaugh.
the class AttachmentTransferServer method startServer.
public boolean startServer(final char[] password) {
boolean result = false;
// If a password has been specified, create an EncryptionManager
if (password != null && password.length > 0) {
encryptionManager = new EncryptionManager(password);
}
try {
ServerBootstrap b = new ServerBootstrap();
b.group(eventLoopGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(final SocketChannel ch) throws Exception {
ch.pipeline().addLast(new DelimiterBasedFrameDecoder(((TRANSFER_BUFFER_SIZE + 2) / 3) * 4 + PATH_MAX, true, Delimiters.lineDelimiter()), new StringEncoder(CharsetUtil.UTF_8), new StringDecoder(CharsetUtil.UTF_8), new Base64Encoder(), new Base64Decoder(), new ServerTransferHandler());
}
});
// Start the server.
final ChannelFuture future = b.bind(port).sync();
if (future.isDone() && future.isSuccess()) {
result = true;
logger.info("File Transfer Server started successfully");
} else {
logger.info("Failed to start the File Transfer Server");
}
} catch (final InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
stopServer();
}
return result;
}
use of jgnash.util.EncryptionManager in project jgnash by ccavanaugh.
the class DistributedLockManager method connectToServer.
/**
* Starts the connection with the lock server.
*
* @param password connection password
* @return {@code true} if successful
*/
public boolean connectToServer(final char[] password) {
boolean result = false;
// If a password has been specified, create an EncryptionManager
if (password != null && password.length > 0) {
encryptionManager = new EncryptionManager(password);
}
final Bootstrap bootstrap = new Bootstrap();
eventLoopGroup = new NioEventLoopGroup();
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class).handler(new Initializer()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, ConnectionFactory.getConnectionTimeout() * 1000).option(ChannelOption.SO_KEEPALIVE, true);
try {
// Start the connection attempt.
channel = bootstrap.connect(host, port).sync().channel();
// send this channels uuid
channel.writeAndFlush(encrypt(UUID_PREFIX + uuid) + EOL_DELIMITER).sync();
result = true;
logger.info("Connection made with Distributed Lock Server");
} catch (final InterruptedException e) {
logger.log(Level.SEVERE, "Failed to connect to Distributed Lock Server", e);
disconnectFromServer();
}
return result;
}
use of jgnash.util.EncryptionManager in project jgnash by ccavanaugh.
the class MessageBusServer method startServer.
public boolean startServer(final DataStoreType dataStoreType, final String dataBasePath, final char[] password) {
boolean result = false;
logger.info("Starting message bus server on port: " + port);
this.dataBasePath = dataBasePath;
this.dataStoreType = dataStoreType.name();
// If a password has been specified, create an EncryptionManager
if (password != null && password.length > 0) {
encryptionManager = new EncryptionManager(password);
}
eventLoopGroup = new NioEventLoopGroup();
final ServerBootstrap bootstrap = new ServerBootstrap();
try {
bootstrap.group(eventLoopGroup).channel(NioServerSocketChannel.class).childHandler(new MessageBusRemoteInitializer()).childOption(ChannelOption.SO_KEEPALIVE, true);
final ChannelFuture future = bootstrap.bind(port);
future.sync();
if (future.isDone() && future.isSuccess()) {
logger.info("Message Bus Server started successfully");
result = true;
} else {
logger.info("Failed to start the Message Bus Server");
}
} catch (final InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
stopServer();
}
return result;
}
use of jgnash.util.EncryptionManager in project jgnash by ccavanaugh.
the class MessageBusClient method connectToServer.
boolean connectToServer(final char[] password) {
boolean result = false;
// If a password has been specified, create an EncryptionManager
if (password != null && password.length > 0) {
encryptionManager = new EncryptionManager(password);
}
eventLoopGroup = new NioEventLoopGroup();
final Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class).handler(new MessageBusClientInitializer()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConnectionTimeout() * 1000).option(ChannelOption.SO_KEEPALIVE, true);
channelLock.lock();
try {
// Start the connection attempt.
channel = bootstrap.connect(host, port).sync().channel();
result = true;
logger.info("Connected to remote message server");
} catch (final InterruptedException e) {
logger.log(Level.SEVERE, "Failed to connect to remote message bus", e);
disconnectFromServer();
} finally {
channelLock.unlock();
}
return result;
}
Aggregations