diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/registration/RegisterResource.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/registration/RegisterResource.java index 7a0058cd12..5cbe794db7 100644 --- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/registration/RegisterResource.java +++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/registration/RegisterResource.java @@ -17,7 +17,6 @@ import static org.eclipse.leshan.core.californium.ResponseCodeUtil.toCoapResponseCode; -import java.net.InetSocketAddress; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -162,9 +161,8 @@ private void handleRegister(CoapExchange exchange, Request request) { // Handle request // ------------------------------- - InetSocketAddress serverEndpoint = exchange.advanced().getEndpoint().getAddress(); final SendableResponse sendableResponse = registrationHandler.register(sender, - registerRequest, serverEndpoint); + registerRequest); RegisterResponse response = sendableResponse.getResponse(); // Create CoAP Response from LwM2m request diff --git a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CaliforniumTestSupport.java b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CaliforniumTestSupport.java index ce50866641..458cca1e8c 100644 --- a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CaliforniumTestSupport.java +++ b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CaliforniumTestSupport.java @@ -37,7 +37,7 @@ public void givenASimpleClient() throws UnknownHostException { registrationAddress = InetSocketAddress.createUnresolved("localhost", LwM2m.DEFAULT_COAP_PORT); Registration.Builder builder = new Registration.Builder("ID", "urn:client", - Identity.unsecure(Inet4Address.getLoopbackAddress(), 1000), registrationAddress); + Identity.unsecure(Inet4Address.getLoopbackAddress(), 1000)); registration = builder.build(); } diff --git a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java index b3c2e58edd..20a8e92d8e 100644 --- a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java +++ b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/CoapRequestBuilderTest.java @@ -18,7 +18,6 @@ import static org.junit.Assert.*; import java.net.Inet4Address; -import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.HashMap; @@ -77,7 +76,7 @@ private Registration newRegistration() throws UnknownHostException { private Registration newRegistration(String rootpath) throws UnknownHostException { Builder b = new Registration.Builder("regid", "endpoint", - Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354), new InetSocketAddress(0)); + Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354)); if (rootpath != null) { Map attr = new HashMap<>(); attr.put("rt", "oma.lwm2m"); diff --git a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/InMemoryRegistrationStoreTest.java b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/InMemoryRegistrationStoreTest.java index 0175baab4c..b8c31046b5 100644 --- a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/InMemoryRegistrationStoreTest.java +++ b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/InMemoryRegistrationStoreTest.java @@ -16,11 +16,9 @@ package org.eclipse.leshan.server.californium.impl; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; import org.eclipse.leshan.Link; -import org.eclipse.leshan.LwM2m; import org.eclipse.leshan.core.request.BindingMode; import org.eclipse.leshan.core.request.Identity; import org.eclipse.leshan.server.californium.registration.InMemoryRegistrationStore; @@ -95,8 +93,7 @@ public void update_registration_to_extend_time_to_live() { private void givenASimpleRegistration(Long lifetime) { - Registration.Builder builder = new Registration.Builder(registrationId, ep, Identity.unsecure(address, port), - InetSocketAddress.createUnresolved("localhost", LwM2m.DEFAULT_COAP_PORT)); + Registration.Builder builder = new Registration.Builder(registrationId, ep, Identity.unsecure(address, port)); registration = builder.lifeTimeInSec(lifetime).smsNumber(sms).bindingMode(binding).objectLinks(objectLinks) .build(); diff --git a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/ObservationServiceTest.java b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/ObservationServiceTest.java index 42ef527682..dd019699f9 100644 --- a/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/ObservationServiceTest.java +++ b/leshan-server-cf/src/test/java/org/eclipse/leshan/server/californium/impl/ObservationServiceTest.java @@ -16,13 +16,11 @@ package org.eclipse.leshan.server.californium.impl; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.util.Map; import java.util.Set; import org.eclipse.californium.core.coap.Request; -import org.eclipse.leshan.LwM2m; import org.eclipse.leshan.core.californium.EndpointContextUtil; import org.eclipse.leshan.core.node.LwM2mPath; import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder; @@ -157,12 +155,10 @@ private Observation givenAnObservation(String registrationId, LwM2mPath target) } public Registration givenASimpleClient(String registrationId) { - InetSocketAddress registrationAddress = InetSocketAddress.createUnresolved("localhost", - LwM2m.DEFAULT_COAP_PORT); Registration.Builder builder; try { builder = new Registration.Builder(registrationId, registrationId + "_ep", - Identity.unsecure(InetAddress.getLocalHost(), 10000), registrationAddress); + Identity.unsecure(InetAddress.getLocalHost(), 10000)); return builder.build(); } catch (UnknownHostException e) { throw new RuntimeException(e); diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/Registration.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/Registration.java index afd17b796f..5dfb1e92da 100644 --- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/Registration.java +++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/Registration.java @@ -52,11 +52,6 @@ public class Registration implements Serializable { private final Identity identity; - /* - * The address of the LWM2M Server's CoAP end point the client used to register. - */ - private final InetSocketAddress registrationEndpointAddress; - private final long lifeTimeInSec; private final String smsNumber; @@ -86,20 +81,17 @@ public class Registration implements Serializable { private final Date lastUpdate; protected Registration(String id, String endpoint, Identity identity, String lwM2mVersion, Long lifetimeInSec, - String smsNumber, BindingMode bindingMode, Link[] objectLinks, - InetSocketAddress registrationEndpointAddress, Date registrationDate, Date lastUpdate, + String smsNumber, BindingMode bindingMode, Link[] objectLinks, Date registrationDate, Date lastUpdate, Map additionalRegistrationAttributes, Map supportedObjects) { Validate.notNull(id); Validate.notEmpty(endpoint); Validate.notNull(identity); - Validate.notNull(registrationEndpointAddress); this.id = id; this.identity = identity; this.endpoint = endpoint; this.smsNumber = smsNumber; - this.registrationEndpointAddress = registrationEndpointAddress; this.objectLinks = objectLinks; // Parse object link to extract root path. @@ -175,23 +167,6 @@ public int getPort() { return identity.getPeerAddress().getPort(); } - /** - * Gets the network address and port number of LWM2M Server's CoAP endpoint the client originally registered at. - * - * A LWM2M Server may listen on multiple CoAP end points, e.g. a non-secure and a secure one. Clients are often - * behind a firewall which will only let incoming UDP packets pass if they originate from the same address:port that - * the client has initiated communication with, e.g. by means of registering with the LWM2M Server. It is therefore - * important to know, which of the server's CoAP end points the client contacted for registration. - * - * This information can be used to uniquely identify the CoAP endpoint that should be used to access resources on - * the client. - * - * @return the network address and port number - */ - public InetSocketAddress getRegistrationEndpointAddress() { - return registrationEndpointAddress; - } - public Link[] getObjectLinks() { return objectLinks; } @@ -338,9 +313,9 @@ public Map getSupportedObject() { @Override public String toString() { return String.format( - "Registration [registrationDate=%s, identity=%s, registrationEndpoint=%s, lifeTimeInSec=%s, smsNumber=%s, lwM2mVersion=%s, bindingMode=%s, endpoint=%s, registrationId=%s, objectLinks=%s, lastUpdate=%s]", - registrationDate, identity, registrationEndpointAddress, lifeTimeInSec, smsNumber, lwM2mVersion, - bindingMode, endpoint, id, Arrays.toString(objectLinks), lastUpdate); + "Registration [registrationDate=%s, identity=%s, lifeTimeInSec=%s, smsNumber=%s, lwM2mVersion=%s, bindingMode=%s, endpoint=%s, registrationId=%s, objectLinks=%s, lastUpdate=%s]", + registrationDate, identity, lifeTimeInSec, smsNumber, lwM2mVersion, bindingMode, endpoint, id, + Arrays.toString(objectLinks), lastUpdate); } /** @@ -413,7 +388,6 @@ public static class Builder { private final String registrationId; private final String endpoint; private final Identity identity; - private final InetSocketAddress registrationEndpointAddress; private Date registrationDate; private Date lastUpdate; @@ -425,18 +399,14 @@ public static class Builder { private Map supportedObjects; private Map additionalRegistrationAttributes; - public Builder(String registrationId, String endpoint, Identity identity, - InetSocketAddress registrationEndpointAddress) { + public Builder(String registrationId, String endpoint, Identity identity) { Validate.notNull(registrationId); Validate.notEmpty(endpoint); Validate.notNull(identity); - Validate.notNull(registrationEndpointAddress); this.registrationId = registrationId; this.endpoint = endpoint; this.identity = identity; - this.registrationEndpointAddress = registrationEndpointAddress; - } public Builder registrationDate(Date registrationDate) { @@ -487,8 +457,8 @@ public Builder additionalRegistrationAttributes(Map additionalRe public Registration build() { return new Registration(Builder.this.registrationId, Builder.this.endpoint, Builder.this.identity, Builder.this.lwM2mVersion, Builder.this.lifeTimeInSec, Builder.this.smsNumber, this.bindingMode, - this.objectLinks, this.registrationEndpointAddress, this.registrationDate, this.lastUpdate, - this.additionalRegistrationAttributes, this.supportedObjects); + this.objectLinks, this.registrationDate, this.lastUpdate, this.additionalRegistrationAttributes, + this.supportedObjects); } } diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationHandler.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationHandler.java index 2c7a695832..bb2a902ce9 100644 --- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationHandler.java +++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationHandler.java @@ -17,7 +17,6 @@ *******************************************************************************/ package org.eclipse.leshan.server.registration; -import java.net.InetSocketAddress; import java.util.Date; import org.eclipse.leshan.core.request.DeregisterRequest; @@ -51,12 +50,10 @@ public RegistrationHandler(RegistrationServiceImpl registrationService, Authoriz this.registrationIdProvider = registrationIdProvider; } - public SendableResponse register(Identity sender, RegisterRequest registerRequest, - InetSocketAddress serverEndpoint) { + public SendableResponse register(Identity sender, RegisterRequest registerRequest) { Registration.Builder builder = new Registration.Builder( - registrationIdProvider.getRegistrationId(registerRequest), registerRequest.getEndpointName(), sender, - serverEndpoint); + registrationIdProvider.getRegistrationId(registerRequest), registerRequest.getEndpointName(), sender); builder.lwM2mVersion(registerRequest.getLwVersion()).lifeTimeInSec(registerRequest.getLifetime()) .bindingMode(registerRequest.getBindingMode()).objectLinks(registerRequest.getObjectLinks()) diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationUpdate.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationUpdate.java index 474284c314..92bbd7a05e 100644 --- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationUpdate.java +++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/registration/RegistrationUpdate.java @@ -80,7 +80,7 @@ public Registration update(Registration registration) { Date lastUpdate = new Date(); Registration.Builder builder = new Registration.Builder(registration.getId(), registration.getEndpoint(), - identity, registration.getRegistrationEndpointAddress()); + identity); builder.lwM2mVersion(registration.getLwM2mVersion()).lifeTimeInSec(lifeTimeInSec).smsNumber(smsNumber) .bindingMode(bindingMode).objectLinks(linkObject).registrationDate(registration.getRegistrationDate()) diff --git a/leshan-server-core/src/test/java/org/eclipse/leshan/server/queue/PresenceServiceTest.java b/leshan-server-core/src/test/java/org/eclipse/leshan/server/queue/PresenceServiceTest.java index e8530d4bc0..08ce00b7e0 100644 --- a/leshan-server-core/src/test/java/org/eclipse/leshan/server/queue/PresenceServiceTest.java +++ b/leshan-server-core/src/test/java/org/eclipse/leshan/server/queue/PresenceServiceTest.java @@ -18,7 +18,6 @@ import static org.junit.Assert.*; import java.net.Inet4Address; -import java.net.InetSocketAddress; import java.net.UnknownHostException; import org.eclipse.leshan.core.request.BindingMode; @@ -62,9 +61,8 @@ public void testIsOnline() throws Exception { } private Registration givenASimpleClient() throws UnknownHostException { - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 5683); Registration.Builder builder = new Registration.Builder("ID", "urn:client", - Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354), address); + Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354)); Registration reg = builder.build(); presenceService.setAwake(reg); @@ -72,10 +70,9 @@ private Registration givenASimpleClient() throws UnknownHostException { } private Registration givenASimpleClientWithQueueMode() throws UnknownHostException { - InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 5683); Registration.Builder builder = new Registration.Builder("ID", "urn:client", - Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354), address); + Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354)); Registration reg = builder.bindingMode(BindingMode.UQ).build(); presenceService.setAwake(reg); diff --git a/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationSortObjectLinksTest.java b/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationSortObjectLinksTest.java index 12321b2b48..eb93c92ce6 100644 --- a/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationSortObjectLinksTest.java +++ b/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationSortObjectLinksTest.java @@ -17,7 +17,6 @@ package org.eclipse.leshan.server.registration; import java.net.Inet4Address; -import java.net.InetSocketAddress; import java.net.UnknownHostException; import org.eclipse.leshan.Link; @@ -35,7 +34,7 @@ public void sort_link_object_on_get() throws UnknownHostException { objs[2] = null; Registration.Builder builder = new Registration.Builder("registrationId", "endpoint", - Identity.unsecure(Inet4Address.getLocalHost(), 1), new InetSocketAddress(212)).objectLinks(objs); + Identity.unsecure(Inet4Address.getLocalHost(), 1)).objectLinks(objs); Registration r = builder.build(); diff --git a/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationTest.java b/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationTest.java index cd1a5d6fb6..ac289c8b59 100644 --- a/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationTest.java +++ b/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationTest.java @@ -88,8 +88,7 @@ public void test_supported_object_given_an_object_link_with_not_lwm2m_url() { private Registration given_a_registration_with_object_link_like(String objectLinks) { Builder builder = new Registration.Builder("id", "endpoin", - Identity.unsecure(InetSocketAddress.createUnresolved("localhost", 0)), - InetSocketAddress.createUnresolved("localhost", 0)); + Identity.unsecure(InetSocketAddress.createUnresolved("localhost", 0))); builder.objectLinks(Link.parse(objectLinks.getBytes())); return builder.build(); diff --git a/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationUpdateTest.java b/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationUpdateTest.java index 171e8a9a28..3cf9e3f87a 100644 --- a/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationUpdateTest.java +++ b/leshan-server-core/src/test/java/org/eclipse/leshan/server/registration/RegistrationUpdateTest.java @@ -16,7 +16,6 @@ package org.eclipse.leshan.server.registration; import java.net.Inet4Address; -import java.net.InetSocketAddress; import java.util.HashMap; import java.util.Map; @@ -34,7 +33,7 @@ public class RegistrationUpdateTest { @Test public void testAdditionalAttributesUpdate() throws Exception { Registration.Builder builder = new Registration.Builder("registrationId", "endpoint", - Identity.unsecure(Inet4Address.getLocalHost(), 1), new InetSocketAddress(212)); + Identity.unsecure(Inet4Address.getLocalHost(), 1)); Map additionalAttributes = new HashMap(); additionalAttributes.put("x", "1"); diff --git a/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java b/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java index 7eb467aef1..b189fbe109 100644 --- a/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java +++ b/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java @@ -15,7 +15,6 @@ *******************************************************************************/ package org.eclipse.leshan.server.redis.serialization; -import java.net.InetSocketAddress; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -38,8 +37,6 @@ public static JsonObject jSerialize(Registration r) { JsonObject o = Json.object(); o.add("regDate", r.getRegistrationDate().getTime()); o.add("identity", IdentitySerDes.serialize(r.getIdentity())); - o.add("regAddr", r.getRegistrationEndpointAddress().getHostString()); - o.add("regPort", r.getRegistrationEndpointAddress().getPort()); o.add("lt", r.getLifeTimeInSec()); if (r.getSmsNumber() != null) { o.add("sms", r.getSmsNumber()); @@ -87,8 +84,7 @@ public static byte[] bSerialize(Registration r) { public static Registration deserialize(JsonObject jObj) { Registration.Builder b = new Registration.Builder(jObj.getString("regId", null), jObj.getString("ep", null), - IdentitySerDes.deserialize(jObj.get("identity").asObject()), - new InetSocketAddress(jObj.getString("regAddr", null), jObj.getInt("regPort", 0))); + IdentitySerDes.deserialize(jObj.get("identity").asObject())); b.bindingMode(BindingMode.valueOf(jObj.getString("bnd", null))); b.lastUpdate(new Date(jObj.getLong("lastUp", 0))); b.lifeTimeInSec(jObj.getLong("lt", 0)); diff --git a/leshan-server-redis/src/test/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDesTest.java b/leshan-server-redis/src/test/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDesTest.java index b80b0a3d00..5cba1dd5c6 100644 --- a/leshan-server-redis/src/test/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDesTest.java +++ b/leshan-server-redis/src/test/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDesTest.java @@ -18,14 +18,12 @@ import static org.junit.Assert.assertEquals; import java.net.Inet4Address; -import java.net.InetSocketAddress; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.eclipse.leshan.Link; import org.eclipse.leshan.core.request.Identity; -import org.eclipse.leshan.server.redis.serialization.RegistrationSerDes; import org.eclipse.leshan.server.registration.Registration; import org.junit.Test; @@ -42,7 +40,7 @@ public void ser_and_des_are_equals() throws Exception { objs[1] = new Link("/0/2"); Registration.Builder builder = new Registration.Builder("registrationId", "endpoint", - Identity.unsecure(Inet4Address.getLoopbackAddress(), 1), new InetSocketAddress(212)).objectLinks(objs); + Identity.unsecure(Inet4Address.getLoopbackAddress(), 1)).objectLinks(objs); builder.registrationDate(new Date(100L)); builder.lastUpdate(new Date(101L));