1COAP_CONTEXT(3) libcoap Manual COAP_CONTEXT(3)
2
3
4
6 coap_context, coap_new_context, coap_free_context,
7 coap_context_set_max_idle_sessions, coap_context_get_max_idle_sessions,
8 coap_context_set_max_handshake_sessions,
9 coap_context_get_max_handshake_sessions,
10 coap_context_set_session_timeout, coap_context_get_session_timeout,
11 coap_context_set_csm_timeout, coap_context_get_csm_timeout,
12 coap_context_set_max_token_size - Work with CoAP contexts
13
15 #include <coap3/coap.h>
16
17 coap_context_t *coap_new_context(const coap_address_t *listen_addr);
18
19 void coap_free_context(coap_context_t *context);
20
21 void coap_context_set_max_idle_sessions(coap_context_t *context,
22 unsigned int max_idle_sessions);
23
24 unsigned int coap_context_get_max_idle_sessions( const coap_context_t
25 *context);
26
27 void coap_context_set_max_handshake_sessions(coap_context_t *context,
28 unsigned int max_handshake_sessions);
29
30 unsigned int coap_context_get_max_handshake_sessions( const
31 coap_context_t *context);
32
33 void coap_context_set_session_timeout(coap_context_t *context, unsigned
34 int session_timeout);
35
36 unsigned int coap_context_get_session_timeout( const coap_context_t
37 *context);
38
39 void coap_context_set_csm_timeout(coap_context_t *context, unsigned int
40 csm_timeout);
41
42 unsigned int coap_context_get_csm_timeout(const coap_context_t
43 *context);
44
45 void coap_context_set_max_token_size(coap_context_t *context, size_t
46 max_token_size);
47
48 For specific (D)TLS library support, link with -lcoap-3-notls,
49 -lcoap-3-gnutls, -lcoap-3-openssl, -lcoap-3-mbedtls or
50 -lcoap-3-tinydtls. Otherwise, link with -lcoap-3 to get the default
51 (D)TLS library support.
52
54 This man page focuses on the CoAP Context and how to update or get
55 information from the opaque coap_context_t structure.
56
57 The CoAP stack’s global state is stored in a coap_context_t Context
58 object. Resources, Endpoints and Sessions are associated with this
59 context object. There can be more than one coap_context_t object per
60 application, it is up to the application to manage each one
61 accordingly.
62
64 Function: coap_new_context()
65
66 The coap_new_context() function creates a new Context that is then used
67 to keep all the CoAP Resources, Endpoints and Sessions information. The
68 optional listen_addr parameter, if set for a CoAP server, creates an
69 Endpoint that is added to the context that is listening for
70 un-encrypted traffic on the IP address and port number defined by
71 listen_addr.
72
73 Function: coap_free_context()
74
75 The coap_free_context() function must be used to release the CoAP stack
76 context. It clears all entries from the receive queue and send queue
77 and deletes the Resources that have been registered with context, and
78 frees the attached Sessions and Endpoints.
79
80 WARNING: It is unsafe to call coap_free_context() in an atexit()
81 handler as other libraries may also call atexit() and clear down some
82 CoAP required functionality.
83
84 Function: coap_context_set_max_idle_sessions()
85
86 The coap_context_set_max_idle_sessions() function sets the maximum
87 number of idle server sessions to max_idle_sessions for context. If
88 this number is exceeded, the least recently used server session is
89 completely removed. 0 (the initial default) means that the number of
90 idle sessions is not monitored.
91
92 Function: coap_context_get_max_idle_sessions()
93
94 The coap_context_get_max_idle_sessions() function returns the maximum
95 number of idle server sessions for context.
96
97 Function: coap_context_set_max_handshake_sessions()
98
99 The coap_context_set_max_handshake_sessions() function sets the maximum
100 number of outstanding server sessions in (D)TLS handshake to
101 max_handshake_sessions for context. If this number is exceeded, the
102 least recently used server session in handshake is completely removed.
103 0 (the default) means that the number of handshakes is not monitored.
104
105 Function: coap_context_get_max_handshake_sessions()
106
107 The coap_context_get_max_handshake_sessions() function returns the
108 maximum number of outstanding server sessions in (D)TLS handshake for
109 context.
110
111 Function: coap_context_set_session_timeout()
112
113 The coap_context_set_session_timeout() function sets the number of
114 seconds of inactivity to session_timeout for context before an idle
115 server session is removed. 0 (the default) means wait for the default
116 of 300 seconds.
117
118 Function: coap_context_get_session_timeout()
119
120 The coap_context_get_session_timeout() function returns the seconds to
121 wait before timing out an idle server session for context.
122
123 Function: coap_context_set_csm_timeout()
124
125 The coap_context_set_csm_timeout() function sets the number of seconds
126 to wait for a (TCP) CSM negotiation response from the peer to
127 csm_timeout for context. 0 (the default) means wait forever.
128
129 Function: coap_context_get_csm_timeout()
130
131 The coap_context_get_csm_timeout() function returns the seconds to wait
132 for a (TCP) CSM negotiation response from the peer for context,
133
134 Function: coap_context_set_max_token_size()
135
136 The coap_context_set_max_token_size() function sets the max_token_size
137 for context. max_token_size must be greater than 8 to indicate support
138 for RFC8974 up to max_token_size bytes, else 8 to disable RFC8974 (if
139 previously set).
140
141 NOTE: For the client, it will send an initial PDU to test the server
142 supports the requested extended token size as per "RFC8794 Section
143 2.2.2"
144
146 coap_new_context() returns a newly created context or NULL if there is
147 a creation failure.
148
149 coap_context_get_max_idle_sessions() returns the maximum number of idle
150 server sessions.
151
152 coap_context_get_max_handshake_sessions() returns the maximum number of
153 outstanding server sessions in (D)TLS handshake.
154
155 coap_context_get_session_timeout() returns the seconds to wait before
156 timing out an idle server session.
157
158 coap_context_get_csm_timeout() returns the seconds to wait for a (TCP)
159 CSM negotiation response from the peer.
160
162 coap_session(3)
163
165 See
166
167 "RFC7252: The Constrained Application Protocol (CoAP)"
168
169 "RFC8974: Extended Tokens and Stateless Clients in the Constrained
170 Application Protocol (CoAP)"
171
172 for further information.
173
175 Please report bugs on the mailing list for libcoap:
176 libcoap-developers@lists.sourceforge.net or raise an issue on GitHub at
177 https://github.com/obgm/libcoap/issues
178
180 The libcoap project <libcoap-developers@lists.sourceforge.net>
181
182
183
184coap_context 4.3.4 10/09/2023 COAP_CONTEXT(3)