Skip to content

Commit

Permalink
Fix missing receive time for incoming blockwise transfers.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
  • Loading branch information
boaks committed Feb 7, 2024
1 parent 25b4247 commit 958e83b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,9 @@ protected boolean hasBlock(BlockOption block, BlockOption messageOffset) {
* the message, therefore it's very short after actual receiving the
* message.
*
* If a "transparent blockwise-transfers" is received, the time reflects the
* time of the first block.
*
* @return the nano timestamp
* @see ClockUtil#nanoRealtime()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ public final synchronized void assembleReceivedMessage(final Message message) {
message.getOptions().removeBlock1();
message.getOptions().removeBlock2();
message.addMessageSize(messageSize);
message.setNanoTimestamp(firstMessage.getNanoTimestamp());
if (buf.position() > 0) {
if (!message.isIntendedPayload()) {
message.setUnintendedPayload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
import static org.eclipse.californium.core.test.lockstep.IntegrationTestTools.createLockstepEndpoint;
import static org.eclipse.californium.core.test.lockstep.IntegrationTestTools.createRequest;
import static org.eclipse.californium.core.test.lockstep.IntegrationTestTools.printServerLog;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -220,6 +222,7 @@ public void testSimpleGET() throws Exception {

Response response = request.waitForResponse(RESPONSE_TIMEOUT_IN_MS);
assertResponseContainsExpectedPayload(response, respPayload);
assertThat(response.getNanoTimestamp(), is(not(0L)));
}

/**
Expand Down Expand Up @@ -1075,6 +1078,7 @@ public void testAtomicBlockwisePOSTWithBlockwiseResponse() throws Exception {
Response response = request.waitForResponse(RESPONSE_TIMEOUT_IN_MS);
printServerLog(clientInterceptor);
assertResponseContainsExpectedPayload(response, CHANGED, respPayload);
assertThat(response.getNanoTimestamp(), is(not(0L)));
}

@Test
Expand All @@ -1093,6 +1097,7 @@ public void testRandomAccessGET() throws Exception {
Response response = request.waitForResponse(RESPONSE_TIMEOUT_IN_MS);
printServerLog(clientInterceptor);
assertResponseContainsExpectedPayload(response, CONTENT, respPayload.substring(256));
assertThat(response.getNanoTimestamp(), is(not(0L)));
}

@Test
Expand Down Expand Up @@ -1141,6 +1146,7 @@ public void testObserveWithBlockwiseResponse() throws Exception {
Response notification1 = notificationListener.waitForResponse(RESPONSE_TIMEOUT_IN_MS);
assertResponseContainsExpectedPayload(notification1, respPayload);
assertNumberOfReceivedNotifications(notificationListener, 1, true);
assertThat(notification1.getNanoTimestamp(), is(not(0L)));

clientInterceptor.logNewLine("... time passes ...");
respPayload = generateRandomPayload(290);
Expand Down Expand Up @@ -1187,6 +1193,8 @@ public void testObserveWithBlockwiseResponse() throws Exception {
Response notification2 = notificationListener.waitForResponse(RESPONSE_TIMEOUT_IN_MS);
assertResponseContainsExpectedPayload(notification2, respPayload);
assertNumberOfReceivedNotifications(notificationListener, 1, true);
assertThat(notification2.getNanoTimestamp(), is(not(0L)));
assertThat(notification2.getNanoTimestamp(), is(greaterThan(notification1.getNanoTimestamp())));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
import static org.eclipse.californium.core.test.lockstep.IntegrationTestTools.createChangedLockstepEndpoint;
import static org.eclipse.californium.core.test.lockstep.IntegrationTestTools.generateNextToken;
import static org.eclipse.californium.core.test.lockstep.IntegrationTestTools.printServerLog;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -133,7 +134,7 @@ public class BlockwiseServerSideTest {
private CoapTestEndpoint serverEndpoint;
private LockstepEndpoint client;
private int mid = 7000;
private TestResource testResource;
private MyTestResource testResource;
private String respPayload;
private String reqtPayload;
private byte[] etag;
Expand All @@ -155,7 +156,7 @@ public void setup() throws Exception {
etag = null;
expectedMid = null;
expectedToken = null;
testResource = new TestResource(RESOURCE_PATH);
testResource = new MyTestResource(RESOURCE_PATH);
testResource.setObservable(true);
setupServerAndClient();
}
Expand Down Expand Up @@ -684,6 +685,7 @@ public void testSimpleAtomicBlockwisePUT() throws Exception {
expectedMid = ++mid;
client.sendRequest(CON, PUT, expectedToken, expectedMid).path(RESOURCE_PATH).block1(2, false, 128).payload(reqtPayload.substring(256)).go();
client.expectResponse(ACK, CHANGED, expectedToken, expectedMid).block1(2, false, 128).payload(respPayload).go();
// assertThat()
}

@Test
Expand Down Expand Up @@ -1161,11 +1163,11 @@ public void testObserveWithBlockwiseResponseEarlyNegotiation() throws Exception
}

// All tests are made with this resource
private class TestResource extends CoapResource {
private class MyTestResource extends CoapResource {

public AtomicInteger calls = new AtomicInteger();

public TestResource(String name) {
public MyTestResource(String name) {
super(name);
}

Expand All @@ -1181,11 +1183,13 @@ public void handlePUT(final CoapExchange exchange) {
if (expectedToken != null) {
assertThat("request did not contain expected token", exchange.advanced().getRequest().getToken(), is(expectedToken));
}
assertThat("request did not provide the receive time", exchange.advanced().getRequest().getNanoTimestamp(), is(not(0L)));
respond(exchange, ResponseCode.CHANGED, respPayload);
}

public void handlePOST(final CoapExchange exchange) {
assertThat("server did not receive expected request payload", exchange.getRequestText(), is(reqtPayload));
assertThat("request did not provide the receive time", exchange.advanced().getRequest().getNanoTimestamp(), is(not(0L)));
respond(exchange, ResponseCode.CHANGED, respPayload);
}

Expand Down

0 comments on commit 958e83b

Please sign in to comment.