log ip, if available, when connection fails (mostly for tls)

This commit is contained in:
jesopo 2020-07-03 10:31:23 +01:00
parent 32e1e40cd2
commit 2d6efc4975
2 changed files with 8 additions and 3 deletions

View file

@ -204,8 +204,12 @@ class Bot(object):
try:
server.connect()
except Exception as e:
self.log.warn("Failed to connect to %s: %s",
[str(server), str(e)])
ip = ""
if server.socket.connected_ip is not None:
ip = f" ({server.socket.connected_ip})"
self.log.warn("Failed to connect to %s%s: %s",
[str(server), ip, str(e)])
self.log.debug("Connection failure reason:", exc_info=True)
return False
self.servers[server.fileno()] = server

View file

@ -69,11 +69,12 @@ class Socket(IRCObject.Object):
5.0)
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
self.connected_ip = self._socket.getpeername()[0]
if self._tls:
self._tls_wrap()
self.connect_time = time.time()
self.connected_ip = self._socket.getpeername()[0]
self.cached_fileno = self._socket.fileno()
self.connected = True