Com-AugustCellars / CoAP-CSharp

CoAP Implementation in C#
Other
41 stars 19 forks source link

Ability to remove Option UriPort in CoapClient #78

Closed trampster closed 4 years ago

trampster commented 4 years ago

The coap service we are talking to will return BadOption if we specify a UriPort.

Having talked to the creators of that code they say UriPort is a harmful option because it breaks port forwarding / NAT traversal.

If I create the request myself I can call request.RemoveOption, however for the observes I'm using the CoapClient and I can see no way to remove this option.

jimsch commented 4 years ago

What is the URL you are sending the request to?

trampster commented 4 years ago

Why was this closed?

Removing this option works (I've tried manually with a request) because it is not used to determine what port to send the request to. It is included as an option in the packet. (so can only be useful to the receiver).

However this break NAT traversal because the port changes when you traverse a NAT due to port forwarding. So the port in the option is no longer correct. And any implementation of CoAP that relies on it will therefore not work over a NAT.

To be 100% clear I'm not asking for a ability to turn off specifying a Uri port to send my packet to. I'm asking for the ability to turn off the 'Option' UriPort which is included in the CoapMessage.

Not having this option works fine, I have a fork that doesn't include it which works fine.

I would rather use the upstream version, instead of maintaining a fork but can't if I don't have the ability to remove the UriPort option.

trampster commented 4 years ago

If you are willing to accept a pull request that adds a method to CoapClient to turn this off. (like the RemoveOption method on request).

Then I'm happy to submit one.

jimsch commented 4 years ago

It was closed because I hit the wrong button

jimsch commented 4 years ago

Pull requests gladly accepted

jimsch commented 4 years ago

I think that the code is supposed to omit sending the URI Port option in the event that the default port is used in the URI. This is the reason that I asked about the URL above.

trampster commented 4 years ago

Yeah, it's a non default port.

jimsch commented 4 years ago

One possible way to address this would be to define a TargetEndpoint property. The URI would then have the default port, but the destination of the message would be defined separately if needed.