diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 06c064597d..1ee15aeb57 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,8 @@ Here is a (non-exclusive, non-prioritized) list of things you might be able to h * features (both ideas and code are welcome) * test cases +There are a couple of [enhancement issues](https://github.com/eclipse-californium/californium/issues?q=is%3Aissue+label%3Ahibernate), which have been closed for longer inactivity. Maybe, if you like to help and spend some time, you will be welcome. + In order to get you started as fast as possible we need to go through some organizational issues first, though. ## Eclipse Contributor Agreement diff --git a/DEPENDENCIES b/DEPENDENCIES index ae5c8543d9..a157ec09fc 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,32 +1,33 @@ maven/mavencentral/com.github.peteroupc/numbers/1.8.2, CC0-1.0, approved, clearlydefined -maven/mavencentral/com.google.code.gson/gson/2.8.8, Apache-2.0, approved, CQ23496 +maven/mavencentral/com.google.code.gson/gson/2.10, Apache-2.0, approved, #6159 maven/mavencentral/com.google.errorprone/error_prone_annotations/2.3.4, Apache-2.0, approved, #807 maven/mavencentral/com.google.guava/failureaccess/1.0.1, Apache-2.0, approved, CQ22654 -maven/mavencentral/com.google.guava/guava/30.0-android, Apache-2.0, approved, clearlydefined -maven/mavencentral/com.google.guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava, LicenseRef-NONE, approved, #803 +maven/mavencentral/com.google.guava/guava/30.1-android, Apache-2.0 AND CC0-1.0 AND LicenseRef-Public-Domain, approved, CQ23244 +maven/mavencentral/com.google.guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava, Apache-2.0, approved, CQ22657 maven/mavencentral/com.google.j2objc/j2objc-annotations/1.3, Apache-2.0, approved, CQ21195 maven/mavencentral/com.upokecenter/cbor/4.5.2, CC0-1.0, approved, clearlydefined -maven/mavencentral/info.picocli/picocli/4.6.2, Apache-2.0, approved, clearlydefined -maven/mavencentral/io.netty/netty-buffer/4.1.76.Final, Apache-2.0, approved, CQ21842 -maven/mavencentral/io.netty/netty-codec/4.1.76.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 -maven/mavencentral/io.netty/netty-common/4.1.76.Final, Apache-2.0 AND MIT AND CC0-1.0, approved, CQ21843 -maven/mavencentral/io.netty/netty-handler/4.1.76.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 -maven/mavencentral/io.netty/netty-resolver/4.1.76.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 -maven/mavencentral/io.netty/netty-transport/4.1.76.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 -maven/mavencentral/org.apache.httpcomponents.client5/httpclient5/5.1, Apache-2.0 AND MIT, approved, #255 -maven/mavencentral/org.apache.httpcomponents.core5/httpcore5-h2/5.1.1, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.apache.httpcomponents.core5/httpcore5/5.1.1, Apache-2.0, approved, clearlydefined +maven/mavencentral/info.picocli/picocli/4.7.0, Apache-2.0, approved, #4365 +maven/mavencentral/io.netty/netty-buffer/4.1.87.Final, Apache-2.0, approved, CQ21842 +maven/mavencentral/io.netty/netty-codec/4.1.87.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 +maven/mavencentral/io.netty/netty-common/4.1.87.Final, Apache-2.0 AND MIT AND CC0-1.0, approved, CQ21843 +maven/mavencentral/io.netty/netty-handler/4.1.87.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 +maven/mavencentral/io.netty/netty-resolver/4.1.87.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 +maven/mavencentral/io.netty/netty-transport-native-unix-common/4.1.87.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 +maven/mavencentral/io.netty/netty-transport/4.1.87.Final, Apache-2.0 AND BSD-3-Clause AND MIT, approved, CQ20926 +maven/mavencentral/org.apache.httpcomponents.client5/httpclient5/5.1.3, Apache-2.0, approved, #6276 +maven/mavencentral/org.apache.httpcomponents.core5/httpcore5-h2/5.1.3, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.apache.httpcomponents.core5/httpcore5/5.1.3, Apache-2.0, approved, clearlydefined maven/mavencentral/org.checkerframework/checker-compat-qual/2.5.5, MIT, approved, clearlydefined -maven/mavencentral/org.eclipse.californium/californium-core/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/californium-proxy2/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/cf-cli/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/cf-cluster/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/cf-oscore/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/cf-plugtest-server/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/cf-unix-health/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/element-connector-tcp-netty/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/element-connector/3.5.0-SNAPSHOT, , approved, science.californium -maven/mavencentral/org.eclipse.californium/scandium/3.5.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/californium-core/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/californium-proxy2/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/cf-cli/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/cf-cluster/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/cf-oscore/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/cf-plugtest-server/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/cf-unix-health/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/element-connector-tcp-netty/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/element-connector/3.8.0-SNAPSHOT, , approved, science.californium +maven/mavencentral/org.eclipse.californium/scandium/3.8.0-SNAPSHOT, , approved, science.californium maven/mavencentral/org.osgi/org.osgi.compendium/5.0.0, Apache-2.0, approved, CQ9373 maven/mavencentral/org.osgi/org.osgi.core/5.0.0, Apache-2.0, approved, CQ5932 maven/mavencentral/org.slf4j/slf4j-api/1.7.36, MIT, approved, CQ13368 diff --git a/README.md b/README.md index 381f396288..86cd7128a9 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ More information can be found at [http://www.eclipse.org/californium/](http://www.eclipse.org/californium/) and [http://coap.technology/](http://coap.technology/). +Like to help improving Californium? Then consider to [contribute](#contributing). + # Build using Maven You need to have a working maven installation to build Californium. @@ -19,7 +21,7 @@ $ mvn clean install Executable JARs of the examples with all dependencies can be found in the `demo-apps/run` folder. -The build-process in branch `main` is tested for jdk 7, jdk 8, jdk 11, jdk 15, jdk 16 and jdk 17. +The build-process in branch `main` is tested for jdk 7, jdk 8, jdk 11 and jdk 17. For jdk 7 the revapi maven-plugin is disabled, it requires at least java 8. To generate the javadocs, add "-DcreateJavadoc=true" to the command line and set the `JAVA_HOME`. @@ -38,7 +40,7 @@ To (re-)build versions before that date the unit tests must therefore be skipped $ mvn clean install -DskipTests ``` -Earlier versions (3.0.0-Mx, 2.6.5 and before) may also fail to build with newer JDKs, especially, if java 16 or 17 is used! That is cause by the unit test dependency to a deprecated version of "mockito". If such a (re-)build is required, the unit tests must be skipped (which is in the meantime anyway required caused by the "non-existing.host"). +Earlier versions (3.0.0-Mx, 2.6.5 and before) may also fail to build with newer JDKs, especially, if java 17 is used! That is cause by the unit test dependency to a deprecated version of "mockito". If such a (re-)build is required, the unit tests must be skipped (which is in the meantime anyway required caused by the "non-existing.host"). In combination with the "non-existing.host" now existing, the build with unit test only works for the current heads of the branches `2.6.x`, `2.7.x` and `main`! @@ -76,7 +78,7 @@ $ mvn clean install -DuseToolchainJavadoc=true ## Build with jdk11 and EdDSA support -To support EdDSA, either java 15, java 16, java 17 or java 11 with [ed25519-java](https://github.com/str4d/ed25519-java) is required at runtime. Using java 15 (or newer) to build Californium, leaves out `ed25519-java`, using java 11 for building, includes `ed25519-java` by default. If `ed25519-java` should **NOT** be included into the californium's jars, add `-Dno.net.i2p.crypto.eddsa=true` to maven's arguments. +To support EdDSA, either java 17 or java 11 with [ed25519-java](https://github.com/str4d/ed25519-java) is required at runtime. Using java 17 (or newer) to build Californium, leaves out `ed25519-java`, using java 11 for building, includes `ed25519-java` by default. If `ed25519-java` should **NOT** be included into the californium's jars, add `-Dno.net.i2p.crypto.eddsa=true` to maven's arguments. ```sh $ mvn clean install -Dno.net.i2p.crypto.eddsa=true @@ -94,7 +96,7 @@ In that case, it's still possible to use `ed25519-java`, if the [eddsa-0.3.0.jar ## Run unit tests using Bouncy Castle as alternative JCE provider -With 3.0 a first, experimental support for using Bouncy Castle (version 1.69, bcprov-jdk15on, bcpkix-jdk15on, and, for tls, bctls-jdk15on) is implemented. With 3.3 the tests are using the updated version 1.70 (for tls also bcutil-jdk15on is used additionally) and with 3.8 version 1.71.1 is used. +With 3.0 a first, experimental support for using Bouncy Castle (version 1.69, bcprov-jdk15on, bcpkix-jdk15on, and, for tls, bctls-jdk15on) is implemented. With 3.3 the tests are using the updated version 1.70 (for tls also bcutil-jdk15on is used additionally) and with 3.8 version 1.72 is used. To demonstrate the basic functions, run the unit-tests using the profile `bc-tests` @@ -120,7 +122,7 @@ With that, it gets very time consuming to test all combinations. Therefore, if y # Using Californium in Maven Projects -We are publishing Californium's artifacts for milestones and releases to [Maven Central](https://search.maven.org/search?q=g:org.eclipse.californium%20a:parent%20v:3.7.0). +We are publishing Californium's artifacts for milestones and releases to [Maven Central](https://search.maven.org/search?q=g:org.eclipse.californium%20a:parent%20v:3.8.0). To use the latest released version as a library in your projects, add the following dependency to your `pom.xml` (without the dots): @@ -130,7 +132,7 @@ to your `pom.xml` (without the dots): org.eclipse.californium californium-core - 3.7.0 + 3.8.0 ... @@ -154,7 +156,7 @@ You will therefore need to add the Eclipse Repository to your `pom.xml` first: ... ``` -You can then simply depend on `3.8.0-SNAPSHOT`. +You can then simply depend on `3.9.0-SNAPSHOT`. # Eclipse @@ -177,7 +179,7 @@ In IntelliJ, choose *[File.. » Open]* then select the location of the clon A test server is running at coap://californium.eclipseprojects.io:5683/ -It is an instance of the [cf-plugtest-server](https://repo.eclipse.org/content/repositories/californium-releases/org/eclipse/californium/cf-plugtest-server/3.7.0/cf-plugtest-server-3.7.0.jar) from the demo-apps. +It is an instance of the [cf-plugtest-server](https://repo.eclipse.org/content/repositories/californium-releases/org/eclipse/californium/cf-plugtest-server/3.8.0/cf-plugtest-server-3.8.0.jar) from the demo-apps. The root resource responds with its current version. More information can be found at [http://www.eclipse.org/californium](http://www.eclipse.org/californium) and technical details at [https://projects.eclipse.org/projects/iot.californium](https://projects.eclipse.org/projects/iot.californium). @@ -230,7 +232,7 @@ OSCORE Key Rederivation: For some systems (particularly when multicasting), it may be necessary to specify/restrict californium to a particular network interface, or interfaces. This can be achieved by setting the `COAP_NETWORK_INTERFACES` JVM parameter to a suitable regex, for example: -`java -DCOAP_NETWORK_INTERFACES='.*wpan0' -jar target/cf-helloworld-server-3.7.0.jar MulticastTestServer` +`java -DCOAP_NETWORK_INTERFACES='.*wpan0' -jar target/cf-helloworld-server-3.8.0.jar MulticastTestServer` # Contact @@ -240,3 +242,5 @@ or create an issue here on GitHub. # Contributing Please check out our [contribution guidelines](CONTRIBUTING.md) + +There are a couple of [enhancement issues](https://github.com/eclipse-californium/californium/issues?q=is%3Aissue+label%3Ahibernate), which have been closed for longer inactivity. Maybe, if you like to help and spend some time, you will be welcome. diff --git a/SECURITY.md b/SECURITY.md index 4d7fa137f3..cc216f66bf 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,9 +2,11 @@ ## Reporting a Vulnerability -Californium supports the use of [GitHub security advisories](https://help.github.com/en/articles/managing-security-vulnerabilities-in-your-project) as pilot for [eclipse](https://www.eclipse.org/) projects. Please consider to use it for reporting vulnerabilities. +Californium supports the use of [GitHub security advisories](https://help.github.com/en/articles/managing-security-vulnerabilities-in-your-project) as pilot for [eclipse](https://www.eclipse.org/) projects. -Alternatively may also report a vulnerability opening a [bugzilla ticket](https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Community&component=Vulnerability+Reports&keywords=security&groups=Security_Advisories). +To report a vulnerability, [go directly to the form](https://github.com/eclipse-californium/californium/security/advisories/new). Alternatively, switch to the [Security tab](https://github.com/eclipse-californium/californium/security), then click "Report a vulnerability" and another "Report a vulnerability" button again. + +You may also report a vulnerability opening a [bugzilla ticket](https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Community&component=Vulnerability+Reports&keywords=security&groups=Security_Advisories). For more details, please look at [https://www.eclipse.org/security](https://www.eclipse.org/security). @@ -12,9 +14,9 @@ For more details, please look at [https://www.eclipse.org/security](https://www. | Version | Supported | | ------- | ------------------ | -| 3.8.0-SNAPSHOT (main) | :heavy_check_mark: | -| 3.7.0 | :heavy_check_mark: | -| 3.6.0, 3.5.0, 3.4.0, 3.3.1, 3.2.0, 3.1.0, 3.0.0 | :question: | +| 3.9.0-SNAPSHOT (main) | :heavy_check_mark: | +| 3.8.0 | :heavy_check_mark: | +| 3.8.0, 3.6.0, 3.5.0, 3.4.0,
3.3.1, 3.2.0, 3.1.0,
3.0.0 | :question: | | 2.7.4 | :question: | | 2.7.3, 2.6.6, 2.5.0, 2.4.1,
2.3.1, 2.2.3, 2.1.0,
2.0.0 | :question: | | before 2.0.0 | :x: | diff --git a/assembly/pom.xml b/assembly/pom.xml index 23e9a83f41..9beaa582eb 100644 --- a/assembly/pom.xml +++ b/assembly/pom.xml @@ -3,7 +3,7 @@ org.eclipse.californium parent - 3.8.0-SNAPSHOT + 3.9.0-SNAPSHOT californium-assembly diff --git a/bom/pom.xml b/bom/pom.xml index 83cf874d9b..098aa52563 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -8,7 +8,7 @@ org.eclipse.californium parent - 3.8.0-SNAPSHOT + 3.9.0-SNAPSHOT cf-bom pom @@ -17,7 +17,7 @@ Californium (Cf) Bill Of Materials - 4.6.3 + 4.7.0 2.10 4.5.2 1.7.36 diff --git a/californium-core/api-changes.json b/californium-core/api-changes.json index 460c5c98fa..bb9a69ce27 100644 --- a/californium-core/api-changes.json +++ b/californium-core/api-changes.json @@ -45,6 +45,69 @@ ] } } + ], + "3.8.0": [ + { + "extension": "revapi.differences", + "configuration": { + "ignore": true, + "differences": [ + { + "code": "java.method.parameterTypeChanged", + "old": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.CongestionControlLayer::createRemoteEndpoint(===java.net.InetSocketAddress===)", + "new": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.CongestionControlLayer::createRemoteEndpoint(===java.lang.Object===)", + "parameterIndex": "0", + "justification": "Bugfix InetSocketAddress was already generally replaced by Object and EndpointIdentityResolver" + }, + { + "code": "java.method.parameterTypeChanged", + "old": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.BasicRto::createRemoteEndpoint(===java.net.InetSocketAddress===)", + "new": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.BasicRto::createRemoteEndpoint(===java.lang.Object===)", + "parameterIndex": "0", + "justification": "Bugfix InetSocketAddress was already generally replaced by Object and EndpointIdentityResolver" + }, + { + "code": "java.method.parameterTypeChanged", + "old": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.Cocoa::createRemoteEndpoint(===java.net.InetSocketAddress===)", + "new": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.Cocoa::createRemoteEndpoint(===java.lang.Object===)", + "parameterIndex": "0", + "justification": "Bugfix InetSocketAddress was already generally replaced by Object and EndpointIdentityResolver" + }, + { + "code": "java.method.parameterTypeChanged", + "old": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.LinuxRto::createRemoteEndpoint(===java.net.InetSocketAddress===)", + "new": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.LinuxRto::createRemoteEndpoint(===java.lang.Object===)", + "parameterIndex": "0", + "justification": "Bugfix InetSocketAddress was already generally replaced by Object and EndpointIdentityResolver" + }, + { + "code": "java.method.parameterTypeChanged", + "old": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.PeakhopperRto::createRemoteEndpoint(===java.net.InetSocketAddress===)", + "new": "parameter org.eclipse.californium.core.network.stack.RemoteEndpoint org.eclipse.californium.core.network.stack.congestioncontrol.PeakhopperRto::createRemoteEndpoint(===java.lang.Object===)", + "parameterIndex": "0", + "justification": "Bugfix InetSocketAddress was already generally replaced by Object and EndpointIdentityResolver" + }, + { + "code": "java.method.parameterTypeChanged", + "old": "parameter void org.eclipse.californium.core.network.stack.RemoteEndpoint::(===java.net.InetSocketAddress===, int, int, boolean)", + "new": "parameter void org.eclipse.californium.core.network.stack.RemoteEndpoint::(===java.lang.Object===, int, int, boolean)", + "parameterIndex": "0", + "justification": "Bugfix InetSocketAddress was already generally replaced by Object and EndpointIdentityResolver" + }, + { + "code": "java.method.removed", + "old": "method java.net.InetSocketAddress org.eclipse.californium.core.network.stack.RemoteEndpoint::getRemoteAddress()", + "justification": "Bugfix InetSocketAddress was already generally replaced by Object and EndpointIdentityResolver" + }, + { + "code": "java.method.numberOfParametersChanged", + "old": "method org.eclipse.californium.core.coap.Option org.eclipse.californium.core.network.serialization.DataParser::createOption(int, byte[])", + "new": "method org.eclipse.californium.core.coap.Option org.eclipse.californium.core.network.serialization.DataParser::createOption(int, int, byte[])", + "justification": "Redesign of new and rather rare used API. Omit new major release for mainly one user of this function." + } + ] + } + } ] } diff --git a/californium-core/pom.xml b/californium-core/pom.xml index 8cd5767b70..5a920c1209 100644 --- a/californium-core/pom.xml +++ b/californium-core/pom.xml @@ -8,7 +8,7 @@ org.eclipse.californium cf-bom - 3.8.0-SNAPSHOT + 3.9.0-SNAPSHOT ../bom californium-core diff --git a/californium-core/src/main/java/org/eclipse/californium/core/CoapObserveRelation.java b/californium-core/src/main/java/org/eclipse/californium/core/CoapObserveRelation.java index 1098230517..6547659dc1 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/CoapObserveRelation.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/CoapObserveRelation.java @@ -122,7 +122,8 @@ public void setNotificationListener(NotificationListener listener) { /** * Sets the current response or notification. * - * Use {@link #orderer} to filter deprecated responses. + * Use {@link #orderer} to filter deprecated responses over UDP. + * Responses over TCP are already in order. * * @param response the response or notification * @return {@code true}, response is accepted by {@link #orderer}, diff --git a/californium-core/src/main/java/org/eclipse/californium/core/coap/BlockOption.java b/californium-core/src/main/java/org/eclipse/californium/core/coap/BlockOption.java index 5837c0499f..9ebac5cefe 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/coap/BlockOption.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/coap/BlockOption.java @@ -22,6 +22,7 @@ ******************************************************************************/ package org.eclipse.californium.core.coap; +import org.eclipse.californium.core.coap.option.StandardOptionRegistry; import org.eclipse.californium.elements.util.Bytes; /** @@ -32,8 +33,8 @@ public final class BlockOption { /** * SZX for BERT blockwise. * - * See RFC8323, 6. - * Block-Wise Transfer and Reliable Transports. + * See RFC8323, 6. Block-Wise Transfer and Reliable Transports. * * @since 3.0 */ @@ -49,14 +50,15 @@ public final class BlockOption { * @param szx the szx * @param m the m * @param num the num - * @throws IllegalArgumentException if the szx is < 0 or > 7 or - * if num is not a 20-bit uint. + * @throws IllegalArgumentException if the szx is < 0 or > 7 or if num + * is not a 20-bit uint. */ public BlockOption(final int szx, final boolean m, final int num) { if (szx < 0 || 7 < szx) { - throw new IllegalArgumentException("Block option's szx "+ szx + " must be between 0 and 7 inclusive"); + throw new IllegalArgumentException("Block option's szx " + szx + " must be between 0 and 7 inclusive"); } else if (num < 0 || (1 << 20) - 1 < num) { - throw new IllegalArgumentException("Block option's num "+ num + " must be between 0 and " + (1 << 20 - 1) + " inclusive"); + throw new IllegalArgumentException( + "Block option's num " + num + " must be between 0 and " + (1 << 20 - 1) + " inclusive"); } else { this.szx = szx; this.m = m; @@ -69,14 +71,16 @@ public BlockOption(final int szx, final boolean m, final int num) { * * @param value the bytes * @throws NullPointerException if the specified bytes are null - * @throws IllegalArgumentException if the specified value's length is larger than 3 + * @throws IllegalArgumentException if the specified value's length is + * larger than 3 */ public BlockOption(final byte[] value) { if (value == null) { throw new NullPointerException(); } else if (value.length > 3) { - throw new IllegalArgumentException("Block option's length " + value.length + " must be at most 3 bytes inclusive"); + throw new IllegalArgumentException( + "Block option's length " + value.length + " must be at most 3 bytes inclusive"); } else if (value.length == 0) { this.szx = 0; this.m = false; @@ -99,8 +103,9 @@ public BlockOption(final byte[] value) { * * @return {@code true}, if BERT is used, {@code false}, otherwise. * @see #BERT_SZX See - * RFC8323, 6. - * Block-Wise Transfer and Reliable Transports. + * RFC8323, 6. Block-Wise Transfer and Reliable + * Transports. * @since 3.0 */ public boolean isBERT() { @@ -111,8 +116,7 @@ public boolean isBERT() { * Assert, that the payload-size doesn't exceed blocksize. * * @param payloadSize payload-size to check. - * @throws IllegalStateException if the payload-size exceeds the - * blocksize. + * @throws IllegalStateException if the payload-size exceeds the blocksize. */ public void assertPayloadSize(int payloadSize) { if (szx < BERT_SZX && payloadSize > 0) { @@ -168,7 +172,10 @@ public int getNum() { * Gets the encoded block option as 0-3 byte array. * * The value of the Block Option is a variable-size (0 to 3 byte). - *
+	 * 
+ *
+ * + *
 	 *  0
 	 *  0 1 2 3 4 5 6 7
 	 * +-+-+-+-+-+-+-+-+
@@ -184,27 +191,23 @@ public int getNum() {
 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 	 * |                   NUM                 |M| SZX |
 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-	 * 

+ *
+ * + *
+ *
* * @return the value */ public byte[] getValue() { - int last = szx | (m ? 1<<3 : 0); - if (num == 0 && !m && szx==0) { + int last = szx | (m ? 1 << 3 : 0); + if (num == 0 && !m && szx == 0) { return Bytes.EMPTY; } else if (num < 1 << 4) { - return new byte[] {(byte) (last | (num << 4))}; + return new byte[] { (byte) (last | (num << 4)) }; } else if (num < 1 << 12) { - return new byte[] { - (byte) (num >> 4), - (byte) (last | (num << 4)), - }; + return new byte[] { (byte) (num >> 4), (byte) (last | (num << 4)) }; } else { - return new byte[] { - (byte) (num >> 12), - (byte) (num >> 4), - (byte) (last | (num << 4)), - }; + return new byte[] { (byte) (num >> 12), (byte) (num >> 4), (byte) (last | (num << 4)) }; } } @@ -226,14 +229,19 @@ public int getOffset() { * @throws IllegalArgumentException if number is neither * {@link OptionNumberRegistry#BLOCK1} nor * {@link OptionNumberRegistry#BLOCK2}. + * @deprecated obsolete * @since 3.0 */ + @Deprecated public Option toOption(int number) { - if (number != OptionNumberRegistry.BLOCK1 && number != OptionNumberRegistry.BLOCK2) { - throw new IllegalArgumentException("Block Option must be either block1(" + OptionNumberRegistry.BLOCK1 - + ") or block2(" + OptionNumberRegistry.BLOCK2 + "), not " + number + "!"); + if (StandardOptionRegistry.BLOCK1.getNumber() == number) { + return StandardOptionRegistry.BLOCK1.create(getValue()); + } else if (StandardOptionRegistry.BLOCK2.getNumber() == number) { + return StandardOptionRegistry.BLOCK2.create(getValue()); } - return new Option(number, getValue()); + throw new IllegalArgumentException( + "Block Option must be either block1(" + StandardOptionRegistry.BLOCK1.getNumber() + ") or block2(" + + StandardOptionRegistry.BLOCK2.getNumber() + "), not " + number + "!"); } @Override @@ -243,7 +251,7 @@ public String toString() { @Override public boolean equals(final Object o) { - if (! (o instanceof BlockOption)) { + if (!(o instanceof BlockOption)) { return false; } BlockOption block = (BlockOption) o; @@ -260,7 +268,8 @@ public int hashCode() { /** * Gets the 3-bit SZX code for a block size as specified by - * RFC 7959, Section 2.2: + * RFC 7959, Section 2.2: * *
 	 * 16 bytes = 2^4 --> 0
@@ -268,12 +277,13 @@ public int hashCode() {
 	 * 1024 bytes = 2^10 -> 6
 	 * 
*

- * This method is tolerant towards illegal block sizes - * that are < 16 or > 1024 bytes in that it will return the corresponding - * codes for sizes 16 or 1024 respectively. + * This method is tolerant towards illegal block sizes that are + * < 16 or > 1024 bytes in that it will return the corresponding codes + * for sizes 16 or 1024 respectively. * * @param blockSize The block size in bytes. - * @return The szx code for the largest number of bytes that is less than or equal to the block size. + * @return The szx code for the largest number of bytes that is less than or + * equal to the block size. */ public static int size2Szx(int blockSize) { @@ -290,9 +300,9 @@ public static int size2Szx(int blockSize) { /** * Gets the number of bytes corresponding to a szx code. *

- * This method is tolerant towards illegal codes - * that are < 0 or > 6 in that it will return the corresponding - * values for codes 0 or 6 respectively. + * This method is tolerant towards illegal codes that are < 0 or + * > 6 in that it will return the corresponding values for codes 0 or 6 + * respectively. * * @param szx The code. * @return The corresponding number of bytes. diff --git a/californium-core/src/main/java/org/eclipse/californium/core/coap/ClientObserveRelation.java b/californium-core/src/main/java/org/eclipse/californium/core/coap/ClientObserveRelation.java index f75eab2a5b..9a7d30055f 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/coap/ClientObserveRelation.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/coap/ClientObserveRelation.java @@ -13,6 +13,8 @@ * Contributors: * Bosch IO.GmbH - initial implementation, * mainly copied from CoapObserveRelation + * Rogier Cobben - added confirmable flag and methods to control + * the type of reregister and cancel requests. ******************************************************************************/ package org.eclipse.californium.core.coap; @@ -49,9 +51,26 @@ public class ClientObserveRelation { /** The endpoint. */ protected final Endpoint endpoint; + /** + * The orderer. + * + * Only used for UDP, {@code null} for TCP. + * + * @see RFC8323, 7.1. Notifications and Reordering + */ + private final ObserveNotificationOrderer orderer; + /** The re-registration backoff duration [ms]. */ private final long reregistrationBackoffMillis; + /** + * Indicate transport over TCP. + * + * @since 3.8 + */ + protected final boolean tcp; + /** * Indicates, that an observe request or a (proactive) cancel observe * request is pending. @@ -72,12 +91,16 @@ public class ClientObserveRelation { /** Indicates whether a proactive cancel request is pending. */ private volatile boolean proactiveCancel = false; + /** + * Indicates whether reregister and cancel requests are sent confirmable. + * + * @since 3.8 + */ + private volatile boolean confirmable; + /** The current notification. */ private volatile Response current = null; - /** The orderer. */ - private volatile ObserveNotificationOrderer orderer; - /** * Task to schedule {@link CoapObserveRelation#reregister()}. */ @@ -127,8 +150,10 @@ private void next() { */ public ClientObserveRelation(Request request, Endpoint endpoint, ScheduledThreadPoolExecutor executor) { this.request = request; + this.confirmable = request.isConfirmable(); + this.tcp = CoAP.isTcpScheme(request.getScheme()); this.endpoint = endpoint; - this.orderer = new ObserveNotificationOrderer(); + this.orderer = tcp ? null : new ObserveNotificationOrderer(); this.reregistrationBackoffMillis = endpoint.getConfig().get(CoapConfig.NOTIFICATION_REREGISTRATION_BACKOFF, TimeUnit.MILLISECONDS); this.scheduler = executor; @@ -136,6 +161,29 @@ public ClientObserveRelation(Request request, Endpoint endpoint, ScheduledThread this.request.setProtectFromOffload(); } + /** + * Checks if the relation is reregistered and cancelled confirmable or + * non-confirmable. + * + * @return {@code true}, if the relation is reregistered and cancelled + * confirmable. + * @since 3.8 + */ + public boolean isConfirmable() { + return confirmable; + } + + /** + * Set the relation reregister and cancel message type. + * + * @param confirmable when {@code true} reregister and cancel requests are + * sent confirmable, non-confirmable otherwise. + * @since 3.8 + */ + public void setConfirmable(boolean confirmable) { + this.confirmable = confirmable; + } + /** * Refreshes the Observe relationship with a new GET request with same token * and options. The method also resets the notification orderer, since the @@ -161,6 +209,7 @@ public boolean reregister() { } if (requestPending.compareAndSet(false, true)) { Request refresh = Request.newGet(); + refresh.setConfirmable(confirmable); EndpointContext destinationContext = response != null ? response.getSourceContext() : request.getDestinationContext(); refresh.setDestinationContext(destinationContext); @@ -168,6 +217,8 @@ public boolean reregister() { refresh.setToken(request.getToken()); // copy options refresh.setOptions(request.getOptions()); + // same scheme + refresh.setScheme(request.getScheme()); refresh.setMaxResourceBodySize(request.getMaxResourceBodySize()); if (request.isUnintendedPayload()) { @@ -188,7 +239,9 @@ public boolean reregister() { // update request in observe handle for correct cancellation // reset orderer to accept any sequence number since server // might have rebooted - this.orderer = new ObserveNotificationOrderer(); + if (this.orderer != null) { + this.orderer.reset(); + } endpoint.sendRequest(refresh); @@ -209,11 +262,14 @@ private void sendCancelObserve() { : request.getDestinationContext(); Request cancel = Request.newGet(); + cancel.setConfirmable(confirmable); cancel.setDestinationContext(destinationContext); // use same Token cancel.setToken(request.getToken()); // copy options cancel.setOptions(request.getOptions()); + // same scheme + cancel.setScheme(request.getScheme()); // set Observe to cancel cancel.setObserveCancel(); @@ -250,7 +306,7 @@ private void cancel() { /** * Marks this relation as canceled. * - * @param canceled true if this relation has been canceled + * @param canceled {@code true} if this relation has been canceled */ protected void setCanceled(boolean canceled) { this.canceled.set(canceled); @@ -282,7 +338,7 @@ public void proactiveCancel() { */ public void reactiveCancel() { Request request = this.request; - if (CoAP.isTcpScheme(request.getScheme())) { + if (tcp) { LOGGER.info("change to cancel the observe {} proactive over TCP.", request.getTokenString()); proactiveCancel(); } else if (this.canceled.compareAndSet(false, true)) { @@ -295,7 +351,7 @@ public void reactiveCancel() { /** * Checks if the relation has been canceled. * - * @return true, if the relation has been canceled + * @return {@code true}, if the relation has been canceled */ public boolean isCanceled() { return canceled.get(); @@ -313,7 +369,8 @@ public Response getCurrentResponse() { /** * Sets the current response or notification. * - * Use {@link #orderer} to filter deprecated responses. + * Use {@link #orderer} to filter deprecated responses over UDP. + * Responses over TCP are already in order. * * @param response the response or notification * @return {@code true}, response is accepted by {@link #orderer}, @@ -325,14 +382,17 @@ public boolean onResponse(Response response) { Integer observe = response.getOptions().getObserve(); // check, if observation is still ongoing boolean prepareNext = observe != null && !isCanceled(); - isNew = orderer.isNew(response); + // RFC8323, 7.1. Notifications and Reordering + // For TCP, the observe option may be empty, + // and MUST be ignored + isNew = orderer == null || orderer.isNew(response); if (isNew) { current = response; LOGGER.debug("Updated with {}", response); } else if (prepareNext) { // renew preparation also for reregistration responses, // which may still be unchanged - prepareNext = orderer.getCurrent() == observe; + prepareNext = orderer == null || orderer.getCurrent() == observe; } if (prepareNext) { prepareReregistration(response); @@ -351,7 +411,11 @@ public boolean onResponse(Response response) { * @return {@code true}, if matched, {@code false}, if not. */ public boolean matchRequest(Request request) { - return this.request.getToken().equals(request.getToken()); + // the client observe relation is created + // before the token is assigned sending the + // request. + Token token = this.request.getToken(); + return token != null && token.equals(request.getToken()); } private void setReregistrationHandle(ScheduledFuture reregistrationHandle) { diff --git a/californium-core/src/main/java/org/eclipse/californium/core/coap/NoResponseOption.java b/californium-core/src/main/java/org/eclipse/californium/core/coap/NoResponseOption.java index 4668fae407..6d7a43db16 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/coap/NoResponseOption.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/coap/NoResponseOption.java @@ -16,6 +16,7 @@ package org.eclipse.californium.core.coap; import org.eclipse.californium.core.coap.CoAP.CodeClass; +import org.eclipse.californium.core.coap.option.StandardOptionRegistry; import org.eclipse.californium.elements.util.Bytes; /** @@ -150,7 +151,7 @@ public boolean suppress(CoAP.ResponseCode code) { * @return generic option. */ public Option toOption() { - return new Option(OptionNumberRegistry.NO_RESPONSE, getValue()); + return StandardOptionRegistry.NO_RESPONSE.create(getValue()); } @Override diff --git a/californium-core/src/main/java/org/eclipse/californium/core/coap/Option.java b/californium-core/src/main/java/org/eclipse/californium/core/coap/Option.java index 079b3d4ac3..ce76430ecd 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/coap/Option.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/coap/Option.java @@ -24,14 +24,22 @@ import java.util.Arrays; +import org.eclipse.californium.core.coap.option.EmptyOptionDefinition; +import org.eclipse.californium.core.coap.option.IntegerOptionDefinition; +import org.eclipse.californium.core.coap.option.OpaqueOptionDefinition; +import org.eclipse.californium.core.coap.option.OptionDefinition; +import org.eclipse.californium.core.coap.option.StandardOptionRegistry; +import org.eclipse.californium.core.coap.option.StringOptionDefinition; import org.eclipse.californium.elements.util.Bytes; import org.eclipse.californium.elements.util.StringUtil; /** - * Both requests and responses may include a list of one or more options. An - * Option number is constructed with a bit mask to indicate if an option is + * Both requests and responses may include a list of one or more options. + * + * An option number is constructed with a bit mask to indicate if an option is * Critical/Elective, Unsafe/Safe and in the case of Safe, also a Cache-Key - * indication. + * indication. See RFC7252 5.4.6. Option Numbers. * *


  *   0   1   2   3   4   5   6   7
@@ -48,37 +56,57 @@
  * NoCacheKey = ((onum & 0x1e) == 0x1c);
  * 

* - * {@code CoAP} defines several option numbers detailed in {@link OptionNumberRegistry}. + * {@code CoAP} defines several option numbers detailed in + * {@link OptionNumberRegistry}. *

- * Class variables {@code number} and {@code value} directly maps to {@code CoAP} request - * and response options as is. In {@code CoAP} specification {@code number} is - * an option header key as {@code int} and {@code value} is represented as - * a raw byte array {@code byte[]}. User must be careful when using {@code value} directly - * as depending on actual option, {@code value} may be {@code empty}, {@code opaque}, - * {@code uint} or {@code string}. For example, for {@code uint} the number 0 is represented - * with an empty option value (a zero-length sequence of bytes) and the number 1 by a single - * byte with the numerical value of 1 (bit combination 00000001 in most significant bit first - * notation). A recipient MUST be prepared to process values with leading zero bytes. + * Class variables {@code number} and {@code value} directly maps to + * {@code CoAP} request and response options as is. In {@code CoAP} + * specification {@code number} is an option header key as {@code int} and + * {@code value} is represented as a raw byte array {@code byte[]}. User must be + * careful when using {@code value} directly as depending on actual option, + * {@code value} may be {@code empty}, {@code opaque}, {@code uint} or + * {@code string}. For example, for {@code uint} the number 0 is represented + * with an empty option value (a zero-length sequence of bytes) and the number 1 + * by a single byte with the numerical value of 1 (bit combination 00000001 in + * most significant bit first notation). A recipient MUST be prepared to process + * values with leading zero bytes. *

* {@code Option} has helper methods, namely {@link #getIntegerValue()} and * {@link #toValueString()} taking into account actual option type and how it * may be represented in a native {@code value}. + * + * Since 3.8 {@link OptionDefinition} is introduced and is the preferred and + * future way to specify, which option is represented. The option number on it's + * own represents this only for the traditional options, but options introduced + * with RFC8323 5.2. Signaling Option Numbers dependent also on the + * message code. + * + *

+ * 
+ *   Option maxAge = StandardOptionRegistry.MAX_AGE.create(10);
+ * 
+ * 
* * @see OptionSet */ public class Option implements Comparable