Skip to content

Commit

Permalink
Remove unused getRegistrationEndpointAddress() method in Registration
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 8, 2019
1 parent 4d4cd10 commit f3d3079
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,9 +161,8 @@ private void handleRegister(CoapExchange exchange, Request request) {

// Handle request
// -------------------------------
InetSocketAddress serverEndpoint = exchange.advanced().getEndpoint().getAddress();
final SendableResponse<RegisterResponse> sendableResponse = registrationHandler.register(sender,
registerRequest, serverEndpoint);
registerRequest);
RegisterResponse response = sendableResponse.getResponse();

// Create CoAP Response from LwM2m request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> attr = new HashMap<>();
attr.put("rt", "oma.lwm2m");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> additionalRegistrationAttributes, Map<Integer, String> 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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -338,9 +313,9 @@ public Map<Integer, String> 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);
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -425,18 +399,14 @@ public static class Builder {
private Map<Integer, String> supportedObjects;
private Map<String, String> 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) {
Expand Down Expand Up @@ -487,8 +457,8 @@ public Builder additionalRegistrationAttributes(Map<String, String> 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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,12 +50,10 @@ public RegistrationHandler(RegistrationServiceImpl registrationService, Authoriz
this.registrationIdProvider = registrationIdProvider;
}

public SendableResponse<RegisterResponse> register(Identity sender, RegisterRequest registerRequest,
InetSocketAddress serverEndpoint) {
public SendableResponse<RegisterResponse> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,20 +61,18 @@ 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);
return reg;
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String, String> additionalAttributes = new HashMap<String, String>();
additionalAttributes.put("x", "1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down

0 comments on commit f3d3079

Please sign in to comment.