/** * If we receive an ACK or RST, we mark the outgoing request or response as * acknowledged or rejected respectively and cancel its retransmission. */ @Override public void receiveEmptyMessage(final Exchange exchange, final EmptyMessage message) { exchange.setFailedTransmissionCount(0); // TODO: If this is an observe relation, the current response might not // be the one that is being acknowledged. The current response might // already be the next NON notification. if (message.getType() == Type.ACK) { if (exchange.isOfLocalOrigin()) { exchange.getCurrentRequest().setAcknowledged(true); } else { exchange.getCurrentResponse().setAcknowledged(true); } } else if (message.getType() == Type.RST) { if (exchange.isOfLocalOrigin()) { exchange.getCurrentRequest().setRejected(true); } else { exchange.getCurrentResponse().setRejected(true); } } else { LOGGER.log(Level.WARNING, "received empty message that is neither ACK nor RST: {0}", message); } exchange.setRetransmissionHandle(null); upper().receiveEmptyMessage(exchange, message); }
private BlockwiseStatus findRequestBlockStatus(final Exchange exchange, final Request request) { BlockwiseStatus status = exchange.getRequestBlockStatus(); if (status == null) { if (exchange.isOfLocalOrigin()) { // we are sending a large body out in a POST/GET to a peer // we only need to buffer one block each status = new BlockwiseStatus(preferredBlockSize, request.getOptions().getContentFormat()); } else { // we are receiving a large body in a POST/GET from a peer // we need to be prepared to buffer up to MAX_RESOURCE_BODY_SIZE bytes int bufferSize = maxResourceBodySize; if (request.getOptions().hasBlock1() && request.getOptions().hasSize1()) { // use size indication for allocating buffer bufferSize = request.getOptions().getSize1(); } status = new BlockwiseStatus(bufferSize, request.getOptions().getContentFormat()); } status.setFirst(request); status.setCurrentSzx(computeSZX(preferredBlockSize)); exchange.setRequestBlockStatus(status); LOGGER.log(Level.FINER, "There is no assembler status yet. Create and set new Block1 status: {0}", status); } else { LOGGER.log(Level.FINER, "Current Block1 status: {0}", status); } // sets a timeout to complete exchange prepareBlockCleanup(exchange); return status; }
private BlockwiseStatus findResponseBlockStatus(final Exchange exchange, final Response response) { BlockwiseStatus status = exchange.getResponseBlockStatus(); if (status == null) { if (exchange.isOfLocalOrigin()) { // we are receiving a large body in response to a request originating locally // we need to be prepared to buffer up to MAX_RESOURCE_BODY_SIZE bytes int bufferSize = maxResourceBodySize; if (response.getOptions().hasBlock2() && response.getOptions().hasSize2()) { // use size indication for allocating buffer bufferSize = response.getOptions().getSize2(); } status = new BlockwiseStatus(bufferSize, response.getOptions().getContentFormat()); } else { // we are sending out a large body in response to a request from a peer // we do not need to buffer and assemble anything status = new BlockwiseStatus(0, response.getOptions().getContentFormat()); } status.setCurrentSzx(computeSZX(preferredBlockSize)); status.setFirst(response); exchange.setResponseBlockStatus(status); LOGGER.log(Level.FINER, "There is no blockwise status yet. Create and set new Block2 status: {0}", status); } else { LOGGER.log(Level.FINER, "Current Block2 status: {0}", status); } // sets a timeout to complete exchange prepareBlockCleanup(exchange); return status; }