Skip to content

Commit

Permalink
Replace Java URI usage by EndpointUri
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Sep 6, 2024
1 parent baa124f commit e3974c3
Show file tree
Hide file tree
Showing 66 changed files with 322 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.eclipse.leshan.integration.tests.lockstep;

import java.net.InetSocketAddress;
import java.net.URI;
import java.util.List;
import java.util.Random;

Expand All @@ -30,6 +29,7 @@
import org.eclipse.californium.elements.config.Configuration;
import org.eclipse.californium.elements.config.SystemConfig;
import org.eclipse.californium.elements.config.UdpConfig;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.EndpointUriUtil;
import org.eclipse.leshan.core.link.DefaultLinkSerializer;
import org.eclipse.leshan.core.link.LinkSerializer;
Expand All @@ -56,7 +56,7 @@ public class LockStepLwM2mClient extends LockstepEndpoint {

private final String endpointName;

public LockStepLwM2mClient(final URI destination) {
public LockStepLwM2mClient(final EndpointUri destination) {
this(EndpointUriUtil.getSocketAddr(destination));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.lang.annotation.RetentionPolicy;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
Expand All @@ -53,6 +52,7 @@
import org.eclipse.californium.core.config.CoapConfig;
import org.eclipse.californium.elements.AddressEndpointContext;
import org.eclipse.californium.elements.config.Configuration;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.link.LinkParser;
import org.eclipse.leshan.core.link.lwm2m.DefaultLwM2mLinkParser;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void register_with_invalid_request(String givenServerEndpointProvider) th

// create a register request without the list of supported object
Request invalidRegisterRequest = new Request(Code.POST);
URI destinationURI = server.getEndpoint(Protocol.COAP).getURI();
EndpointUri destinationURI = server.getEndpoint(Protocol.COAP).getURI();
invalidRegisterRequest
.setDestinationContext(new AddressEndpointContext(destinationURI.getHost(), destinationURI.getPort()));
invalidRegisterRequest.getOptions().setContentFormat(ContentFormat.LINK.getCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.leshan.integration.tests.observe;

import java.net.URI;
import java.util.Random;

import org.eclipse.californium.core.coap.CoAP.Type;
Expand All @@ -26,13 +25,14 @@
import org.eclipse.californium.elements.Connector;
import org.eclipse.californium.elements.EndpointContext;
import org.eclipse.californium.elements.RawData;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.request.ContentFormat;

public class TestObserveUtil {
public static Random r = new Random();

public static void sendNotification(Connector connector, URI destination, byte[] payload, byte[] token, int observe,
ContentFormat contentFormat) {
public static void sendNotification(Connector connector, EndpointUri destination, byte[] payload, byte[] token,
int observe, ContentFormat contentFormat) {

// create observe response
Response response = new Response(org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.cert.Certificate;
import java.util.List;
import java.util.stream.Stream;
Expand All @@ -51,6 +50,7 @@
import org.eclipse.californium.scandium.dtls.PskPublicInformation;
import org.eclipse.californium.scandium.dtls.pskstore.AdvancedPskStore;
import org.eclipse.leshan.client.servers.ServerInfo;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.request.ReadRequest;
import org.eclipse.leshan.core.request.exception.SendFailedException;
Expand Down Expand Up @@ -210,7 +210,7 @@ public void dont_sent_request_if_identity_change(String givenServerEndpointProvi
request.setMID(0);
byte[] ping = new UdpDataSerializer().getByteArray(request);
// sent it
URI destinationUri = server.getEndpoint(Protocol.COAPS).getURI();
EndpointUri destinationUri = server.getEndpoint(Protocol.COAPS).getURI();
connector.send(RawData.outbound(ping,
new AddressEndpointContext(destinationUri.getHost(), destinationUri.getPort()), callback, false));
// Wait until new handshake DTLS is done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
package org.eclipse.leshan.integration.tests.util;

import java.net.InetSocketAddress;
import java.net.URI;

import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.Protocol;

public class LeshanProxyBuilder {

public static ReverseProxy givenReverseProxyFor(LeshanTestServer server, Protocol protocol) {
URI serverEndpointUri = server.getEndpoint(protocol).getURI();
EndpointUri serverEndpointUri = server.getEndpoint(protocol).getURI();
return new ReverseProxy(new InetSocketAddress("localhost", 0),
new InetSocketAddress(serverEndpointUri.getHost(), serverEndpointUri.getPort()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
Expand All @@ -34,6 +33,7 @@
import org.eclipse.leshan.bsserver.endpoint.LwM2mBootstrapServerEndpointsProvider;
import org.eclipse.leshan.bsserver.security.BootstrapSecurityStore;
import org.eclipse.leshan.bsserver.security.BootstrapSecurityStoreAdapter;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.link.lwm2m.LwM2mLinkParser;
import org.eclipse.leshan.core.node.codec.DefaultLwM2mDecoder;
Expand Down Expand Up @@ -206,7 +206,7 @@ private BootstrapServerProtocolProvider getCaliforniumProtocolProviderSupporting
if (protocolToUse.equals(Protocol.COAP)) {
return new CoapBootstrapServerProtocolProvider() {
@Override
public CaliforniumBootstrapServerEndpointFactory createDefaultEndpointFactory(URI uri) {
public CaliforniumBootstrapServerEndpointFactory createDefaultEndpointFactory(EndpointUri uri) {
return new CoapOscoreBootstrapServerEndpointFactory(uri);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import static org.mockito.Mockito.timeout;

import java.net.InetSocketAddress;
import java.net.URI;
import java.security.cert.Certificate;
import java.util.List;
import java.util.Map;
Expand All @@ -47,6 +46,7 @@
import org.eclipse.leshan.client.send.DataSender;
import org.eclipse.leshan.client.servers.LwM2mServer;
import org.eclipse.leshan.client.util.LinkFormatHelper;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.EndpointUriUtil;
import org.eclipse.leshan.core.link.LinkSerializer;
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributeParser;
Expand Down Expand Up @@ -244,10 +244,10 @@ public Exception waitForBootstrapFailure(LeshanBootstrapServer server, long time

private boolean isServerIdentifiedByUri(LeshanTestServer server, String expectedUri) {
for (LwM2mServerEndpoint endpoint : server.getEndpoints()) {
URI endpointURI = endpoint.getURI();
EndpointUri endpointURI = endpoint.getURI();
InetSocketAddress endpointAddr = EndpointUriUtil.getSocketAddr(endpointURI);
if (proxy != null && endpointAddr.equals(proxy.getServerAddress())) {
URI proxyUri = EndpointUriUtil.replaceAddress(endpointURI, proxy.getClientSideProxyAddress());
EndpointUri proxyUri = EndpointUriUtil.replaceAddress(endpointURI, proxy.getClientSideProxyAddress());
if (proxyUri.toString().equals(expectedUri)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.eclipse.leshan.core.LwM2mId.OSCORE;

import java.net.InetSocketAddress;
import java.net.URI;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
Expand Down Expand Up @@ -59,6 +58,7 @@
import org.eclipse.leshan.client.util.LinkFormatHelper;
import org.eclipse.leshan.core.CertificateUsage;
import org.eclipse.leshan.core.LwM2mId;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.EndpointUriUtil;
import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.link.LinkSerializer;
Expand Down Expand Up @@ -135,7 +135,7 @@ public LeshanTestClient build() {
try {
// connect to LWM2M Server
if (server != null) {
URI uri = getServerUri();
EndpointUri uri = getServerUri();

int serverID = 12345;

Expand Down Expand Up @@ -166,7 +166,7 @@ public LeshanTestClient build() {
// connect to LWM2M Bootstrap Server
else if (bootstrapServer != null) {
LwM2mBootstrapServerEndpoint endpoint = bootstrapServer.getEndpoint(protocolToUse);
URI uri = endpoint.getURI();
EndpointUri uri = endpoint.getURI();
Security securityEnabler = null;

if (pskIdentity != null && pskKey != null) {
Expand Down Expand Up @@ -458,9 +458,9 @@ public LeshanTestClientBuilder behind(ReverseProxy proxy) {
return this;
}

private URI getServerUri() {
private EndpointUri getServerUri() {
LwM2mServerEndpoint endpoint = server.getEndpoint(protocolToUse);
URI serverUri = endpoint.getURI();
EndpointUri serverUri = endpoint.getURI();
// we force usage of "localhost" as hostname to be sure that X.509 test works.
// see : https://github.com/eclipse-leshan/leshan/issues/1461#issuecomment-1631143202
if (proxy != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
Expand All @@ -29,6 +28,7 @@
import org.eclipse.californium.elements.config.Configuration;
import org.eclipse.californium.scandium.config.DtlsConfig;
import org.eclipse.californium.scandium.config.DtlsConfig.DtlsRole;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.endpoint.Protocol;
import org.eclipse.leshan.core.link.lwm2m.LwM2mLinkParser;
import org.eclipse.leshan.core.node.codec.DefaultLwM2mDecoder;
Expand Down Expand Up @@ -237,7 +237,7 @@ private ServerProtocolProvider getCaliforniumProtocolProviderSupportingOscore(Pr
if (protocolToUse.equals(Protocol.COAP)) {
return new CoapServerProtocolProvider() {
@Override
public CaliforniumServerEndpointFactory createDefaultEndpointFactory(URI uri) {
public CaliforniumServerEndpointFactory createDefaultEndpointFactory(EndpointUri uri) {
return new CoapOscoreServerEndpointFactory(uri);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*******************************************************************************/
package org.eclipse.leshan.bsserver;

import java.net.URI;

import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.peer.LwM2mPeer;
import org.eclipse.leshan.core.request.BootstrapRequest;
import org.eclipse.leshan.core.response.BootstrapResponse;
Expand All @@ -31,5 +30,6 @@

public interface BootstrapHandler {

SendableResponse<BootstrapResponse> bootstrap(LwM2mPeer sender, BootstrapRequest request, URI serverEndpointUri);
SendableResponse<BootstrapResponse> bootstrap(LwM2mPeer sender, BootstrapRequest request,
EndpointUri serverEndpointUri);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;

import org.eclipse.leshan.bsserver.security.BootstrapAuthorizer;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.model.LwM2mModel;
import org.eclipse.leshan.core.peer.LwM2mPeer;
import org.eclipse.leshan.core.request.BootstrapRequest;
Expand Down Expand Up @@ -52,7 +53,10 @@ public interface BootstrapSession {
*/
LwM2mPeer getClientTransportData();

URI getEndpointUsed();
/**
* @return the URI of the endpoint used for this session
*/
EndpointUri getEndpointUsed();

/**
* @return <code>true</code> if the LwM2M client is authorized to start a bootstrap session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.net.URI;

import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.peer.LwM2mPeer;
import org.eclipse.leshan.core.request.BootstrapRequest;
import org.eclipse.leshan.core.request.DownlinkBootstrapRequest;
Expand Down Expand Up @@ -102,7 +103,7 @@ public String toString() {
*
* @return a BootstrapSession, possibly authorized.
*/
public BootstrapSession begin(BootstrapRequest request, LwM2mPeer client, URI endpointUsed);
public BootstrapSession begin(BootstrapRequest request, LwM2mPeer client, EndpointUri endpointUsed);

/**
* Generally called after {@link #begin(BootstrapRequest, LwM2mPeer, URI)} to know if there is something to do on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import static org.eclipse.leshan.bsserver.BootstrapFailureCause.REQUEST_FAILED;
import static org.eclipse.leshan.bsserver.BootstrapFailureCause.UNAUTHORIZED;

import java.net.URI;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.leshan.bsserver.BootstrapSessionManager.BootstrapPolicy;
import org.eclipse.leshan.bsserver.request.BootstrapDownlinkRequestSender;
import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.peer.LwM2mPeer;
import org.eclipse.leshan.core.request.BootstrapFinishRequest;
import org.eclipse.leshan.core.request.BootstrapRequest;
Expand Down Expand Up @@ -82,7 +82,8 @@ public DefaultBootstrapHandler(BootstrapDownlinkRequestSender sender, BootstrapS
}

@Override
public SendableResponse<BootstrapResponse> bootstrap(LwM2mPeer sender, BootstrapRequest request, URI endpointUsed) {
public SendableResponse<BootstrapResponse> bootstrap(LwM2mPeer sender, BootstrapRequest request,
EndpointUri endpointUsed) {
String endpoint = request.getEndpointName();

// Start session, checking the BS credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*******************************************************************************/
package org.eclipse.leshan.bsserver;

import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.leshan.core.endpoint.EndpointUri;
import org.eclipse.leshan.core.model.LwM2mModel;
import org.eclipse.leshan.core.peer.LwM2mPeer;
import org.eclipse.leshan.core.request.BootstrapRequest;
Expand All @@ -42,7 +42,7 @@ public class DefaultBootstrapSession implements BootstrapSession {
private final ContentFormat contentFormat;
private final Map<String, String> applicationData;
private final long creationTime;
private final URI endpointUsed;
private final EndpointUri endpointUsed;
private final BootstrapRequest request;

private volatile LwM2mModel model;
Expand All @@ -62,7 +62,7 @@ public class DefaultBootstrapSession implements BootstrapSession {
* @param applicationData Data that could be attached to a session.
*/
public DefaultBootstrapSession(BootstrapRequest request, LwM2mPeer client, boolean authorized,
Map<String, String> applicationData, URI endpointUsed) {
Map<String, String> applicationData, EndpointUri endpointUsed) {
this(request, client, authorized, null, applicationData, endpointUsed);
}

Expand All @@ -76,7 +76,7 @@ public DefaultBootstrapSession(BootstrapRequest request, LwM2mPeer client, boole
* @param applicationData Data that could be attached to a session.
*/
public DefaultBootstrapSession(BootstrapRequest request, LwM2mPeer client, boolean authorized,
ContentFormat contentFormat, Map<String, String> applicationData, URI endpointUsed) {
ContentFormat contentFormat, Map<String, String> applicationData, EndpointUri endpointUsed) {
this(request, client, authorized, contentFormat, applicationData, System.currentTimeMillis(), endpointUsed);
}

Expand All @@ -91,7 +91,8 @@ public DefaultBootstrapSession(BootstrapRequest request, LwM2mPeer client, boole
* @param creationTime The creation time of this session in ms.
*/
public DefaultBootstrapSession(BootstrapRequest request, LwM2mPeer client, boolean authorized,
ContentFormat contentFormat, Map<String, String> applicationData, long creationTime, URI endpointUsed) {
ContentFormat contentFormat, Map<String, String> applicationData, long creationTime,
EndpointUri endpointUsed) {
Validate.notNull(request);
this.id = RandomStringUtils.random(10, true, true);
this.request = request;
Expand Down Expand Up @@ -132,7 +133,7 @@ public LwM2mPeer getClientTransportData() {
}

@Override
public URI getEndpointUsed() {
public EndpointUri getEndpointUsed() {
return endpointUsed;
}

Expand Down
Loading

0 comments on commit e3974c3

Please sign in to comment.