@@ -844,6 +844,8 @@ def fetch_credentials(self, address, session_id, type, conndesc):
844844 return None , None , None
845845
846846 def write_wireguard_config (self , response , decode , wgkey , conndesc , iface ):
847+ CONFIG = MeileConfig .read_configuration (MeileConfig .CONFFILE )
848+ user_dns = CONFIG ['network' ].get ('dns' , '9.9.9.9' )
847849 if len (decode ) < 100 :
848850 self .connected = {
849851 "v2ray_pid" : None ,
@@ -899,7 +901,7 @@ def write_wireguard_config(self, response, decode, wgkey, conndesc, iface):
899901 config .set ("Interface" , "PrivateKey" , wgkey .privkey )
900902 config .set (
901903 "Interface" , "DNS" ,
902- "," .join (["127.0.0.1" , "1.0.0.1" , "1.1.1.1" ])
904+ "," .join ([user_dns , "1.0.0.1" , "1.1.1.1" ])
903905 )
904906
905907 config .add_section ("Peer" )
@@ -1218,46 +1220,39 @@ def connect(self,
12181220 if pltfrm == Arch .LINUX :
12191221 child = pexpect .spawn (f"pkexec sh -c 'ip link delete { iface } ; wg-quick up { config_file } '" )
12201222 child .expect (pexpect .EOF )
1221- ok = wait_for_tunnel_iface (iface = ["wg99" , "utun3" ], timeout = 300 )
1222- if ok is None :
1223- self .connected = {"v2ray_pid" : None ,
1224- "result" : False ,
1225- "status" : "Error bringing up wireguard interface" ,
1226- "session_id" : session_id }
1227- return
1223+
12281224 elif pltfrm == Arch .OSX :
12291225 connectBASH = [sentinel_connect_bash ]
12301226 proc2 = subprocess .Popen (connectBASH )
12311227 proc2 .wait (timeout = 30 )
12321228 pid2 = proc2 .pid
12331229 proc_out , proc_err = proc2 .communicate ()
1234- ok = wait_for_tunnel_iface (iface = ["wg99" , "utun3" ], timeout = 300 )
1235- if ok is None :
1236- self .connected = {"v2ray_pid" : None ,
1237- "result" : False ,
1238- "status" : "Error bringing up wireguard interface" ,
1239- "session_id" : session_id }
1240- return
1230+
12411231 elif pltfrm == Arch .WINDOWS :
12421232 wgup = [gsudo , MeileConfig .WIREGUARD_BIN , "/installtunnelservice" , config_file ]
12431233 wg_process = subprocess .Popen (wgup )
1244- ok = wait_for_tunnel_iface (iface = ["wg99" , "utun3" ], timeout = 300 )
1245- if ok is None :
1246- self .connected = {"v2ray_pid" : None ,
1247- "result" : False ,
1248- "status" : "Error bringing up wireguard interface" ,
1249- "session_id" : session_id }
1250- return
12511234
1252- if psutil .net_if_addrs ().get (iface ) or psutil .net_if_addrs ().get ("utun3" ):
1235+
1236+ #if psutil.net_if_addrs().get(iface) or psutil.net_if_addrs().get("utun3"):
1237+ tuniface = wait_for_tunnel_iface (iface = [iface , "utun3" ], timeout = 30 )
1238+ if tuniface is not None :
12531239 self .connected = {"v2ray_pid" : None ,
12541240 "result" : True ,
1255- "status" : iface ,
1241+ "status" : tuniface ,
12561242 "session_id" : session_id }
12571243 conndesc .write ("Checking network connection...\n " )
12581244 conndesc .flush ()
1259- sleep (1 )
1260- self .get_ip_address ()
1245+ sleep (2 )
1246+ if self .get_ip_address ():
1247+ self .connected = {"v2ray_pid" : None ,
1248+ "result" : True ,
1249+ "status" : tuniface ,
1250+ "session_id" : session_id }
1251+ else :
1252+ self .connected = {"v2ray_pid" : None ,
1253+ "result" : False ,
1254+ "status" : "Error establising connection to internet. Try a differnt node." ,
1255+ "session_id" : session_id }
12611256 sleep (1 )
12621257 conndesc .close ()
12631258 return
@@ -1297,26 +1292,14 @@ def connect(self,
12971292 if pltfrm == Arch .OSX :
12981293 chdir (MeileConfig .BASEDIR )
12991294 return
1300-
1301- if pltfrm != Arch .OSX :
1302- for iface in psutil .net_if_addrs ().keys ():
1303- if "tun" in iface :
1304- tuniface = True
1305- break
1306- else :
1307- if psutil .net_if_addrs ().get ("utun123" ):
1308- self .connected = {"v2ray_pid" : v2ray_handler .v2ray_pid ,
1309- "result" : True ,
1310- "status" : "utun123" ,
1311- "session_id" : session_id }
1312- print (self .connected )
1313- tuniface = True
1314-
1315- if tuniface is True :
1316- print (self .connected )
1295+
1296+ tuniface = wait_for_tunnel_iface (iface = ["tun" , "utun3" , "utun123" ], timeout = 30 )
1297+
1298+ if tuniface is not None :
1299+ print ("Tunnel interface is up:" , tuniface )
13171300 conndesc .write ("Checking network connection...\n " )
13181301 conndesc .flush ()
1319- sleep (1 )
1302+ sleep (3.3 )
13201303 if self .get_ip_address ():
13211304 self .connected = {"v2ray_pid" : v2ray_handler .v2ray_pid ,
13221305 "result" : True ,
0 commit comments