44import gettext
55import threading
66import logging
7+ import socket
78
89from gi .repository import GObject , GLib
910
@@ -79,6 +80,8 @@ def __init__(self, ident, hostname, display_hostname, ip_info, port, local_ident
7980
8081 self .has_zc_presence = False # This is currently unused.
8182
83+ self .last_register = 0
84+
8285 def start_remote_thread (self ):
8386 # func = lambda: return
8487
@@ -104,7 +107,7 @@ def remote_thread_v1(self):
104107
105108 def run_secure_loop ():
106109 logging .debug ("Remote: Starting a new connection loop for %s (%s:%d)"
107- % (self .display_hostname , self .ip_info . ip4_address , self .port ))
110+ % (self .display_hostname , self .ip_info , self .port ))
108111
109112 cert = auth .get_singleton ().get_cached_cert (self .hostname , self .ip_info )
110113 creds = grpc .ssl_channel_credentials (cert )
@@ -121,7 +124,7 @@ def run_secure_loop():
121124
122125 if not self .ping_timer .is_set ():
123126 logging .debug ("Remote: Unable to establish secure connection with %s (%s:%d). Trying again in %ds"
124- % (self .display_hostname , self .ip_info . ip4_address , self .port , CHANNEL_RETRY_WAIT_TIME ))
127+ % (self .display_hostname , self .ip_info , self .port , CHANNEL_RETRY_WAIT_TIME ))
125128 self .ping_timer .wait (CHANNEL_RETRY_WAIT_TIME )
126129 return True # run_secure_loop()
127130
@@ -134,13 +137,13 @@ def run_secure_loop():
134137
135138 if self .busy :
136139 logging .debug ("Remote Ping: Skipping keepalive ping to %s (%s:%d) (busy)"
137- % (self .display_hostname , self .ip_info . ip4_address , self .port ))
140+ % (self .display_hostname , self .ip_info , self .port ))
138141 self .busy = False
139142 else :
140143 try :
141144 # t = GLib.get_monotonic_time()
142145 logging .debug ("Remote Ping: to %s (%s:%d)"
143- % (self .display_hostname , self .ip_info . ip4_address , self .port ))
146+ % (self .display_hostname , self .ip_info , self .port ))
144147 self .stub .Ping (warp_pb2 .LookupName (id = self .local_ident ,
145148 readable_name = util .get_hostname ()),
146149 timeout = 5 )
@@ -150,7 +153,7 @@ def run_secure_loop():
150153 self .set_remote_status (RemoteStatus .AWAITING_DUPLEX )
151154 if self .check_duplex_connection ():
152155 logging .debug ("Remote: Connected to %s (%s:%d)"
153- % (self .display_hostname , self .ip_info . ip4_address , self .port ))
156+ % (self .display_hostname , self .ip_info , self .port ))
154157
155158 self .set_remote_status (RemoteStatus .ONLINE )
156159
@@ -161,12 +164,12 @@ def run_secure_loop():
161164 duplex_fail_counter += 1
162165 if duplex_fail_counter > DUPLEX_MAX_FAILURES :
163166 logging .debug ("Remote: CheckDuplexConnection to %s (%s:%d) failed too many times"
164- % (self .display_hostname , self .ip_info . ip4_address , self .port ))
167+ % (self .display_hostname , self .ip_info , self .port ))
165168 self .ping_timer .wait (CHANNEL_RETRY_WAIT_TIME )
166169 return True
167170 except grpc .RpcError as e :
168171 logging .debug ("Remote: Ping failed, shutting down %s (%s:%d)"
169- % (self .display_hostname , self .ip_info . ip4_address , self .port ))
172+ % (self .display_hostname , self .ip_info , self .port ))
170173 break
171174
172175 self .ping_timer .wait (CONNECTED_PING_TIME if self .status == RemoteStatus .ONLINE else DUPLEX_WAIT_PING_TIME )
@@ -185,7 +188,7 @@ def run_secure_loop():
185188 continue
186189 except Exception as e :
187190 logging .critical ("!! Major problem starting connection loop for %s (%s:%d): %s"
188- % (self .display_hostname , self .ip_info . ip4_address , self .port , e ))
191+ % (self .display_hostname , self .ip_info , self .port , e ))
189192
190193 self .set_remote_status (RemoteStatus .OFFLINE )
191194 self .run_thread_alive = False
@@ -195,7 +198,9 @@ def remote_thread_v2(self):
195198
196199 self .emit_machine_info_changed () # Let's make sure the button doesn't have junk in it if we fail to connect.
197200
198- logging .debug ("Remote: Attempting to connect to %s (%s) - api version 2" % (self .display_hostname , self .ip_info .ip4_address ))
201+ remote_ip , _ , ip_version = self .ip_info .get_usable_ip ()
202+ logging .debug ("Remote: Attempting to connect to %s (%s) - api version 2" % (self .display_hostname , remote_ip ))
203+ remote_ip = remote_ip if ip_version == socket .AF_INET else "[%s]" % (remote_ip ,)
199204
200205 self .set_remote_status (RemoteStatus .INIT_CONNECTING )
201206
@@ -212,7 +217,7 @@ def run_secure_loop():
212217 ('grpc.http2.min_ping_interval_without_data_ms' , 5000 )
213218 )
214219
215- with grpc .secure_channel ("%s:%d" % (self . ip_info . ip4_address , self .port ), creds , options = opts ) as channel :
220+ with grpc .secure_channel ("%s:%d" % (remote_ip , self .port ), creds , options = opts ) as channel :
216221
217222 def channel_state_changed (state ):
218223 if state != grpc .ChannelConnectivity .READY :
@@ -335,7 +340,7 @@ def rpc_call(self, func, *args, **kargs):
335340 except Exception as e :
336341 # exception concurrent.futures.thread.BrokenThreadPool is not available in bionic/python3 < 3.7
337342 logging .critical ("!! RPC threadpool failure while submitting call to %s (%s:%d): %s"
338- % (self .display_hostname , self .ip_info . ip4_address , self .port , e ))
343+ % (self .display_hostname , self .ip_info , self .port , e ))
339344
340345 # Not added to thread pool
341346 def check_duplex_connection (self ):
0 commit comments