...
|
...
|
@@ -28,12 +28,10 @@ import org.eclipse.leshan.core.node.LwM2mObjectInstance; |
28
|
28
|
import org.eclipse.leshan.core.node.LwM2mPath;
|
29
|
29
|
import org.eclipse.leshan.core.node.LwM2mResource;
|
30
|
30
|
import org.eclipse.leshan.core.observation.Observation;
|
31
|
|
-import org.eclipse.leshan.core.request.ExecuteRequest;
|
32
|
31
|
import org.eclipse.leshan.core.request.ObserveRequest;
|
33
|
32
|
import org.eclipse.leshan.core.request.ReadRequest;
|
34
|
33
|
import org.eclipse.leshan.core.request.WriteCompositeRequest;
|
35
|
34
|
import org.eclipse.leshan.core.request.WriteRequest;
|
36
|
|
-import org.eclipse.leshan.core.response.ExecuteResponse;
|
37
|
35
|
import org.eclipse.leshan.core.response.ObserveResponse;
|
38
|
36
|
import org.eclipse.leshan.core.response.ReadCompositeResponse;
|
39
|
37
|
import org.eclipse.leshan.core.response.ReadResponse;
|
...
|
...
|
@@ -77,7 +75,6 @@ import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObser |
77
|
75
|
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveRequest;
|
78
|
76
|
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MDiscoverCallback;
|
79
|
77
|
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MDiscoverRequest;
|
80
|
|
-import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MExecuteRequest;
|
81
|
78
|
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback;
|
82
|
79
|
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback;
|
83
|
80
|
import org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveRequest;
|
...
|
...
|
@@ -89,6 +86,7 @@ import org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogServic |
89
|
86
|
import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService;
|
90
|
87
|
import org.thingsboard.server.transport.lwm2m.server.session.LwM2MSessionManager;
|
91
|
88
|
import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore;
|
|
89
|
+import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2mSecurityStore;
|
92
|
90
|
import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
|
93
|
91
|
|
94
|
92
|
import javax.annotation.PostConstruct;
|
...
|
...
|
@@ -135,8 +133,6 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
135
|
133
|
|
136
|
134
|
public LwM2mValueConverterImpl converter;
|
137
|
135
|
|
138
|
|
- private static final String REBOOT_ID = "/3/0/4";
|
139
|
|
-
|
140
|
136
|
private final TransportService transportService;
|
141
|
137
|
private final LwM2mTransportContext context;
|
142
|
138
|
private final LwM2MAttributesService attributesService;
|
...
|
...
|
@@ -150,6 +146,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
150
|
146
|
private final LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler;
|
151
|
147
|
private final LwM2mVersionedModelProvider modelProvider;
|
152
|
148
|
private final RegistrationStore registrationStore;
|
|
149
|
+ private final TbLwM2mSecurityStore securityStore;
|
153
|
150
|
|
154
|
151
|
public DefaultLwM2MUplinkMsgHandler(TransportService transportService,
|
155
|
152
|
LwM2MTransportServerConfig config,
|
...
|
...
|
@@ -163,7 +160,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
163
|
160
|
LwM2mTransportContext context,
|
164
|
161
|
TbLwM2MDtlsSessionStore sessionStore,
|
165
|
162
|
LwM2mVersionedModelProvider modelProvider,
|
166
|
|
- RegistrationStore registrationStore) {
|
|
163
|
+ RegistrationStore registrationStore, TbLwM2mSecurityStore securityStore) {
|
167
|
164
|
this.transportService = transportService;
|
168
|
165
|
this.sessionManager = sessionManager;
|
169
|
166
|
this.attributesService = attributesService;
|
...
|
...
|
@@ -177,6 +174,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
177
|
174
|
this.sessionStore = sessionStore;
|
178
|
175
|
this.modelProvider = modelProvider;
|
179
|
176
|
this.registrationStore = registrationStore;
|
|
177
|
+ this.securityStore = securityStore;
|
180
|
178
|
}
|
181
|
179
|
|
182
|
180
|
@PostConstruct
|
...
|
...
|
@@ -282,15 +280,12 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
282
|
280
|
* @param observations - !!! Warn: if have not finishing unReg, then this operation will be finished on next Client`s connect
|
283
|
281
|
*/
|
284
|
282
|
public void unReg(Registration registration, Collection<Observation> observations) {
|
285
|
|
- executor.submit(() -> {
|
286
|
|
- LwM2mClient client = clientContext.getClientByEndpoint(registration.getEndpoint());
|
287
|
|
- logService.log(client, LOG_LWM2M_INFO + ": Client unRegistration");
|
288
|
|
- doUnReg(registration, client);
|
289
|
|
- });
|
|
283
|
+ executor.submit(() -> doUnReg(registration, clientContext.getClientByEndpoint(registration.getEndpoint())));
|
290
|
284
|
}
|
291
|
285
|
|
292
|
286
|
private void doUnReg(Registration registration, LwM2mClient client) {
|
293
|
287
|
try {
|
|
288
|
+ logService.log(client, LOG_LWM2M_INFO + ": Client unRegistration");
|
294
|
289
|
clientContext.unregister(client, registration);
|
295
|
290
|
SessionInfoProto sessionInfo = client.getSession();
|
296
|
291
|
if (sessionInfo != null) {
|
...
|
...
|
@@ -405,23 +400,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
405
|
400
|
|
406
|
401
|
@Override
|
407
|
402
|
public void onDeviceDelete(DeviceId deviceId) {
|
408
|
|
- LwM2mClient client = clientContext.getClientByDeviceId(deviceId.getId());
|
409
|
|
- TbLwM2MExecuteRequest request = TbLwM2MExecuteRequest.builder().versionedId(REBOOT_ID).timeout(clientContext.getRequestTimeout(client)).build();
|
410
|
|
- defaultLwM2MDownlinkMsgHandler.sendExecuteRequest(client, request, new DownlinkRequestCallback<>() {
|
411
|
|
- @Override
|
412
|
|
- public void onSuccess(ExecuteRequest request, ExecuteResponse response) {
|
413
|
|
- }
|
414
|
|
-
|
415
|
|
- @Override
|
416
|
|
- public void onValidationError(String params, String msg) {
|
417
|
|
- }
|
418
|
|
-
|
419
|
|
- @Override
|
420
|
|
- public void onError(String params, Exception e) {
|
421
|
|
- }
|
422
|
|
- });
|
423
|
|
- registrationStore.removeRegistration(client.getRegistration().getId());
|
424
|
|
- doUnReg(client.getRegistration(), client);
|
|
403
|
+ clearAndUnregister(clientContext.getClientByDeviceId(deviceId.getId()));
|
425
|
404
|
}
|
426
|
405
|
|
427
|
406
|
@Override
|
...
|
...
|
@@ -920,8 +899,8 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
920
|
899
|
*/
|
921
|
900
|
@Override
|
922
|
901
|
public void onToTransportUpdateCredentials(SessionInfoProto sessionInfo, TransportProtos.ToTransportUpdateCredentialsProto updateCredentials) {
|
923
|
|
- log.info("[{}] idList [{}] valueList updateCredentials", updateCredentials.getCredentialsIdList(), updateCredentials.getCredentialsValueList());
|
924
|
|
- this.clientContext.removeCredentials(sessionInfo);
|
|
902
|
+ log.info("[{}] updateCredentials", sessionInfo);
|
|
903
|
+ clearAndUnregister(clientContext.getClientBySessionInfo(sessionInfo));
|
925
|
904
|
}
|
926
|
905
|
|
927
|
906
|
/**
|
...
|
...
|
@@ -998,4 +977,16 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl |
998
|
977
|
.setLastActivityTime(System.currentTimeMillis())
|
999
|
978
|
.build(), TransportServiceCallback.EMPTY);
|
1000
|
979
|
}
|
|
980
|
+
|
|
981
|
+ private void clearAndUnregister(LwM2mClient client) {
|
|
982
|
+ client.lock();
|
|
983
|
+ try {
|
|
984
|
+ Registration registration = client.getRegistration();
|
|
985
|
+ doUnReg(registration, client);
|
|
986
|
+ securityStore.remove(registration.getEndpoint(), registration.getId());
|
|
987
|
+ registrationStore.removeRegistration(registration.getId());
|
|
988
|
+ } finally {
|
|
989
|
+ client.unlock();
|
|
990
|
+ }
|
|
991
|
+ }
|
1001
|
992
|
} |
...
|
...
|
|