Skip to content

Commit

Permalink
fix: support 7.01 CSM without any options
Browse files Browse the repository at this point in the history
  • Loading branch information
szysas committed Mar 21, 2018
1 parent 2a33496 commit 23e62f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ private boolean handleSignal(CoapPacket packet) {

if (packet.getCode() == Code.C701_CSM) {
SignalingOptions signalingOpts = packet.headers().toSignallingOptions(packet.getCode());
Long maxMessageSize = signalingOpts.getMaxMessageSize();
Boolean blockWiseTransferBERT = signalingOpts.getBlockWiseTransfer();
CoapTcpCSM remoteCapabilities = CoapTcpCSM.BASE.withNewOptions(maxMessageSize, blockWiseTransferBERT);

CoapTcpCSM remoteCapabilities = CoapTcpCSM.BASE;
if (signalingOpts != null) {
Long maxMessageSize = signalingOpts.getMaxMessageSize();
Boolean blockWiseTransferBERT = signalingOpts.getBlockWiseTransfer();
remoteCapabilities = CoapTcpCSM.BASE.withNewOptions(maxMessageSize, blockWiseTransferBERT);
}
csmStorage.put(packet.getRemoteAddress(), CoapTcpCSM.min(ownCapability, remoteCapabilities));

} else if (packet.getCode() == Code.C702_PING) {
CoapPacket pongResp = new CoapPacket(Code.C703_PONG, MessageType.Acknowledgement, packet.getRemoteAddress());
pongResp.setToken(packet.getToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
import protocolTests.utils.CoapPacketBuilder;


/*
draft-ietf-core-coap-tcp-tls-09
*/
public class CoapTcpMessagingTest {

private final CoapTransport coapTransport = mock(CoapTransport.class);
Expand All @@ -61,7 +58,7 @@ public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
public void tearDown() {
tcpMessaging.stop();
}

Expand Down Expand Up @@ -162,6 +159,15 @@ public void should_set_minimal_remote_capabilities_fromSmall() throws CoapExcept
assertFalse(csmStorage.getOrDefault(LOCAL_1_5683).isBlockTransferEnabled());
}

@Test
public void should_set_remote_capabilities_when_empty_csm() throws CoapException, IOException {
receive(newCoapPacket(LOCAL_1_5683).con(Code.C701_CSM));

assertNothingSent();
assertEquals(501, csmStorage.getOrDefault(LOCAL_1_5683).getMaxMessageSize());
assertFalse(csmStorage.getOrDefault(LOCAL_1_5683).isBlockTransferEnabled());
}

@Test
public void should_send_ping_message() throws Exception {
tcpMessaging.ping(LOCAL_1_5683, mock(Callback.class));
Expand Down

0 comments on commit 23e62f3

Please sign in to comment.