@Override public void start() throws Exception { MqttServerOptions options = new MqttServerOptions() .setPort(1883) .setHost("0.0.0.0");
@Override public void start() throws Exception { MqttServerOptions options = new MqttServerOptions() .setPort(8883) .setPemKeyCertOptions(new PemKeyCertOptions() .setKeyPath("server-key.pem") .setCertPath("server-cert.pem")) .setSsl(true);
@Before public void before(TestContext context) { MqttServerOptions options = new MqttServerOptions() .setPort(MQTT_SERVER_TLS_PORT) .setKeyCertOptions(Cert.SERVER_PEM_ROOT_CA.get()) .setSsl(true); // just useful for enabling decryption using Wireshark (which doesn't support default Diffie-Hellmann for key exchange) // options.addEnabledCipherSuite("TLS_RSA_WITH_AES_256_CBC_SHA256"); this.setUp(context, options); }
private Future<Void> bindInsecureMqttServer() { if (isInsecurePortEnabled()) { final MqttServerOptions options = new MqttServerOptions(); options .setHost(getConfig().getInsecurePortBindAddress()) .setPort(determineInsecurePort()) .setMaxMessageSize(getConfig().getMaxPayloadSize()); return bindMqttServer(options, insecureServer).map(server -> { insecureServer = server; return (Void) null; }).recover(t -> { return Future.failedFuture(t); }); } else { return Future.succeededFuture(); } }
@Before public void before(TestContext context) { MqttServerOptions options = new MqttServerOptions() .setPort(MQTT_SERVER_TLS_PORT) .setKeyCertOptions(Cert.SERVER_PEM_ROOT_CA.get()) .setTrustOptions(Trust.SERVER_PEM_ROOT_CA.get()) .setSsl(true) .setClientAuth(ClientAuth.REQUEST); this.setUp(context, options); }
MqttServerOptions options = new MqttServerOptions(); options.setMaxMessageSize(this.options.getMaxMessageSize()); options.setHost(this.options.getBindAddress()).setPort(this.options.getListenPort()); options.setAutoClientId(true); .setCertPath(this.options.getCertFile()); options.setKeyCertOptions(pemKeyCertOptions) .setSsl(this.options.isSsl());
/** * Return an MQTT server instance using default options * * @param vertx Vert.x instance * @return MQTT server instance */ static MqttServer create(Vertx vertx) { return new MqttServerImpl(vertx, new MqttServerOptions()); }
/** * Create an options from JSON * * @param json the JSON */ public MqttServerOptions(JsonObject json) { super(json); // override the default port this.setPort(json.getInteger("port", DEFAULT_PORT)); this.maxMessageSize = json.getInteger("maxMessageSize", DEFAULT_MAX_MESSAGE_SIZE); this.isAutoClientId = json.getBoolean("isAutoClientId", true); if ((this.maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) { Arguments.require(this.getReceiveBufferSize() >= this.maxMessageSize, "Receiver buffer size can't be lower than max message size"); } }
@Before public void before(TestContext context) { MqttServerOptions options = new MqttServerOptions(); options.setMaxMessageSize(MQTT_MAX_MESSAGE_SIZE); this.setUp(context, options); }
@Before public void before(TestContext context) { MqttServerOptions options = new MqttServerOptions(); options.setTimeoutOnConnect(MQTT_TIMEOUT_ON_CONNECT); this.setUp(context, options); }
/** * Default constructor */ public MqttServerOptions() { super(); // override the default port this.setPort(DEFAULT_PORT); this.maxMessageSize = DEFAULT_MAX_MESSAGE_SIZE; this.isAutoClientId = true; this.timeoutOnConnect = DEFAULT_TIMEOUT_ON_CONNECT; }
private void initChannel(ChannelPipeline pipeline) { pipeline.addBefore("handler", "mqttEncoder", MqttEncoder.INSTANCE); if (this.options.getMaxMessageSize() > 0) { pipeline.addBefore("handler", "mqttDecoder", new MqttDecoder(this.options.getMaxMessageSize())); } else { // max message size not set, so the default from Netty MQTT codec is used pipeline.addBefore("handler", "mqttDecoder", new MqttDecoder()); } // adding the idle state handler for timeout on CONNECT packet pipeline.addBefore("handler", "idle", new IdleStateHandler(this.options.timeoutOnConnect(), 0, 0)); pipeline.addBefore("handler", "timeoutOnConnect", new ChannelDuplexHandler() { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { IdleStateEvent e = (IdleStateEvent) evt; if (e.state() == IdleState.READER_IDLE) { // as MQTT 3.1.1 describes, if no packet is sent after a "reasonable" time (here CONNECT timeout) // the connection is closed ctx.channel().close(); } } } }); } }
/** * Set max MQTT message size * * @param maxMessageSize max MQTT message size (variable header + payload) * @return MQTT server options instance */ public MqttServerOptions setMaxMessageSize(int maxMessageSize) { Arguments.require(maxMessageSize > 0 || maxMessageSize == DEFAULT_MAX_MESSAGE_SIZE, "maxMessageSize must be > 0"); if ((maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) { Arguments.require(this.getReceiveBufferSize() >= maxMessageSize, "Receiver buffer size can't be lower than max message size"); } this.maxMessageSize = maxMessageSize; return this; }
@Override protected void initChannel(ChannelPipeline pipeline) { if (logEnabled) { pipeline.addLast("logging", new LoggingHandler()); } pipeline.addLast("mqttEncoder", MqttEncoder.INSTANCE); if (this.mqttServerOptions.getMaxMessageSize() > 0) { pipeline.addLast("mqttDecoder", new MqttDecoder(this.mqttServerOptions.getMaxMessageSize())); } else { // max message size not set, so the default from Netty MQTT codec is used pipeline.addLast("mqttDecoder", new MqttDecoder()); } }
@Before public void before(TestContext context) { MqttServerOptions options = new MqttServerOptions() .setPort(MQTT_SERVER_TLS_PORT) .setKeyCertOptions(Cert.SERVER_PEM_ROOT_CA.get()) .setSsl(true); // just useful for enabling decryption using Wireshark (which doesn't support default Diffie-Hellmann for key exchange) // options.addEnabledCipherSuite("TLS_RSA_WITH_AES_256_CBC_SHA256"); this.setUp(context, options); }
private Future<Void> bindInsecureMqttServer() { if (isInsecurePortEnabled()) { final MqttServerOptions options = new MqttServerOptions(); options .setHost(getConfig().getInsecurePortBindAddress()) .setPort(determineInsecurePort()) .setMaxMessageSize(getConfig().getMaxPayloadSize()); return bindMqttServer(options, insecureServer).map(server -> { insecureServer = server; return (Void) null; }).recover(t -> { return Future.failedFuture(t); }); } else { return Future.succeededFuture(); } }
@Before public void before(TestContext context) { MqttServerOptions options = new MqttServerOptions() .setPort(MQTT_SERVER_TLS_PORT) .setKeyCertOptions(Cert.SERVER_PEM_ROOT_CA.get()) .setTrustOptions(Trust.SERVER_PEM_ROOT_CA.get()) .setSsl(true) .setClientAuth(ClientAuth.REQUEST); this.setUp(context, options); }
/** * Return an MQTT server instance using default options * * @param vertx Vert.x instance * @return MQTT server instance */ static MqttServer create(Vertx vertx) { return new MqttServerImpl(vertx, new MqttServerOptions()); }
/** * Create an options from JSON * * @param json the JSON */ public MqttServerOptions(JsonObject json) { super(json); // override the default port this.setPort(json.getInteger("port", DEFAULT_PORT)); this.maxMessageSize = json.getInteger("maxMessageSize", DEFAULT_MAX_MESSAGE_SIZE); this.isAutoClientId = json.getBoolean("isAutoClientId", true); this.timeoutOnConnect = json.getInteger("timeoutOnConnect", DEFAULT_TIMEOUT_ON_CONNECT); if ((this.maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) { Arguments.require(this.getReceiveBufferSize() >= this.maxMessageSize, "Receiver buffer size can't be lower than max message size"); } }
@Before public void before(TestContext context) { MqttServerOptions options = new MqttServerOptions(); options.setMaxMessageSize(MQTT_MAX_MESSAGE_SIZE); this.setUp(context, options); }