Skip to content

Commit

Permalink
Redesign configuration.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@bosch.io>
  • Loading branch information
Achim Kraus committed Jul 19, 2021
1 parent 9f06e79 commit 7b426f3
Show file tree
Hide file tree
Showing 230 changed files with 9,008 additions and 6,952 deletions.
4 changes: 4 additions & 0 deletions MIGRATION_HINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Since 3.0 the sub-class may be ignored, depending on the provided value of the `

The IPv6-scope-separator "%" is replaced by the URL-encoded form "%25" (also fixed in 2.6.4).

`DtlsEndpointContext.KEY_RESUMPTION_TIMEOUT` is renamed into `DtlsEndpointContext.KEY_AUTO_HANDSHAKE_TIMEOUT`. The key's value is adjusted as well. The feature not only supports abbreviated handshakes, it also starts full handshakes, if the session is not able to be resumed.

### Scandium:

Redesigned! May cause also unaware changes! If you detect one, please create an issue on
Expand Down Expand Up @@ -194,6 +196,8 @@ are removed and must be replaced by

13) Removed `CoapResource.createClient(???)`. Though `Resource.getExecutor()` may return `null`, it depends on the implementation of the `Resource` not to return `null`, but that changes other executions. Therefore implement `createClient(???)` for the specific `Resources` and provide the executors there.

14) Removed `CoapEndpoint.Builder.setConnectorWithAutoConfiguration(UDPConnector)`. `Configuration` must now be provided to the Connector's constructors.

### Californium-Proxy2:

1) Update to http-client 5.0.3 and http-core 5.0.2. The apache http-components are not encapsulated. Therefore this update causes several API changes, where these classes are used. Please consider the migration information on the [apache http-components web-page](https://hc.apache.org/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.californium.elements.exception.ConnectorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.eclipse.californium.core.coap.BlockOption;
import org.eclipse.californium.core.coap.CoAP;
import org.eclipse.californium.core.coap.CoAP.Type;
import org.eclipse.californium.core.config.CoapConfig;
import org.eclipse.californium.core.coap.LinkFormat;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.eclipse.californium.core.coap.MessageObserver;
Expand All @@ -69,11 +67,13 @@
import org.eclipse.californium.core.coap.Token;
import org.eclipse.californium.core.network.Endpoint;
import org.eclipse.californium.core.network.EndpointManager;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.core.observe.NotificationListener;
import org.eclipse.californium.elements.EndpointContext;
import org.eclipse.californium.elements.exception.ConnectorException;
import org.eclipse.californium.elements.util.ExecutorsUtil;
import org.eclipse.californium.elements.util.NamedThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The Class CoapClient.
Expand Down Expand Up @@ -179,9 +179,8 @@ public CoapClient(String scheme, String host, int port, String... path) {
* Gets the maximum amount of time that synchronous method calls will block
* and wait.
* <p>
* If this property is {@code null}, the value is from configuration property
* {@link org.eclipse.californium.core.network.config.NetworkConfig.Keys#EXCHANGE_LIFETIME}
* of the effective endpoint.
* If this property is {@code null}, the value is from configuration
* property {@link CoapConfig#EXCHANGE_LIFETIME} of the effective endpoint.
*
* @return The timeout in milliseconds, or {@code null}.
*/
Expand All @@ -195,9 +194,7 @@ public Long getTimeout() {
* infinitely.
* <p>
* If this property is {@code null}, the value is from configuration
* property
* {@link org.eclipse.californium.core.network.config.NetworkConfig.Keys#EXCHANGE_LIFETIME}
* of the effective endpoint.
* property {@link CoapConfig#EXCHANGE_LIFETIME} of the effective endpoint.
* <p>
* Under normal circumstances this property should be set to at least the
* <em>EXCHANGE_LIFETIME</em> (the default) in order to account for
Expand Down Expand Up @@ -515,7 +512,7 @@ private boolean ping(Long timeout) {
assignClientUriIfEmpty(request);
Endpoint outEndpoint = getEffectiveEndpoint(request);
if (timeout == null) {
timeout = outEndpoint.getConfig().getLong(NetworkConfig.Keys.EXCHANGE_LIFETIME);
timeout = outEndpoint.getConfig().get(CoapConfig.EXCHANGE_LIFETIME, TimeUnit.MILLISECONDS);
}
send(request, outEndpoint).waitForResponse(timeout);
return request.isRejected();
Expand Down Expand Up @@ -1177,7 +1174,7 @@ private CoapResponse synchronous(Request request, Endpoint outEndpoint) throws C
try {
Long timeout = getTimeout();
if (timeout == null) {
timeout = outEndpoint.getConfig().getLong(NetworkConfig.Keys.EXCHANGE_LIFETIME);
timeout = outEndpoint.getConfig().get(CoapConfig.EXCHANGE_LIFETIME, TimeUnit.MILLISECONDS);
}
Response response = send(request, outEndpoint).waitForResponse(timeout);
if (response == null) {
Expand Down Expand Up @@ -1593,6 +1590,7 @@ private class ObserveMessageObserverImpl extends MessageObserverImpl {
* specified relation.
*
* @param handler the Response handler
* @param multicast {@code true}, for multicast requests, {@code false}, otherwise.
* @param relation the Observe relation
*/
public ObserveMessageObserverImpl(CoapHandler handler, boolean multicast, CoapObserveRelation relation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.eclipse.californium.core.coap.CoAP.ResponseCode;
import org.eclipse.californium.core.config.CoapConfig;
import org.eclipse.californium.core.network.CoapEndpoint;
import org.eclipse.californium.core.network.Endpoint;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.core.server.MessageDeliverer;
import org.eclipse.californium.core.server.ServerInterface;
import org.eclipse.californium.core.server.ServerMessageDeliverer;
Expand All @@ -52,13 +49,16 @@
import org.eclipse.californium.core.server.resources.Resource;
import org.eclipse.californium.elements.Connector;
import org.eclipse.californium.elements.PersistentConnector;
import org.eclipse.californium.elements.config.Configuration;
import org.eclipse.californium.elements.util.DataStreamReader;
import org.eclipse.californium.elements.util.DatagramWriter;
import org.eclipse.californium.elements.util.ExecutorsUtil;
import org.eclipse.californium.elements.util.NamedThreadFactory;
import org.eclipse.californium.elements.util.SerializationUtil;
import org.eclipse.californium.elements.util.StringUtil;
import org.eclipse.californium.elements.util.WipAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An execution environment for CoAP {@link Resource}s.
Expand Down Expand Up @@ -122,8 +122,8 @@ public class CoapServer implements ServerInterface {
/** The root resource. */
private final Resource root;

/** The network configuration used by this server. */
private final NetworkConfig config;
/** The configuration used by this server. */
private final Configuration config;

/** The message deliverer. */
private MessageDeliverer deliverer;
Expand Down Expand Up @@ -152,7 +152,7 @@ public class CoapServer implements ServerInterface {
* assigned, it will bind to CoAP's default port 5683.
*/
public CoapServer() {
this(NetworkConfig.getStandard());
this(Configuration.getStandard());
}

/**
Expand All @@ -164,25 +164,26 @@ public CoapServer() {
* will bind to CoAP's default port 5683 on {@link #start()}.
*/
public CoapServer(final int... ports) {
this(NetworkConfig.getStandard(), ports);
this(Configuration.getStandard(), ports);
}

/**
* Constructs a server with the specified configuration that listens to the
* specified ports after method {@link #start()} is called.
*
* @param config the configuration, if {@code null} the configuration
* returned by {@link NetworkConfig#getStandard()} is used.
* returned by {@link Configuration#getStandard()} is used.
* @param ports the ports to bind to. If empty or {@code null} and no
* endpoints are added with {@link #addEndpoint(Endpoint)}, it
* will bind to CoAP's default port 5683 on {@link #start()}.
* @since 3.0 (changed parameter to Configuration)
*/
public CoapServer(final NetworkConfig config, final int... ports) {
public CoapServer(final Configuration config, final int... ports) {
// global configuration that is passed down (can be observed for changes)
if (config != null) {
this.config = config;
} else {
this.config = NetworkConfig.getStandard();
this.config = Configuration.getStandard();
}
setTag(null);
// resources
Expand All @@ -201,7 +202,7 @@ public CoapServer(final NetworkConfig config, final int... ports) {
for (int port : ports) {
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setPort(port);
builder.setNetworkConfig(config);
builder.setConfiguration(config);
addEndpoint(builder.build());
}
}
Expand Down Expand Up @@ -258,18 +259,18 @@ public synchronized void start() {
// sets the central thread pool for the protocol stage over all
// endpoints
setExecutors(ExecutorsUtil.newScheduledThreadPool(//
this.config.getInt(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT),
this.config.get(CoapConfig.PROTOCOL_STAGE_THREAD_COUNT),
new NamedThreadFactory("CoapServer(main)#")), //$NON-NLS-1$
ExecutorsUtil.newDefaultSecondaryScheduler("CoapServer(secondary)#"), false);
}

if (endpoints.isEmpty()) {
// servers should bind to the configured port (while clients should use an ephemeral port through the default endpoint)
int port = config.getInt(NetworkConfig.Keys.COAP_PORT);
int port = config.get(CoapConfig.COAP_PORT);
LOGGER.info("{}no endpoints have been defined for server, setting up server endpoint on default port {}", getTag(), port);
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setPort(port);
builder.setNetworkConfig(config);
builder.setConfiguration(config);
addEndpoint(builder.build());
}

Expand Down Expand Up @@ -602,12 +603,12 @@ public Resource getRoot() {
}

/**
* Get the network configuration of this server.
* Get the configuration of this server.
*
* @return the network configuration
* @since 2.1
* @return the configuration
* @since 3.0 (changed return type to Configuration)
*/
public NetworkConfig getConfig() {
public Configuration getConfig() {
return config;
}

Expand All @@ -630,7 +631,6 @@ private class RootResource extends CoapResource {

public RootResource() {
super("");
String nodeId = config.getString(NetworkConfig.Keys.DTLS_CONNECTION_ID_NODE_ID);
String title = "CoAP RFC 7252";
if (StringUtil.CALIFORNIUM_VERSION != null) {
String version = "Cf " + StringUtil.CALIFORNIUM_VERSION;
Expand All @@ -642,10 +642,7 @@ public RootResource() {
.append("****************************************************************\n")
.append("This server is using the Eclipse Californium (Cf) CoAP framework\n")
.append("published under EPL+EDL: http://www.eclipse.org/californium/\n\n");
if (nodeId != null && !nodeId.isEmpty()) {
builder.append("node id = ").append(nodeId).append("\n\n");
}
builder.append("(c) 2014-2020 Institute for Pervasive Computing, ETH Zurich and others\n");
builder.append("(c) 2014-2021 Institute for Pervasive Computing, ETH Zurich and others\n");
String master = StringUtil.getConfiguration("COAP_ROOT_RESOURCE_FOOTER");
if (master != null) {
builder.append(master).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.californium.core.CoapObserveRelation;
import org.eclipse.californium.core.config.CoapConfig;
import org.eclipse.californium.core.network.Endpoint;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.core.observe.ObserveNotificationOrderer;
import org.eclipse.californium.elements.EndpointContext;
import org.slf4j.Logger;
Expand Down Expand Up @@ -129,7 +130,7 @@ public ClientObserveRelation(Request request, Endpoint endpoint, ScheduledThread
this.endpoint = endpoint;
this.orderer = new ObserveNotificationOrderer();
this.reregistrationBackoffMillis = endpoint.getConfig()
.getLong(NetworkConfig.Keys.NOTIFICATION_REREGISTRATION_BACKOFF);
.get(CoapConfig.NOTIFICATION_REREGISTRATION_BACKOFF, TimeUnit.MILLISECONDS);
this.scheduler = executor;
this.request.addMessageObserver(pendingRequestObserver);
this.request.setProtectFromOffload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.eclipse.californium.core.Utils;
import org.eclipse.californium.core.coap.CoAP.Type;
import org.eclipse.californium.core.config.CoapConfig;
import org.eclipse.californium.core.network.TokenGenerator;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.eclipse.californium.core.network.config.NetworkConfig.Keys;
import org.eclipse.californium.core.network.stack.ReliabilityLayerParameters;
import org.eclipse.californium.core.observe.ObserveManager;
import org.eclipse.californium.elements.EndpointContext;
import org.eclipse.californium.elements.EndpointContextUtil;
import org.eclipse.californium.elements.config.Configuration;
import org.eclipse.californium.elements.util.Bytes;
import org.eclipse.californium.elements.util.ClockUtil;
import org.eclipse.californium.elements.util.NetworkInterfacesUtil;
import org.eclipse.californium.elements.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The class Message models the base class of all CoAP messages. CoAP messages
Expand Down Expand Up @@ -158,7 +158,7 @@ public enum OffloadMode {

/**
* Message specific parameter. Overwrites then general ones from
* {@link NetworkConfig}.
* {@link Configuration}.
*/
private volatile ReliabilityLayerParameters parameters;

Expand Down Expand Up @@ -578,8 +578,8 @@ public Message setOptions(OptionSet options) {
* outgoing requests, this limits the size of the response.
*
* @return maximum resource body size. {@code 0} to use the
* {@link NetworkConfig} value of
* {@link Keys#MAX_RESOURCE_BODY_SIZE}.
* {@link Configuration} value of
* {@link CoapConfig#MAX_RESOURCE_BODY_SIZE}.
* @since 2.3
*/
public int getMaxResourceBodySize() {
Expand All @@ -593,8 +593,8 @@ public int getMaxResourceBodySize() {
* outgoing requests, this limits the size of the response.
*
* @param maxResourceBodySize maximum resource body size. {@code 0} or
* default is defined by the {@link NetworkConfig} value of
* {@link Keys#MAX_RESOURCE_BODY_SIZE}.
* default is defined by the {@link Configuration} value of
* {@link CoapConfig#MAX_RESOURCE_BODY_SIZE}.
* @since 2.3
*/
public void setMaxResourceBodySize(int maxResourceBodySize) {
Expand Down Expand Up @@ -1287,12 +1287,12 @@ public void retransmitting() {
* heap usage, when message is kept for deduplication.
*
* The server-side offloads message when sending the first response when
* {@link Keys#USE_MESSAGE_OFFLOADING} is enabled. Requests are
* {@link CoapConfig#USE_MESSAGE_OFFLOADING} is enabled. Requests are
* {@link OffloadMode#FULL} offloaded, responses are
* {@link OffloadMode#PAYLOAD} offloaded.
*
* A client-side may also chose to offload requests and responses based on
* {@link Keys#USE_MESSAGE_OFFLOADING}, when the request and responses are
* {@link CoapConfig#USE_MESSAGE_OFFLOADING}, when the request and responses are
* not longer used by the client.
*
* For messages with {@link #setProtectFromOffload()}, offloading is
Expand Down Expand Up @@ -1420,6 +1420,8 @@ public void removeMessageObserver(final MessageObserver observer) {
/**
* Get list of {@link MessageObserver}. If not already defined, create a new
* one. This method is thread-safe and creates exactly one list.
*
* @return list of {@link MessageObserver}
*/
private List<MessageObserver> ensureMessageObserverList() {
List<MessageObserver> list = messageObservers.get();
Expand Down
Loading

0 comments on commit 7b426f3

Please sign in to comment.