coap_read(), coap_write() and coap_run_once() are confusing in their names
and do not really describe what they do.
For example, coap_read() does both reading and writing, coap_write() may
do some writing, but primarily is used to determine what should be monitored
and for how long to wait in the following select() or epoll_wait() calls.
coap_run_once() implies that the code is only to be run once - again confusing.
By renaming coap_read() to coap_io_do_io(), this better describes what this
function does.
By renaming coap_write() to coap_io_prepare_io() this better describes what this
function does.
By renaming coap_run_once() to coap_io_process(), this better describes what
this function does.
By renaming coap_io_do_events() to coap_io_do_epoll(), this better describes what
this function does and is associated with.
A wrapper function coap_io_prepare_epoll() has been created, using
coap_io_prepare_io() with some preset values to simplify function usage.
include/coap2/net.h:
Update with the new function names, and deprecate the old functions. Also
document the fact that coap_io_prepare_io(), coap_io_do_io(),
coap_io_prepare_epoll(), and coap_io_do_epoll() are really internal functions.
Create app_io module for Doxygen.
libcoap-2.map:
libcoap-2.sym:
Expose the new functions to applications.
examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/contiki/coap-observer.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
man/coap_io.txt.in:
man/coap_observe.txt.in:
src/coap_io.c:
src/coap_io_lwip.c:
src/net.c:
src/pdu.c:
Update using the new function names.
Setting the etimer has been moved out of coap_io_process() into
coap_io_do_epoll(), making the logic easier for applications to use
coap_io_do_epoll() should they need to. This also gets rid of a
potential timing window where a pending etimer event gets missed.
coap_io_do_epoll() now calls coap_io_prepare_epoll() if the etimer has
triggered removing the need for applications using coap_io_do_epoll() to
set up their own loops if etimer is triggered.
include/coap2/coap_subscribe_internal.h and
include/coap2/coap_session_internal.h contain the information not exposed
to applications.
This internal information was moved out of the respective
include/coap2/subscribe.h and include/coap2/coap_session.h files comprising of
the coap_subscription_t and coap_endpoint_t definitions.
To ease inter .h file dependencies, a new file
include/coap2/coap_forward_decls.h is added to include forward declarations
for both libcoap and applications.
Makefile.am:
Include include/coap2/coap_*internal.h as files for distribution, but not
installed for applications to use.
Include include/coap2/coap_forward_decls.h, so it is installed for
applications.
include/coap2/coap.h.in:
Include "coap_forward_decls.h"
include/coap2/coap_forward_decls.h: (New)
Forward declare structures and typedef the structures defined in
coap_internal.h.
include/coap2/coap_internal.h: (New)
Includes all the required #include files that libcoap internally needs.
include/coap2/coap_session_internal.h: (New)
Include the coap_endpoint_t information taken from
include/coap2/coap_session.h.
include/coap2/coap_session.h:
Remove coap_endpoint_t definition.
include/coap2/lwippools.h:
Add in coap_forward_decls.h and coap_internal.h to handle the LwIP memory
allocations.
include/coap2/resource.h:
Add in "block.h" to allow things to build.
include/coap2/coap_subscribe_internal.h: (New)
Include the coap_subscription_t information taken from
include/coap2/subscribe.h.
include/coap2/subscribe.h:
Remove coap_subscription_t definition.
libcoap-2.map:
libcoap-2.sym:
Updated, removing coap_subscription_init().
src/address.c:
src/asyn.c:
src/block.c:
src/coap_debug.c:
src/coap_event.c:
src/coap_gnutls.c:
src/coap_hashkey.c:
src/coap_io.c:
src/coap_io_lwip.c:
src/coap_notls.c:
src/coap_openssl.c:
src/coap_session.c:
src/coap_time.c:
src/coap_tinydtls.c:
src/encode.c:
src/mem.c:
src/net.c:
src/option.c:
src/pdu.c:
src/resource.c:
src/str.c:
src/subscribe.c:
src/uri.c:
Add in '#include "coap_internal.h"' to the source files.
Remove other libcoap #include files.
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:
Update for Windows build (not tested).
examples/contiki/server.c:
src/coap_io.c:
Remove knowledge of endpoint from the server and update Contiki's
version of coap_run_once() to do the work instead.
====
Other structures (plus some internal required #defines) will follow as
separate PRs.
As a server, idle sessions are left around in case the client wants to do
further work using the same 5 tuple IP information.
With constrained systems, the number of sessions is limited, and so it is
easy to run out of sessions.
src/coap_session.c:
If there is an idle session, context->max_idle_sessions is not set and
a new session cannot be created, free off the oldest session and retry
the creation again.
examples/contiki/README:
examples/lwip/README:
Tidy up the documentation
This then removes the need for name polution/confict of debug(), info() and
warn() when building other projects that use libcoap and need to #include the
libcoap header files
Updated:
examples/client.c
examples/contiki/coap-observer.c
examples/etsi_iot_01.c
include/coap2/debug.h
src/async.c
src/block.c
src/coap_io.c
src/coap_openssl.c
src/coap_session.c
src/coap_tinydtls.c
src/debug.c
src/mem.c
src/net.c
src/option.c
src/pdu.c
src/resource.c
src/uri.c
If the debug() etc. macros are still required, then the change to
include/coap2/debug.h just needs to be reverted.
There are also a couple of space changes - to cause log output to be columnar
e.g "ERR" was padded to "ERR ", so that "EMRG" or "ERR " log output output was
aligned in the same way.
This is a replacement for PR#51, and partially deals with name polution issues
raised in Issue #50.
Parameter re-aligned some long strings, splitting strings across multiple lines
Update code to use new APIs
[Some code changes modelled on PR #202, some code being moved between files]
Remove #ifdef WITH_LWIP from coap_io.c as file is not used
Add in resource time to lwip
Update for Travis build
Report on Contiki memory allocate failures to ease debugging
Make the different memory type counts configurable by using the -D option
included in a CFLAGS definition to the ./configure command line
.travis.yml
BUILDING
Makefile.libcoap
examples/contiki/Makefile
examples/contiki/README new
examples/contiki/server.c
examples/contiki/.gitignore (new)
examples/lwip/Makefile
examples/lwip/README
examples/lwip/lwipopts.h
examples/lwip/server-coap.c
examples/lwip/server.c
include/coap/address.h
include/coap/coap_io.h
include/coap/lwippools.h
include/coap/pdu.h
scripts/build.sh
src/address.c
src/coap_io.c
src/coap_io_lwip.c
src/coap_session.c
src/mem.c
src/net.c
src/pdu.c
New struct coap_binary_t - same as coap_string_t, used for tokens
Deprecate struct str with the intent of removing it downstream as it
polutes namespace.
Make end of coap_string_t data a NUL.
Updated coap_make_str_const(), removing .length= and .s= to keep upstream
compilers happy.
Update Doxygen for str.h
Files:
examples/client.c
examples/coap-rd.c
examples/coap-server.c
examples/contiki/server.c
examples/etsi_iot_01.c
include/coap/resource.h
include/coap/str.h
include/coap/subscribe.h
man/coap_observe.txt.in
src/net.c
src/resource.c
src/str.c
src/uri.c
tests/test_options.c
Update
coap_show_pdu()'s API is now coap_show_pdu(coap_log_t, coap_pdu_t*)
New function void coap_set_show_pdu_output(int use_fprintf)
Default is use fprintf() instead of coap_log()
The output buffer size can be configuring -DCOAP_DEBUG_BUF_SIZE
Output COAP_OPTION_SIZE2 option as well
For binary data, output ascii readable equivalent immediately under the
hex output for ease of debugging.
include/coap/debug.h
src/debug.c
Update coap_show_pdu() API
New function coap_set_show_pdu_output()
Update coap_show_pdu() code
include/coap/pdu.h
Define the coap debug output debug buffer size
COAP_DEBUG_BUF_SIZE
examples/client.c
examples/contiki/coap-observer.c
src/net.c
tests/test_wellknown.c
tests/test_pdu.c
Update coap_show_pdu() calls
libcoap-2.map
libcoap-2.sym
New function coap_set_show_pdu_output()
Update code / examples / man pages with the updated function.
include/coap/libcoap.h:
Add in new define COAP_DEPRECATED to generate compiler warnings when used
include/coap/encode.h
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.
Make coap_encode_var_bytes() a wrapper for coap_encode_var_safe() and
mark it as COAP_DEPRECATED for backwards compatability
src/encode.c:
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.
examples/coap-server.c:
examples/contiki/server.c:
Make the ticks resource consistent in case
The value of the observe option is kept for each resource rather than being global to the context.
The value of the observe option must wrap to be stay below 2^24.
The value of the observe option must be different from the initial value when a notification is sent.
Make coap_pdu-t independent of the header style.
Use C99 sized types when applicable.
Use transaction ids in host byte order in the library.
Make coap_pdu_t payload storage grow on demand.
Add parsing and encoding of PDUs with UDP or TCP style headers.
Adapt examples and unit tests to the new PDU format.
handle_periodic_timer() in rpl-timers.c relies on the optimizer to
remove the if(0)-guarded call to rpl_ns_periodic() when storing
mode is selected. This does not happen with clang's default options
and thus leads to an error for the undefined reference at link time.
This modification adds -Os to fix this.
The debug function for printing lladdress have been renamed and moved
to net-debug.h. This change now includes this header and uses the
appropriate macros instead.
The new structure of libcoap allows to clone Contiki in a
subdirectory. The example build now uses Makefile to first clone
Contiki and then invoke Makefile.contiki for the actual build.
The TARGET is set to minimal-net by default but can be changed to
any other (tested) target.
Some configuration flags have been changed since Contiki version 3.
The Makefile.contiki for building a server example that uses libcoap
as a Contiki app has been fixed. The following builds now succeed:
make -f Makefile.contiki TARGET=minimal-net
make -f Makefile.contiki TARGET=econotag
make -f Makefile.contiki TARGET=mbxxx
uip_ds6_prefix_add is using 6 arguments, better use explicit argument
list than let the compiler decide. Some compiler will complain if some
optionally arguments are missed.
Made vpath %.c point to ../../src and repaired include path.
The common part of the Makefile has been moved to Makefile.common
to leverage Makefile creation for other platforms such as econotag.
Directory examples/contiki now contains a small example server for
Contiki and a Makefile for platform minimal-net.
Build:
make contiki # clones Contiki
make server # creates the minimal-net coap server
Run:
Unfortunately, you have to run the server with sudo unless you
set CAP_NET_ADMIN for both, the server executable, and ifconfig
(sudo setcap cap_net_admin+pei ...).
sudo ./server
Then, add the server's interface address to the tap0 device and
optionally set a default route:
sudo ip -6 a a aaaa::1000 dev tap0
sudo ip -6 r a aaaa::/64 dev tap0
Although everything should work now, it does not. I had to send
router advertisements on tap0:
sudo radvd -C ./radvd.conf
Note that on Debian (and Ubuntu, and ...), radvd will not start
when IPv6 forwarding is disabled (which is usually the case on
end systems). Trying to enable like this did not work for me:
sudo sysctl -w net.ipv6.conf.tap0.forwarding=1
sudo sysctl -w net.ipv6.conf.tap0.mc_forwarding=1
Workaround (ugly): get the radvd sources, compile them and use that.