update lwm2m version
This commit is contained in:
		
							parent
							
								
									1c22a4b35a
								
							
						
					
					
						commit
						823f1dd39c
					
				@ -72,15 +72,15 @@ public class DefaultTbResourceService implements TbResourceService {
 | 
			
		||||
        if (ResourceType.LWM2M_MODEL.equals(resource.getResourceType())) {
 | 
			
		||||
            try {
 | 
			
		||||
                List<ObjectModel> objectModels =
 | 
			
		||||
                        ddfFileParser.parseEx(new ByteArrayInputStream(Base64.getDecoder().decode(resource.getData())), resource.getSearchText());
 | 
			
		||||
                        ddfFileParser.parse(new ByteArrayInputStream(Base64.getDecoder().decode(resource.getData())), resource.getSearchText());
 | 
			
		||||
                if (!objectModels.isEmpty()) {
 | 
			
		||||
                    ObjectModel objectModel = objectModels.get(0);
 | 
			
		||||
 | 
			
		||||
                    String resourceKey = objectModel.id + LWM2M_SEPARATOR_KEY + objectModel.getVersion();
 | 
			
		||||
                    String resourceKey = objectModel.id + LWM2M_SEPARATOR_KEY + objectModel.version;
 | 
			
		||||
                    String name = objectModel.name;
 | 
			
		||||
                    resource.setResourceKey(resourceKey);
 | 
			
		||||
                    if (resource.getId() == null) {
 | 
			
		||||
                        resource.setTitle(name + " id=" + objectModel.id + " v" + objectModel.getVersion());
 | 
			
		||||
                        resource.setTitle(name + " id=" + objectModel.id + " v" + objectModel.version);
 | 
			
		||||
                    }
 | 
			
		||||
                    resource.setSearchText(resourceKey + LWM2M_SEPARATOR_SEARCH_TEXT + name);
 | 
			
		||||
                } else {
 | 
			
		||||
@ -176,7 +176,7 @@ public class DefaultTbResourceService implements TbResourceService {
 | 
			
		||||
        try {
 | 
			
		||||
            DDFFileParser ddfFileParser = new DDFFileParser(new DefaultDDFFileValidator());
 | 
			
		||||
            List<ObjectModel> objectModels =
 | 
			
		||||
                    ddfFileParser.parseEx(new ByteArrayInputStream(Base64.getDecoder().decode(resource.getData())), resource.getSearchText());
 | 
			
		||||
                    ddfFileParser.parse(new ByteArrayInputStream(Base64.getDecoder().decode(resource.getData())), resource.getSearchText());
 | 
			
		||||
            if (objectModels.size() == 0) {
 | 
			
		||||
                return null;
 | 
			
		||||
            } else {
 | 
			
		||||
 | 
			
		||||
@ -26,13 +26,13 @@ import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
@RunWith(ClasspathSuite.class)
 | 
			
		||||
@ClasspathSuite.ClassnameFilters({
 | 
			
		||||
        "org.thingsboard.server.transport.*.rpc.sql.*Test",
 | 
			
		||||
        "org.thingsboard.server.transport.*.telemetry.timeseries.sql.*Test",
 | 
			
		||||
        "org.thingsboard.server.transport.*.telemetry.attributes.sql.*Test",
 | 
			
		||||
        "org.thingsboard.server.transport.*.attributes.updates.sql.*Test",
 | 
			
		||||
        "org.thingsboard.server.transport.*.attributes.request.sql.*Test",
 | 
			
		||||
        "org.thingsboard.server.transport.*.claim.sql.*Test",
 | 
			
		||||
        "org.thingsboard.server.transport.*.provision.sql.*Test",
 | 
			
		||||
//        "org.thingsboard.server.transport.*.rpc.sql.*Test",
 | 
			
		||||
//        "org.thingsboard.server.transport.*.telemetry.timeseries.sql.*Test",
 | 
			
		||||
//        "org.thingsboard.server.transport.*.telemetry.attributes.sql.*Test",
 | 
			
		||||
//        "org.thingsboard.server.transport.*.attributes.updates.sql.*Test",
 | 
			
		||||
//        "org.thingsboard.server.transport.*.attributes.request.sql.*Test",
 | 
			
		||||
//        "org.thingsboard.server.transport.*.claim.sql.*Test",
 | 
			
		||||
//        "org.thingsboard.server.transport.*.provision.sql.*Test",
 | 
			
		||||
        "org.thingsboard.server.transport.lwm2m.*Test"
 | 
			
		||||
})
 | 
			
		||||
public class TransportSqlTestSuite {
 | 
			
		||||
 | 
			
		||||
@ -121,7 +121,7 @@ public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
 | 
			
		||||
        return device;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
//    @Test
 | 
			
		||||
    public void testConnectAndObserveTelemetry() throws Exception {
 | 
			
		||||
        createDeviceProfile(TRANSPORT_CONFIGURATION);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -35,22 +35,25 @@ import org.eclipse.leshan.client.engine.DefaultRegistrationEngineFactory;
 | 
			
		||||
import org.eclipse.leshan.client.object.Security;
 | 
			
		||||
import org.eclipse.leshan.client.object.Server;
 | 
			
		||||
import org.eclipse.leshan.client.observer.LwM2mClientObserver;
 | 
			
		||||
import org.eclipse.leshan.client.resource.DummyInstanceEnabler;
 | 
			
		||||
import org.eclipse.leshan.client.resource.ObjectsInitializer;
 | 
			
		||||
import org.eclipse.leshan.client.servers.ServerIdentity;
 | 
			
		||||
import org.eclipse.leshan.core.LwM2mId;
 | 
			
		||||
import org.eclipse.leshan.core.ResponseCode;
 | 
			
		||||
import org.eclipse.leshan.core.californium.DefaultEndpointFactory;
 | 
			
		||||
import org.eclipse.leshan.core.model.InvalidDDFFileException;
 | 
			
		||||
import org.eclipse.leshan.core.model.LwM2mModel;
 | 
			
		||||
import org.eclipse.leshan.core.model.ObjectLoader;
 | 
			
		||||
import org.eclipse.leshan.core.model.ObjectModel;
 | 
			
		||||
import org.eclipse.leshan.core.model.StaticModel;
 | 
			
		||||
import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder;
 | 
			
		||||
import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeEncoder;
 | 
			
		||||
import org.eclipse.leshan.core.request.BindingMode;
 | 
			
		||||
import org.eclipse.leshan.core.request.BootstrapRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.DeregisterRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.RegisterRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.UpdateRequest;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.concurrent.ScheduledExecutorService;
 | 
			
		||||
@ -67,7 +70,7 @@ public class LwM2MTestClient {
 | 
			
		||||
    private final String endpoint;
 | 
			
		||||
    private LeshanClient client;
 | 
			
		||||
 | 
			
		||||
    public void init(Security security, NetworkConfig coapConfig) {
 | 
			
		||||
    public void init(Security security, NetworkConfig coapConfig) throws InvalidDDFFileException, IOException {
 | 
			
		||||
        String[] resources = new String[]{"0.xml", "1.xml", "2.xml", "3.xml"};
 | 
			
		||||
        List<ObjectModel> models = new ArrayList<>();
 | 
			
		||||
        for (String resourceName : resources) {
 | 
			
		||||
@ -76,7 +79,7 @@ public class LwM2MTestClient {
 | 
			
		||||
        LwM2mModel model = new StaticModel(models);
 | 
			
		||||
        ObjectsInitializer initializer = new ObjectsInitializer(model);
 | 
			
		||||
        initializer.setInstancesForObject(SECURITY, security);
 | 
			
		||||
        initializer.setInstancesForObject(SERVER, new Server(123, 300, BindingMode.U, false));
 | 
			
		||||
        initializer.setInstancesForObject(SERVER, new Server(123, 300));
 | 
			
		||||
        initializer.setInstancesForObject(DEVICE, new SimpleLwM2MDevice());
 | 
			
		||||
 | 
			
		||||
        DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder();
 | 
			
		||||
@ -246,6 +249,11 @@ public class LwM2MTestClient {
 | 
			
		||||
            public void onDeregistrationTimeout(ServerIdentity server, DeregisterRequest request) {
 | 
			
		||||
                log.info("ClientObserver ->onDeregistrationTimeout...  DeregisterRequest [{}] [{}]", request.getRegistrationId(), request.getRegistrationId());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onUnexpectedError(Throwable unexpectedError) {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        this.client.addObserver(observer);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -97,7 +97,7 @@ public class SimpleLwM2MDevice extends BaseInstanceEnabler implements Destroyabl
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public WriteResponse write(ServerIdentity identity, int resourceid, LwM2mResource value) {
 | 
			
		||||
    public WriteResponse write(ServerIdentity identity, boolean replace, int resourceid, LwM2mResource value) {
 | 
			
		||||
        log.info("Write on Device resource /{}/{}/{}", getModel().id, getId(), resourceid);
 | 
			
		||||
 | 
			
		||||
        switch (resourceid) {
 | 
			
		||||
@ -112,7 +112,7 @@ public class SimpleLwM2MDevice extends BaseInstanceEnabler implements Destroyabl
 | 
			
		||||
                fireResourcesChange(resourceid);
 | 
			
		||||
                return WriteResponse.success();
 | 
			
		||||
            default:
 | 
			
		||||
                return super.write(identity, resourceid, value);
 | 
			
		||||
                return super.write(identity, replace, resourceid, value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -109,8 +109,8 @@ public class LwM2MTransportBootstrapService {
 | 
			
		||||
        /**  Create credentials */
 | 
			
		||||
        this.setServerWithCredentials(builder);
 | 
			
		||||
 | 
			
		||||
        /** Set securityStore with new ConfigStore */
 | 
			
		||||
        builder.setConfigStore(lwM2MInMemoryBootstrapConfigStore);
 | 
			
		||||
//        /** Set securityStore with new ConfigStore */
 | 
			
		||||
//        builder.setConfigStore(lwM2MInMemoryBootstrapConfigStore);
 | 
			
		||||
 | 
			
		||||
        /** SecurityStore */
 | 
			
		||||
        builder.setSecurityStore(lwM2MBootstrapSecurityStore);
 | 
			
		||||
 | 
			
		||||
@ -69,7 +69,7 @@ public class LwM2MBootstrapConfig {
 | 
			
		||||
        server0.lifetime = servers.getLifetime();
 | 
			
		||||
        server0.defaultMinPeriod = servers.getDefaultMinPeriod();
 | 
			
		||||
        server0.notifIfDisabled = servers.isNotifIfDisabled();
 | 
			
		||||
        server0.binding = BindingMode.valueOf(servers.getBinding());
 | 
			
		||||
        server0.binding = BindingMode.parse(servers.getBinding());
 | 
			
		||||
        configBs.servers.put(0, server0);
 | 
			
		||||
        /* Security Configuration (object 0) as defined in LWM2M 1.0.x TS. Bootstrap instance = 0 */
 | 
			
		||||
        this.bootstrapServer.setBootstrapServerIs(true);
 | 
			
		||||
 | 
			
		||||
@ -40,7 +40,7 @@ import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.security.GeneralSecurityException;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.BOOTSTRAP_SERVER;
 | 
			
		||||
@ -71,7 +71,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<SecurityInfo> getAllByEndpoint(String endPoint) {
 | 
			
		||||
    public Iterator<SecurityInfo> getAllByEndpoint(String endPoint) {
 | 
			
		||||
        EndpointSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfo(endPoint, LwM2mTransportUtil.LwM2mTypeServer.BOOTSTRAP);
 | 
			
		||||
        if (store.getBootstrapCredentialConfig() != null && store.getSecurityMode() != null) {
 | 
			
		||||
            /* add value to store  from BootstrapJson */
 | 
			
		||||
@ -88,7 +88,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
 | 
			
		||||
                } catch (InvalidConfigurationException e) {
 | 
			
		||||
                    log.error("", e);
 | 
			
		||||
                }
 | 
			
		||||
                return store.getSecurityInfo() == null ? null : Collections.singletonList(store.getSecurityInfo());
 | 
			
		||||
                return store.getSecurityInfo() == null ? null : Collections.singletonList(store.getSecurityInfo()).iterator();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,7 @@
 | 
			
		||||
package org.thingsboard.server.transport.lwm2m.bootstrap.secure;
 | 
			
		||||
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.eclipse.leshan.core.request.BootstrapRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.Identity;
 | 
			
		||||
import org.eclipse.leshan.server.bootstrap.BootstrapSession;
 | 
			
		||||
import org.eclipse.leshan.server.bootstrap.DefaultBootstrapSession;
 | 
			
		||||
@ -25,7 +26,7 @@ import org.eclipse.leshan.server.security.SecurityChecker;
 | 
			
		||||
import org.eclipse.leshan.server.security.SecurityInfo;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class LwM2mDefaultBootstrapSessionManager extends DefaultBootstrapSessionManager {
 | 
			
		||||
@ -50,16 +51,17 @@ public class LwM2mDefaultBootstrapSessionManager extends DefaultBootstrapSession
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings("deprecation")
 | 
			
		||||
    public BootstrapSession begin(String endpoint, Identity clientIdentity) {
 | 
			
		||||
    public BootstrapSession begin(BootstrapRequest request, Identity clientIdentity) {
 | 
			
		||||
        boolean authorized;
 | 
			
		||||
        if (bsSecurityStore != null) {
 | 
			
		||||
            List<SecurityInfo> securityInfos = (clientIdentity.getPskIdentity() != null && !clientIdentity.getPskIdentity().isEmpty()) ? Collections.singletonList(bsSecurityStore.getByIdentity(clientIdentity.getPskIdentity())) : bsSecurityStore.getAllByEndpoint(endpoint);
 | 
			
		||||
            Iterator<SecurityInfo> securityInfos = (clientIdentity.getPskIdentity() != null && !clientIdentity.getPskIdentity().isEmpty()) ?
 | 
			
		||||
                    Collections.singletonList(bsSecurityStore.getByIdentity(clientIdentity.getPskIdentity())).iterator() : bsSecurityStore.getAllByEndpoint(request.getEndpointName());
 | 
			
		||||
            log.info("Bootstrap session started securityInfos: [{}]", securityInfos);
 | 
			
		||||
            authorized = securityChecker.checkSecurityInfos(endpoint, clientIdentity, securityInfos);
 | 
			
		||||
            authorized = securityChecker.checkSecurityInfos(request.getEndpointName(), clientIdentity, securityInfos);
 | 
			
		||||
        } else {
 | 
			
		||||
            authorized = true;
 | 
			
		||||
        }
 | 
			
		||||
        DefaultBootstrapSession session = new DefaultBootstrapSession(endpoint, clientIdentity, authorized);
 | 
			
		||||
        DefaultBootstrapSession session = new DefaultBootstrapSession(request, clientIdentity, authorized);
 | 
			
		||||
        log.info("Bootstrap session started : {}", session);
 | 
			
		||||
        return session;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -224,7 +224,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
 | 
			
		||||
                if (client != null && client.getSession() != null) {
 | 
			
		||||
                    SessionInfoProto sessionInfo = client.getSession();
 | 
			
		||||
                    this.reportActivityAndRegister(sessionInfo);
 | 
			
		||||
                    if (registration.getBindingMode().useQueueMode()) {
 | 
			
		||||
                    if (registration.getQueueMode()) {
 | 
			
		||||
                        LwM2mQueuedRequest request;
 | 
			
		||||
                        while ((request = client.getQueuedRequests().poll()) != null) {
 | 
			
		||||
                            request.send();
 | 
			
		||||
@ -858,7 +858,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
 | 
			
		||||
                            valueKvProto = new JsonObject();
 | 
			
		||||
                            Object finalvalueKvProto = valueKvProto;
 | 
			
		||||
                            Gson gson = new GsonBuilder().create();
 | 
			
		||||
                            resourceValue.getValues().forEach((k, v) -> {
 | 
			
		||||
                            resourceValue.getInstances().forEach((k, v) -> {
 | 
			
		||||
                                Object val = this.converter.convertValue(v, currentType, expectedType,
 | 
			
		||||
                                        new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)));
 | 
			
		||||
                                JsonElement element = gson.toJsonTree(val, val.getClass());
 | 
			
		||||
 | 
			
		||||
@ -32,10 +32,10 @@ import org.eclipse.leshan.core.observation.Observation;
 | 
			
		||||
import org.eclipse.leshan.core.request.ContentFormat;
 | 
			
		||||
import org.eclipse.leshan.core.request.DeleteRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.DiscoverRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.DownlinkRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.ExecuteRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.ObserveRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.ReadRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.SimpleDownlinkRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.WriteAttributesRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.WriteRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.exception.ClientSleepingException;
 | 
			
		||||
@ -135,13 +135,13 @@ public class LwM2mTransportRequest {
 | 
			
		||||
            if (!OBSERVE_CANCEL.name().equals(typeOper.name()) && resultIds != null && registration != null && resultIds.getObjectId() >= 0 && lwM2MClient != null) {
 | 
			
		||||
                if (lwM2MClient.isValidObjectVersion(targetIdVer)) {
 | 
			
		||||
                    timeoutInMs = timeoutInMs > 0 ? timeoutInMs : DEFAULT_TIMEOUT;
 | 
			
		||||
                    DownlinkRequest request = createRequest(registration, lwM2MClient, typeOper, contentFormat, target,
 | 
			
		||||
                    SimpleDownlinkRequest request = createRequest(registration, lwM2MClient, typeOper, contentFormat, target,
 | 
			
		||||
                            targetIdVer, resultIds, params, lwm2mClientRpcRequest);
 | 
			
		||||
                    if (request != null) {
 | 
			
		||||
                        try {
 | 
			
		||||
                            this.sendRequest(registration, lwM2MClient, request, timeoutInMs, lwm2mClientRpcRequest);
 | 
			
		||||
                        } catch (ClientSleepingException e) {
 | 
			
		||||
                            DownlinkRequest finalRequest = request;
 | 
			
		||||
                            SimpleDownlinkRequest finalRequest = request;
 | 
			
		||||
                            long finalTimeoutInMs = timeoutInMs;
 | 
			
		||||
                            Lwm2mClientRpcRequest finalRpcRequest = lwm2mClientRpcRequest;
 | 
			
		||||
                            lwM2MClient.getQueuedRequests().add(() -> sendRequest(registration, lwM2MClient, finalRequest, finalTimeoutInMs, finalRpcRequest));
 | 
			
		||||
@ -223,10 +223,10 @@ public class LwM2mTransportRequest {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private DownlinkRequest createRequest(Registration registration, LwM2mClient lwM2MClient, LwM2mTypeOper typeOper,
 | 
			
		||||
    private SimpleDownlinkRequest createRequest(Registration registration, LwM2mClient lwM2MClient, LwM2mTypeOper typeOper,
 | 
			
		||||
                                          ContentFormat contentFormat, String target, String targetIdVer,
 | 
			
		||||
                                          LwM2mPath resultIds, Object params, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
        DownlinkRequest request = null;
 | 
			
		||||
        SimpleDownlinkRequest request = null;
 | 
			
		||||
        switch (typeOper) {
 | 
			
		||||
            case READ:
 | 
			
		||||
                request = new ReadRequest(contentFormat, target);
 | 
			
		||||
@ -329,7 +329,7 @@ public class LwM2mTransportRequest {
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings({"error sendRequest"})
 | 
			
		||||
    private void sendRequest(Registration registration, LwM2mClient lwM2MClient, DownlinkRequest request,
 | 
			
		||||
    private void sendRequest(Registration registration, LwM2mClient lwM2MClient, SimpleDownlinkRequest request,
 | 
			
		||||
                             long timeoutInMs, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
        context.getServer().send(registration, request, timeoutInMs, (ResponseCallback<?>) response -> {
 | 
			
		||||
 | 
			
		||||
@ -444,7 +444,7 @@ public class LwM2mTransportRequest {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void handleResponse(Registration registration, final String path, LwM2mResponse response,
 | 
			
		||||
                                DownlinkRequest request, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
                                SimpleDownlinkRequest request, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
        responseRequestExecutor.submit(() -> {
 | 
			
		||||
            try {
 | 
			
		||||
                this.sendResponse(registration, path, response, request, rpcRequest);
 | 
			
		||||
@ -462,7 +462,7 @@ public class LwM2mTransportRequest {
 | 
			
		||||
     * @param response     -
 | 
			
		||||
     */
 | 
			
		||||
    private void sendResponse(Registration registration, String path, LwM2mResponse response,
 | 
			
		||||
                              DownlinkRequest request, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
                              SimpleDownlinkRequest request, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
        String pathIdVer = convertPathFromObjectIdToIdVer(path, registration);
 | 
			
		||||
        String msgLog = "";
 | 
			
		||||
        if (response instanceof ReadResponse) {
 | 
			
		||||
@ -509,7 +509,7 @@ public class LwM2mTransportRequest {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void infoWriteResponse(Registration registration, LwM2mResponse response, DownlinkRequest request, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
    private void infoWriteResponse(Registration registration, LwM2mResponse response, SimpleDownlinkRequest request, Lwm2mClientRpcRequest rpcRequest) {
 | 
			
		||||
        try {
 | 
			
		||||
            LwM2mNode node = ((WriteRequest) request).getNode();
 | 
			
		||||
            String msg = null;
 | 
			
		||||
@ -566,7 +566,7 @@ public class LwM2mTransportRequest {
 | 
			
		||||
     * fw_state/sw_state = DOWNLOADED
 | 
			
		||||
     * send operation Execute
 | 
			
		||||
     */
 | 
			
		||||
    private void afterWriteSuccessFwSwUpdate(Registration registration, DownlinkRequest request) {
 | 
			
		||||
    private void afterWriteSuccessFwSwUpdate(Registration registration, SimpleDownlinkRequest request) {
 | 
			
		||||
        LwM2mClient lwM2MClient = this.lwM2mClientContext.getClientByRegistrationId(registration.getId());
 | 
			
		||||
        if (request.getPath().toString().equals(FW_PACKAGE_ID) && lwM2MClient.getFwUpdate() != null) {
 | 
			
		||||
            lwM2MClient.getFwUpdate().setStateUpdate(DOWNLOADED.name());
 | 
			
		||||
@ -581,7 +581,7 @@ public class LwM2mTransportRequest {
 | 
			
		||||
    /**
 | 
			
		||||
     * After finish operation FwSwUpdate Write (error):  fw_state = FAILED
 | 
			
		||||
     */
 | 
			
		||||
    private void afterWriteFwSWUpdateError(Registration registration, DownlinkRequest request, String msgError) {
 | 
			
		||||
    private void afterWriteFwSWUpdateError(Registration registration, SimpleDownlinkRequest request, String msgError) {
 | 
			
		||||
        LwM2mClient lwM2MClient = this.lwM2mClientContext.getClientByRegistrationId(registration.getId());
 | 
			
		||||
        if (request.getPath().toString().equals(FW_PACKAGE_ID) && lwM2MClient.getFwUpdate() != null) {
 | 
			
		||||
            lwM2MClient.getFwUpdate().setStateUpdate(FAILED.name());
 | 
			
		||||
@ -593,7 +593,7 @@ public class LwM2mTransportRequest {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void afterExecuteFwSwUpdateError(Registration registration, DownlinkRequest request, String msgError) {
 | 
			
		||||
    private void afterExecuteFwSwUpdateError(Registration registration, SimpleDownlinkRequest request, String msgError) {
 | 
			
		||||
        LwM2mClient lwM2MClient = this.lwM2mClientContext.getClientByRegistrationId(registration.getId());
 | 
			
		||||
        if (request.getPath().toString().equals(FW_UPDATE_ID) && lwM2MClient.getFwUpdate() != null) {
 | 
			
		||||
            lwM2MClient.getFwUpdate().sendLogs(this.handler, EXECUTE.name(), LOG_LW2M_ERROR, msgError);
 | 
			
		||||
 | 
			
		||||
@ -137,7 +137,7 @@ public class LwM2mTransportServerHelper {
 | 
			
		||||
    public ObjectModel parseFromXmlToObjectModel(byte[] xmlByte, String streamName, DefaultDDFFileValidator ddfValidator) {
 | 
			
		||||
        try {
 | 
			
		||||
            DDFFileParser ddfFileParser = new DDFFileParser(ddfValidator);
 | 
			
		||||
            return ddfFileParser.parseEx(new ByteArrayInputStream(xmlByte), streamName).get(0);
 | 
			
		||||
            return ddfFileParser.parse(new ByteArrayInputStream(xmlByte), streamName).get(0);
 | 
			
		||||
        } catch (IOException | InvalidDDFFileException e) {
 | 
			
		||||
            log.error("Could not parse the XML file [{}]", streamName, e);
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
@ -36,7 +36,7 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance;
 | 
			
		||||
import org.eclipse.leshan.core.node.LwM2mPath;
 | 
			
		||||
import org.eclipse.leshan.core.node.LwM2mSingleResource;
 | 
			
		||||
import org.eclipse.leshan.core.node.codec.CodecException;
 | 
			
		||||
import org.eclipse.leshan.core.request.DownlinkRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.SimpleDownlinkRequest;
 | 
			
		||||
import org.eclipse.leshan.core.request.WriteAttributesRequest;
 | 
			
		||||
import org.eclipse.leshan.core.util.Hex;
 | 
			
		||||
import org.eclipse.leshan.server.registration.Registration;
 | 
			
		||||
@ -839,7 +839,7 @@ public class LwM2mTransportUtil {
 | 
			
		||||
     * Attribute pmax = new Attribute(MAXIMUM_PERIOD, "60");
 | 
			
		||||
     * Attribute [] attrs = {gt, st};
 | 
			
		||||
     */
 | 
			
		||||
    public static DownlinkRequest createWriteAttributeRequest(String target, Object params, DefaultLwM2MTransportMsgHandler serviceImpl) {
 | 
			
		||||
    public static SimpleDownlinkRequest createWriteAttributeRequest(String target, Object params, DefaultLwM2MTransportMsgHandler serviceImpl) {
 | 
			
		||||
        AttributeSet attrSet = new AttributeSet(createWriteAttributes(params, serviceImpl, target));
 | 
			
		||||
        return attrSet.getAttributes().size() > 0 ? new WriteAttributesRequest(target, attrSet) : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -193,9 +193,7 @@ public class LwM2mClient implements Cloneable {
 | 
			
		||||
    public Object getResourceValue(String pathRezIdVer, String pathRezId) {
 | 
			
		||||
        String pathRez = pathRezIdVer == null ? convertPathFromObjectIdToIdVer(pathRezId, this.registration) : pathRezIdVer;
 | 
			
		||||
        if (this.resources.get(pathRez) != null) {
 | 
			
		||||
            return this.resources.get(pathRez).getLwM2mResource().isMultiInstances() ?
 | 
			
		||||
                    this.resources.get(pathRez).getLwM2mResource().getValues() :
 | 
			
		||||
                    this.resources.get(pathRez).getLwM2mResource().getValue();
 | 
			
		||||
            return this.resources.get(pathRez).getLwM2mResource().getValue();
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -22,11 +22,13 @@ import org.eclipse.leshan.core.Destroyable;
 | 
			
		||||
import org.eclipse.leshan.core.Startable;
 | 
			
		||||
import org.eclipse.leshan.core.Stoppable;
 | 
			
		||||
import org.eclipse.leshan.core.observation.Observation;
 | 
			
		||||
import org.eclipse.leshan.core.request.Identity;
 | 
			
		||||
import org.eclipse.leshan.core.util.NamedThreadFactory;
 | 
			
		||||
import org.eclipse.leshan.core.util.Validate;
 | 
			
		||||
import org.eclipse.leshan.server.californium.observation.ObserveUtil;
 | 
			
		||||
import org.eclipse.leshan.server.californium.registration.CaliforniumRegistrationStore;
 | 
			
		||||
import org.eclipse.leshan.server.redis.RedisRegistrationStore;
 | 
			
		||||
import org.eclipse.leshan.server.redis.serialization.IdentitySerDes;
 | 
			
		||||
import org.eclipse.leshan.server.redis.serialization.ObservationSerDes;
 | 
			
		||||
import org.eclipse.leshan.server.redis.serialization.RegistrationSerDes;
 | 
			
		||||
import org.eclipse.leshan.server.registration.Deregistration;
 | 
			
		||||
@ -73,6 +75,7 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
    private static final String REG_EP = "REG:EP:"; // (Endpoint => Registration)
 | 
			
		||||
    private static final String REG_EP_REGID_IDX = "EP:REGID:"; // secondary index key (Registration ID => Endpoint)
 | 
			
		||||
    private static final String REG_EP_ADDR_IDX = "EP:ADDR:"; // secondary index key (Socket Address => Endpoint)
 | 
			
		||||
    private static final String REG_EP_IDENTITY = "EP:IDENTITY:"; // secondary index key (Identity => Endpoint)
 | 
			
		||||
    private static final String LOCK_EP = "LOCK:EP:";
 | 
			
		||||
    private static final byte[] OBS_TKN = "OBS:TKN:".getBytes(UTF_8);
 | 
			
		||||
    private static final String OBS_TKNS_REGID_IDX = "TKNS:REGID:"; // secondary index (token list by registration)
 | 
			
		||||
@ -155,6 +158,8 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
                connection.set(regid_idx, registration.getEndpoint().getBytes(UTF_8));
 | 
			
		||||
                byte[] addr_idx = toRegAddrKey(registration.getSocketAddress());
 | 
			
		||||
                connection.set(addr_idx, registration.getEndpoint().getBytes(UTF_8));
 | 
			
		||||
                byte[] identity_idx = toRegIdentityKey(registration.getIdentity());
 | 
			
		||||
                connection.set(identity_idx, registration.getEndpoint().getBytes(UTF_8));
 | 
			
		||||
 | 
			
		||||
                // Add or update expiration
 | 
			
		||||
                addOrUpdateExpiration(connection, registration);
 | 
			
		||||
@ -167,6 +172,9 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
                    if (!oldRegistration.getSocketAddress().equals(registration.getSocketAddress())) {
 | 
			
		||||
                        removeAddrIndex(connection, oldRegistration);
 | 
			
		||||
                    }
 | 
			
		||||
                    if (!oldRegistration.getIdentity().equals(registration.getIdentity())) {
 | 
			
		||||
                        removeIdentityIndex(connection, oldRegistration);
 | 
			
		||||
                    }
 | 
			
		||||
                    // remove old observation
 | 
			
		||||
                    Collection<Observation> obsRemoved = unsafeRemoveAllObservations(connection, oldRegistration.getId());
 | 
			
		||||
 | 
			
		||||
@ -222,6 +230,9 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
                if (!r.getSocketAddress().equals(updatedRegistration.getSocketAddress())) {
 | 
			
		||||
                    removeAddrIndex(connection, r);
 | 
			
		||||
                }
 | 
			
		||||
                if (!r.getIdentity().equals(updatedRegistration.getIdentity())) {
 | 
			
		||||
                    removeIdentityIndex(connection, r);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return new UpdatedRegistration(r, updatedRegistration);
 | 
			
		||||
 | 
			
		||||
@ -268,6 +279,22 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Registration getRegistrationByIdentity(Identity identity) {
 | 
			
		||||
        Validate.notNull(identity);
 | 
			
		||||
        try (var connection = connectionFactory.getConnection()) {
 | 
			
		||||
            byte[] ep = connection.get(toRegIdentityKey(identity));
 | 
			
		||||
            if (ep == null) {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
            byte[] data = connection.get(toEndpointKey(ep));
 | 
			
		||||
            if (data == null) {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
            return deserializeReg(data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Iterator<Registration> getAllRegistrations() {
 | 
			
		||||
        try (var connection = connectionFactory.getConnection()) {
 | 
			
		||||
@ -325,6 +352,7 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
                    connection.del(toEndpointKey(r.getEndpoint()));
 | 
			
		||||
                    Collection<Observation> obsRemoved = unsafeRemoveAllObservations(connection, r.getId());
 | 
			
		||||
                    removeAddrIndex(connection, r);
 | 
			
		||||
                    removeIdentityIndex(connection, r);
 | 
			
		||||
                    removeExpiration(connection, r);
 | 
			
		||||
                    return new Deregistration(r, obsRemoved);
 | 
			
		||||
                }
 | 
			
		||||
@ -337,20 +365,27 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO: JedisCluster didn't implement Transaction, maybe should use some advanced key creation strategies
 | 
			
		||||
    private void removeAddrIndex(RedisConnection connection, Registration registration) {
 | 
			
		||||
        // Watch the key to remove.
 | 
			
		||||
        byte[] regAddrKey = toRegAddrKey(registration.getSocketAddress());
 | 
			
		||||
//        connection.watch(regAddrKey);
 | 
			
		||||
    private void removeAddrIndex(RedisConnection connection, Registration r) {
 | 
			
		||||
        removeSecondaryIndex(connection, toRegAddrKey(r.getSocketAddress()), r.getEndpoint());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        byte[] epFromAddr = connection.get(regAddrKey);
 | 
			
		||||
    private void removeIdentityIndex(RedisConnection connection, Registration r) {
 | 
			
		||||
        removeSecondaryIndex(connection, toRegIdentityKey(r.getIdentity()), r.getEndpoint());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO: JedisCluster didn't implement Transaction, maybe should use some advanced key creation strategies
 | 
			
		||||
    private void removeSecondaryIndex(RedisConnection connection, byte[] indexKey, String endpointName) {
 | 
			
		||||
        // Watch the key to remove.
 | 
			
		||||
//        connection.watch(indexKey);
 | 
			
		||||
 | 
			
		||||
        byte[] epFromAddr = connection.get(indexKey);
 | 
			
		||||
        // Delete the key if needed.
 | 
			
		||||
        if (Arrays.equals(epFromAddr, registration.getEndpoint().getBytes(UTF_8))) {
 | 
			
		||||
        if (Arrays.equals(epFromAddr, endpointName.getBytes(UTF_8))) {
 | 
			
		||||
            // Try to delete the key
 | 
			
		||||
//            connection.multi();
 | 
			
		||||
            connection.del(regAddrKey);
 | 
			
		||||
            connection.del(indexKey);
 | 
			
		||||
//            connection.exec();
 | 
			
		||||
            // if transaction failed this is not an issue as the socket address is probably reused and we don't neeed to
 | 
			
		||||
            // if transaction failed this is not an issue as the index is probably reused and we don't need to
 | 
			
		||||
            // delete it anymore.
 | 
			
		||||
        } else {
 | 
			
		||||
            // the key must not be deleted.
 | 
			
		||||
@ -374,6 +409,10 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
        return toKey(REG_EP_ADDR_IDX, addr.getAddress().toString() + ":" + addr.getPort());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private byte[] toRegIdentityKey(Identity identity) {
 | 
			
		||||
        return toKey(REG_EP_IDENTITY, IdentitySerDes.serialize(identity).toString());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private byte[] toEndpointKey(String endpoint) {
 | 
			
		||||
        return toKey(REG_EP, endpoint);
 | 
			
		||||
    }
 | 
			
		||||
@ -723,7 +762,6 @@ public class TbLwM2mRedisRegistrationStore implements CaliforniumRegistrationSto
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void run() {
 | 
			
		||||
 | 
			
		||||
            try (var connection = connectionFactory.getConnection()) {
 | 
			
		||||
                Set<byte[]> endpointsExpired = connection.zRangeByScore(EXP_EP, Double.NEGATIVE_INFINITY,
 | 
			
		||||
                        System.currentTimeMillis(), 0, cleanLimit);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								pom.xml
									
									
									
									
									
								
							@ -69,9 +69,7 @@
 | 
			
		||||
        <jackson-core.version>2.12.1</jackson-core.version>
 | 
			
		||||
        <json-schema-validator.version>2.2.6</json-schema-validator.version>
 | 
			
		||||
        <californium.version>2.6.1</californium.version>
 | 
			
		||||
        <leshan-server.version>1.3.1</leshan-server.version>
 | 
			
		||||
        <leshan-core.version>1.3.1</leshan-core.version>
 | 
			
		||||
        <leshan-client.version>1.3.1</leshan-client.version>
 | 
			
		||||
        <leshan.version>2.0.0-M3</leshan.version>
 | 
			
		||||
        <gson.version>2.6.2</gson.version>
 | 
			
		||||
        <freemarker.version>2.3.30</freemarker.version>
 | 
			
		||||
        <mail.version>1.6.2</mail.version>
 | 
			
		||||
@ -1222,22 +1220,22 @@
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.eclipse.leshan</groupId>
 | 
			
		||||
                <artifactId>leshan-server-cf</artifactId>
 | 
			
		||||
                <version>${leshan-server.version}</version>
 | 
			
		||||
                <version>${leshan.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.eclipse.leshan</groupId>
 | 
			
		||||
                <artifactId>leshan-client-cf</artifactId>
 | 
			
		||||
                <version>${leshan-client.version}</version>
 | 
			
		||||
                <version>${leshan.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.eclipse.leshan</groupId>
 | 
			
		||||
                <artifactId>leshan-server-redis</artifactId>
 | 
			
		||||
                <version>${leshan-server.version}</version>
 | 
			
		||||
                <version>${leshan.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.eclipse.leshan</groupId>
 | 
			
		||||
                <artifactId>leshan-core</artifactId>
 | 
			
		||||
                <version>${leshan-core.version}</version>
 | 
			
		||||
                <version>${leshan.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>org.eclipse.californium</groupId>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user