Skip to content

Commit

Permalink
update CHANGELOG, fiddle more with doq proxy code
Browse files Browse the repository at this point in the history
  • Loading branch information
tykling committed Feb 21, 2024
1 parent 1a608e3 commit f2ac11b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- No changes yet
### Added
- Unit tests for proxy code


### Fixed
- Proxy support for DoQ should work properly now



## [v1.0.0-beta5] - 2024-02-20
Expand Down
21 changes: 12 additions & 9 deletions src/dns_exporter/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,31 @@ def __init__(
self.config = config
self.query = query
self.labels = labels

# set proxy?
if self.config.proxy:
socks.set_default_proxy(
proxy_type=getattr(socks, self.config.proxy.scheme.upper()),
addr=self.config.proxy.hostname,
port=self.config.proxy.port,
)
# use proxy socket for protocols udp, tcp, doh
dns.query.socket_factory = socks.socksocket
# this should begin working pending the next dnspython release
# for protocol doq - method depends on the dnspython version
# https://github.com/rthalley/dnspython/issues/1059
# dns.quic._sync.socket_factory = socks.socksocket
# patch socket.socket until then
socket.socket = socks.socksocket # type: ignore
if hasattr(dns.quic._sync, "socket_factory"):
dns.quic._sync.socket_factory = socks.socksocket
else:
socket.socket = socks.socksocket # type: ignore
logger.debug(f"Using proxy {self.config.proxy.geturl()}")
else:
# restore regular socket.socket for protocols udp, tcp, doh
dns.query.socket_factory = socket.socket
# this should begin working pending the next dnspython release
# for protocol doq - method depends on the dnspython version
# https://github.com/rthalley/dnspython/issues/1059
# dns.quic._sync.socket_factory = socket.socket
# unpatch socket.socket until then
socket.socket = _socket # type: ignore
if hasattr(dns.quic._sync, "socket_factory"):
dns.quic._sync.socket_factory = socket.socket
else:
socket.socket = _socket # type: ignore
logger.debug("Not using a proxy for this request")

def describe(self) -> Iterator[Union[CounterMetricFamily, GaugeMetricFamily]]:
Expand Down
2 changes: 1 addition & 1 deletion src/dns_exporter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def __post_init__(self) -> None:

# validate proxy
if self.proxy:
# proxy support doesn't work for DoT and DoQ for now
# proxy support doesn't work for DoT for now
if self.protocol in ["dot"]:
logger.error(f"proxy not valid for protocol {self.protocol}")
raise ConfigError(
Expand Down

0 comments on commit f2ac11b

Please sign in to comment.