From 8595b7e04b9971c8356c79c80eb55fef35022dd7 Mon Sep 17 00:00:00 2001 From: valentin benozillo Date: Tue, 24 Apr 2018 15:28:46 +0000 Subject: [PATCH 1/4] Add compatibility for Ipv6 address --- fluent/sender.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fluent/sender.py b/fluent/sender.py index 6762856..9081310 100644 --- a/fluent/sender.py +++ b/fluent/sender.py @@ -121,6 +121,17 @@ def close(self): self._close() self.pendings = None + + def _host_is_ipv6(self) : + try : + socket.inet_pton(socket.AF_INET6, self.host) + return True + except : + try : + socket.inet_aton(self.host) + return False + except Exception as e: + raise e def _make_packet(self, label, timestamp, data): if label: @@ -203,7 +214,10 @@ def _reconnect(self): sock.settimeout(self.timeout) sock.connect(self.host[len('unix://'):]) else: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if self._host_is_ipv6() : + sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + else : + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(self.timeout) # This might be controversial and may need to be removed sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) From 3105f94c0eaf7bd4fb201ba436895a7ad9882e99 Mon Sep 17 00:00:00 2001 From: valentin benozillo Date: Wed, 25 Apr 2018 09:00:17 +0000 Subject: [PATCH 2/4] Fix how to check if the host is IPv6, work with domain name PIP8 ok --- fluent/sender.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/fluent/sender.py b/fluent/sender.py index 9081310..25a3ca0 100644 --- a/fluent/sender.py +++ b/fluent/sender.py @@ -121,17 +121,13 @@ def close(self): self._close() self.pendings = None - - def _host_is_ipv6(self) : - try : - socket.inet_pton(socket.AF_INET6, self.host) - return True - except : - try : - socket.inet_aton(self.host) - return False - except Exception as e: - raise e + + def _is_ipv6_host(self): + try: + socket.getaddrinfo(self.host, None, socket.AF_INET6) + return True + except socket.error: + return False def _make_packet(self, label, timestamp, data): if label: @@ -214,10 +210,12 @@ def _reconnect(self): sock.settimeout(self.timeout) sock.connect(self.host[len('unix://'):]) else: - if self._host_is_ipv6() : - sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) - else : - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if self._host_is_ipv6(): + sock = socket.socket(socket.AF_INET6, + socket.SOCK_STREAM) + else: + sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM) sock.settimeout(self.timeout) # This might be controversial and may need to be removed sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) From 6b4efa31311e58aa884a10aa79d6fd757158be43 Mon Sep 17 00:00:00 2001 From: valentin benozillo Date: Wed, 25 Apr 2018 09:27:53 +0000 Subject: [PATCH 3/4] =?UTF-8?q?Fix=20how=20to=20check=20if=20the=20host=20?= =?UTF-8?q?is=20IPv6,=20work=20with=20domain=20name=20PIP8=20ok=20w=20to?= =?UTF-8?q?=20check=20if=20the=20host=20is=20IPv6,=20work=20with=20domain?= =?UTF-8?q?=20name=1BOC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fluent/sender.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent/sender.py b/fluent/sender.py index 25a3ca0..647203b 100644 --- a/fluent/sender.py +++ b/fluent/sender.py @@ -210,7 +210,7 @@ def _reconnect(self): sock.settimeout(self.timeout) sock.connect(self.host[len('unix://'):]) else: - if self._host_is_ipv6(): + if self._is_ipv6_host(): sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) else: From edebe052d97a9a2b0786bb4067519df71e0cb314 Mon Sep 17 00:00:00 2001 From: valentin benozillo Date: Thu, 3 May 2018 12:34:16 +0000 Subject: [PATCH 4/4] Fix: use Ipv4 by default --- fluent/sender.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fluent/sender.py b/fluent/sender.py index 647203b..aaf6e49 100644 --- a/fluent/sender.py +++ b/fluent/sender.py @@ -122,9 +122,9 @@ def close(self): self._close() self.pendings = None - def _is_ipv6_host(self): + def _is_ipv4_host(self): try: - socket.getaddrinfo(self.host, None, socket.AF_INET6) + socket.getaddrinfo(self.host, None, socket.AF_INET) return True except socket.error: return False @@ -210,11 +210,11 @@ def _reconnect(self): sock.settimeout(self.timeout) sock.connect(self.host[len('unix://'):]) else: - if self._is_ipv6_host(): - sock = socket.socket(socket.AF_INET6, + if self._is_ipv4_host(): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) else: - sock = socket.socket(socket.AF_INET, + sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) sock.settimeout(self.timeout) # This might be controversial and may need to be removed