-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#3503] Enable clients requesting server time in CoAP responses
Added support for letting CoAP devices indicate to the CoAP adapter to include the adapter's local system time in its CoAP response. For this purpose the device needs to either include the (non-standard) "Time" option in its request or include the "hono-time" request parameter. The adapter will then include its local system time in the response's Time option. Also added integration tests verifying the behavior. Signed-off-by: Stefan Freyr Stefansson <[email protected]>
- Loading branch information
Showing
9 changed files
with
389 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
adapters/coap/src/main/java/org/eclipse/hono/adapter/coap/option/TimeOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.eclipse.hono.adapter.coap.option; | ||
|
||
import org.eclipse.californium.core.coap.Option; | ||
|
||
/** | ||
* CoAP custom time option. | ||
* <p> | ||
* Used in CoAP request to indicate that the client wants to get the servers system-time in milliseconds. | ||
* Any value in the option as part of a request is ignored. | ||
* <p> | ||
* If the option is present in a request, the server adds also a time option to the response with the | ||
* servers system-time in milliseconds. Also, a client can request this option be included in a response via the | ||
* {@value #QUERY_PARAMETER_NAME} request parameter. | ||
* <p> | ||
* This option uses the same option number as is used in the Californium cloud-demo-server application | ||
* (<a href="https://github.com/boaks/californium/blob/add_cloud_demo_server/demo-apps/cf-cloud-demo-server/src/main/java/org/eclipse/californium/cloud/option/TimeOption.java#L49">see here</a>). | ||
* TODO: update link once it's been merged into the eclipse-californium project. | ||
*/ | ||
public final class TimeOption extends Option { | ||
|
||
/** | ||
* The COAP option number. | ||
* <p> | ||
* <b>NOTE:</b> this option number is in the "experimental" range and as such is not suitable for | ||
* interoperability with other CoAP implementations. This implementation should be changed if CoAP ever | ||
* defines its own official option number for reporting server time. | ||
* <p> | ||
* For further information and discussion, see: | ||
* <ul> | ||
* <li> <a href="https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#option-numbers">IANA CoAP Option Numbers</a> </li> | ||
* <li> <a href="https://github.com/eclipse-californium/californium/issues/2134">Question about server time reporting in Californium</a> </li> | ||
* <li> <a href="https://github.com/eclipse-hono/hono/issues/3502">Issue for adding a time option to Hono</a> </li> | ||
* <li> <a href="https://github.com/eclipse-hono/hono/pull/3503">Pull request for adding a time option to Hono</a> </li> | ||
* </ul> | ||
*/ | ||
public static final int NUMBER = 0xfde8; | ||
|
||
/** | ||
* The request parameter name clients should use to request the server <em>time</em> be sent back as part of the | ||
* response (as a time option). | ||
*/ | ||
public static final String QUERY_PARAMETER_NAME = "hono-time"; | ||
|
||
/** | ||
* Create time option with current system time. | ||
*/ | ||
public TimeOption() { | ||
super(NUMBER, System.currentTimeMillis()); | ||
} | ||
|
||
/** | ||
* Create time option. | ||
* | ||
* @param time time in system milliseconds. | ||
*/ | ||
public TimeOption(final long time) { | ||
super(NUMBER, time); | ||
} | ||
|
||
/** | ||
* Create time option. | ||
* | ||
* @param value time in system milliseconds as byte array. | ||
*/ | ||
public TimeOption(final byte[] value) { | ||
super(NUMBER, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.