Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forced TCP #4

Open
mwillfox opened this issue Oct 12, 2018 · 2 comments
Open

Allow forced TCP #4

mwillfox opened this issue Oct 12, 2018 · 2 comments

Comments

@mwillfox
Copy link

Hi, I'm looking to use this library in AWS Lambda which does not allow UDP sockets. Is there a way we can force TCP protocol to be used? Thanks.

@al45tair
Copy link
Owner

There isn't an option on the Resolver classes for that at present, no, though it'd be easy enough to add an argument to the Resolver.lookup method to force the use of TCP; in fact, I just checked in some code that does just that — see 7434579. Let me know if it works for you.

@mwillfox
Copy link
Author

mwillfox commented Oct 16, 2018

I've forked the repo and have a working solution to this. Basically I've implemented the same changes as your commit but also had to implement the eof_received function in DNSProtocol for TCP communication. One other issue I had to tackle for AWS Lambda is that ipv6 is not allowed. To fix this, I have used self.prefer_ipv6 to determine if we should attempt to convert the server address to ipv6 or leave as ipv4.

if self.prefer_ipv6 and (isinstance(self.server[0], ipaddress.IPv4Address)
    or (isinstance(self.server[0], str)
        and _ipv4_re.match(self.server[0]))):
    self.server = ('::ffff:' + str(self.server[0]), self.server[1])

I can open a PR if you are interested in incorporating these changes. Let me know if using prefer_ipv6 in that way is appropriate or if we should force ipv4 in another way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants