chrysn / aiocoap

The Python CoAP library
Other
262 stars 119 forks source link

Connection time role reversal for CoAP-over-WS #311

Open JoachimErnst opened 11 months ago

JoachimErnst commented 11 months ago

We would like to use CoAP over WS. Is there a simple example availabe showing how the WS-client opens a websocket connection and then the WS-server side acts as CoAP client and sends a CoAP request to the original client. There are some remarks on that in the doc but it is not clear how to do it. Best Regards Joachim

chrysn commented 11 months ago

There are a few possible things to do (provided you have installed aiocoap with all extras):

JoachimErnst commented 11 months ago

I checked the server.py and slightly adapted client for calling coap+ws already. This worked immediately and the info and debug on the server window show that first the websocket connection was opened and then used for the coap messages, starting with the mandatory csm message. When the client script finished, the websocket connection was closed.

INFO:websockets.server:server listening on [::]:8683 INFO:websockets.server:server listening on 0.0.0.0:8683 DEBUG:coap-server:Server ready to receive requests .. INFO:websockets.server:connection open DEBUG:coap-server:Sending message: <aiocoap.Message at 0x7fa0f1d543d0: no mtype, 7.01 Csm (no MID, empty token) remote None, 2 option(s)> DEBUG:coap-server:Sending message: <aiocoap.Message at 0x7fa0f1d561a0: no mtype, 2.05 Content (no MID, token d927) remote <WSRemote at 0x7fa0f1d55ba0, hostinfo 127.0.0.1:46710, local localhost:8683>, 1 option(s), 123 byte(s) payload> DEBUG:coap-server:Sending message: <aiocoap.Message at 0x7fa0f1d565f0: no mtype, 2.05 Content (no MID, token d928) remote <WSRemote at 0x7fa0f1d55ba0, hostinfo 127.0.0.1:46710, local localhost:8683>, 16 byte(s) payload> .. INFO:websockets.server:connection closed

What I am look for now, is how the websocket server side may act as coap client, sending requests using the established websocket connection.

The documentation of the transport.ws module says: .. Requests to a CoAP-over-WS client can be made by assigning the remote to an outgoing request. How can this statement be implemented? There is more background information needed or even the server.py example needed some lines of extensions.

Von: chrysn @.> Gesendet: Dienstag, 18. Juli 2023 10:08 An: chrysn/aiocoap @.> Cc: Ernst Joachim, SBC-SAS-RCS @.>; Author @.> Betreff: Re: [chrysn/aiocoap] Is there an example of CoAP over WS? (Issue #311)

There are a few possible things to do (provided you have installed aiocoap with all extras):

— Reply to this email directly, view it on GitHubhttps://github.com/chrysn/aiocoap/issues/311#issuecomment-1639724577, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZ4BYEROFEZDK4JGOLKVV2TXQY753ANCNFSM6AAAAAA2N4PCNY. You are receiving this because you authored the thread.Message ID: @.**@.>>

chrysn commented 11 months ago

This is a rather exotic application (and thus not suitable for the server.py minimal example), but there is an example in aiocoap.cli.rd around how proxy_active is used to store remotes, and how in apply_redirection it is fed into a proxying step.

I'm a bit curious though: In my view of the CoAP architecture, this is predominantly used in reverse proxying. How do you set up the reverse proxy if it is not a resource directory (whose implementation is the example I gave)?

JoachimErnst commented 11 months ago

I'd like to give you more insight into the project we plan to do, but needed a private channel due to confidentiality.

BR Joachim

Von: chrysn @.> Gesendet: Dienstag, 18. Juli 2023 22:56 An: chrysn/aiocoap @.> Cc: Ernst Joachim, SBC-SAS-RCS @.>; Author @.> Betreff: Re: [chrysn/aiocoap] Is there an example of CoAP over WS? (Issue #311)

This is a rather exotic application (and thus not suitable for the server.py minimal example), but there is an example in aiocoap.cli.rd around how proxy_active is used to store remotes, and how in apply_redirection it is fed into a proxying step.

I'm a bit curious though: In my view of the CoAP architecture, this is predominantly used in reverse proxying. How do you set up the reverse proxy if it is not a resource directory (whose implementation is the example I gave)?

— Reply to this email directly, view it on GitHubhttps://github.com/chrysn/aiocoap/issues/311#issuecomment-1640980014, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZ4BYEVMRCJNJLSQMEAR2SLXQ3Z47ANCNFSM6AAAAAA2N4PCNY. You are receiving this because you authored the thread.Message ID: @.**@.>>

chrysn commented 11 months ago

It's fundamentally possible to assign a remote through which no request has been received, but it would need some interfaces aiocoap is currently not exposing. The How and Where will depend on general use cases

Please contact me at christian@amsuess.com to check whether we can generalize your specific use case into something that can be added and documented in aiocoap. (That address is also the general entry point for professional services around aiocoap, which should ease managing confidentiality concerns.)