obgm / libcoap

A CoAP (RFC 7252) implementation in C
Other
795 stars 423 forks source link

Adding compiler options for enabling/disabling network layer #838

Open jqiaobln opened 2 years ago

jqiaobln commented 2 years ago

Is your feature request related to a problem? Please describe.

Coap is a transport layer protocol. It should be fully functional without assumptions of underlying security and network layer.

Libcoap has options to compile without TLS libraries; however it always includes networking layer code, i.e. coap_io.c and address.c, etc.

Describe the solution you'd like

Libcoap will improve its reusability and modulization if there are compiler options which can enable/disable the network layer code.

E.g. a project whose TLS and networking layer are handled by some other libraries, can integrate libcoap without including coap_io.c, address.c and the system networking libraries: socket, tcp, etc.

obgm commented 2 years ago

@jqiaobln There is a defined interface for the underlying read/write operations on the network. Ports for non-POSIX platforms show how to replace them. Data structures such as coap_address_t can be replaced to serve special needs as well. DTLS and TLS can be switched off (there is no point in abstracting these away because the supported DTLS and TLS libraries address very specific transport layer characteristics). Therefore, it is fairly easy to port the networking code to different transport layer abstractions by replacing certain. c files as done for the existing ports.

mrdeep1 commented 1 year ago

@jqiaobln libcoap is now broken down into protocol layers, making it much easier to intercept at the level appropriate for your application.

So, in your cited case, the coap_netif_*() functions (in src/coap_netif.c) can call whatever is appropriate. You may also want to adjust the indexing table coap_layers_coap[] in src/coap_io.c (or its equivalent in one of your files) to point into your equivalent functions.

Each layer function calls the next function in the protocol stack (when it has finished processing) with its level as an index - e.g. session->sock.lfunc[COAP_LAYER_WS].write(session, (uint8_t*)buf, strlen(buf)); for invoking the next layer down when doing a write having completed the COAP_LAYER_WSwrite logic.