├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── appspec.yml ├── buildspec.yml ├── ec2-scripts ├── create_run_script.sh ├── run.sh.template ├── start.sh ├── stop.sh └── testing_build_triggers.sh ├── ext ├── cheatsheet.adoc └── todo.txt ├── images ├── MQTT-SN-Aggregating-Gateway-Sys.png ├── MQTT-SN-Aggregating-Gateway-Sys.vsdx ├── client-cli.png ├── connector.png ├── dash.png ├── gateway-cli.png ├── mqttsn-arch.png ├── peak-message-count.png ├── security.png ├── waves-1400px.png └── waves-400px.png ├── mqtt-sn-client ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── slj │ │ │ └── mqtt │ │ │ └── sn │ │ │ └── client │ │ │ ├── MqttsnClientConnectException.java │ │ │ ├── impl │ │ │ ├── MqttsnClient.java │ │ │ ├── MqttsnClientMessageHandler.java │ │ │ ├── MqttsnClientRuntimeRegistry.java │ │ │ ├── MqttsnClientUdpOptions.java │ │ │ ├── cli │ │ │ │ ├── ClientInteractiveMain.java │ │ │ │ ├── MqttsnInteractiveClient.java │ │ │ │ └── MqttsnInteractiveClientLauncher.java │ │ │ └── examples │ │ │ │ └── Example.java │ │ │ └── spi │ │ │ ├── IMqttsnClient.java │ │ │ ├── IMqttsnClientRuntimeRegistry.java │ │ │ ├── MqttsnClientOptions.java │ │ │ └── SaslAuthHandler.java │ ├── micropython │ │ └── mqttsn-tinyclient │ │ │ ├── __init__.py │ │ │ ├── mqttsn-tinyclient-1_2.py │ │ │ └── mqttsn-tinyclient-2_0.py │ └── resources │ │ └── config.yml │ └── test │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── client │ └── test │ └── ClientConnectionTest.java ├── mqtt-sn-cloud-client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── slj │ │ │ └── mqtt │ │ │ └── sn │ │ │ └── cloud │ │ │ └── client │ │ │ ├── http │ │ │ ├── HttpClient.java │ │ │ └── HttpResponse.java │ │ │ └── impl │ │ │ └── HttpCloudServiceImpl.java │ └── resources │ │ ├── connectors.json │ │ └── services.json │ └── test │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── cloud │ └── test │ └── HttpCloudClientTest.java ├── mqtt-sn-codec ├── README.md ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── slj │ │ └── mqtt │ │ └── sn │ │ ├── ExampleUsage.java │ │ ├── MqttsnConstants.java │ │ ├── MqttsnMessageRules.java │ │ ├── MqttsnSpecificationValidator.java │ │ ├── PublishData.java │ │ ├── codec │ │ ├── AbstractMqttsnCodec.java │ │ ├── AbstractMqttsnMessageFactory.java │ │ ├── AbstractProtectionScheme.java │ │ ├── MqttsnCodecException.java │ │ ├── MqttsnCodecs.java │ │ └── MqttsnUnsupportedVersionException.java │ │ ├── descriptor │ │ ├── Descriptor.java │ │ ├── FieldDescriptor.java │ │ ├── FlagsDescriptor.java │ │ ├── PacketDescriptor.java │ │ └── ProtocolDescriptor.java │ │ ├── spi │ │ ├── IMqttsnCodec.java │ │ ├── IMqttsnConnectPacket.java │ │ ├── IMqttsnDisconnectPacket.java │ │ ├── IMqttsnIdentificationPacket.java │ │ ├── IMqttsnMessage.java │ │ ├── IMqttsnMessageFactory.java │ │ ├── IMqttsnMessageValidator.java │ │ ├── IMqttsnOriginatingMessageSource.java │ │ ├── IMqttsnProtocolVersionPacket.java │ │ ├── IMqttsnPublishPacket.java │ │ └── IProtectionScheme.java │ │ └── wire │ │ ├── AbstractMqttsnMessage.java │ │ ├── MqttsnWireUtils.java │ │ ├── version1_2 │ │ ├── Mqttsn_v1_2_Codec.java │ │ ├── Mqttsn_v1_2_MessageFactory.java │ │ ├── Mqttsn_v1_2_ProtocolDescriptor.java │ │ └── payload │ │ │ ├── AbstractMqttsnMessageWithFlagsField.java │ │ │ ├── AbstractMqttsnMessageWithTopicData.java │ │ │ ├── AbstractMqttsnPublishMessageConfirmation.java │ │ │ ├── AbstractMqttsnSimpleMessage.java │ │ │ ├── AbstractMqttsnSubscribeUnsubscribe.java │ │ │ ├── AbstractMqttsnWillMessage.java │ │ │ ├── AbstractMqttsnWillTopicMessage.java │ │ │ ├── AbstractMqttsnWillresp.java │ │ │ ├── MqttsnAdvertise.java │ │ │ ├── MqttsnConnack.java │ │ │ ├── MqttsnConnect.java │ │ │ ├── MqttsnDisconnect.java │ │ │ ├── MqttsnEncapsmsg.java │ │ │ ├── MqttsnGwInfo.java │ │ │ ├── MqttsnHelo.java │ │ │ ├── MqttsnPingreq.java │ │ │ ├── MqttsnPingresp.java │ │ │ ├── MqttsnPuback.java │ │ │ ├── MqttsnPubcomp.java │ │ │ ├── MqttsnPublish.java │ │ │ ├── MqttsnPubrec.java │ │ │ ├── MqttsnPubrel.java │ │ │ ├── MqttsnRegack.java │ │ │ ├── MqttsnRegister.java │ │ │ ├── MqttsnSearchGw.java │ │ │ ├── MqttsnSuback.java │ │ │ ├── MqttsnSubscribe.java │ │ │ ├── MqttsnUnsuback.java │ │ │ ├── MqttsnUnsubscribe.java │ │ │ ├── MqttsnWillmsg.java │ │ │ ├── MqttsnWillmsgreq.java │ │ │ ├── MqttsnWillmsgresp.java │ │ │ ├── MqttsnWillmsgupd.java │ │ │ ├── MqttsnWilltopic.java │ │ │ ├── MqttsnWilltopicreq.java │ │ │ ├── MqttsnWilltopicresp.java │ │ │ └── MqttsnWilltopicudp.java │ │ └── version2_0 │ │ ├── Mqttsn_v2_0_Codec.java │ │ ├── Mqttsn_v2_0_MessageFactory.java │ │ ├── Mqttsn_v2_0_ProtocolDescriptor.java │ │ └── payload │ │ ├── AbstractAeadProtectionScheme.java │ │ ├── AbstractAuthenticationOnlyProtectionScheme.java │ │ ├── MqttsnAuth.java │ │ ├── MqttsnConnack_V2_0.java │ │ ├── MqttsnConnect_V2_0.java │ │ ├── MqttsnDisconnect_V2_0.java │ │ ├── MqttsnPingreq_V2_0.java │ │ ├── MqttsnPingresp_V2_0.java │ │ ├── MqttsnProtection.java │ │ ├── MqttsnPuback_V2_0.java │ │ ├── MqttsnPublish_V2_0.java │ │ ├── MqttsnRegack_V2_0.java │ │ ├── MqttsnSuback_V2_0.java │ │ ├── MqttsnSubscribe_V2_0.java │ │ ├── MqttsnUnsuback_V2_0.java │ │ ├── MqttsnUnsubscribe_V2_0.java │ │ ├── ProtectionKey.java │ │ └── ProtectionPacketFlags.java │ └── test │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── wire │ ├── version1_2 │ └── payload │ │ └── Mqttsn1_2WireTests.java │ └── version2_0 │ └── payload │ └── Mqttsn2_0WireTests.java ├── mqtt-sn-core ├── ext │ └── create-keystore.sh ├── licenses │ ├── apache2.txt │ ├── epl2.txt │ ├── gnu-public-lesser-gpl.txt │ └── mit.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── slj │ │ │ └── mqtt │ │ │ ├── sn │ │ │ ├── cli │ │ │ │ └── AbstractInteractiveCli.java │ │ │ ├── cloud │ │ │ │ ├── DescriptorProperty.java │ │ │ │ ├── IMqttsnCloudService.java │ │ │ │ ├── MqttsnCloudAccount.java │ │ │ │ ├── MqttsnCloudConstants.java │ │ │ │ ├── MqttsnCloudEmail.java │ │ │ │ ├── MqttsnCloudServiceDescriptor.java │ │ │ │ ├── MqttsnCloudServiceException.java │ │ │ │ ├── MqttsnCloudToken.java │ │ │ │ ├── MqttsnConnectorDescriptor.java │ │ │ │ └── ProtocolBridgeDescriptor.java │ │ │ ├── impl │ │ │ │ ├── AbstractConnectionStateListener.java │ │ │ │ ├── AbstractDeadLetterQueue.java │ │ │ │ ├── AbstractMqttsnBackoffThreadService.java │ │ │ │ ├── AbstractMqttsnMessageHandler.java │ │ │ │ ├── AbstractMqttsnMessageRegistry.java │ │ │ │ ├── AbstractMqttsnMessageStateService.java │ │ │ │ ├── AbstractMqttsnRuntime.java │ │ │ │ ├── AbstractMqttsnRuntimeRegistry.java │ │ │ │ ├── AbstractMqttsnSessionBeanRegistry.java │ │ │ │ ├── AbstractMqttsnTransport.java │ │ │ │ ├── AbstractMqttsnUdpTransport.java │ │ │ │ ├── AbstractSubscriptionRegistry.java │ │ │ │ ├── AbstractTopicRegistry.java │ │ │ │ ├── AbstractTrafficListener.java │ │ │ │ ├── AbstractTransport.java │ │ │ │ ├── AbstractWillRegistry.java │ │ │ │ ├── MqttsnContextFactory.java │ │ │ │ ├── MqttsnDefaultClientIdFactory.java │ │ │ │ ├── MqttsnDefaultTopicModifier.java │ │ │ │ ├── MqttsnFilesystemStorageService.java │ │ │ │ ├── MqttsnMessageQueueProcessor.java │ │ │ │ ├── MqttsnSearchableSessionRegistry.java │ │ │ │ ├── MqttsnSecurityService.java │ │ │ │ ├── MqttsnSessionRegistry.java │ │ │ │ ├── MqttsnVMObjectReaderWriter.java │ │ │ │ ├── ServiceSort.java │ │ │ │ ├── metrics │ │ │ │ │ ├── IMqttsnMetrics.java │ │ │ │ │ ├── MqttsnContrainedSizeMetric.java │ │ │ │ │ ├── MqttsnCountingMetric.java │ │ │ │ │ ├── MqttsnMetric.java │ │ │ │ │ ├── MqttsnMetricsService.java │ │ │ │ │ ├── MqttsnSnapshotMetric.java │ │ │ │ │ └── MqttsnTemporalMetric.java │ │ │ │ └── ram │ │ │ │ │ ├── MqttsnFileBackedInMemoryMessageQueue.java │ │ │ │ │ ├── MqttsnInMemoryDeadLetterQueue.java │ │ │ │ │ ├── MqttsnInMemoryMessageQueue.java │ │ │ │ │ ├── MqttsnInMemoryMessageRegistry.java │ │ │ │ │ ├── MqttsnInMemoryMessageStateService.java │ │ │ │ │ ├── MqttsnInMemorySubscriptionRegistry.java │ │ │ │ │ ├── MqttsnInMemoryTopicRegistry.java │ │ │ │ │ └── MqttsnInMemoryWillRegistry.java │ │ │ ├── model │ │ │ │ ├── AbstractContextObject.java │ │ │ │ ├── AbstractOptions.java │ │ │ │ ├── ClientIdentifierContext.java │ │ │ │ ├── ClientState.java │ │ │ │ ├── IAuthHandler.java │ │ │ │ ├── IClientIdentifierContext.java │ │ │ │ ├── IContextObject.java │ │ │ │ ├── IDataRef.java │ │ │ │ ├── IMqttsnMessageContext.java │ │ │ │ ├── IMqttsnMetric.java │ │ │ │ ├── IMqttsnMetricAlarm.java │ │ │ │ ├── INetworkContext.java │ │ │ │ ├── IPacketTXRXJob.java │ │ │ │ ├── IPreferenceNamespace.java │ │ │ │ ├── InflightMessage.java │ │ │ │ ├── IntegerDataRef.java │ │ │ │ ├── MqttsnClientCredentials.java │ │ │ │ ├── MqttsnDeadLetterQueueBean.java │ │ │ │ ├── MqttsnMessageContext.java │ │ │ │ ├── MqttsnMetricSample.java │ │ │ │ ├── MqttsnOptions.java │ │ │ │ ├── MqttsnQueueAcceptException.java │ │ │ │ ├── MqttsnSecurityOptions.java │ │ │ │ ├── MqttsnWaitToken.java │ │ │ │ ├── PacketTXRXJob.java │ │ │ │ ├── RequeueableInflightMessage.java │ │ │ │ ├── TopicInfo.java │ │ │ │ ├── TrafficEntry.java │ │ │ │ └── session │ │ │ │ │ ├── IQueuedPublishMessage.java │ │ │ │ │ ├── ISession.java │ │ │ │ │ ├── ISubscription.java │ │ │ │ │ ├── ITopicRegistration.java │ │ │ │ │ ├── IWillData.java │ │ │ │ │ └── impl │ │ │ │ │ ├── QueuedPublishMessageImpl.java │ │ │ │ │ ├── SessionBeanImpl.java │ │ │ │ │ ├── SessionImpl.java │ │ │ │ │ ├── SubscriptionImpl.java │ │ │ │ │ ├── TopicRegistrationImpl.java │ │ │ │ │ └── WillDataImpl.java │ │ │ ├── net │ │ │ │ ├── ContextTransportLocator.java │ │ │ │ ├── MqttsnTcpOptions.java │ │ │ │ ├── MqttsnTcpTransport.java │ │ │ │ ├── MqttsnUdpBatchTransport.java │ │ │ │ ├── MqttsnUdpOptions.java │ │ │ │ ├── MqttsnUdpTransport.java │ │ │ │ ├── NetworkAddress.java │ │ │ │ ├── NetworkAddressRegistry.java │ │ │ │ └── NetworkContext.java │ │ │ ├── spi │ │ │ │ ├── AbstractMqttsnService.java │ │ │ │ ├── IMqttsnApplicationProfile.java │ │ │ │ ├── IMqttsnAuthenticationService.java │ │ │ │ ├── IMqttsnAuthorizationService.java │ │ │ │ ├── IMqttsnClientIdFactory.java │ │ │ │ ├── IMqttsnConnectionStateListener.java │ │ │ │ ├── IMqttsnContextFactory.java │ │ │ │ ├── IMqttsnDeadLetterQueue.java │ │ │ │ ├── IMqttsnMessageHandler.java │ │ │ │ ├── IMqttsnMessageQueue.java │ │ │ │ ├── IMqttsnMessageQueueProcessor.java │ │ │ │ ├── IMqttsnMessageRegistry.java │ │ │ │ ├── IMqttsnMessageStateService.java │ │ │ │ ├── IMqttsnMetricsService.java │ │ │ │ ├── IMqttsnObjectReaderWriter.java │ │ │ │ ├── IMqttsnPayloadModifier.java │ │ │ │ ├── IMqttsnPublishFailureListener.java │ │ │ │ ├── IMqttsnPublishReceivedListener.java │ │ │ │ ├── IMqttsnPublishSentListener.java │ │ │ │ ├── IMqttsnQueueProcessorStateService.java │ │ │ │ ├── IMqttsnRuntimeRegistry.java │ │ │ │ ├── IMqttsnSecurityService.java │ │ │ │ ├── IMqttsnService.java │ │ │ │ ├── IMqttsnSessionRegistry.java │ │ │ │ ├── IMqttsnStorageService.java │ │ │ │ ├── IMqttsnSubscriptionRegistry.java │ │ │ │ ├── IMqttsnTopicModifier.java │ │ │ │ ├── IMqttsnTopicRegistry.java │ │ │ │ ├── IMqttsnTrafficListener.java │ │ │ │ ├── IMqttsnTransport.java │ │ │ │ ├── IMqttsnWillRegistry.java │ │ │ │ ├── INetworkAddressRegistry.java │ │ │ │ ├── ITransport.java │ │ │ │ ├── ITransportLocator.java │ │ │ │ ├── MqttsnException.java │ │ │ │ ├── MqttsnExpectationFailedException.java │ │ │ │ ├── MqttsnIllegalFormatException.java │ │ │ │ ├── MqttsnNotFoundException.java │ │ │ │ ├── MqttsnRuntimeException.java │ │ │ │ ├── MqttsnSecurityException.java │ │ │ │ ├── MqttsnService.java │ │ │ │ ├── NetworkRegistryException.java │ │ │ │ └── RuntimeConfig.java │ │ │ ├── tools │ │ │ │ ├── LifecycleEmulator.java │ │ │ │ └── ProtocolInformationGenerator.java │ │ │ └── utils │ │ │ │ ├── Environment.java │ │ │ │ ├── Files.java │ │ │ │ ├── General.java │ │ │ │ ├── MqttsnUtils.java │ │ │ │ ├── Numbers.java │ │ │ │ ├── Pair.java │ │ │ │ ├── RollingList.java │ │ │ │ ├── Security.java │ │ │ │ ├── ServiceUtils.java │ │ │ │ ├── StringTable.java │ │ │ │ ├── StringTableWriters.java │ │ │ │ ├── ThreadDump.java │ │ │ │ ├── TopicPath.java │ │ │ │ └── TransientObjectLocks.java │ │ │ └── tree │ │ │ ├── Example.java │ │ │ ├── IMqttTree.java │ │ │ ├── ISearchableMqttTree.java │ │ │ ├── MqttTree.java │ │ │ ├── MqttTreeConstants.java │ │ │ ├── MqttTreeException.java │ │ │ ├── MqttTreeInputException.java │ │ │ ├── MqttTreeLimitExceededException.java │ │ │ ├── MqttTreeNode.java │ │ │ ├── MqttTreeNodeVisitor.java │ │ │ ├── MqttTreeUtils.java │ │ │ ├── SearchableMqttTree.java │ │ │ ├── radix │ │ │ ├── DuplicateKeyException.java │ │ │ ├── RadixTree.java │ │ │ ├── RadixTreeImpl.java │ │ │ ├── RadixTreeNode.java │ │ │ ├── Visitor.java │ │ │ └── VisitorImpl.java │ │ │ └── ui │ │ │ ├── MqttTreeViewer.java │ │ │ ├── MqttTreeViewerLauncher.java │ │ │ ├── MqttViewerUtils.java │ │ │ ├── TestForm.form │ │ │ └── TestForm.java │ └── resources │ │ ├── ascii.txt │ │ └── logback.xml │ └── test │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── test │ ├── MqttsnTestRuntime.java │ ├── MqttsnTestRuntimeRegistry.java │ └── cases │ ├── IntegrityTests.java │ └── SubscriptionTests.java ├── mqtt-sn-gateway-connector-aws-iotcore ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── gateway │ └── connector │ └── aws │ └── iotcore │ ├── AWSIoTCoreAggregatingGatewayInteractiveMain.java │ ├── AWSIoTCoreMqttsnConnection.java │ ├── AWSIoTCoreMqttsnConnector.java │ ├── AwsCertUtils.java │ └── PrivateKeyReader.java ├── mqtt-sn-gateway-connector-paho ├── README.md ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── gateway │ └── connector │ ├── custom │ └── CustomMqttBrokerConnector.java │ ├── paho │ ├── PahoGatewayInteractiveMain.java │ ├── PahoGatewayMain.java │ └── PahoMqttsnBrokerConnection.java │ └── thingstream │ └── ThingstreamConnector.java ├── mqtt-sn-gateway-console ├── dependency-reduced-pom.xml ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── slj │ │ └── mqtt │ │ └── sn │ │ └── console │ │ ├── IMqttsnConsole.java │ │ ├── MqttsnConsoleOptions.java │ │ ├── MqttsnGatewayMain.java │ │ ├── chart │ │ └── ChartJSUtils.java │ │ ├── http │ │ ├── Html.java │ │ ├── HttpBadRequestException.java │ │ ├── HttpConstants.java │ │ ├── HttpException.java │ │ ├── HttpInternalServerError.java │ │ ├── HttpNotFoundException.java │ │ ├── HttpUtils.java │ │ ├── IHttpRequestResponse.java │ │ ├── IHttpRequestResponseHandler.java │ │ ├── MimeTypeNotFoundException.java │ │ ├── UsernamePassword.java │ │ ├── impl │ │ │ ├── AbstractHttpRequestResponseHandler.java │ │ │ ├── HttpRequestResponse.java │ │ │ └── handlers │ │ │ │ ├── AsyncContentHandler.java │ │ │ │ ├── AsyncFieldHandler.java │ │ │ │ ├── HelloWorldHandler.java │ │ │ │ ├── RedirectHandler.java │ │ │ │ ├── RenderPageHandler.java │ │ │ │ └── StaticFileHandler.java │ │ └── sun │ │ │ ├── SunHttpHandlerProxy.java │ │ │ ├── SunHttpRequestResponse.java │ │ │ └── SunHttpServerBootstrap.java │ │ └── impl │ │ ├── BridgeHandler.java │ │ ├── ChartHandler.java │ │ ├── ClientAccessHandler.java │ │ ├── CloudHandler.java │ │ ├── CloudStatusHandler.java │ │ ├── CommandHandler.java │ │ ├── ConfigHandler.java │ │ ├── ConnectorHandler.java │ │ ├── ConnectorStatusHandler.java │ │ ├── ConsoleAsyncMetricFieldHandler.java │ │ ├── DLQHandler.java │ │ ├── LogHandler.java │ │ ├── MqttsnConsoleAjaxRealmHandler.java │ │ ├── MqttsnConsoleService.java │ │ ├── MqttsnStaticWebsiteHandler.java │ │ ├── SearchHandler.java │ │ ├── SessionHandler.java │ │ ├── TopicHandler.java │ │ └── TransportHandler.java │ └── resources │ ├── httpd │ ├── css │ │ ├── ribbon.css │ │ └── style.css │ ├── html │ │ ├── bridges.html │ │ ├── clients.html │ │ ├── cloud.html │ │ ├── cluster.html │ │ ├── config.html │ │ ├── connectors.html │ │ ├── dashboard.html │ │ ├── dead-letter.html │ │ ├── index.html │ │ ├── licenses.html │ │ ├── logs.html │ │ ├── session.html │ │ ├── settings.html │ │ ├── system.html │ │ ├── topics.html │ │ ├── transport.html │ │ └── typeahead.html │ ├── img │ │ ├── cloud-logo-no-background.png │ │ ├── favicon │ │ │ ├── android-chrome-192x192.png │ │ │ ├── android-chrome-512x512.png │ │ │ ├── apple-touch-icon.png │ │ │ ├── browserconfig.xml │ │ │ ├── favicon-16x16.png │ │ │ ├── favicon-32x32.png │ │ │ ├── favicon.ico │ │ │ ├── mstile-150x150.png │ │ │ ├── safari-pinned-tab.svg │ │ │ └── site.webmanifest │ │ ├── logo-no-background-round.png │ │ └── logo-no-background.png │ └── js │ │ ├── autocomplete.js │ │ └── script.js │ └── licenses │ ├── apache2.txt │ ├── epl2.txt │ ├── gnu-public-lesser-gpl.txt │ └── mit.txt ├── mqtt-sn-gateway ├── README.md ├── ext │ ├── example-start-commands.txt │ └── run.sh ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── gateway │ ├── cli │ ├── MqttsnInteractiveGateway.java │ ├── MqttsnInteractiveGatewayLauncher.java │ └── MqttsnInteractiveGatewayWithKeystore.java │ ├── impl │ ├── MqttsnGateway.java │ ├── MqttsnGatewayRuntimeRegistry.java │ ├── MqttsnJacksonReaderWriter.java │ ├── backend │ │ ├── AbstractMqttsnBackendConnection.java │ │ └── AbstractMqttsnBackendService.java │ ├── bridge │ │ ├── AbstractProtocolBridge.java │ │ ├── AbstractProtocolBridgeConnection.java │ │ ├── LoadGeneratingBridge.java │ │ └── ProtocolBridgeService.java │ ├── connector │ │ ├── AbstractMqttsnConnector.java │ │ ├── LoopbackGatewayInteractiveMain.java │ │ ├── LoopbackMqttsnConnection.java │ │ └── LoopbackMqttsnConnector.java │ └── gateway │ │ ├── MqttsnGatewayAdvertiseService.java │ │ ├── MqttsnGatewayAuthenticationService.java │ │ ├── MqttsnGatewayExpansionHandler.java │ │ ├── MqttsnGatewayMessageHandler.java │ │ ├── MqttsnGatewayQueueProcessorStateService.java │ │ ├── MqttsnGatewaySessionService.java │ │ └── type │ │ ├── MqttsnAggregatingGateway.java │ │ └── MqttsnTransparentGateway.java │ └── spi │ ├── ConnectResult.java │ ├── DisconnectResult.java │ ├── GatewayConfig.java │ ├── GatewayMetrics.java │ ├── MqttsnInvalidSessionStateException.java │ ├── PublishResult.java │ ├── ReceiveResult.java │ ├── RegisterResult.java │ ├── Result.java │ ├── SubscribeResult.java │ ├── UnsubscribeResult.java │ ├── bridge │ ├── IProtocolBridge.java │ ├── IProtocolBridgeConnection.java │ ├── IProtocolBridgeService.java │ ├── ProtocolBridgeClientContext.java │ ├── ProtocolBridgeException.java │ └── ProtocolBridgeOptions.java │ ├── connector │ ├── IMqttsnBackendService.java │ ├── IMqttsnConnector.java │ ├── IMqttsnConnectorConnection.java │ ├── MqttsnConnectorException.java │ └── MqttsnConnectorOptions.java │ └── gateway │ ├── IMqttsnGatewayAdvertiseService.java │ ├── IMqttsnGatewayClusterService.java │ ├── IMqttsnGatewayExpansionHandler.java │ ├── IMqttsnGatewayRuntimeRegistry.java │ ├── IMqttsnGatewaySessionService.java │ ├── MqttsnGatewayOptions.java │ └── MqttsnGatewayPerformanceProfile.java ├── mqtt-sn-load-test ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── load │ ├── AbstractExecutionInput.java │ ├── AbstractExecutionProfile.java │ ├── ExecutionInput.java │ ├── ExecutionProfile.java │ ├── ExecutionProgress.java │ ├── LoadTestException.java │ ├── impl │ ├── ConnectPublishProfile.java │ ├── ConnectSubscribeUnsubscribeLoopProfile.java │ ├── ConnectSubscribeWaitProfile.java │ └── MqttsnClientProfile.java │ ├── runner │ ├── AbstractLoadTest.java │ ├── AbstractLoadTestRunner.java │ ├── ThreadPerProfileLoadTestRunner.java │ └── ThreadPoolLoadTestRunner.java │ └── tests │ ├── OpenConnectionNoStateTestMain.java │ ├── OpenConnectionTestMain.java │ ├── PublishOnlyTestMain.java │ ├── SubscribeAndWaitTestMain.java │ ├── SubscribeUnsubscribeTestMain.java │ └── TestHelper.java ├── mqtt-sn-protection-runtimes ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── slj │ │ │ └── mqtt │ │ │ └── sn │ │ │ └── protection │ │ │ └── runtime │ │ │ ├── ProtectionExampleClientCli.java │ │ │ └── ProtectionExampleGatewayCli.java │ └── resources │ │ ├── client1-aes128.key │ │ ├── client1-aes192.key │ │ ├── client1-aes256.key │ │ ├── client1-hmac.key │ │ └── gateway1-hmac.key │ └── test │ └── java │ ├── ProtectionSchemaIT.java │ └── TestKeyWrite.java ├── mqtt-sn-protection ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── slj │ └── mqtt │ └── sn │ └── protection │ ├── alg │ ├── AbstractProtectionSchemeCcm.java │ ├── AbstractProtectionSchemeCmac.java │ ├── AbstractProtectionSchemeGcm.java │ ├── MqttsnProtectionAlgorithmInitializer.java │ ├── ProtectionSchemeCcm_128_128.java │ ├── ProtectionSchemeCcm_128_192.java │ ├── ProtectionSchemeCcm_128_256.java │ ├── ProtectionSchemeCcm_64_128.java │ ├── ProtectionSchemeCcm_64_192.java │ ├── ProtectionSchemeCcm_64_256.java │ ├── ProtectionSchemeChaCha20_Poly1305.java │ ├── ProtectionSchemeCmac128.java │ ├── ProtectionSchemeCmac192.java │ ├── ProtectionSchemeCmac256.java │ ├── ProtectionSchemeGcm_128_128.java │ ├── ProtectionSchemeGcm_128_192.java │ ├── ProtectionSchemeGcm_128_256.java │ ├── ProtectionSchemeHmacSha256.java │ └── ProtectionSchemeHmacSha3_256.java │ ├── impl │ ├── InMemoryProtectedSenderRegistry.java │ ├── MqttsnProtectionService.java │ └── ProtectionUtils.java │ └── spi │ ├── IProtectedSenderRegistry.java │ ├── MqttsnProtectionOptions.java │ └── ProtectedSender.java ├── pom.xml └── site ├── images ├── logo-no-background.png └── logo-white.png └── pages └── packet-listing12.html /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /.idea/.gitignore 3 | /.idea/compiler.xml 4 | /.idea/jarRepositories.xml 5 | /.idea/misc.xml 6 | /.idea/modules.xml 7 | /.idea/uiDesigner.xml 8 | /.idea/vcs.xml 9 | codebuild_build.sh 10 | artifacts/ 11 | target/ 12 | /mqtt-sn-gateway/mqtt-sn-gateway.iml 13 | /mqtt-sn-core-sec/mqtt-sn-core-sec.iml 14 | /mqtt-sn-core/mqtt-sn-core.iml 15 | /mqtt-sn-codec/mqtt-sn-codec.iml 16 | /mqtt-sn-client/mqtt-sn-client.iml 17 | /mqtt-publisher/ 18 | /mqtt-sn-core/ext/my-keystore.jks 19 | /mqtt-sn-core/ext/my-truststore.jks 20 | mqtt-sn-core-sec/ 21 | mqtt-sn-client-sec/ 22 | /client.properties 23 | /config.properties 24 | /gateway.properties 25 | /gateway-keystore.properties 26 | /gateway-keystore-aws.properties 27 | /mqtt-sn-gateway-cluster/ 28 | /mqtt-sn-gateway-dtls/ 29 | /mqtt-sn-client/src/main/rust/ 30 | /mqtt-sn-gateway-dtls/ 31 | /mqtt-sn-runtimes/mqtt-sn-client/.lck 32 | /mqtt-sn-runtimes/mqtt-sn-gateway/.lck 33 | /mqtt-sn-runtimes/mqtt-sn-client/mqtt-sn-client-credentials 34 | /mqtt-sn-runtimes/mqtt-sn-gateway/mqtt-sn-client-credentials 35 | /mqtt-sn-runtimes/mqtt-sn-load-test/mqtt-sn-client-credentials 36 | /mqtt-sn-runtimes/mqtt-sn-client/mqtt-sn-settings.xml 37 | /mqtt-sn-runtimes/mqtt-sn-gateway/mqtt-sn-settings.xml 38 | /mqtt-sn-runtimes/mqtt-sn-load-test/mqtt-sn-settings.xml 39 | /mqtt-sn-runtimes/mqtt-sn-gateway/mqtt-sn-settings-old.xml 40 | /mqtt-sn-gateway-connector-google-iotcore/dependency-reduced-pom.xml 41 | /mqtt-sn-gateway-connector-paho/dependency-reduced-pom.xml 42 | /mqtt-sn-gateway-connector-aws-iotcore/dependency-reduced-pom.xml 43 | /mqtt-sn-gateway/dependency-reduced-pom.xml 44 | /mqtt-sn-client/dependency-reduced-pom.xml 45 | /mqtt-sn-runtimes/mqtt-sn-gateway/_message-queues-overflow/34643532633864362D323037652D346663342D386531342D333333653366646564646638 46 | /mqtt-sn-runtimes/ 47 | /site 48 | -------------------------------------------------------------------------------- /appspec.yml: -------------------------------------------------------------------------------- 1 | version: 0.0 2 | os: linux 3 | files: 4 | - source: / 5 | destination: /home/ubuntu/mqtt-sn-gateway-udp 6 | hooks: 7 | ApplicationStop: 8 | - location: stop.sh 9 | timeout: 30 10 | runas: root 11 | AfterInstall: 12 | - location: create_run_script.sh 13 | timeout: 30 14 | runas: ubuntu 15 | ApplicationStart: 16 | - location: start.sh 17 | timeout: 30 18 | runas: root 19 | -------------------------------------------------------------------------------- /buildspec.yml: -------------------------------------------------------------------------------- 1 | version: 0.2 2 | 3 | phases: 4 | install: 5 | runtime-versions: 6 | java: openjdk8 7 | build: 8 | commands: 9 | - echo Build started on `date` 10 | - mvn -f mqtt-sn-codec clean install 11 | - mvn -f mqtt-sn-core clean install 12 | - mvn -f mqtt-sn-gateway clean install 13 | 14 | artifacts: 15 | files: 16 | - mqtt-sn-gateway-artefact/target/mqtt-sn-gateway-1.0.0.jar 17 | - ec2-scripts/* 18 | - appspec.yml 19 | discard-paths: yes 20 | -------------------------------------------------------------------------------- /ec2-scripts/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2021 Simon Johnson 4 | # 5 | # Find me on GitHub: 6 | # https://github.com/simon622 7 | # 8 | # Licensed to the Apache Software Foundation (ASF) under one 9 | # or more contributor license agreements. See the NOTICE file 10 | # distributed with this work for additional information 11 | # regarding copyright ownership. The ASF licenses this file 12 | # to you under the Apache License, Version 2.0 (the 13 | # "License"); you may not use this file except in compliance 14 | # with the License. You may obtain a copy of the License at 15 | # 16 | # http://www.apache.org/licenses/LICENSE-2.0 17 | # 18 | # Unless required by applicable law or agreed to in writing, 19 | # software distributed under the License is distributed on an 20 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 | # KIND, either express or implied. See the License for the 22 | # specific language governing permissions and limitations 23 | # under the License. 24 | # 25 | 26 | systemctl start mqtt-sn-gateway-udp.service 27 | -------------------------------------------------------------------------------- /ec2-scripts/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2021 Simon Johnson 4 | # 5 | # Find me on GitHub: 6 | # https://github.com/simon622 7 | # 8 | # Licensed to the Apache Software Foundation (ASF) under one 9 | # or more contributor license agreements. See the NOTICE file 10 | # distributed with this work for additional information 11 | # regarding copyright ownership. The ASF licenses this file 12 | # to you under the Apache License, Version 2.0 (the 13 | # "License"); you may not use this file except in compliance 14 | # with the License. You may obtain a copy of the License at 15 | # 16 | # http://www.apache.org/licenses/LICENSE-2.0 17 | # 18 | # Unless required by applicable law or agreed to in writing, 19 | # software distributed under the License is distributed on an 20 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21 | # KIND, either express or implied. See the License for the 22 | # specific language governing permissions and limitations 23 | # under the License. 24 | # 25 | 26 | systemctl stop mqtt-sn-gateway-udp.service 27 | -------------------------------------------------------------------------------- /ec2-scripts/testing_build_triggers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Copyright (c) 2021 Simon Johnson 5 | # 6 | # Find me on GitHub: 7 | # https://github.com/simon622 8 | # 9 | # Licensed to the Apache Software Foundation (ASF) under one 10 | # or more contributor license agreements. See the NOTICE file 11 | # distributed with this work for additional information 12 | # regarding copyright ownership. The ASF licenses this file 13 | # to you under the Apache License, Version 2.0 (the 14 | # "License"); you may not use this file except in compliance 15 | # with the License. You may obtain a copy of the License at 16 | # 17 | # http://www.apache.org/licenses/LICENSE-2.0 18 | # 19 | # Unless required by applicable law or agreed to in writing, 20 | # software distributed under the License is distributed on an 21 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 22 | # KIND, either express or implied. See the License for the 23 | # specific language governing permissions and limitations 24 | # under the License. 25 | # 26 | 27 | # Testing the CodeBuild commit message filter. 28 | # First *without* the message regex... [BUILD] 29 | # Trying again with the commit message regex 30 | # WebHook test for CodePipeline after manual creation of JSON webhook. 31 | # CodePipeline approval test via SNS 32 | -------------------------------------------------------------------------------- /ext/cheatsheet.adoc: -------------------------------------------------------------------------------- 1 | = MQTT-SN Cheatsheet 2 | Simon Johnson 3 | 3.0, July 29, 2022: AsciiDoc article template 4 | :toc: 5 | :icons: font 6 | :url-quickref: https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/ 7 | 8 | Content entered directly below the header but before the first section heading is called the preamble. 9 | 10 | == First level heading 11 | 12 | This is a paragraph with a *bold* word and an _italicized_ word. 13 | 14 | MQTT-SN Foo 15 | ==== 16 | Content in an example block is subject to normal substitutions. 17 | ==== 18 | 19 | 20 | -------------------------------------------------------------------------------- /ext/todo.txt: -------------------------------------------------------------------------------- 1 | Forwarder packet implementation 2 | Auth SASL simple username password 3 | 4 | 5 | Cloud 6 | Alarms 7 | Multi service 8 | Transport (Settings) 9 | Remove notif 10 | Logs 11 | Message viewer 12 | 13 | 14 | java -jar -DconsolePort=8080 mqtt-sn-gateway-console-0.2.0.jar 2442 simonId >> gateway.log 2>&1 & -------------------------------------------------------------------------------- /images/MQTT-SN-Aggregating-Gateway-Sys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/MQTT-SN-Aggregating-Gateway-Sys.png -------------------------------------------------------------------------------- /images/MQTT-SN-Aggregating-Gateway-Sys.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/MQTT-SN-Aggregating-Gateway-Sys.vsdx -------------------------------------------------------------------------------- /images/client-cli.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/client-cli.png -------------------------------------------------------------------------------- /images/connector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/connector.png -------------------------------------------------------------------------------- /images/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/dash.png -------------------------------------------------------------------------------- /images/gateway-cli.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/gateway-cli.png -------------------------------------------------------------------------------- /images/mqttsn-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/mqttsn-arch.png -------------------------------------------------------------------------------- /images/peak-message-count.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/peak-message-count.png -------------------------------------------------------------------------------- /images/security.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/security.png -------------------------------------------------------------------------------- /images/waves-1400px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/waves-1400px.png -------------------------------------------------------------------------------- /images/waves-400px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/images/waves-400px.png -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/java/org/slj/mqtt/sn/client/MqttsnClientConnectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.client; 26 | 27 | public class MqttsnClientConnectException extends Exception { 28 | public MqttsnClientConnectException() { 29 | } 30 | 31 | public MqttsnClientConnectException(String message) { 32 | super(message); 33 | } 34 | 35 | public MqttsnClientConnectException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | 39 | public MqttsnClientConnectException(Throwable cause) { 40 | super(cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/java/org/slj/mqtt/sn/client/impl/MqttsnClientUdpOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.client.impl; 26 | 27 | import org.slj.mqtt.sn.net.MqttsnUdpOptions; 28 | 29 | public class MqttsnClientUdpOptions extends MqttsnUdpOptions { 30 | { 31 | //-- set all the client ports to wildcard 0 for localhost availability assignment 32 | withPort(DEFAULT_LOCAL_CLIENT_PORT); 33 | withSecurePort(DEFAULT_LOCAL_CLIENT_PORT); 34 | withBroadcastPort(DEFAULT_LOCAL_CLIENT_PORT); 35 | withBindBroadcastListener(true); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/java/org/slj/mqtt/sn/client/spi/IMqttsnClientRuntimeRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.client.spi; 26 | 27 | import org.slj.mqtt.sn.spi.IMqttsnRuntimeRegistry; 28 | 29 | public interface IMqttsnClientRuntimeRegistry extends IMqttsnRuntimeRegistry { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/java/org/slj/mqtt/sn/client/spi/MqttsnClientOptions.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.client.spi; 2 | 3 | import org.slj.mqtt.sn.model.MqttsnOptions; 4 | 5 | /** 6 | * @author Simon L Johnson 7 | */ 8 | public class MqttsnClientOptions extends MqttsnOptions { 9 | 10 | public static boolean DEFAULT_DISCONNECT_STOPS_TRANSPORT = true; 11 | public static boolean DEFAULT_SLEEP_STOPS_TRANSPORT = false; 12 | 13 | public boolean disconnectStopsTransport = DEFAULT_DISCONNECT_STOPS_TRANSPORT; 14 | public boolean sleepStopsTransport = DEFAULT_SLEEP_STOPS_TRANSPORT; 15 | 16 | 17 | public boolean getDisconnectStopsTransport() { 18 | return disconnectStopsTransport; 19 | } 20 | 21 | public MqttsnClientOptions withDisconnectStopsTransport(boolean defaultDisconnectStopsTransport) { 22 | disconnectStopsTransport = defaultDisconnectStopsTransport; 23 | return this; 24 | } 25 | 26 | public boolean getSleepStopsTransport() { 27 | return sleepStopsTransport; 28 | } 29 | 30 | public MqttsnClientOptions withSleepStopsTransport(boolean sleepStopsTransport) { 31 | this.sleepStopsTransport = sleepStopsTransport; 32 | return this; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/java/org/slj/mqtt/sn/client/spi/SaslAuthHandler.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.client.spi; 2 | 3 | import java.util.Map; 4 | import javax.security.auth.callback.CallbackHandler; 5 | import javax.security.sasl.Sasl; 6 | import javax.security.sasl.SaslClient; 7 | import javax.security.sasl.SaslException; 8 | import org.slj.mqtt.sn.model.IAuthHandler; 9 | 10 | public class SaslAuthHandler implements IAuthHandler { 11 | 12 | private final SaslClient saslClient; 13 | private final String mechanism; 14 | 15 | public SaslAuthHandler(String mechanism, String authorisationId, String serverName, Map props, CallbackHandler callbackHandler) throws SaslException { 16 | this.mechanism = mechanism; 17 | String[] mechanisms = {mechanism}; 18 | saslClient = Sasl.createSaslClient( 19 | mechanisms, 20 | authorisationId, 21 | "MQTT-SN", 22 | serverName, 23 | props, 24 | callbackHandler); 25 | } 26 | 27 | @Override 28 | public String getMechanism() { 29 | return mechanism; 30 | } 31 | 32 | @Override 33 | public boolean isComplete() { 34 | return saslClient.isComplete(); 35 | } 36 | 37 | @Override 38 | public byte[] handleChallenge(byte[] challenge) throws SaslException { 39 | if(!saslClient.isComplete()){ 40 | return saslClient.evaluateChallenge(challenge); 41 | } 42 | throw new SaslException("Challenge is complete"); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/micropython/mqttsn-tinyclient/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-client/src/main/micropython/mqttsn-tinyclient/__init__.py -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/micropython/mqttsn-tinyclient/mqttsn-tinyclient-1_2.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | # Set up the MQTT-SN message 4 | msg_type = 0x0C # MQTT-SN PUBLISH message type 5 | msg_id = 0 # The message ID (16-bit unsigned integer) 6 | payload = b"hello world" # The payload to send 7 | length = 7 + len(payload) 8 | qos = 3 9 | 10 | # a pre-defined topic id (set to “0b01”) 11 | topic_id_type = 0b01 12 | topic_id = 1 # The topic ID to publish to (16-bit unsigned integer) 13 | 14 | # short topic name (set to “0b10”) 15 | # topic_id_type = 0b10 16 | short_topic_name = b"ab" 17 | 18 | # Set up the MQTT-SN message header and payload 19 | # length, msgType, flags, TopicId, MsgId, Data 20 | flags = (False << 7) | (qos << 5) | (False << 4) | (False << 3) | (False << 2) | topic_id_type 21 | header = bytearray([length, msg_type, flags]) 22 | if topic_id_type == 0b01: 23 | data = bytearray(topic_id.to_bytes(2, 'big')) 24 | else: 25 | data = short_topic_name 26 | 27 | data += bytearray(msg_id.to_bytes(2, 'big')) 28 | data += payload 29 | 30 | # Set up the UDP socket and send the message 31 | i = 1 32 | while i < 10: 33 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 34 | sock.sendto(header + data, ("localhost", 2442)) 35 | i = i + 1 36 | -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/micropython/mqttsn-tinyclient/mqttsn-tinyclient-2_0.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | # Set up the MQTT-SN message 4 | msg_type = 0x0C # MQTT-SN PUBLISH message type 5 | payload = b"hello world" # The payload to send 6 | length = 5 + len(payload) 7 | qos = 3 8 | 9 | # a pre-defined topic id (set to “0b01”) 10 | topic_id_type = 0b01 11 | topic_id = 25 # The topic ID to publish to (16-bit unsigned integer) 12 | 13 | # short topic name (set to “0b10”) 14 | # topic_id_type = 0b10 15 | short_topic_name = b"ab" 16 | 17 | # Set up the MQTT-SN message header and payload 18 | # length, msgType, flags, TopicId, MsgId, Data 19 | flags = (False << 7) | (qos << 5) | (False << 4) | (False << 3) | (False << 2) | topic_id_type 20 | header = bytearray([length, msg_type, flags]) 21 | if topic_id_type == 0b01: 22 | data = bytearray(topic_id.to_bytes(2, 'big')) 23 | else: 24 | data = short_topic_name 25 | 26 | data += payload 27 | 28 | # Set up the UDP socket and send the message 29 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 30 | sock.sendto(header + data, ("gateway.mqtt-sn.cloud", 2443)) 31 | -------------------------------------------------------------------------------- /mqtt-sn-client/src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | contextId: someClientId 2 | maxMessagesInQueue: 100 3 | maxWait: 10000 4 | maxProtocolMessageSize: 1024 -------------------------------------------------------------------------------- /mqtt-sn-codec/README.md: -------------------------------------------------------------------------------- 1 | # mqtt-sn-codec 2 | Full, dependency free java implementation of the MQTT-SN protocol specification. Abstraction of the underlying model to support pluggable wire protocols. 3 | 4 | ```java 5 | public class ExampleUsage { 6 | public static void main(String[] args) throws Exception { 7 | 8 | //-- select the version of the protocol you wish to use. The versions 9 | //-- registered on the interface are thread-safe, pre-constructed singletons. 10 | //-- you can also manually construct your codecs and manage their lifecycle if you so desire. 11 | IMqttsnCodec mqttsnVersion1_2 = MqttsnCodecs.MQTTSN_CODEC_VERSION_1_2; 12 | 13 | //-- each codec supplies a message factory allowing convenient construction of messages for use 14 | //-- in your application. 15 | IMqttsnMessageFactory factory = mqttsnVersion1_2.createMessageFactory(); 16 | 17 | //-- construct a connect message with your required configuration 18 | IMqttsnMessage connect = 19 | factory.createConnect("testClientId", 60, false, true); 20 | 21 | //-- encode the connect message for wire transport... 22 | byte[] arr = mqttsnVersion1_2.encode(connect); 23 | 24 | //-- then on the other side of the wire.. 25 | connect = mqttsnVersion1_2.decode(arr); 26 | } 27 | } 28 | ``` -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/codec/MqttsnCodecException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.codec; 26 | 27 | public class MqttsnCodecException extends RuntimeException { 28 | 29 | public MqttsnCodecException() { 30 | } 31 | 32 | public MqttsnCodecException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttsnCodecException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnCodecException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/codec/MqttsnUnsupportedVersionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.codec; 26 | 27 | public class MqttsnUnsupportedVersionException extends MqttsnCodecException { 28 | 29 | public MqttsnUnsupportedVersionException() { 30 | } 31 | 32 | public MqttsnUnsupportedVersionException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttsnUnsupportedVersionException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnUnsupportedVersionException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/descriptor/Descriptor.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.descriptor; 2 | 3 | /** 4 | * @author Simon L Johnson 5 | */ 6 | public abstract class Descriptor { 7 | 8 | private String name; 9 | private String description; 10 | 11 | public Descriptor(final String name, final String description) { 12 | this.name = name; 13 | this.description = description; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public String getDescription() { 21 | return description; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/descriptor/FlagsDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.descriptor; 2 | 3 | /** 4 | * @author Simon L Johnson 5 | */ 6 | public class FlagsDescriptor extends Descriptor { 7 | 8 | private final int startIdx; 9 | private final int endIdx; 10 | 11 | public FlagsDescriptor(final String name, final String description, final int startIdx, final int endIdx) { 12 | super(name, description); 13 | this.startIdx = startIdx; 14 | this.endIdx = endIdx; 15 | } 16 | 17 | public FlagsDescriptor(final String name, final String description, final int startIdx) { 18 | super(name, description); 19 | this.startIdx = startIdx; 20 | this.endIdx = startIdx; 21 | } 22 | 23 | public int getStartIdx() { 24 | return startIdx; 25 | } 26 | 27 | public int getEndIdx() { 28 | return endIdx; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/descriptor/ProtocolDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.descriptor; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | /** 8 | * @author Simon L Johnson 9 | */ 10 | public class ProtocolDescriptor extends Descriptor { 11 | 12 | private List packets = new ArrayList<>(); 13 | 14 | public ProtocolDescriptor(final String name, final String description) { 15 | super(name, description); 16 | } 17 | 18 | public void addPacketDescriptor(final PacketDescriptor packetDescriptor){ 19 | this.packets.add(packetDescriptor); 20 | } 21 | 22 | public List getPackets() { 23 | return Collections.unmodifiableList(packets); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IMqttsnConnectPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public interface IMqttsnConnectPacket { 28 | } 29 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IMqttsnDisconnectPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public interface IMqttsnDisconnectPacket { 28 | } 29 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IMqttsnIdentificationPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public interface IMqttsnIdentificationPacket { 28 | 29 | String getClientId(); 30 | } 31 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IMqttsnMessageValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.codec.MqttsnCodecException; 28 | 29 | public interface IMqttsnMessageValidator { 30 | 31 | void validate() throws MqttsnCodecException; 32 | } 33 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IMqttsnOriginatingMessageSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | /** 28 | * Some messages maybe sent in either direction from a given context, and so we should be able to establish the direction of 29 | * transit; 30 | * 31 | * Consider MO (Mobile originated) or MT (mobile terminated) network traffic. 32 | */ 33 | public enum IMqttsnOriginatingMessageSource { 34 | 35 | LOCAL, 36 | REMOTE 37 | 38 | } 39 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IMqttsnProtocolVersionPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public interface IMqttsnProtocolVersionPacket { 28 | 29 | int getProtocolVersion(); 30 | } 31 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IMqttsnPublishPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public interface IMqttsnPublishPacket { 28 | 29 | int getQoS(); 30 | } 31 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/spi/IProtectionScheme.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.spi; 2 | 3 | public interface IProtectionScheme { 4 | 5 | String getName(); 6 | 7 | byte getIndex(); 8 | 9 | short getNominalTagLengthInBytes(); 10 | 11 | short getBlockSizeInBytes(); 12 | 13 | boolean isAuthenticationOnly(); 14 | 15 | byte[] getCryptoMaterial(byte cryptoMaterialLength); 16 | } 17 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version1_2/payload/AbstractMqttsnSimpleMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.wire.version1_2.payload; 26 | 27 | import org.slj.mqtt.sn.codec.MqttsnCodecException; 28 | import org.slj.mqtt.sn.wire.AbstractMqttsnMessage; 29 | 30 | public abstract class AbstractMqttsnSimpleMessage extends AbstractMqttsnMessage { 31 | 32 | @Override 33 | public void decode(byte[] data) throws MqttsnCodecException { 34 | } 35 | 36 | @Override 37 | public byte[] encode() throws MqttsnCodecException { 38 | 39 | byte[] data = new byte[2]; 40 | data[0] = (byte) data.length; 41 | data[1] = (byte) getMessageType(); 42 | return data; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version1_2/payload/MqttsnPubcomp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.wire.version1_2.payload; 26 | 27 | import org.slj.mqtt.sn.MqttsnConstants; 28 | 29 | public class MqttsnPubcomp extends AbstractMqttsnPublishMessageConfirmation { 30 | 31 | @Override 32 | public int getMessageType() { 33 | return MqttsnConstants.PUBCOMP; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | final StringBuilder sb = new StringBuilder("MqttsnPubcomp{"); 39 | sb.append("msgId=").append(id); 40 | sb.append('}'); 41 | return sb.toString(); 42 | } 43 | } -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version1_2/payload/MqttsnPubrec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.wire.version1_2.payload; 26 | 27 | import org.slj.mqtt.sn.MqttsnConstants; 28 | 29 | public class MqttsnPubrec extends AbstractMqttsnPublishMessageConfirmation { 30 | 31 | @Override 32 | public int getMessageType() { 33 | return MqttsnConstants.PUBREC; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | final StringBuilder sb = new StringBuilder("MqttsnPubrec{"); 39 | sb.append("id=").append(id); 40 | sb.append('}'); 41 | return sb.toString(); 42 | } 43 | } -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version1_2/payload/MqttsnPubrel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.wire.version1_2.payload; 26 | 27 | import org.slj.mqtt.sn.MqttsnConstants; 28 | 29 | public class MqttsnPubrel extends AbstractMqttsnPublishMessageConfirmation { 30 | 31 | @Override 32 | public int getMessageType() { 33 | return MqttsnConstants.PUBREL; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | final StringBuilder sb = new StringBuilder("MqttsnPubrel{"); 39 | sb.append("id=").append(id); 40 | sb.append('}'); 41 | return sb.toString(); 42 | } 43 | } -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version1_2/payload/MqttsnUnsubscribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.wire.version1_2.payload; 26 | 27 | import org.slj.mqtt.sn.MqttsnConstants; 28 | 29 | import java.util.Arrays; 30 | 31 | public class MqttsnUnsubscribe extends AbstractMqttsnSubscribeUnsubscribe { 32 | @Override 33 | public int getMessageType() { 34 | return MqttsnConstants.UNSUBSCRIBE; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "MqttsnUnsubscribe{" + 40 | "msgId=" + id + 41 | ", topicData=" + Arrays.toString(topicData) + 42 | ", topicType=" + topicType + 43 | '}'; 44 | } 45 | } -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version1_2/payload/MqttsnWillmsgreq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.wire.version1_2.payload; 26 | 27 | import org.slj.mqtt.sn.MqttsnConstants; 28 | 29 | public class MqttsnWillmsgreq extends AbstractMqttsnSimpleMessage { 30 | 31 | @Override 32 | public int getMessageType() { 33 | return MqttsnConstants.WILLMSGREQ; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | final StringBuilder sb = new StringBuilder("MqttsnWillmsgreq{"); 39 | sb.append('}'); 40 | return sb.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version1_2/payload/MqttsnWilltopicreq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.wire.version1_2.payload; 26 | 27 | import org.slj.mqtt.sn.MqttsnConstants; 28 | 29 | public class MqttsnWilltopicreq extends AbstractMqttsnSimpleMessage { 30 | 31 | @Override 32 | public int getMessageType() { 33 | return MqttsnConstants.WILLTOPICREQ; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | final StringBuilder sb = new StringBuilder("MqttsnWilltopicreq{"); 39 | sb.append('}'); 40 | return sb.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version2_0/Mqttsn_v2_0_ProtocolDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.wire.version2_0; 2 | 3 | import org.slj.mqtt.sn.descriptor.ProtocolDescriptor; 4 | 5 | /** 6 | * @author Simon L Johnson 7 | */ 8 | public class Mqttsn_v2_0_ProtocolDescriptor extends ProtocolDescriptor { 9 | 10 | public static final ProtocolDescriptor INSTANCE = new Mqttsn_v2_0_ProtocolDescriptor(); 11 | 12 | private Mqttsn_v2_0_ProtocolDescriptor() { 13 | super("Mqtt-Sn Version 2.0", "An evolution of the 1.2 SN protocol for battery constrained, network enabled devices"); 14 | initPacketDescriptors(); 15 | } 16 | 17 | protected void initPacketDescriptors(){ 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version2_0/payload/AbstractAeadProtectionScheme.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.wire.version2_0.payload; 2 | 3 | import java.security.MessageDigest; 4 | 5 | import org.slj.mqtt.sn.codec.AbstractProtectionScheme; 6 | import org.slj.mqtt.sn.codec.MqttsnCodecException; 7 | import org.slj.mqtt.sn.spi.IProtectionScheme; 8 | 9 | public abstract class AbstractAeadProtectionScheme extends AbstractProtectionScheme implements IProtectionScheme 10 | { 11 | private static final String IV_NONCE_HASH_ALGORITHM="SHA-256"; 12 | 13 | protected MessageDigest digest; 14 | protected byte allowedKeyLength; 15 | 16 | public AbstractAeadProtectionScheme() 17 | { 18 | authenticationOnly=false; 19 | try 20 | { 21 | digest = MessageDigest.getInstance(IV_NONCE_HASH_ALGORITHM); 22 | } 23 | catch(Exception e) 24 | { 25 | throw new MqttsnCodecException(e); 26 | } 27 | } 28 | 29 | //It returns the plaintext payload if the authenticity is verified, an exception otherwise 30 | abstract public byte[] unprotect(byte[] associatedData, byte[] encryptedPayload, byte[] tagToBeVerified, byte[] key) throws MqttsnCodecException; 31 | 32 | //It returns the tag of nominalTagLength 33 | abstract public byte[] protect(byte[] associatedData, byte[] plaintextPayload, byte[] key, byte[] encryptedPayload); 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version2_0/payload/AbstractAuthenticationOnlyProtectionScheme.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.wire.version2_0.payload; 2 | 3 | import org.slj.mqtt.sn.codec.AbstractProtectionScheme; 4 | import org.slj.mqtt.sn.codec.MqttsnCodecException; 5 | 6 | public abstract class AbstractAuthenticationOnlyProtectionScheme extends AbstractProtectionScheme 7 | { 8 | protected byte allowedKeyLength=Byte.MIN_VALUE; 9 | 10 | public AbstractAuthenticationOnlyProtectionScheme() 11 | { 12 | authenticationOnly=true; 13 | } 14 | 15 | //It returns the authenticatedPayload if the authenticity is verified, an exception otherwise 16 | abstract public byte[] unprotect(byte[] authenticatedPayload, byte[] tagToBeVerified, byte[] key) throws MqttsnCodecException; 17 | 18 | //It returns the tag of nominalTagLength 19 | abstract public byte[] protect(byte[] payloadToBeAuthenticated, byte[] key); 20 | } 21 | -------------------------------------------------------------------------------- /mqtt-sn-codec/src/main/java/org/slj/mqtt/sn/wire/version2_0/payload/ProtectionKey.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.wire.version2_0.payload; 2 | 3 | import java.security.MessageDigest; 4 | 5 | import org.slj.mqtt.sn.codec.MqttsnCodecException; 6 | import org.slj.mqtt.sn.wire.MqttsnWireUtils; 7 | 8 | public class ProtectionKey 9 | { 10 | private String protectionKeyHash; 11 | private byte[] protectionKey; 12 | private short protectionKeyLength; 13 | private MessageDigest digest; 14 | 15 | public ProtectionKey(byte[] protectionKey) throws MqttsnCodecException 16 | { 17 | try 18 | { 19 | digest = MessageDigest.getInstance("SHA-256"); 20 | } 21 | catch(Exception e) 22 | { 23 | throw new MqttsnCodecException(e); 24 | } 25 | this.protectionKey = protectionKey; 26 | this.protectionKeyLength=(short)protectionKey.length; 27 | this.protectionKeyHash = MqttsnWireUtils.toHex(digest.digest(protectionKey)); 28 | } 29 | 30 | byte[] getProtectionKey() 31 | { 32 | return protectionKey; 33 | } 34 | 35 | short getProtectionKeyLength() 36 | { 37 | return protectionKeyLength; 38 | } 39 | 40 | public String getProtectionKeyHash() 41 | { 42 | return protectionKeyHash; 43 | } 44 | } -------------------------------------------------------------------------------- /mqtt-sn-core/licenses/mit.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 2 | 3 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/cloud/MqttsnCloudConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.cloud; 26 | 27 | public interface MqttsnCloudConstants { 28 | 29 | //-- use simple bearer tokens 30 | String AUTHORIZATION_HEADER = "Authorization"; 31 | String BEARER_TOKEN_HEADER = "Bearer %s"; 32 | 33 | String CONTENT_TYPE = "Content-Type"; 34 | String CONTENT_ENCODING = "Content-Encoding"; 35 | } 36 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/cloud/MqttsnCloudServiceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.cloud; 26 | 27 | public class MqttsnCloudServiceException extends Exception { 28 | 29 | public MqttsnCloudServiceException() { 30 | } 31 | 32 | public MqttsnCloudServiceException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttsnCloudServiceException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnCloudServiceException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/cloud/MqttsnCloudToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.cloud; 26 | 27 | import java.util.Date; 28 | 29 | public class MqttsnCloudToken { 30 | 31 | protected String token; 32 | protected Date expires; 33 | 34 | public MqttsnCloudToken(String token, Date expires) { 35 | this.token = token; 36 | this.expires = expires; 37 | } 38 | 39 | public MqttsnCloudToken() { 40 | } 41 | 42 | public String getToken() { 43 | return token; 44 | } 45 | 46 | public void setToken(String token) { 47 | this.token = token; 48 | } 49 | 50 | public Date getExpires() { 51 | return expires; 52 | } 53 | 54 | public void setExpires(Date expires) { 55 | this.expires = expires; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/impl/AbstractConnectionStateListener.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.impl; 2 | 3 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 4 | import org.slj.mqtt.sn.spi.IMqttsnConnectionStateListener; 5 | 6 | /** 7 | * @author Simon L Johnson 8 | */ 9 | public abstract class AbstractConnectionStateListener implements IMqttsnConnectionStateListener { 10 | 11 | @Override 12 | public void notifyConnected(IClientIdentifierContext context) { 13 | 14 | } 15 | 16 | @Override 17 | public void notifyRemoteDisconnect(IClientIdentifierContext context) { 18 | 19 | } 20 | 21 | @Override 22 | public void notifyActiveTimeout(IClientIdentifierContext context) { 23 | 24 | } 25 | 26 | @Override 27 | public void notifyLocalDisconnect(IClientIdentifierContext context, Throwable t) { 28 | 29 | } 30 | 31 | @Override 32 | public void notifyConnectionLost(IClientIdentifierContext context, Throwable t) { 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/impl/AbstractTrafficListener.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.impl; 2 | 3 | import org.slj.mqtt.sn.model.INetworkContext; 4 | import org.slj.mqtt.sn.spi.IMqttsnMessage; 5 | import org.slj.mqtt.sn.spi.IMqttsnTrafficListener; 6 | 7 | /** 8 | * Convenience hook for implementing listeners 9 | * @author Simon L Johnson 10 | */ 11 | public abstract class AbstractTrafficListener implements IMqttsnTrafficListener { 12 | 13 | @Override 14 | public void trafficSent(INetworkContext context, byte[] data, IMqttsnMessage message) { 15 | //Override me 16 | } 17 | 18 | @Override 19 | public void trafficReceived(INetworkContext context, byte[] data, IMqttsnMessage message) { 20 | //Override me 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/impl/AbstractWillRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.impl; 26 | 27 | import org.slj.mqtt.sn.spi.IMqttsnWillRegistry; 28 | 29 | public abstract class AbstractWillRegistry 30 | extends AbstractMqttsnSessionBeanRegistry implements IMqttsnWillRegistry { 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/impl/MqttsnDefaultTopicModifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.impl; 26 | 27 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 28 | import org.slj.mqtt.sn.spi.AbstractMqttsnService; 29 | import org.slj.mqtt.sn.spi.IMqttsnTopicModifier; 30 | 31 | /** 32 | * Default implementation does nothing to the topic 33 | */ 34 | public class MqttsnDefaultTopicModifier extends AbstractMqttsnService implements IMqttsnTopicModifier { 35 | 36 | @Override 37 | public String modifyTopic(IClientIdentifierContext context, String topicName) { 38 | return topicName; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/impl/ServiceSort.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.impl; 26 | 27 | import org.slj.mqtt.sn.spi.IMqttsnService; 28 | import org.slj.mqtt.sn.spi.MqttsnService; 29 | import org.slj.mqtt.sn.utils.ServiceUtils; 30 | 31 | import java.util.Comparator; 32 | 33 | public class ServiceSort implements Comparator { 34 | 35 | @Override 36 | public int compare(IMqttsnService o1, IMqttsnService o2) { 37 | 38 | return getSortValue(o2) - getSortValue(o1); 39 | } 40 | 41 | 42 | private static int getSortValue(IMqttsnService service){ 43 | MqttsnService a = ServiceUtils.getAnnotationFromBind(service); 44 | if(a != null){ 45 | return a.order(); 46 | } 47 | return 0; 48 | } 49 | } 50 | 51 | 52 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/impl/metrics/MqttsnMetric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.impl.metrics; 26 | 27 | import org.slj.mqtt.sn.model.IMqttsnMetric; 28 | 29 | public abstract class MqttsnMetric implements IMqttsnMetric { 30 | 31 | private final String name; 32 | private final String description; 33 | 34 | public MqttsnMetric(String name, String description){ 35 | this.name = name; 36 | this.description = description; 37 | } 38 | 39 | @Override 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | @Override 45 | public String getDescription() { 46 | return description; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/ClientState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | public enum ClientState { 28 | ACTIVE, DISCONNECTED, AWAKE, ASLEEP, LOST 29 | } 30 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IAuthHandler.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.model; 2 | 3 | import java.io.IOException; 4 | 5 | public interface IAuthHandler { 6 | 7 | String getMechanism(); 8 | 9 | boolean isComplete(); 10 | 11 | byte[] handleChallenge(byte[] challenge) throws IOException; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IClientIdentifierContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | public interface IClientIdentifierContext extends IContextObject { 28 | 29 | int getProtocolVersion(); 30 | 31 | String getId(); 32 | 33 | boolean isAssignedClientId(); 34 | 35 | void setAssignedClientId(boolean clientId); 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IContextObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | import java.io.Serializable; 28 | 29 | public interface IContextObject extends Serializable { 30 | 31 | Serializable getContextObject(String contextObjectKey); 32 | 33 | boolean putContextObject(String contextObjectKey, Serializable contextObject); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IDataRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | import java.io.Serializable; 28 | 29 | public interface IDataRef extends Serializable { 30 | 31 | T getId(); 32 | } 33 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IMqttsnMessageContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | import org.slj.mqtt.sn.model.session.ISession; 28 | 29 | public interface IMqttsnMessageContext { 30 | 31 | INetworkContext getNetworkContext(); 32 | 33 | IClientIdentifierContext getClientContext(); 34 | 35 | ISession getSession(); 36 | 37 | void setSession(ISession session); 38 | 39 | int getProtocolVersion(); 40 | } 41 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IMqttsnMetric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | import java.util.Date; 28 | import java.util.List; 29 | 30 | public interface IMqttsnMetric { 31 | 32 | String getName(); 33 | 34 | String getDescription(); 35 | 36 | List getSamples(Date from, Date to, int max); 37 | 38 | List getSamples(Date from, int max); 39 | 40 | List getSamples(Date from); 41 | 42 | MqttsnMetricSample getLastSample(); 43 | 44 | MqttsnMetricSample getMaxSample(); 45 | 46 | MqttsnMetricSample getMinSample(); 47 | 48 | Long getTotalValue(); 49 | 50 | void putSample(MqttsnMetricSample sample); 51 | 52 | void increment(long by); 53 | } 54 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IMqttsnMetricAlarm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | public interface IMqttsnMetricAlarm { 28 | 29 | String getMetricName(); 30 | 31 | long getThresholdValue(); 32 | 33 | String getAlarmEmailAddresses(); 34 | 35 | int getFirePeriodBackoff(); 36 | 37 | int getMinSamplesBeforeActive(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/INetworkContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | import org.slj.mqtt.sn.net.NetworkAddress; 28 | import org.slj.mqtt.sn.spi.ITransport; 29 | 30 | public interface INetworkContext extends IContextObject { 31 | 32 | int getReceivePort(); 33 | 34 | void setReceivePort(int port); 35 | 36 | NetworkAddress getNetworkAddress(); 37 | 38 | void setNetworkAddress(NetworkAddress address); 39 | 40 | ITransport getTransport(); 41 | } 42 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IPacketTXRXJob.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.model; 2 | 3 | public interface IPacketTXRXJob { 4 | 5 | INetworkContext getNetworkContext(); 6 | 7 | Throwable getError(); 8 | 9 | boolean isComplete(); 10 | 11 | boolean isError(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/IPreferenceNamespace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | public interface IPreferenceNamespace { 28 | 29 | String getNamespace(); 30 | } 31 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/MqttsnQueueAcceptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model; 26 | 27 | public class MqttsnQueueAcceptException extends Exception{ 28 | public MqttsnQueueAcceptException() { 29 | } 30 | 31 | public MqttsnQueueAcceptException(String message) { 32 | super(message); 33 | } 34 | 35 | public MqttsnQueueAcceptException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | 39 | public MqttsnQueueAcceptException(Throwable cause) { 40 | super(cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/PacketTXRXJob.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.model; 2 | 3 | public class PacketTXRXJob implements IPacketTXRXJob { 4 | 5 | private boolean complete = false; 6 | private Throwable error; 7 | private INetworkContext networkContext; 8 | 9 | 10 | public PacketTXRXJob() { 11 | } 12 | 13 | public void setComplete(boolean complete) { 14 | this.complete = complete; 15 | } 16 | 17 | public void setError(Throwable error) { 18 | this.error = error; 19 | } 20 | 21 | public void setNetworkContext(INetworkContext networkContext) { 22 | this.networkContext = networkContext; 23 | } 24 | 25 | @Override 26 | public INetworkContext getNetworkContext() { 27 | return networkContext; 28 | } 29 | 30 | @Override 31 | public Throwable getError() { 32 | return error; 33 | } 34 | 35 | @Override 36 | public boolean isComplete() { 37 | return complete; 38 | } 39 | 40 | @Override 41 | public boolean isError() { 42 | return error != null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/session/IQueuedPublishMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model.session; 26 | 27 | import org.slj.mqtt.sn.PublishData; 28 | import org.slj.mqtt.sn.model.IDataRef; 29 | import org.slj.mqtt.sn.model.MqttsnWaitToken; 30 | 31 | import java.io.Serializable; 32 | 33 | public interface IQueuedPublishMessage extends Serializable { 34 | 35 | PublishData getData(); 36 | long getCreated(); 37 | int getRetryCount(); 38 | int getGrantedQoS(); 39 | IDataRef getDataRefId(); 40 | int getPacketId(); 41 | MqttsnWaitToken getToken(); 42 | void setToken(MqttsnWaitToken token); 43 | void incrementRetry(); 44 | void setPacketId(int packetId); 45 | void setRetryCount(int retryCount); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/session/ISession.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model.session; 26 | 27 | import org.slj.mqtt.sn.model.ClientState; 28 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 29 | 30 | import java.util.Date; 31 | 32 | public interface ISession { 33 | 34 | IClientIdentifierContext getContext(); 35 | 36 | ClientState getClientState(); 37 | 38 | Date getLastSeen(); 39 | 40 | Date getSessionStarted(); 41 | 42 | int getMaxPacketSize(); 43 | 44 | int getKeepAlive(); 45 | 46 | long getSessionExpiryInterval(); 47 | 48 | int getProtocolVersion(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/session/ISubscription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model.session; 26 | 27 | import org.slj.mqtt.sn.utils.TopicPath; 28 | 29 | public interface ISubscription { 30 | 31 | TopicPath getTopicPath(); 32 | 33 | int getGrantedQoS(); 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/session/ITopicRegistration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model.session; 26 | 27 | public interface ITopicRegistration { 28 | 29 | String getTopicPath(); 30 | 31 | int getAliasId(); 32 | 33 | boolean isConfirmed(); 34 | 35 | void setConfirmed(boolean confirmed); 36 | } 37 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/model/session/IWillData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.model.session; 26 | 27 | import org.slj.mqtt.sn.utils.TopicPath; 28 | 29 | public interface IWillData { 30 | 31 | TopicPath getTopicPath(); 32 | 33 | byte[] getData(); 34 | 35 | boolean isRetained(); 36 | 37 | int getQos(); 38 | } 39 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/net/ContextTransportLocator.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.net; 2 | 3 | import org.slj.mqtt.sn.model.INetworkContext; 4 | import org.slj.mqtt.sn.model.IPacketTXRXJob; 5 | import org.slj.mqtt.sn.spi.*; 6 | 7 | import java.util.concurrent.Future; 8 | 9 | public class ContextTransportLocator extends AbstractMqttsnService implements ITransportLocator { 10 | 11 | @Override 12 | public Future writeToTransport(INetworkContext context, IMqttsnMessage message) 13 | throws MqttsnException { 14 | return ((IMqttsnTransport)context.getTransport()).writeToTransport(context, message); 15 | } 16 | 17 | @Override 18 | public ITransport getTransport(INetworkContext context) throws MqttsnException { 19 | return context.getTransport(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnApplicationProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import java.util.List; 28 | 29 | public interface IMqttsnApplicationProfile { 30 | 31 | List getDefinedTopicTemplates(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnClientIdFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | @MqttsnService 28 | public interface IMqttsnClientIdFactory extends IMqttsnService { 29 | 30 | String createClientId(String clientIdSeed) throws MqttsnException; 31 | 32 | String resolvedClientId(String clientIdTokenOrInput) throws MqttsnException; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnMetricsService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.model.IMqttsnMetric; 28 | import org.slj.mqtt.sn.model.IMqttsnMetricAlarm; 29 | 30 | @MqttsnService 31 | public interface IMqttsnMetricsService extends IMqttsnService { 32 | 33 | IMqttsnMetric getMetric(String metricName); 34 | void registerMetric(IMqttsnMetric metric); 35 | void registerAlarm(IMqttsnMetricAlarm alarm); 36 | Long getLatestValue(String metricName); 37 | Long getMaxValue(String metricName); 38 | Long getMinValue(String metricName); 39 | Long getTotalValue(String metricName); 40 | } 41 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnObjectReaderWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | 28 | import org.slj.mqtt.sn.impl.MqttsnVMObjectReaderWriter; 29 | 30 | import java.io.Serializable; 31 | 32 | /** 33 | * Interface out the reading and writing of JSON as there could be any number of implementions we want to use 34 | * according to the environment 35 | */ 36 | public interface IMqttsnObjectReaderWriter { 37 | 38 | IMqttsnObjectReaderWriter DEFAULT = new MqttsnVMObjectReaderWriter(); 39 | 40 | byte[] write(Serializable o) throws MqttsnException; 41 | 42 | T load(Class clz, byte[] arr) throws MqttsnException; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnPayloadModifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 28 | 29 | public interface IMqttsnPayloadModifier extends IMqttsnService{ 30 | 31 | /** 32 | * Method called before publish payload to sent to the connector for processing 33 | * @param context 34 | * @param topicName 35 | * @return 36 | */ 37 | byte[] modifyPayload(IClientIdentifierContext context, String topicName, byte[] inputPayload) throws MqttsnException ; 38 | } 39 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnPublishFailureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 28 | import org.slj.mqtt.sn.utils.TopicPath; 29 | 30 | public interface IMqttsnPublishFailureListener { 31 | 32 | void sendFailure(IClientIdentifierContext context, TopicPath topicPath, int qos, boolean retained, byte[] data, IMqttsnMessage message, int retryCount); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnPublishReceivedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 28 | import org.slj.mqtt.sn.utils.TopicPath; 29 | 30 | public interface IMqttsnPublishReceivedListener { 31 | 32 | void receive(IClientIdentifierContext context, TopicPath topicPath, int qos, boolean retained, byte[] data, IMqttsnMessage message); 33 | } 34 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnPublishSentListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 28 | import org.slj.mqtt.sn.utils.TopicPath; 29 | 30 | public interface IMqttsnPublishSentListener { 31 | 32 | void sent(IClientIdentifierContext context, TopicPath topicPath, int qos, boolean retained, byte[] data, IMqttsnMessage message); 33 | } 34 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public interface IMqttsnService { 28 | 29 | void start(T runtime) throws MqttsnException; 30 | 31 | void stop() throws MqttsnException; 32 | 33 | boolean running(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnTopicModifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 28 | 29 | @MqttsnService 30 | public interface IMqttsnTopicModifier extends IMqttsnService{ 31 | 32 | /** 33 | * Method called before any interactions into or out of the registry to allow for 34 | * hooking to manipulate topic formats 35 | * @param context 36 | * @param topicName 37 | * @return 38 | */ 39 | String modifyTopic(IClientIdentifierContext context, String topicName) throws MqttsnException ; 40 | } 41 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/IMqttsnWillRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import org.slj.mqtt.sn.model.session.ISession; 28 | import org.slj.mqtt.sn.model.session.IWillData; 29 | 30 | /** 31 | * Stores and Maintains will data associated with a given context 32 | */ 33 | @MqttsnService 34 | public interface IMqttsnWillRegistry extends IMqttsnService { 35 | 36 | void setWillMessage(ISession session, IWillData willData); 37 | 38 | void updateWillTopic(ISession session, String topicPath, int qos, boolean retain); 39 | 40 | void updateWillMessage(ISession session, byte[] data); 41 | 42 | IWillData getWillMessage(ISession session); 43 | 44 | boolean hasWillMessage(ISession session); 45 | 46 | void clear(ISession session) throws MqttsnException; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/ITransport.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.spi; 2 | 3 | import org.slj.mqtt.sn.model.INetworkContext; 4 | import org.slj.mqtt.sn.model.IPacketTXRXJob; 5 | import org.slj.mqtt.sn.utils.StringTable; 6 | 7 | import java.util.concurrent.Future; 8 | 9 | @MqttsnService(order = MqttsnService.FIRST) 10 | public interface ITransport extends IMqttsnService { 11 | 12 | void receiveFromTransport(INetworkContext context, byte[] data) throws MqttsnException ; 13 | 14 | Future writeToTransport(INetworkContext context, byte[] data) throws MqttsnException ; 15 | 16 | Future writeToTransportWithCallback(INetworkContext context, byte[] data, Runnable task) ; 17 | 18 | void connectionLost(INetworkContext context, Throwable t); 19 | 20 | StringTable getTransportDetails(); 21 | 22 | String getName(); 23 | 24 | int getPort(); 25 | 26 | String getDescription(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/ITransportLocator.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.spi; 2 | 3 | import org.slj.mqtt.sn.model.INetworkContext; 4 | import org.slj.mqtt.sn.model.IPacketTXRXJob; 5 | 6 | import java.util.concurrent.Future; 7 | 8 | @MqttsnService(order = MqttsnService.ANY) 9 | public interface ITransportLocator extends IMqttsnService { 10 | 11 | Future writeToTransport(INetworkContext context, IMqttsnMessage message) throws MqttsnException; 12 | 13 | ITransport getTransport(INetworkContext context) throws MqttsnException; 14 | } 15 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/MqttsnException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public class MqttsnException extends Exception { 28 | 29 | public MqttsnException() { 30 | } 31 | 32 | public MqttsnException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttsnException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/MqttsnExpectationFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public class MqttsnExpectationFailedException extends MqttsnException { 28 | 29 | public MqttsnExpectationFailedException() { 30 | } 31 | 32 | public MqttsnExpectationFailedException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttsnExpectationFailedException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnExpectationFailedException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/MqttsnIllegalFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | /** 28 | * Denotes an error in the format of an object or primitive passed into an SPI 29 | */ 30 | public class MqttsnIllegalFormatException extends Exception { 31 | public MqttsnIllegalFormatException() { 32 | super(); 33 | } 34 | 35 | public MqttsnIllegalFormatException(String message) { 36 | super(message); 37 | } 38 | 39 | public MqttsnIllegalFormatException(String message, Throwable cause) { 40 | super(message, cause); 41 | } 42 | 43 | public MqttsnIllegalFormatException(Throwable cause) { 44 | super(cause); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/MqttsnNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public class MqttsnNotFoundException extends MqttsnException { 28 | 29 | public MqttsnNotFoundException() { 30 | } 31 | 32 | public MqttsnNotFoundException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttsnNotFoundException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnNotFoundException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/MqttsnRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public class MqttsnRuntimeException extends RuntimeException { 28 | 29 | public MqttsnRuntimeException() { 30 | } 31 | 32 | public MqttsnRuntimeException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttsnRuntimeException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnRuntimeException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/MqttsnSecurityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public class MqttsnSecurityException extends SecurityException { 28 | 29 | public MqttsnSecurityException() { 30 | } 31 | 32 | public MqttsnSecurityException(String s) { 33 | super(s); 34 | } 35 | 36 | public MqttsnSecurityException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttsnSecurityException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/MqttsnService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.TYPE) 34 | public @interface MqttsnService { 35 | 36 | int FIRST = 100, ANY = 50, LAST = 10, RESERVED = 0; 37 | 38 | int order() default ANY; 39 | } 40 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/NetworkRegistryException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public class NetworkRegistryException extends Exception { 28 | 29 | public NetworkRegistryException() { 30 | } 31 | 32 | public NetworkRegistryException(String message) { 33 | super(message); 34 | } 35 | 36 | public NetworkRegistryException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public NetworkRegistryException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/spi/RuntimeConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.spi; 26 | 27 | public interface RuntimeConfig { 28 | 29 | String HOSTNAME = "hostName"; 30 | String CLIENTID = "clientId"; 31 | String PORT = "port"; 32 | String PROTOCOL_VERSION = "protocolVersion"; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/tools/LifecycleEmulator.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.tools; 2 | 3 | import org.slj.mqtt.sn.spi.IMqttsnCodec; 4 | 5 | /** 6 | * @author Simon L Johnson 7 | */ 8 | public class LifecycleEmulator { 9 | 10 | private final IMqttsnCodec codec; 11 | 12 | public LifecycleEmulator(final IMqttsnCodec codec) { 13 | this.codec = codec; 14 | } 15 | 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/utils/Numbers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.utils; 26 | 27 | import java.text.DecimalFormat; 28 | 29 | public class Numbers { 30 | 31 | public static double round2(double d){ 32 | 33 | double result = d * 100; 34 | result = Math.round(result); 35 | result = result / 100; 36 | return result; 37 | } 38 | 39 | public static String round2_display(double d){ 40 | 41 | DecimalFormat format = new DecimalFormat(); 42 | format.setMaximumFractionDigits(2); 43 | format.setMinimumFractionDigits(2); 44 | return format.format(round2(d)); 45 | } 46 | 47 | public static double percent(double val, double of){ 48 | 49 | return (val / of) * 100; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/sn/utils/ServiceUtils.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.utils; 2 | 3 | import org.slj.mqtt.sn.spi.IMqttsnService; 4 | import org.slj.mqtt.sn.spi.MqttsnService; 5 | 6 | import java.lang.annotation.Annotation; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | public class ServiceUtils { 12 | 13 | public static Class getServiceBind(IMqttsnService instance){ 14 | 15 | Class bindCls = null; 16 | //try and bind against the annotated interface 17 | List> list = new ArrayList<>(); 18 | Class searchClass = instance.getClass(); 19 | while (searchClass != null) { 20 | Class[] a = searchClass.getInterfaces(); 21 | if(a != null && a.length > 0){ 22 | list.addAll(Arrays.asList(a)); 23 | } 24 | // recurse point 25 | searchClass = searchClass.getSuperclass(); 26 | } 27 | Class[] clss = list.toArray(new Class[list.size()]); 28 | for (Class c : clss){ 29 | Annotation[] anno = c.getAnnotations(); 30 | if (anno.length == 0) { 31 | continue; 32 | } 33 | for (Annotation a : anno){ 34 | if(a.annotationType() == MqttsnService.class){ 35 | bindCls = c; 36 | } 37 | } 38 | } 39 | 40 | if(bindCls == null){ 41 | bindCls = instance.getClass(); 42 | } 43 | return bindCls; 44 | } 45 | 46 | public static MqttsnService getAnnotationFromBind(IMqttsnService instance){ 47 | Class c = getServiceBind(instance); 48 | return (MqttsnService) c.getAnnotation(MqttsnService.class); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/Example.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | import java.util.Set; 4 | 5 | public class Example { 6 | public static void main(String[] args) throws MqttTreeException, MqttTreeLimitExceededException { 7 | MqttTree tree = new MqttTree(MqttTree.DEFAULT_SPLIT, true); 8 | 9 | tree.withMaxPathSegments(1024); 10 | tree.withMaxMembersAtLevel(1024); 11 | 12 | tree.subscribe("/this/is/a/topic", "ClientId1", "ClientId2"); 13 | 14 | tree.subscribe("/this/+/a/topic", "ClientId3"); 15 | 16 | tree.subscribe("/this/#", "ClientId4"); 17 | 18 | Set m = tree.search("/this/is/a/topic"); 19 | 20 | System.out.println(String.format("matching search had [%s] members", m.size())); 21 | 22 | m = tree.search("/is/a/different/topic"); 23 | 24 | System.out.println(String.format("non-matching search had [%s] members", m.size())); 25 | 26 | tree.unsubscribe("/this/is/a/topic", "ClientId2"); 27 | 28 | m = tree.search("/this/is/a/topic"); 29 | 30 | System.out.println(String.format("matching search had [%s] members", m.size())); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/IMqttTree.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | import java.util.Set; 4 | 5 | public interface IMqttTree { 6 | 7 | MqttTreeNode subscribe(final String path, final T... members) 8 | throws MqttTreeException, MqttTreeLimitExceededException; 9 | 10 | boolean unsubscribe(final String path, T member) 11 | throws MqttTreeException; 12 | 13 | Set search(final String path); 14 | 15 | boolean hasMembers(final String path); 16 | 17 | boolean hasPath(String path); 18 | 19 | MqttTreeNode getRootNode(); 20 | 21 | void visit(MqttTreeNodeVisitor visitor); 22 | 23 | Set getDistinctPaths(boolean considerMembership); 24 | 25 | int countDistinctPaths(boolean considerMembership); 26 | 27 | int getBranchCount(); 28 | } 29 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/ISearchableMqttTree.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Provides index methods to search the Mqtt Tree character by character. 7 | */ 8 | public interface ISearchableMqttTree extends IMqttTree{ 9 | 10 | /** 11 | * Use the radix index to perform quick lookup of your topic 12 | * @param path - any path prefix you would like to search 13 | * @param max - max results returned by the index 14 | * @return The nodes returned by the prefix search 15 | */ 16 | List> prefixSearch(String path, int max); 17 | } 18 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/MqttTreeConstants.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | public interface MqttTreeConstants { 4 | 5 | char MIN_HIGH_UTF = '\uD800'; 6 | char MAX_HIGH_UTF = '\uDBFF'; 7 | 8 | //-- the optionally restricted range 9 | char MIN_CONTROL1_UTF = '\u0001'; 10 | char MAX_CONTROL1_UTF = '\u001F'; 11 | 12 | char MIN_CONTROL2_UTF = '\u007F'; 13 | char MAX_CONTROL2_UTF = '\u009F'; 14 | char UNICODE_ZERO = '\u0000'; 15 | int UNSIGNED_MAX_16 = 65535; 16 | int MAX_TOPIC_LENGTH = UNSIGNED_MAX_16; 17 | 18 | String SINGLE_LEVEL_WILDCARD = "+"; //U+002B 19 | String MULTI_LEVEL_WILDCARD = "#"; //U+0023 20 | 21 | char PATH_SEP = '/'; //U+002F 22 | char SINGLE_WILDCARD_CHAR = '+'; 23 | } 24 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/MqttTreeException.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | public class MqttTreeException extends RuntimeException{ 4 | 5 | public MqttTreeException() { 6 | } 7 | 8 | public MqttTreeException(String message) { 9 | super(message); 10 | } 11 | 12 | public MqttTreeException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | 16 | public MqttTreeException(Throwable cause) { 17 | super(cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/MqttTreeInputException.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | public class MqttTreeInputException extends MqttTreeException{ 4 | 5 | public MqttTreeInputException() { 6 | } 7 | 8 | public MqttTreeInputException(String message) { 9 | super(message); 10 | } 11 | 12 | public MqttTreeInputException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | 16 | public MqttTreeInputException(Throwable cause) { 17 | super(cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/MqttTreeLimitExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.tree; 26 | 27 | public class MqttTreeLimitExceededException extends Exception { 28 | 29 | public MqttTreeLimitExceededException() { 30 | } 31 | 32 | public MqttTreeLimitExceededException(String message) { 33 | super(message); 34 | } 35 | 36 | public MqttTreeLimitExceededException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public MqttTreeLimitExceededException(Throwable cause) { 41 | super(cause); 42 | } 43 | } -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/MqttTreeNode.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | import java.util.Set; 4 | 5 | public interface MqttTreeNode { 6 | 7 | boolean isRoot(); 8 | 9 | boolean isLeaf(); 10 | 11 | boolean isWildcard(); 12 | 13 | boolean isWildpath(); 14 | 15 | boolean hasChildren(); 16 | 17 | boolean hasMembers(); 18 | 19 | Set getChildPaths(); 20 | 21 | MqttTreeNode getChild(String path); 22 | 23 | String toPath(boolean climb); 24 | 25 | Set getMembers(); 26 | 27 | boolean hasChild(String path); 28 | 29 | int getMemberCount(); 30 | 31 | String getPathSegment(); 32 | 33 | MqttTreeNode getParent(); 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/MqttTreeNodeVisitor.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree; 2 | 3 | public interface MqttTreeNodeVisitor { 4 | 5 | void visit(MqttTreeNode node); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/radix/DuplicateKeyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License 3 | 4 | Copyright (c) 2008 Tahseen Ur Rehman 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | package org.slj.mqtt.tree.radix; 26 | 27 | /** 28 | * excepion thrown if a duplicate key is inserted in a {@link RadixTree} 29 | * 30 | * @author Tahseen Ur Rehman 31 | * email: tahseen.ur.rehman {at.spam.me.not} gmail.com 32 | */ 33 | public class DuplicateKeyException extends RuntimeException 34 | { 35 | private static final long serialVersionUID = 3141795907493885706L; 36 | 37 | public DuplicateKeyException(String msg) 38 | { 39 | super(msg); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/radix/VisitorImpl.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree.radix; 2 | 3 | 4 | /** 5 | * A simple standard implementation for a {@link visitor}. 6 | * 7 | * @author Dennis Heidsiek 8 | * @param 9 | */ 10 | public abstract class VisitorImpl implements Visitor { 11 | 12 | protected R result; 13 | 14 | public VisitorImpl() { 15 | this.result = null; 16 | } 17 | 18 | public VisitorImpl(R initialValue) { 19 | this.result = initialValue; 20 | } 21 | 22 | public R getResult() { 23 | return result; 24 | } 25 | 26 | abstract public void visit(String key, RadixTreeNode parent, RadixTreeNode node); 27 | } -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/ui/MqttTreeViewerLauncher.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree.ui; 2 | 3 | import org.slj.mqtt.tree.*; 4 | 5 | import javax.swing.*; 6 | import java.io.IOException; 7 | 8 | public class MqttTreeViewerLauncher { 9 | 10 | 11 | public static void main(String[] args) throws MqttTreeLimitExceededException, MqttTreeException { 12 | 13 | ISearchableMqttTree tree = new SearchableMqttTree( 14 | new MqttTree(MqttTree.DEFAULT_SPLIT, true)); 15 | 16 | for (int i=0; i<1000; i++){ 17 | tree.subscribe(MqttTreeUtils.generateRandomTopic(20), "SomeClientId"); 18 | } 19 | 20 | SwingUtilities.invokeLater(new Runnable() { 21 | @Override 22 | public void run() { 23 | try { 24 | new MqttTreeViewer(tree); 25 | } catch (IOException e) { 26 | throw new RuntimeException(e); 27 | } 28 | } 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/ui/MqttViewerUtils.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree.ui; 2 | 3 | import javax.swing.*; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | public class MqttViewerUtils { 9 | 10 | public static ImageIcon loadIcon(String iconName) throws IOException { 11 | 12 | byte[] a = loadResource(iconName); 13 | ImageIcon imageIcon = new ImageIcon(a); 14 | return imageIcon; 15 | } 16 | 17 | public static byte[] loadResource(String resourceName) throws IOException { 18 | if(resourceName == null) throw new IOException("cannot load resource"); 19 | if(resourceName.startsWith("/")) { 20 | resourceName = resourceName.substring(1); 21 | } 22 | InputStream is = MqttViewerUtils.class.getResourceAsStream(resourceName); 23 | if(is == null){ 24 | is = MqttViewerUtils.class.getResourceAsStream("/" + resourceName); 25 | } 26 | 27 | if(is == null) throw new IOException("resource not found on class path " + resourceName); 28 | return read(is, 1024); 29 | } 30 | 31 | public static byte[] read(InputStream is, int bufSize) throws IOException { 32 | try(ByteArrayOutputStream baos 33 | = new ByteArrayOutputStream()){ 34 | byte[] buf = new byte[bufSize]; 35 | int length; 36 | while ((length = is.read(buf)) != -1) { 37 | baos.write(buf, 0, length); 38 | } 39 | return baos.toByteArray(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/java/org/slj/mqtt/tree/ui/TestForm.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.tree.ui; 2 | 3 | import javax.swing.*; 4 | 5 | public class TestForm extends JFrame { 6 | private JTextField textField1; 7 | private JTextField textField2; 8 | private JTree tree1; 9 | private JTable table1; 10 | private JPanel mainPanel; 11 | 12 | public TestForm() { 13 | 14 | setContentPane(mainPanel); 15 | setTitle("Welcome"); 16 | setSize(450, 300); 17 | setDefaultCloseOperation(EXIT_ON_CLOSE); 18 | setVisible(true); 19 | } 20 | 21 | public static void main(String[] args) { 22 | TestForm form =new TestForm(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/main/resources/ascii.txt: -------------------------------------------------------------------------------- 1 | ███╗ ███╗ ██████╗ ████████╗████████╗ ███████╗███╗ ██╗ 2 | ████╗ ████║██╔═══██╗╚══██╔══╝╚══██╔══╝ ██╔════╝████╗ ██║ 3 | ██╔████╔██║██║ ██║ ██║ ██║█████╗███████╗██╔██╗ ██║ 4 | ██║╚██╔╝██║██║▄▄ ██║ ██║ ██║╚════╝╚════██║██║╚██╗██║ 5 | ██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ███████║██║ ╚████║ 6 | ╚═╝ ╚═╝ ╚══▀▀═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ 7 | 8 | ███████╗████████╗ █████╗ ██████╗ ████████╗███████╗██████╗ 9 | ██╔════╝╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝██╔════╝██╔══██╗ 10 | ███████╗ ██║ ███████║██████╔╝ ██║ █████╗ ██║ ██║ 11 | ╚════██║ ██║ ██╔══██║██╔══██╗ ██║ ██╔══╝ ██║ ██║ 12 | ███████║ ██║ ██║ ██║██║ ██║ ██║ ███████╗██████╔╝ 13 | ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═════╝ 14 | -------------------------------------------------------------------------------- /mqtt-sn-core/src/test/java/org/slj/mqtt/sn/test/MqttsnTestRuntime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.test; 26 | 27 | import org.slj.mqtt.sn.impl.AbstractMqttsnRuntime; 28 | import org.slj.mqtt.sn.model.MqttsnOptions; 29 | import org.slj.mqtt.sn.net.NetworkAddress; 30 | 31 | import java.io.IOException; 32 | 33 | public class MqttsnTestRuntime extends AbstractMqttsnRuntime { 34 | 35 | public static MqttsnOptions TEST_OPTIONS = new MqttsnOptions(); 36 | public static String TEST_CLIENT_ID = "testClientId-"; 37 | public static NetworkAddress TEST_ADDRESS = NetworkAddress.localhost(10001); 38 | 39 | @Override 40 | public void close() { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-connector-paho/README.md: -------------------------------------------------------------------------------- 1 | # MQTT-SN Paho Connector 2 | Provides the backend TCP/IP connection to the MQTT broker. -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/java/org/slj/mqtt/sn/console/IMqttsnConsole.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.console; 26 | 27 | import com.fasterxml.jackson.databind.ObjectMapper; 28 | import org.slj.mqtt.sn.model.TrafficEntry; 29 | import org.slj.mqtt.sn.spi.IMqttsnService; 30 | import org.slj.mqtt.sn.spi.MqttsnService; 31 | 32 | import java.util.List; 33 | @MqttsnService 34 | public interface IMqttsnConsole extends IMqttsnService { 35 | 36 | ObjectMapper getJsonMapper(); 37 | 38 | void authorizeCloud(); 39 | 40 | List getTraffic(); 41 | } 42 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/java/org/slj/mqtt/sn/console/http/HttpBadRequestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.console.http; 26 | 27 | public class HttpBadRequestException extends HttpException { 28 | 29 | public HttpBadRequestException(String responseMessage) { 30 | super(HttpConstants.SC_BAD_REQUEST, responseMessage); 31 | } 32 | 33 | public HttpBadRequestException(String responseMessage, Throwable cause) { 34 | super(HttpConstants.SC_BAD_REQUEST, responseMessage, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/java/org/slj/mqtt/sn/console/http/HttpInternalServerError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.console.http; 26 | 27 | public class HttpInternalServerError extends HttpException { 28 | 29 | public HttpInternalServerError(String responseMessage, Exception e) { 30 | super(HttpConstants.SC_INTERNAL_SERVER_ERROR, responseMessage, e); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/java/org/slj/mqtt/sn/console/http/HttpNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.console.http; 26 | 27 | public class HttpNotFoundException extends HttpException { 28 | 29 | public HttpNotFoundException(String responseMessage) { 30 | super(HttpConstants.SC_NOT_FOUND, responseMessage); 31 | } 32 | 33 | public HttpNotFoundException(String responseMessage, Throwable cause) { 34 | super(HttpConstants.SC_NOT_FOUND, responseMessage, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/java/org/slj/mqtt/sn/console/http/IHttpRequestResponseHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.console.http; 26 | 27 | import java.io.IOException; 28 | 29 | public interface IHttpRequestResponseHandler { 30 | 31 | void handleRequest(IHttpRequestResponse requestResponse) throws IOException; 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/java/org/slj/mqtt/sn/console/http/MimeTypeNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.console.http; 26 | 27 | import java.io.IOException; 28 | 29 | public class MimeTypeNotFoundException extends IOException{ 30 | 31 | public MimeTypeNotFoundException() { 32 | } 33 | 34 | public MimeTypeNotFoundException(String message) { 35 | super(message); 36 | } 37 | 38 | public MimeTypeNotFoundException(String message, Throwable cause) { 39 | super(message, cause); 40 | } 41 | 42 | public MimeTypeNotFoundException(Throwable cause) { 43 | super(cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/html/cluster.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
Cluster
5 |

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden class. 6 |

7 |
8 |
9 |
-------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/html/config.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
System Configuration
5 |

6 | These are the current property values being used by the runtime. Some properties may be modified. These properties have editor fields. NB: Where a property is updated, it may require a runtime restart in order for it to take affect. 7 |

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
Property NameProperty ValueDescription
19 |
20 |
21 |
22 | 23 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/html/dead-letter.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
Dead Letter Queue
5 |

6 | The dead letter queue is a place where messages are placed when they are unable to be delivered. The reasons for delivery failure could be things ranging from connectivity, max queue sizes exceeded, nature of payload or simply internal errors being encountered. 7 |

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
CreatedClient IdReasonQoSTopic Path
21 |
22 |
23 |
24 | 25 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/html/settings.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |
Settings
6 |

7 |

8 |
9 |
10 |
-------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/html/transport.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
Transport
5 |

6 | MQTT-SN can be delivered over a number of transport layers. These can be plugged into the system independently. 7 |

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
Transport NamePortDescription
19 |
20 |
21 |
22 | 23 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/cloud-logo-no-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/cloud-logo-no-background.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/android-chrome-192x192.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/android-chrome-512x512.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #da532c 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/favicon.ico -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/mstile-150x150.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/android-chrome-512x512.png", 12 | "sizes": "512x512", 13 | "type": "image/png" 14 | } 15 | ], 16 | "theme_color": "#ffffff", 17 | "background_color": "#ffffff", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/logo-no-background-round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/logo-no-background-round.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/httpd/img/logo-no-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-gateway-console/src/main/resources/httpd/img/logo-no-background.png -------------------------------------------------------------------------------- /mqtt-sn-gateway-console/src/main/resources/licenses/mit.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 2 | 3 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /mqtt-sn-gateway/ext/example-start-commands.txt: -------------------------------------------------------------------------------- 1 | -Xmx2048M 2 | -DanonymousPublishAllowed=true 3 | -DwireLoggingEnabled=true 4 | -Dlogback.configurationFile=/path/to/config.xml 5 | -DmaxClientSessions=25000 6 | -DtransportIngressThreadCount=1 7 | -DtransportIngressThreadCount=1 8 | -DgeneralPurposeThreadCount=2 9 | -DqueueProcessorThreadCount=2 10 | -DanonymousPublishAllowed=true 11 | -DconsolePort=8081 12 | 13 | java -jar mqtt-sn-gateway-console-0.2.0.jar -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/DisconnectResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi; 26 | 27 | public class DisconnectResult extends Result { 28 | 29 | public DisconnectResult(STATUS status) { 30 | super(status); 31 | } 32 | 33 | public DisconnectResult(STATUS status, String message) { 34 | super(status); 35 | setMessage(message); 36 | } 37 | 38 | public DisconnectResult(STATUS status, int returnCode, String message) { 39 | super(status); 40 | setMessage(message); 41 | setReturnCode(returnCode); 42 | } 43 | } -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/GatewayConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi; 26 | 27 | import org.slj.mqtt.sn.spi.RuntimeConfig; 28 | 29 | public interface GatewayConfig extends RuntimeConfig { 30 | 31 | String LISTEN_PORT = "listenPort"; 32 | String USERNAME = "username"; 33 | String PASSWORD = "password"; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/GatewayMetrics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi; 26 | 27 | public interface GatewayMetrics { 28 | 29 | String BACKEND_CONNECTOR_PUBLISH = "BACKEND_CONNECTOR_PUBLISH"; 30 | String BACKEND_CONNECTOR_PUBLISH_ERROR = "BACKEND_CONNECTOR_PUBLISH_ERROR"; 31 | String BACKEND_CONNECTOR_PUBLISH_RECEIVE = "BACKEND_CONNECTOR_PUBLISH_RECEIVE"; 32 | String BACKEND_CONNECTOR_PUBLISH_QUEUE_SIZE = "BACKEND_CONNECTOR_PUBLISH_QUEUE_SIZE"; 33 | String BACKEND_CONNECTOR_EXPANSION = "BACKEND_CONNECTOR_EXPANSION"; 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/MqttsnInvalidSessionStateException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi; 26 | 27 | import org.slj.mqtt.sn.spi.MqttsnRuntimeException; 28 | 29 | public class MqttsnInvalidSessionStateException extends MqttsnRuntimeException { 30 | 31 | public MqttsnInvalidSessionStateException() { 32 | } 33 | 34 | public MqttsnInvalidSessionStateException(String message) { 35 | super(message); 36 | } 37 | 38 | public MqttsnInvalidSessionStateException(String message, Throwable cause) { 39 | super(message, cause); 40 | } 41 | 42 | public MqttsnInvalidSessionStateException(Throwable cause) { 43 | super(cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/PublishResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi; 26 | 27 | public class PublishResult extends Result { 28 | 29 | public PublishResult(STATUS status) { 30 | super(status); 31 | } 32 | 33 | public PublishResult(STATUS status, String message) { 34 | super(status); 35 | setMessage(message); 36 | } 37 | 38 | public PublishResult(STATUS status, int returnCode, String message) { 39 | super(status); 40 | setMessage(message); 41 | setReturnCode(returnCode); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/ReceiveResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi; 26 | 27 | public class ReceiveResult extends Result { 28 | 29 | public ReceiveResult(STATUS status) { 30 | super(status); 31 | } 32 | 33 | public ReceiveResult(STATUS status, String message) { 34 | super(status); 35 | setMessage(message); 36 | } 37 | 38 | public ReceiveResult(STATUS status, int returnCode, String message) { 39 | super(status); 40 | setMessage(message); 41 | setReturnCode(returnCode); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/UnsubscribeResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi; 26 | 27 | public class UnsubscribeResult extends Result { 28 | 29 | public UnsubscribeResult(STATUS status){ 30 | super(status); 31 | } 32 | 33 | public UnsubscribeResult(STATUS status, String message) { 34 | super(status); 35 | setMessage(message); 36 | } 37 | 38 | public UnsubscribeResult(STATUS status, int returnCode, String message) { 39 | super(status); 40 | setMessage(message); 41 | setReturnCode(returnCode); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/bridge/IProtocolBridge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi.bridge; 26 | 27 | import org.slj.mqtt.sn.cloud.ProtocolBridgeDescriptor; 28 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 29 | import org.slj.mqtt.sn.spi.IMqttsnRuntimeRegistry; 30 | import org.slj.mqtt.sn.spi.IMqttsnService; 31 | import org.slj.mqtt.sn.spi.MqttsnService; 32 | 33 | @MqttsnService(order = MqttsnService.LAST) 34 | public interface IProtocolBridge { 35 | 36 | T createConnection() throws ProtocolBridgeException; 37 | 38 | String getConnectionString(); 39 | 40 | ProtocolBridgeDescriptor getDescriptor(); 41 | 42 | ProtocolBridgeOptions getDefaultOptions(); 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/bridge/IProtocolBridgeService.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.gateway.spi.bridge; 2 | 3 | import org.slj.mqtt.sn.cloud.ProtocolBridgeDescriptor; 4 | import org.slj.mqtt.sn.spi.IMqttsnService; 5 | import org.slj.mqtt.sn.spi.MqttsnService; 6 | 7 | import java.util.List; 8 | import java.util.concurrent.ScheduledFuture; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | @MqttsnService 12 | public interface IProtocolBridgeService extends IMqttsnService { 13 | 14 | boolean initializeBridge(ProtocolBridgeDescriptor descriptor, ProtocolBridgeOptions options) throws ProtocolBridgeException; 15 | 16 | List getActiveBridges(List descriptors); 17 | 18 | ProtocolBridgeDescriptor getDescriptorById(List descriptors, String bridgeId); 19 | 20 | boolean bridgeAvailable(ProtocolBridgeDescriptor descriptor); 21 | 22 | IProtocolBridgeConnection getActiveConnectionIfExists(ProtocolBridgeDescriptor descriptor) throws ProtocolBridgeException; 23 | 24 | void close(IProtocolBridgeConnection connection) throws ProtocolBridgeException; 25 | 26 | ScheduledFuture schedulePolling(Runnable runnable, long initialDelay, long period, TimeUnit unit); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/bridge/ProtocolBridgeClientContext.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.gateway.spi.bridge; 2 | 3 | import org.slj.mqtt.sn.cloud.ProtocolBridgeDescriptor; 4 | import org.slj.mqtt.sn.model.ClientIdentifierContext; 5 | 6 | public class ProtocolBridgeClientContext extends ClientIdentifierContext { 7 | 8 | protected ProtocolBridgeDescriptor descriptor; 9 | protected ProtocolBridgeOptions options; 10 | 11 | public ProtocolBridgeClientContext(String id, ProtocolBridgeDescriptor descriptor, ProtocolBridgeOptions options) { 12 | super(id); 13 | this.descriptor = descriptor; 14 | this.options = options; 15 | } 16 | 17 | public ProtocolBridgeDescriptor getDescriptor() { 18 | return descriptor; 19 | } 20 | 21 | public void setDescriptor(ProtocolBridgeDescriptor descriptor) { 22 | this.descriptor = descriptor; 23 | } 24 | 25 | public ProtocolBridgeOptions getOptions() { 26 | return options; 27 | } 28 | 29 | public void setOptions(ProtocolBridgeOptions options) { 30 | this.options = options; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/bridge/ProtocolBridgeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi.bridge; 26 | 27 | import org.slj.mqtt.sn.spi.MqttsnException; 28 | 29 | public class ProtocolBridgeException extends MqttsnException { 30 | 31 | public ProtocolBridgeException() { 32 | } 33 | 34 | public ProtocolBridgeException(String message) { 35 | super(message); 36 | } 37 | 38 | public ProtocolBridgeException(String message, Throwable cause) { 39 | super(message, cause); 40 | } 41 | 42 | public ProtocolBridgeException(Throwable cause) { 43 | super(cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/connector/IMqttsnConnector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi.connector; 26 | 27 | import org.slj.mqtt.sn.cloud.MqttsnConnectorDescriptor; 28 | import org.slj.mqtt.sn.spi.IMqttsnService; 29 | import org.slj.mqtt.sn.spi.MqttsnService; 30 | 31 | @MqttsnService(order = MqttsnService.LAST) 32 | public interface IMqttsnConnector extends IMqttsnService { 33 | 34 | T createConnection(MqttsnConnectorOptions options, String clientId) throws MqttsnConnectorException; 35 | 36 | T createConnection(String clientId) throws MqttsnConnectorException; 37 | 38 | String getConnectionString(); 39 | 40 | MqttsnConnectorDescriptor getDescriptor(); 41 | 42 | MqttsnConnectorOptions getDefaultOptions(); 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/connector/MqttsnConnectorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi.connector; 26 | 27 | import org.slj.mqtt.sn.spi.MqttsnException; 28 | 29 | public class MqttsnConnectorException extends MqttsnException { 30 | 31 | public MqttsnConnectorException() { 32 | } 33 | 34 | public MqttsnConnectorException(String message) { 35 | super(message); 36 | } 37 | 38 | public MqttsnConnectorException(String message, Throwable cause) { 39 | super(message, cause); 40 | } 41 | 42 | public MqttsnConnectorException(Throwable cause) { 43 | super(cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/gateway/IMqttsnGatewayAdvertiseService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi.gateway; 26 | 27 | import org.slj.mqtt.sn.spi.IMqttsnService; 28 | import org.slj.mqtt.sn.spi.MqttsnService; 29 | 30 | @MqttsnService 31 | public interface IMqttsnGatewayAdvertiseService extends IMqttsnService { 32 | 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/gateway/IMqttsnGatewayClusterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi.gateway; 26 | 27 | import org.slj.mqtt.sn.model.IClientIdentifierContext; 28 | import org.slj.mqtt.sn.spi.IMqttsnService; 29 | import org.slj.mqtt.sn.spi.MqttsnException; 30 | 31 | /** 32 | * When bound in, sends notification to the cluster service that a device has connected 33 | */ 34 | public interface IMqttsnGatewayClusterService extends IMqttsnService { 35 | 36 | void notifyConnection(IClientIdentifierContext context) throws MqttsnException; 37 | 38 | void notifyAwake(IClientIdentifierContext context) throws MqttsnException; 39 | 40 | void notifyDisconnection(IClientIdentifierContext context) throws MqttsnException; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /mqtt-sn-gateway/src/main/java/org/slj/mqtt/sn/gateway/spi/gateway/IMqttsnGatewayExpansionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.gateway.spi.gateway; 26 | 27 | import org.slj.mqtt.sn.spi.IMqttsnService; 28 | import org.slj.mqtt.sn.spi.MqttsnException; 29 | import org.slj.mqtt.sn.spi.MqttsnService; 30 | 31 | @MqttsnService(order = MqttsnService.LAST) 32 | public interface IMqttsnGatewayExpansionHandler extends IMqttsnService { 33 | 34 | void receiveToSessions(String topicPath, int qos, boolean retained, byte[] payload) throws MqttsnException ; 35 | } 36 | -------------------------------------------------------------------------------- /mqtt-sn-load-test/src/main/java/org/slj/mqtt/sn/load/ExecutionInput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.load; 26 | 27 | import java.util.concurrent.TimeUnit; 28 | 29 | public interface ExecutionInput { 30 | 31 | long getMaxWait(); 32 | 33 | TimeUnit getMaxWaitUnit(); 34 | } 35 | -------------------------------------------------------------------------------- /mqtt-sn-load-test/src/main/java/org/slj/mqtt/sn/load/ExecutionProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.load; 26 | 27 | public interface ExecutionProfile { 28 | 29 | ExecutionProgress initializeProfile(ExecutionInput input) throws LoadTestException; 30 | 31 | void executeProfile(); 32 | 33 | void shutdownProfile(); 34 | 35 | void setProgress(ExecutionProgress progress); 36 | 37 | ExecutionProgress getProgress(); 38 | 39 | String getProfileName(); 40 | } 41 | -------------------------------------------------------------------------------- /mqtt-sn-load-test/src/main/java/org/slj/mqtt/sn/load/LoadTestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.load; 26 | 27 | public class LoadTestException extends Exception { 28 | 29 | public LoadTestException() { 30 | } 31 | 32 | public LoadTestException(String message) { 33 | super(message); 34 | } 35 | 36 | public LoadTestException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public LoadTestException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mqtt-sn-load-test/src/main/java/org/slj/mqtt/sn/load/runner/ThreadPerProfileLoadTestRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.load.runner; 26 | 27 | import org.slj.mqtt.sn.load.ExecutionProfile; 28 | 29 | public class ThreadPerProfileLoadTestRunner extends AbstractLoadTestRunner { 30 | 31 | public ThreadPerProfileLoadTestRunner(Class profile, int numInstances, int rampSeconds) { 32 | super(profile, numInstances, rampSeconds); 33 | } 34 | 35 | void run(Runnable runnable) { 36 | factory.newThread(runnable).start(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mqtt-sn-load-test/src/main/java/org/slj/mqtt/sn/load/tests/TestHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Simon Johnson 3 | * 4 | * Find me on GitHub: 5 | * https://github.com/simon622 6 | * 7 | * Licensed to the Apache Software Foundation (ASF) under one 8 | * or more contributor license agreements. See the NOTICE file 9 | * distributed with this work for additional information 10 | * regarding copyright ownership. The ASF licenses this file 11 | * to you under the Apache License, Version 2.0 (the 12 | * "License"); you may not use this file except in compliance 13 | * with the License. You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, 18 | * software distributed under the License is distributed on an 19 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 | * KIND, either express or implied. See the License for the 21 | * specific language governing permissions and limitations 22 | * under the License. 23 | */ 24 | 25 | package org.slj.mqtt.sn.load.tests; 26 | 27 | import org.slj.mqtt.sn.impl.MqttsnFilesystemStorageService; 28 | import org.slj.mqtt.sn.impl.MqttsnVMObjectReaderWriter; 29 | import org.slj.mqtt.sn.spi.IMqttsnStorageService; 30 | 31 | public class TestHelper { 32 | 33 | public static IMqttsnStorageService storageService = new MqttsnFilesystemStorageService( 34 | new MqttsnVMObjectReaderWriter(), "mqtt-sn-load-test"); 35 | 36 | public static IMqttsnStorageService getTestStorageService(){ 37 | return storageService; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mqtt-sn-protection-runtimes/src/main/resources/client1-aes128.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-protection-runtimes/src/main/resources/client1-aes128.key -------------------------------------------------------------------------------- /mqtt-sn-protection-runtimes/src/main/resources/client1-aes192.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-protection-runtimes/src/main/resources/client1-aes192.key -------------------------------------------------------------------------------- /mqtt-sn-protection-runtimes/src/main/resources/client1-aes256.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-protection-runtimes/src/main/resources/client1-aes256.key -------------------------------------------------------------------------------- /mqtt-sn-protection-runtimes/src/main/resources/client1-hmac.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-protection-runtimes/src/main/resources/client1-hmac.key -------------------------------------------------------------------------------- /mqtt-sn-protection-runtimes/src/main/resources/gateway1-hmac.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/mqtt-sn-protection-runtimes/src/main/resources/gateway1-hmac.key -------------------------------------------------------------------------------- /mqtt-sn-protection/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.slj 8 | mqtt-sn 9 | 0.2.2 10 | 11 | 12 | mqtt-sn-protection 13 | 14 | 15 | 16 | org.slj 17 | mqtt-sn-core 18 | ${mqtt-sn.version} 19 | 20 | 21 | org.mqtt-sn 22 | mqtt-sn-codec 23 | ${mqtt-sn.version} 24 | 25 | 26 | org.bouncycastle 27 | bcprov-jdk18on 28 | 1.73 29 | 30 | 31 | 32 | 33 | 18 34 | 18 35 | UTF-8 36 | 37 | 38 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/MqttsnProtectionAlgorithmInitializer.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | /** 4 | * @author Simon L Johnson 5 | */ 6 | public class MqttsnProtectionAlgorithmInitializer { 7 | 8 | public static void initDefaults(){ 9 | ProtectionSchemeHmacSha256.register(); 10 | ProtectionSchemeHmacSha3_256.register(); 11 | ProtectionSchemeCmac128.register(); 12 | ProtectionSchemeCmac192.register(); 13 | ProtectionSchemeCmac256.register(); 14 | ProtectionSchemeCcm_64_128.register(); 15 | ProtectionSchemeCcm_64_192.register(); 16 | ProtectionSchemeCcm_64_256.register(); 17 | ProtectionSchemeCcm_128_128.register(); 18 | ProtectionSchemeCcm_128_192.register(); 19 | ProtectionSchemeCcm_128_256.register(); 20 | ProtectionSchemeGcm_128_128.register(); 21 | ProtectionSchemeGcm_128_192.register(); 22 | ProtectionSchemeGcm_128_256.register(); 23 | ProtectionSchemeChaCha20_Poly1305.register(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCcm_128_128.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCcm_128_128 extends AbstractProtectionSchemeCcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_CCM_128_128), ProtectionSchemeCcm_128_128.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_CCM_128_128)); 13 | } 14 | 15 | public ProtectionSchemeCcm_128_128(String name, byte index) 16 | { 17 | super(name,index); 18 | this.nominalTagLengthInBytes=16; //128 bits tag 19 | this.nominalTagLengthInBits=(short)(this.nominalTagLengthInBytes*8); 20 | this.allowedKeyLength=16; //128 bits keys allowed in this scheme 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCcm_128_192.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCcm_128_192 extends AbstractProtectionSchemeCcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_CCM_128_192), ProtectionSchemeCcm_128_192.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_CCM_128_192)); 13 | } 14 | 15 | public ProtectionSchemeCcm_128_192(String name, byte index) 16 | { 17 | super(name,index); 18 | this.nominalTagLengthInBytes=16; //128 bits tag 19 | this.nominalTagLengthInBits=(short)(this.nominalTagLengthInBytes*8); 20 | this.allowedKeyLength=24; //192 bits keys allowed in this scheme 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCcm_128_256.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCcm_128_256 extends AbstractProtectionSchemeCcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_CCM_128_256), ProtectionSchemeCcm_128_256.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_CCM_128_256)); 13 | } 14 | 15 | public ProtectionSchemeCcm_128_256(String name, byte index) 16 | { 17 | super(name,index); 18 | this.nominalTagLengthInBytes=16; //128 bits tag 19 | this.nominalTagLengthInBits=(short)(this.nominalTagLengthInBytes*8); 20 | this.allowedKeyLength=32; //256 bits keys allowed in this scheme 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCcm_64_128.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCcm_64_128 extends AbstractProtectionSchemeCcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_CCM_64_128), ProtectionSchemeCcm_64_128.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_CCM_64_128)); 13 | } 14 | 15 | public ProtectionSchemeCcm_64_128(String name, byte index) 16 | { 17 | super(name,index); 18 | this.nominalTagLengthInBytes=8; //64 bits tag 19 | this.nominalTagLengthInBits=(short)(this.nominalTagLengthInBytes*8); 20 | this.allowedKeyLength=16; //128 bits keys allowed in this scheme 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCcm_64_192.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCcm_64_192 extends AbstractProtectionSchemeCcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_CCM_64_192), ProtectionSchemeCcm_64_192.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_CCM_64_192)); 13 | } 14 | 15 | public ProtectionSchemeCcm_64_192(String name, byte index) 16 | { 17 | super(name,index); 18 | this.nominalTagLengthInBytes=8; //64 bits tag 19 | this.nominalTagLengthInBits=(short)(this.nominalTagLengthInBytes*8); 20 | this.allowedKeyLength=24; //192 bits keys allowed in this scheme 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCcm_64_256.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCcm_64_256 extends AbstractProtectionSchemeCcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_CCM_64_256), ProtectionSchemeCcm_64_256.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_CCM_64_256)); 13 | } 14 | 15 | public ProtectionSchemeCcm_64_256(String name, byte index) 16 | { 17 | super(name,index); 18 | this.nominalTagLengthInBytes=8; //64 bits tag 19 | this.nominalTagLengthInBits=(short)(this.nominalTagLengthInBytes*8); 20 | this.allowedKeyLength=32; //256 bits keys allowed in this scheme 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCmac128.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCmac128 extends AbstractProtectionSchemeCmac 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(CMAC_128), ProtectionSchemeCmac128.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(CMAC_128)); 13 | } 14 | 15 | public ProtectionSchemeCmac128(String name, byte index) 16 | { 17 | super(name,index); 18 | this.allowedKeyLength=16; //128 bits keys allowed in this scheme 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCmac192.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCmac192 extends AbstractProtectionSchemeCmac 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(CMAC_192), ProtectionSchemeCmac192.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(CMAC_192)); 13 | } 14 | 15 | public ProtectionSchemeCmac192(String name, byte index) 16 | { 17 | super(name,index); 18 | this.allowedKeyLength=24; //192 bits keys allowed in this scheme 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeCmac256.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeCmac256 extends AbstractProtectionSchemeCmac 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(CMAC_256), ProtectionSchemeCmac256.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(CMAC_256)); 13 | } 14 | 15 | public ProtectionSchemeCmac256(String name, byte index) 16 | { 17 | super(name,index); 18 | this.allowedKeyLength=32; //256 bits keys allowed in this scheme 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeGcm_128_128.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeGcm_128_128 extends AbstractProtectionSchemeGcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_GCM_128_128), ProtectionSchemeGcm_128_128.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_GCM_128_128)); 13 | } 14 | 15 | public ProtectionSchemeGcm_128_128(String name, byte index) 16 | { 17 | super(name,index); 18 | this.allowedKeyLength=16; //128 bits keys allowed in this scheme 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeGcm_128_192.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeGcm_128_192 extends AbstractProtectionSchemeGcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_GCM_128_192), ProtectionSchemeGcm_128_192.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_GCM_128_192)); 13 | } 14 | 15 | public ProtectionSchemeGcm_128_192(String name, byte index) 16 | { 17 | super(name,index); 18 | this.allowedKeyLength=24; //192 bits keys allowed in this scheme 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/alg/ProtectionSchemeGcm_128_256.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.alg; 2 | 3 | public class ProtectionSchemeGcm_128_256 extends AbstractProtectionSchemeGcm 4 | { 5 | public static void register() 6 | { 7 | protectionSchemeClasses.put(Byte.valueOf(AES_GCM_128_256), ProtectionSchemeGcm_128_256.class); 8 | } 9 | 10 | public static void unregister() 11 | { 12 | protectionSchemeClasses.remove(Byte.valueOf(AES_GCM_128_256)); 13 | } 14 | 15 | public ProtectionSchemeGcm_128_256(String name, byte index) 16 | { 17 | super(name,index); 18 | this.allowedKeyLength=32; //256 bits keys allowed in this scheme 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/impl/ProtectionUtils.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.impl; 2 | 3 | import org.slj.mqtt.sn.utils.Files; 4 | 5 | /** 6 | * @author Simon L Johnson 7 | */ 8 | public class ProtectionUtils { 9 | 10 | public static byte[] loadKey(String clientId, String keyName) { 11 | 12 | try { 13 | return Files.read( 14 | ProtectionUtils.class.getResourceAsStream(String.format("/%s-%s.key", clientId, keyName)), 1024); 15 | } catch(Exception e){ 16 | throw new RuntimeException(e); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/spi/IProtectedSenderRegistry.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.spi; 2 | 3 | import org.slj.mqtt.sn.spi.IMqttsnService; 4 | import org.slj.mqtt.sn.spi.MqttsnException; 5 | import org.slj.mqtt.sn.spi.MqttsnService; 6 | 7 | import java.nio.ByteBuffer; 8 | 9 | /** 10 | * @author Simon L Johnson 11 | */ 12 | @MqttsnService 13 | public interface IProtectedSenderRegistry extends IMqttsnService { 14 | 15 | ByteBuffer deriveSenderId(String clientId) throws MqttsnException; 16 | 17 | ProtectedSender lookupProtectedSender(ByteBuffer prefix); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /mqtt-sn-protection/src/main/java/org/slj/mqtt/sn/protection/spi/ProtectedSender.java: -------------------------------------------------------------------------------- 1 | package org.slj.mqtt.sn.protection.spi; 2 | 3 | import org.slj.mqtt.sn.wire.version2_0.payload.ProtectionKey; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * @author Simon L Johnson 10 | */ 11 | public class ProtectedSender { 12 | 13 | private final String clientId; 14 | private final ArrayList protectionKeys = new ArrayList<>(); 15 | 16 | public ProtectedSender(final String clientId, final List protectionKeys){ 17 | this.clientId = clientId; 18 | protectionKeys.forEach(protectionKey -> 19 | this.protectionKeys.add(new ProtectionKey(protectionKey))); 20 | } 21 | 22 | public List getProtectionKeys() { 23 | return protectionKeys; 24 | } 25 | 26 | public String getClientId() { 27 | return clientId; 28 | } 29 | } -------------------------------------------------------------------------------- /site/images/logo-no-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/site/images/logo-no-background.png -------------------------------------------------------------------------------- /site/images/logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simon622/mqtt-sn/217e3d44ba24c5d1881eb7ddec8b411bacd0c458/site/images/logo-white.png --------------------------------------------------------------------------------