plgd-dev / go-coap

Implementation of CoAP Server & Client in Go
https://coap.technology
Apache License 2.0
446 stars 116 forks source link

feat: Propagate CoAP Ping (CON Empty) to Handlers #501

Closed jeffwelder-ellenbytech closed 9 months ago

jeffwelder-ellenbytech commented 10 months ago

Allow ping request to be propagated to application handlers to allow application to keep track of devices that are pinging. This is useful when you have devices observing resources that have to ping to keep routes open.

See issue #500

jeffwelder-ellenbytech commented 10 months ago

@jkralik I reverted the changes to allow the package to process the Pings and attempted to extend an option through a WithPingMonitor() function.

This option allows you to get a con object whenever a device pings the server. I modeled the option somewhat after the inactivityMonitor, and tried to extended it to udp/tcp/dtls.

Please let me know if there's a better way to do this. :)

Danielius1922 commented 10 months ago

@jkralik I reverted the changes to allow the package to process the Pings and attempted to extend an option through a WithPingMonitor() function.

This option allows you to get a con object whenever a device pings the server. I modeled the option somewhat after the inactivityMonitor, and tried to extended it to udp/tcp/dtls.

Please let me know if there's a better way to do this. :)

This implementation is fine, however we talked about this with @jkralik today and we would prefer to change this from just a ping request monitor to a general request monitor to have a more general purpose feature. Any arguments why that could be problematic? If not then, please:

jeffwelder-ellenbytech commented 10 months ago

@Danielius1922 / @jkralik Thank you for reviewing, I like the suggestion!

I've extended the option to include the pool message alongside the connection: type RequestMonitorFunc = func(cc *client.Conn, req *pool.Message)

IsPingMessage is now reduced to a single return line, and exported.

Let me know if there are any more improvements I can make, or what the next steps are with appending to any tests.

jkralik commented 10 months ago

@jeffwelder-ellenbytech Pls could you update the PR and fix the issue mentioned in https://github.com/plgd-dev/go-coap/pull/501#discussion_r1383503732

jeffwelder-ellenbytech commented 10 months ago

@jeffwelder-ellenbytech Pls could you update the PR and fix the issue mentioned in #501 (comment)

@jkralik Sure, using the func NewConnWithOpts(connection coapNet.Conn, cfg Config, opts ...Option)?