Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coap_net.c: Fix CSM timeouts in coap_client_delay_first() #1259

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

mrdeep1
Copy link
Collaborator

@mrdeep1 mrdeep1 commented Oct 18, 2023

Reduce timeout to 1 second and enter established state for servers that only partially implement RFC8323 for TCP support, but do not send a CSM.

@JimmyBaize
Copy link

JimmyBaize commented Oct 19, 2023

I tested it and it works as expected.

But I have a question. why not use csm_timeout (from coap_context_set_csm_timeout) as CSM timeout .

src/coap_net.c Outdated

/* coap_io_process() may have updated session state */
if (session->state == COAP_SESSION_STATE_CSM)
timeout_ms = 1000;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use csm_timeout (from coap_context_set_csm_timeout) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting question. csm_timout is in seconds and by default has a value of 30 seconds. The logic that uses this timeout closes the TCP connection if this timeout occurs and was introduced in 2018.

While it is unlikely that anyone actually calls coap_context_set_csm_timeout(), it is possible and we have to maintain binary functionality with new code, so cannot make use of csm_timeout here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, the connection can never get closed now on a CSM timeout from the CoAP Server even if a low value of 1 to coap_context_set_csm_timeout() will more likely trigger the new CSM is not coming, continue anyway logic, rather than disconnect the session.

I am reluctant to change the parameter of coap_context_set_csm_timeout() to millisecs, rather than seconds as that definitely breaks backward/forward binary compatibility. But a coap_context_set_csm_timeout2() could be created.

As a note here, there must be sufficient delay before timeout so that a CSM response from a slow startup server can be processed before building (in particular the call to coap_session_max_pdu_size()) / sending out the first request.

I think 1000 millisecs is a reasonable low limit timeout to get a CSM response and would not recommend that it goes much lower.

Copy link

@JimmyBaize JimmyBaize Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we allow to keep TCP session when CSM time out. so can we create a coap_context_set_csm_timeout_ms , and use it here?
coap_context_set_csm_timeout_ms and coap_context_set_csm_timeout() to modify the same variable(csm_timeout
in milliseconds)
I want to use a shorter delay to skip waiting for a CSM response, because my existing CoAP cloud service uses Californium (CSM is not supported).

Copy link

@JimmyBaize JimmyBaize Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose we change the csm_timeout variable to milliseconds, and change coap_context_set_csm_timeout() to

void
coap_context_set_csm_timeout(coap_context_t *context,
                             unsigned int csm_timeout) {
  context->csm_timeout_ms = csm_timeout*COAP_TICKS_PER_SECOND;
}

I’m not sure if coap_context_set_csm_timeout_ms and coap_context_set_csm_timeout() can reference the same variable.
If there are two variables, what is the difference between the two timeout variables?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the current usage of coap_context_set_csm_timeout() logic will never trigger and disconnect the TCP session, all that internal logic can get removed, but coap_context_set_csm_timeout()/coap_context_get_csm_timeout() will still need to be there and coap_context_get_csm_timeout() needs to return an appropriate value.

It appears that Californium have no significant desire to fix the CSM issue, but is used by people such as yourself. I think the way forward here is to tag as deprecated coap_context_set_csm_timeout()/coap_context_get_csm_timeout() and create a new coap_context_set_csm_timeout_ms() (using a different internal variable) as coap_context_set_csm_timeout() does not give you the ability to define something under 1 second (note that COAP_TICKS_PER_SECOND is not always 1000). Defining it as 0 for coap_context_set_csm_timeout() does not tie up with the current documentation

       The coap_context_set_csm_timeout() function sets the number of seconds to wait for a (TCP) CSM negotiation
       response from the peer to csm_timeout for context. 0 (the default) means wait forever.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.The idea of creating a new coap_context_set_csm_timeout_ms() is good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes pushed with support for coap_context_set_csm_timeout_ms(). The minimum settable value is 10 milliseconds (and the largest 10,000 milliseconds). The timeout starts from when the TCP session connects (or from when TLS is established if appropriate).

A warning is generated if a CSM is received after the CSM timeout logic has timed out, indicating what the minimum timeout should be. When using libcoap.net as a host, the delay in receiving a CSM is of the order of 32 milliseconds.

In your case, as there is no receipt of a CSM signalling Block transfers are supported, the client reports for each block that is transferred (as debug log) Remote end did not indicate CSM support for Block1 enabled, but still sends the block.

Reduce timeout to 1 second and enter established state for servers that
only partially implement RFC8323 for TCP support, but do not send a CSM.

Add new coap_context_set_csm_timeout_ms() to control the value of the timeout.
@mrdeep1 mrdeep1 merged commit 05d02be into obgm:develop Oct 23, 2023
@mrdeep1 mrdeep1 deleted the timeout_csm branch October 23, 2023 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants