Browse Source

use coap piggybacked responses if possible

pull/6522/head
Jan Christoph Bernack 4 years ago
parent
commit
5f548f2179
No known key found for this signature in database GPG Key ID: BD807E5761329D0A
  1. 14
      common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java

14
common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java

@ -169,7 +169,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
}
private void processProvision(CoapExchange exchange) {
exchange.accept();
deferAccept(exchange);
try {
UUID sessionId = UUID.randomUUID();
log.trace("[{}] Processing provision publish msg [{}]!", sessionId, exchange.advanced().getRequest());
@ -195,7 +195,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
private void processRequest(CoapExchange exchange, SessionMsgType type) {
log.trace("Processing {}", exchange.advanced().getRequest());
exchange.accept();
deferAccept(exchange);
Exchange advanced = exchange.advanced();
Request request = advanced.getRequest();
@ -346,6 +346,16 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
new CoapNoOpCallback(exchange));
}
/**
* Send an empty ACK if we are unable to send the full response within the timeout.
* If the full response is transmitted before the timeout this will not do anything.
* If this is triggered the full response will be sent in a separate CON/NON message.
* Essentially this allows the use of piggybacked responses.
*/
private void deferAccept(CoapExchange exchange) {
transportContext.getScheduler().schedule(exchange::accept, 500, TimeUnit.MILLISECONDS);
}
private UUID toSessionId(TransportProtos.SessionInfoProto sessionInfoProto) {
return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
}

Loading…
Cancel
Save