Merge pull request #6522 from rocknitive/feature/coap-piggyback-response
[3.4] Piggybacked CoAP responses
This commit is contained in:
commit
ee771dd055
@ -706,6 +706,7 @@ transport:
|
|||||||
bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}"
|
bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}"
|
||||||
bind_port: "${COAP_BIND_PORT:5683}"
|
bind_port: "${COAP_BIND_PORT:5683}"
|
||||||
timeout: "${COAP_TIMEOUT:10000}"
|
timeout: "${COAP_TIMEOUT:10000}"
|
||||||
|
piggyback_timeout: "${COAP_PIGGYBACK_TIMEOUT:500}"
|
||||||
psm_activity_timer: "${COAP_PSM_ACTIVITY_TIMER:10000}"
|
psm_activity_timer: "${COAP_PSM_ACTIVITY_TIMER:10000}"
|
||||||
paging_transmission_window: "${COAP_PAGING_TRANSMISSION_WINDOW:10000}"
|
paging_transmission_window: "${COAP_PAGING_TRANSMISSION_WINDOW:10000}"
|
||||||
dtls:
|
dtls:
|
||||||
|
|||||||
@ -38,6 +38,10 @@ public class CoapServerContext {
|
|||||||
@Value("${transport.coap.timeout}")
|
@Value("${transport.coap.timeout}")
|
||||||
private Long timeout;
|
private Long timeout;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Value("${transport.coap.piggyback_timeout}")
|
||||||
|
private Long piggybackTimeout;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Value("${transport.coap.psm_activity_timer:10000}")
|
@Value("${transport.coap.psm_activity_timer:10000}")
|
||||||
private long psmActivityTimer;
|
private long psmActivityTimer;
|
||||||
|
|||||||
@ -29,4 +29,6 @@ public interface CoapServerService {
|
|||||||
|
|
||||||
long getTimeout();
|
long getTimeout();
|
||||||
|
|
||||||
|
long getPiggybackTimeout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,6 +88,11 @@ public class DefaultCoapServerService implements CoapServerService {
|
|||||||
return coapServerContext.getTimeout();
|
return coapServerContext.getTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPiggybackTimeout() {
|
||||||
|
return coapServerContext.getPiggybackTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
private CoapServer createCoapServer() throws UnknownHostException {
|
private CoapServer createCoapServer() throws UnknownHostException {
|
||||||
Configuration networkConfig = new Configuration();
|
Configuration networkConfig = new Configuration();
|
||||||
networkConfig.set(CoapConfig.BLOCKWISE_STRICT_BLOCK2_OPTION, true);
|
networkConfig.set(CoapConfig.BLOCKWISE_STRICT_BLOCK2_OPTION, true);
|
||||||
|
|||||||
@ -69,6 +69,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
|
|
||||||
private final ConcurrentMap<InetSocketAddress, TbCoapDtlsSessionInfo> dtlsSessionsMap;
|
private final ConcurrentMap<InetSocketAddress, TbCoapDtlsSessionInfo> dtlsSessionsMap;
|
||||||
private final long timeout;
|
private final long timeout;
|
||||||
|
private final long piggybackTimeout;
|
||||||
private final CoapClientContext clients;
|
private final CoapClientContext clients;
|
||||||
|
|
||||||
public CoapTransportResource(CoapTransportContext ctx, CoapServerService coapServerService, String name) {
|
public CoapTransportResource(CoapTransportContext ctx, CoapServerService coapServerService, String name) {
|
||||||
@ -77,6 +78,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
this.addObserver(new CoapResourceObserver());
|
this.addObserver(new CoapResourceObserver());
|
||||||
this.dtlsSessionsMap = coapServerService.getDtlsSessionsMap();
|
this.dtlsSessionsMap = coapServerService.getDtlsSessionsMap();
|
||||||
this.timeout = coapServerService.getTimeout();
|
this.timeout = coapServerService.getTimeout();
|
||||||
|
this.piggybackTimeout = coapServerService.getPiggybackTimeout();
|
||||||
this.clients = ctx.getClientContext();
|
this.clients = ctx.getClientContext();
|
||||||
long sessionReportTimeout = ctx.getSessionReportTimeout();
|
long sessionReportTimeout = ctx.getSessionReportTimeout();
|
||||||
ctx.getScheduler().scheduleAtFixedRate(clients::reportActivity, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS);
|
ctx.getScheduler().scheduleAtFixedRate(clients::reportActivity, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS);
|
||||||
@ -169,7 +171,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void processProvision(CoapExchange exchange) {
|
private void processProvision(CoapExchange exchange) {
|
||||||
exchange.accept();
|
deferAccept(exchange);
|
||||||
try {
|
try {
|
||||||
UUID sessionId = UUID.randomUUID();
|
UUID sessionId = UUID.randomUUID();
|
||||||
log.trace("[{}] Processing provision publish msg [{}]!", sessionId, exchange.advanced().getRequest());
|
log.trace("[{}] Processing provision publish msg [{}]!", sessionId, exchange.advanced().getRequest());
|
||||||
@ -195,7 +197,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
|
|
||||||
private void processRequest(CoapExchange exchange, SessionMsgType type) {
|
private void processRequest(CoapExchange exchange, SessionMsgType type) {
|
||||||
log.trace("Processing {}", exchange.advanced().getRequest());
|
log.trace("Processing {}", exchange.advanced().getRequest());
|
||||||
exchange.accept();
|
deferAccept(exchange);
|
||||||
Exchange advanced = exchange.advanced();
|
Exchange advanced = exchange.advanced();
|
||||||
Request request = advanced.getRequest();
|
Request request = advanced.getRequest();
|
||||||
|
|
||||||
@ -346,6 +348,20 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
new CoapNoOpCallback(exchange));
|
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) {
|
||||||
|
if (piggybackTimeout > 0) {
|
||||||
|
transportContext.getScheduler().schedule(exchange::accept, piggybackTimeout, TimeUnit.MILLISECONDS);
|
||||||
|
} else {
|
||||||
|
exchange.accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private UUID toSessionId(TransportProtos.SessionInfoProto sessionInfoProto) {
|
private UUID toSessionId(TransportProtos.SessionInfoProto sessionInfoProto) {
|
||||||
return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
|
return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,6 +89,7 @@ transport:
|
|||||||
bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}"
|
bind_address: "${COAP_BIND_ADDRESS:0.0.0.0}"
|
||||||
bind_port: "${COAP_BIND_PORT:5683}"
|
bind_port: "${COAP_BIND_PORT:5683}"
|
||||||
timeout: "${COAP_TIMEOUT:10000}"
|
timeout: "${COAP_TIMEOUT:10000}"
|
||||||
|
piggyback_timeout: "${COAP_PIGGYBACK_TIMEOUT:500}"
|
||||||
psm_activity_timer: "${COAP_PSM_ACTIVITY_TIMER:10000}"
|
psm_activity_timer: "${COAP_PSM_ACTIVITY_TIMER:10000}"
|
||||||
paging_transmission_window: "${COAP_PAGING_TRANSMISSION_WINDOW:10000}"
|
paging_transmission_window: "${COAP_PAGING_TRANSMISSION_WINDOW:10000}"
|
||||||
dtls:
|
dtls:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user