Search in sources :

Example 1 with TbCoapDtlsSessionInfo

use of org.thingsboard.server.coapserver.TbCoapDtlsSessionInfo in project thingsboard by thingsboard.

the class CoapTransportResource method processRequest.

private void processRequest(CoapExchange exchange, SessionMsgType type) {
    log.trace("Processing {}", exchange.advanced().getRequest());
    exchange.accept();
    Exchange advanced = exchange.advanced();
    Request request = advanced.getRequest();
    var dtlsSessionId = request.getSourceContext().get(KEY_SESSION_ID);
    if (dtlsSessionsMap != null && dtlsSessionId != null && !dtlsSessionId.isEmpty()) {
        TbCoapDtlsSessionInfo tbCoapDtlsSessionInfo = dtlsSessionsMap.computeIfPresent(request.getSourceContext().getPeerAddress(), (dtlsSessionIdStr, dtlsSessionInfo) -> {
            dtlsSessionInfo.setLastActivityTime(System.currentTimeMillis());
            return dtlsSessionInfo;
        });
        if (tbCoapDtlsSessionInfo != null) {
            processRequest(exchange, type, request, tbCoapDtlsSessionInfo.getMsg(), tbCoapDtlsSessionInfo.getDeviceProfile());
        } else {
            processAccessTokenRequest(exchange, type, request);
        }
    } else {
        processAccessTokenRequest(exchange, type, request);
    }
}
Also used : CoapExchange(org.eclipse.californium.core.server.resources.CoapExchange) Exchange(org.eclipse.californium.core.network.Exchange) TbCoapDtlsSessionInfo(org.thingsboard.server.coapserver.TbCoapDtlsSessionInfo) Request(org.eclipse.californium.core.coap.Request)

Aggregations

Request (org.eclipse.californium.core.coap.Request)1 Exchange (org.eclipse.californium.core.network.Exchange)1 CoapExchange (org.eclipse.californium.core.server.resources.CoapExchange)1 TbCoapDtlsSessionInfo (org.thingsboard.server.coapserver.TbCoapDtlsSessionInfo)1