Search in sources :

Example 1 with EncryptionManager

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;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EncryptionManager(jgnash.util.EncryptionManager) ChannelInitializer(io.netty.channel.ChannelInitializer) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NettyTransferHandler(jgnash.engine.attachment.NettyTransferHandler)

Example 2 with EncryptionManager

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;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) EncryptionManager(jgnash.util.EncryptionManager) DelimiterBasedFrameDecoder(io.netty.handler.codec.DelimiterBasedFrameDecoder) StringDecoder(io.netty.handler.codec.string.StringDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Base64Encoder(io.netty.handler.codec.base64.Base64Encoder) StringEncoder(io.netty.handler.codec.string.StringEncoder) Base64Decoder(io.netty.handler.codec.base64.Base64Decoder)

Example 3 with EncryptionManager

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;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EncryptionManager(jgnash.util.EncryptionManager) ChannelInitializer(io.netty.channel.ChannelInitializer) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 4 with EncryptionManager

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;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) EncryptionManager(jgnash.util.EncryptionManager) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 5 with EncryptionManager

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;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EncryptionManager(jgnash.util.EncryptionManager) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

EncryptionManager (jgnash.util.EncryptionManager)6 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)5 Bootstrap (io.netty.bootstrap.Bootstrap)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)3 ChannelFuture (io.netty.channel.ChannelFuture)3 ChannelInitializer (io.netty.channel.ChannelInitializer)3 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)3 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 DelimiterBasedFrameDecoder (io.netty.handler.codec.DelimiterBasedFrameDecoder)1 Base64Decoder (io.netty.handler.codec.base64.Base64Decoder)1 Base64Encoder (io.netty.handler.codec.base64.Base64Encoder)1 StringDecoder (io.netty.handler.codec.string.StringDecoder)1 StringEncoder (io.netty.handler.codec.string.StringEncoder)1 NettyTransferHandler (jgnash.engine.attachment.NettyTransferHandler)1