diff --git a/californium-core/api-changes.json b/californium-core/api-changes.json index 460c5c98fa..6e29c6998e 100644 --- a/californium-core/api-changes.json +++ b/californium-core/api-changes.json @@ -42,6 +42,65 @@ "new": "method void org.eclipse.californium.core.network.stack.BlockwiseStatus::addBlock(byte[], int) throws org.eclipse.californium.core.network.stack.BlockwiseTransferException", "justification": "Internal API" } + ] + } + } + ], + "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" + } + + ] } } diff --git a/californium-core/src/main/java/org/eclipse/californium/core/config/CoapConfig.java b/californium-core/src/main/java/org/eclipse/californium/core/config/CoapConfig.java index 3ffaad9f3f..48df20da7c 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/config/CoapConfig.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/config/CoapConfig.java @@ -32,6 +32,7 @@ import org.eclipse.californium.core.network.deduplication.SweepPerPeerDeduplicator; import org.eclipse.californium.core.network.stack.KeyUri; import org.eclipse.californium.core.observe.ObserveRelation; +import org.eclipse.californium.elements.EndpointIdentityResolver; import org.eclipse.californium.elements.config.BooleanDefinition; import org.eclipse.californium.elements.config.Configuration; import org.eclipse.californium.elements.config.Configuration.ModuleDefinitionsProvider; @@ -689,6 +690,24 @@ public enum CongestionControlMode { MODULE + "CONGESTION_CONTROL_ALGORITHM", "Congestion-Control algorithm (still experimental).", CongestionControlMode.NULL, CongestionControlMode.values()); + /** + * Force congestion control algorithm to use inet-address instead of remote + * peer's identity. + * + * The {@link EndpointIdentityResolver} enables Californium to use a + * different remote identity instead of the inet-address to process states. + * For congestion control that may result in less good results, if an + * inet-address change, maybe caused by a NAT, also causes the quality of + * the ip-route. + * + * @since 3.8 + */ + public static final BooleanDefinition CONGESTION_CONTROL_USE_INET_ADDRESS = new BooleanDefinition( + MODULE + "CONGESTION_CONTROL_USE_INET_ADDRESS", + "Use inet-address for congestion control, even if an other peer identity is used." + + " Enable, if NAT changes are also changing the quality of the ip-route.", + false); + /** * Number of threads to process coap-exchanges. */ diff --git a/californium-core/src/main/java/org/eclipse/californium/core/network/Exchange.java b/californium-core/src/main/java/org/eclipse/californium/core/network/Exchange.java index 459c07f408..0187ee4105 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/network/Exchange.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/network/Exchange.java @@ -79,6 +79,7 @@ import org.eclipse.californium.core.server.resources.CoapExchange; import org.eclipse.californium.elements.Connector; import org.eclipse.californium.elements.EndpointContext; +import org.eclipse.californium.elements.EndpointIdentityResolver; import org.eclipse.californium.elements.UdpMulticastConnector; import org.eclipse.californium.elements.util.ClockUtil; import org.eclipse.californium.elements.util.SerialExecutor; @@ -339,6 +340,7 @@ public enum Origin { * @param origin the origin of the request (LOCAL or REMOTE) * @param executor executor to be used for exchanges. * @throws NullPointerException if request or executor is {@code null} + * @see EndpointIdentityResolver * @since 3.0 (added peersIdentity, executor adapted to mandatory) */ public Exchange(Request request, Object peersIdentity, Origin origin, Executor executor) { @@ -358,6 +360,7 @@ public Exchange(Request request, Object peersIdentity, Origin origin, Executor e * @param notification {@code true} for notification exchange, {@code false} * otherwise * @throws NullPointerException if request or executor is {@code null} + * @see EndpointIdentityResolver * @since 3.0 (added peersIdentity, executor adapted to mandatory) */ public Exchange(Request request, Object peersIdentity, Origin origin, Executor executor, EndpointContext ctx, boolean notification) { @@ -808,6 +811,7 @@ public void setEndpoint(Endpoint endpoint) { * Returns the other peer's identity. * * @return the other peer's identity + * @see EndpointIdentityResolver * @since 3.0 */ public Object getPeersIdentity() { diff --git a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/CongestionControlLayer.java b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/CongestionControlLayer.java index 47ddb8276c..a37c080e50 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/CongestionControlLayer.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/CongestionControlLayer.java @@ -44,6 +44,7 @@ import org.eclipse.californium.core.network.stack.congestioncontrol.LinuxRto; import org.eclipse.californium.core.network.stack.congestioncontrol.PeakhopperRto; import org.eclipse.californium.core.observe.ObserveRelation; +import org.eclipse.californium.elements.EndpointIdentityResolver; import org.eclipse.californium.elements.config.Configuration; import org.eclipse.californium.elements.util.LeastRecentlyUsedCache; @@ -124,7 +125,7 @@ public abstract class CongestionControlLayer extends ReliabilityLayer { private final static int MAX_RTO = 60000; /** The map of remote endpoints */ - private LeastRecentlyUsedCache remoteEndpoints; + private LeastRecentlyUsedCache remoteEndpoints; /** The configuration */ protected final Configuration config; @@ -134,6 +135,14 @@ public abstract class CongestionControlLayer extends ReliabilityLayer { */ protected final String tag; + /** + * Use inet-address for congestion control. + * + * @see CoapConfig#CONGESTION_CONTROL_USE_INET_ADDRESS + * @since 3.8 + */ + private final boolean useInetSocketAddress; + // In CoAP, dithering is applied to the initial RTO of a transmission; // set to true to apply dithering private boolean appliesDithering; @@ -156,6 +165,7 @@ public CongestionControlLayer(String tag, Configuration config) { this.remoteEndpoints = new LeastRecentlyUsedCache<>(config.get(CoapConfig.MAX_ACTIVE_PEERS), config.get(CoapConfig.MAX_PEER_INACTIVITY_PERIOD, TimeUnit.SECONDS)); this.remoteEndpoints.setEvictingOnReadAccess(false); + this.useInetSocketAddress = config.get(CoapConfig.CONGESTION_CONTROL_USE_INET_ADDRESS); setDithering(false); } @@ -181,10 +191,13 @@ public void destroy() { /** * Create new, algorithm specific remote endpoint. * - * @param remoteSocketAddress peer to create the endpoint for. + * @param peersIdentity peer's identity. Usually that's the peer's + * {@link InetSocketAddress}. * @return create endpoint. + * @see EndpointIdentityResolver + * @since 3.8 (exchanged InetSocketAddress to Object) */ - protected abstract RemoteEndpoint createRemoteEndpoint(InetSocketAddress remoteSocketAddress); + protected abstract RemoteEndpoint createRemoteEndpoint(Object peersIdentity); /** * Get remote endpoint. @@ -193,15 +206,21 @@ public void destroy() { * * @param exchange to get the endpoint for * @return endpoint for exchange. - * @see #createRemoteEndpoint(InetSocketAddress) + * @see #createRemoteEndpoint(Object) + * @see #useInetSocketAddress */ protected RemoteEndpoint getRemoteEndpoint(Exchange exchange) { - InetSocketAddress remoteSocketAddress = exchange.getRemoteSocketAddress(); + Object peersIdentity; + if (useInetSocketAddress) { + peersIdentity = exchange.getRemoteSocketAddress(); + } else { + peersIdentity = exchange.getPeersIdentity(); + } synchronized (remoteEndpoints) { - RemoteEndpoint remoteEndpoint = remoteEndpoints.get(remoteSocketAddress); + RemoteEndpoint remoteEndpoint = remoteEndpoints.get(peersIdentity); if (remoteEndpoint == null) { - remoteEndpoint = createRemoteEndpoint(remoteSocketAddress); - remoteEndpoints.put(remoteSocketAddress, remoteEndpoint); + remoteEndpoint = createRemoteEndpoint(peersIdentity); + remoteEndpoints.put(peersIdentity, remoteEndpoint); } return remoteEndpoint; } diff --git a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/RemoteEndpoint.java b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/RemoteEndpoint.java index 0ecfdba02c..5e1e25030d 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/RemoteEndpoint.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/RemoteEndpoint.java @@ -26,6 +26,7 @@ import org.eclipse.californium.core.network.Exchange; import org.eclipse.californium.core.network.stack.CongestionControlLayer.PostponedExchange; import org.eclipse.californium.core.network.stack.congestioncontrol.Cocoa; +import org.eclipse.californium.elements.EndpointIdentityResolver; /** * An abstract class representing the current transmissions and parameters for a @@ -59,9 +60,11 @@ public enum RtoType { } /** - * Inet socket address of remote endpoint. + * The identity of the remote endpoint. + * @see + * @since 3.8 */ - private final InetSocketAddress remoteAddress; + private final Object peersIdentity; /** * Maximum number of concurrent transmissions. */ @@ -105,8 +108,21 @@ public enum RtoType { */ protected long meanOverallRTO; - public RemoteEndpoint(InetSocketAddress remoteAddress, int ackTimeout, int nstart, boolean usesBlindEstimator) { - this.remoteAddress = remoteAddress; + /** + * Create a remote endpoint. + * + * @param peersIdentity peer's identity. Usually that's the peer's + * {@link InetSocketAddress}. + * @param ackTimeout ACK timeout + * @param nstart NSTARt + * @param usesBlindEstimator {@code true}, if blind estimator is used. A + * blind estimation is based on pending exchanges until these + * changes are completed. + * @see EndpointIdentityResolver + * @since 3.8 (exchanged InetSocketAddress to Object) + */ + public RemoteEndpoint(Object peersIdentity, int ackTimeout, int nstart, boolean usesBlindEstimator) { + this.peersIdentity = peersIdentity; this.nstart = nstart; this.usesBlindEstimator = usesBlindEstimator; // Fill Array with initial values @@ -132,8 +148,8 @@ public RemoteEndpoint(InetSocketAddress remoteAddress, int ackTimeout, int nstar * * @return address of remote endpoint */ - public InetSocketAddress getRemoteAddress() { - return remoteAddress; + public Object getPeersIdentity() { + return peersIdentity; } /** diff --git a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/BasicRto.java b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/BasicRto.java index 03a0dd69f6..96d9d24eed 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/BasicRto.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/BasicRto.java @@ -17,8 +17,6 @@ package org.eclipse.californium.core.network.stack.congestioncontrol; -import java.net.InetSocketAddress; - import org.eclipse.californium.core.network.stack.CongestionControlLayer; import org.eclipse.californium.core.network.stack.RemoteEndpoint; import org.eclipse.californium.elements.config.Configuration; @@ -29,8 +27,9 @@ public BasicRto(String tag, Configuration config) { super(tag, config); } - protected RemoteEndpoint createRemoteEndpoint(InetSocketAddress remoteSocketAddress) { - return new RemoteEndpoint(remoteSocketAddress, defaultReliabilityLayerParameters.getAckTimeout(), + @Override + protected RemoteEndpoint createRemoteEndpoint(Object peersIdentity) { + return new RemoteEndpoint(peersIdentity, defaultReliabilityLayerParameters.getAckTimeout(), defaultReliabilityLayerParameters.getNstart(), false) { @Override diff --git a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/Cocoa.java b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/Cocoa.java index 541551847e..497233151a 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/Cocoa.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/Cocoa.java @@ -17,7 +17,6 @@ package org.eclipse.californium.core.network.stack.congestioncontrol; -import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; import org.eclipse.californium.core.network.stack.CongestionControlLayer; @@ -53,8 +52,8 @@ public Cocoa(String tag, Configuration config, boolean strong) { } @Override - protected RemoteEndpoint createRemoteEndpoint(InetSocketAddress remoteSocketAddress) { - return new CocoaRemoteEndpoint(remoteSocketAddress, defaultReliabilityLayerParameters.getAckTimeout(), + protected RemoteEndpoint createRemoteEndpoint(Object peersIdentity) { + return new CocoaRemoteEndpoint(peersIdentity, defaultReliabilityLayerParameters.getAckTimeout(), defaultReliabilityLayerParameters.getNstart(), strong); } @@ -82,8 +81,8 @@ private static class CocoaRemoteEndpoint extends RemoteEndpoint { private Rto strongRto; private long nanoTimestamp; - private CocoaRemoteEndpoint(InetSocketAddress remoteAddress, int ackTimeout, int nstart, boolean strong) { - super(remoteAddress, ackTimeout, nstart, true); + private CocoaRemoteEndpoint(Object peersIdentity, int ackTimeout, int nstart, boolean strong) { + super(peersIdentity, ackTimeout, nstart, true); this.onlyStrong = strong; this.weakRto = new Rto(KWEAK, ackTimeout); this.strongRto = new Rto(KSTRONG, ackTimeout); diff --git a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/LinuxRto.java b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/LinuxRto.java index 423f9143ec..6fa4b681ae 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/LinuxRto.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/LinuxRto.java @@ -17,8 +17,6 @@ package org.eclipse.californium.core.network.stack.congestioncontrol; -import java.net.InetSocketAddress; - import org.eclipse.californium.core.network.stack.CongestionControlLayer; import org.eclipse.californium.core.network.stack.RemoteEndpoint; import org.eclipse.californium.elements.config.Configuration; @@ -30,8 +28,8 @@ public LinuxRto(String tag, Configuration config) { } @Override - protected RemoteEndpoint createRemoteEndpoint(InetSocketAddress remoteSocketAddress) { - return new LinuxRemoteEndpoint(remoteSocketAddress, defaultReliabilityLayerParameters.getAckTimeout(), + protected RemoteEndpoint createRemoteEndpoint(Object peersIdentity) { + return new LinuxRemoteEndpoint(peersIdentity, defaultReliabilityLayerParameters.getAckTimeout(), defaultReliabilityLayerParameters.getNstart()); } @@ -43,8 +41,8 @@ private static class LinuxRemoteEndpoint extends RemoteEndpoint { private long mdev; private long mdev_max; - private LinuxRemoteEndpoint(InetSocketAddress remoteAddress, int ackTimeout, int nstart) { - super(remoteAddress, ackTimeout, nstart, true); + private LinuxRemoteEndpoint(Object peersIdentity, int ackTimeout, int nstart) { + super(peersIdentity, ackTimeout, nstart, true); } private void initializeRTOEstimators(long measuredRTT) { diff --git a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/PeakhopperRto.java b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/PeakhopperRto.java index 90c2db0826..233f83913c 100644 --- a/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/PeakhopperRto.java +++ b/californium-core/src/main/java/org/eclipse/californium/core/network/stack/congestioncontrol/PeakhopperRto.java @@ -17,8 +17,6 @@ package org.eclipse.californium.core.network.stack.congestioncontrol; -import java.net.InetSocketAddress; - import org.eclipse.californium.core.network.stack.CongestionControlLayer; import org.eclipse.californium.core.network.stack.RemoteEndpoint; import org.eclipse.californium.elements.config.Configuration; @@ -30,8 +28,8 @@ public PeakhopperRto(String tag, Configuration config) { } @Override - protected RemoteEndpoint createRemoteEndpoint(InetSocketAddress remoteSocketAddress) { - return new PeakhopperRemoteEndoint(remoteSocketAddress, defaultReliabilityLayerParameters.getAckTimeout(), + protected RemoteEndpoint createRemoteEndpoint(Object peersIdentity) { + return new PeakhopperRemoteEndoint(peersIdentity, defaultReliabilityLayerParameters.getAckTimeout(), defaultReliabilityLayerParameters.getNstart()); } @@ -50,8 +48,8 @@ private static class PeakhopperRemoteEndoint extends RemoteEndpoint { private long[] RTT_sample = new long[RTT_HISTORY_SIZE]; private int currentRtt; - private PeakhopperRemoteEndoint(InetSocketAddress remoteAddress, int ackTimeout, int nstart) { - super(remoteAddress, ackTimeout, nstart, true); + private PeakhopperRemoteEndoint(Object peersIdentity, int ackTimeout, int nstart) { + super(peersIdentity, ackTimeout, nstart, true); } private void initializeRTOEstimators(long measuredRTT) {