dns icon indicating copy to clipboard operation
dns copied to clipboard

Optional interface for a ResponseWriter to expose Conns

Open jefferai opened this issue 2 years ago • 4 comments

Hello, and thanks for a great library!

It would be useful to me if I can get access to the underlying connections in a response object. I only want to do some read-only introspection (I'm aware that actually reading/writing from the conns would be rather dangerous).

It is fairly trivial to do this in a way that won't break backwards compatibility by introducing an optional interface that can be satisfied with one or two functions (depending on if it's one function for tcp and one for udp or if the same function returns both). I've tested this locally and it's a very small change that works well.

Would this be something that would be accepted in a PR? If not, is there another way to get the connection related to an incoming message?

Thanks!

jefferai avatar Oct 03 '23 15:10 jefferai

crypto/tls has let you do this since go1.18 so it doesn't seem like the worst idea (https://pkg.go.dev/crypto/tls#Conn.NetConn). Though they have the benefit of always having a TCP connection (except when using QUIC).

Out of interest, what in particular are you trying to get from the underlying connection?

tmthrgd avatar Oct 31 '23 02:10 tmthrgd

So for what it's worth here's one way to slice it, although there are other ways it can be done (or with other naming)

https://github.com/jefferai/dns/commit/876d499e729fb7e1ca2eef7e438f4cf8ada09cec

Basically I need access to retrieve the local/remote addresses of the connections.

jefferai avatar Nov 01 '23 15:11 jefferai

For more explanation: some platforms (cough, Windows, cough) do not allow you to firewall anything on localhost so if you want to perform any introspection or security controls you have to do it yourself, so having connection information is extremely useful.

jefferai avatar Nov 01 '23 15:11 jefferai

We can close this as the PR to implement it was rejected.

johanbrandhorst avatar Aug 08 '24 18:08 johanbrandhorst