Xpra: Ticket #540: handle connection issues, session events, network drop outs, power events, etc

Follow up from #492, greater scope than #401 and #493.

In this case, the sleep was longer than 60 seconds, but if the TCP connection can be kept alive, why not keep it? (just suspend most of the work on the server until the underlying TCP connection breaks?)

Some links:



Fri, 21 Mar 2014 00:50:17 GMT - Antoine Martin: description changed


Fri, 09 May 2014 14:19:10 GMT - Antoine Martin: milestone changed


Mon, 29 Sep 2014 03:47:46 GMT - Antoine Martin: owner, status, description changed


Tue, 14 Apr 2015 16:38:10 GMT - Antoine Martin: milestone changed

re-scheduling, see also #978


Fri, 13 Nov 2015 13:39:51 GMT - Antoine Martin: milestone changed


Wed, 16 Mar 2016 05:32:39 GMT - Antoine Martin: milestone changed


Tue, 29 Mar 2016 04:41:57 GMT - Antoine Martin:

For win32, found this: DXGI. These two functions are Windows 8 and Platform Update for Windows 7 only (whatever that means):

For OSX, the power event handler is broken and causes crashes (now disabled): #924 / #1137.


Tue, 12 Jul 2016 16:51:50 GMT - Antoine Martin: milestone changed

Milestone renamed


Sun, 21 Aug 2016 09:55:49 GMT - Antoine Martin: milestone changed

Milestone renamed


Thu, 22 Sep 2016 15:24:48 GMT - Antoine Martin:

For OSX, this function may be useful: CGDisplayIsAsleep: Returns a Boolean value indicating whether a display is sleeping (and is therefore not drawable.), but there doesn't seem to be any notifications for this one, so we would need to poll for it regularly.


Tue, 27 Sep 2016 09:46:10 GMT - Antoine Martin: milestone changed

Related to #999 and #401


Sun, 19 Feb 2017 06:36:53 GMT - Antoine Martin: milestone changed


Mon, 10 Jul 2017 14:15:11 GMT - Antoine Martin: milestone changed

re-scheduling


Thu, 17 Aug 2017 09:37:30 GMT - Antoine Martin:

See also ticket:1581#comment:1, the browser API can expose some network information.


Mon, 11 Sep 2017 14:24:13 GMT - Antoine Martin:

r16825 exposes the socket interface link speed to the server, unlike the values we get from the browser the values we get here do make sense. (no idea how chrome gets it so wrong: see ticket:1581#comment:3)

ie with 100Mbps LAN connection:

$ xpra info | grep connection-data.speed
client.connection-data.speed=100000000

Caveats:


Tue, 24 Oct 2017 15:57:01 GMT - Antoine Martin:

As of r17246 (client) and r17247 (server), 80% of the network interface speed is used as bandwidth-limit (#417).

This will do for this release.

On win32, looks like we can get the network adapter's speed from Win32_NetworkAdapter (windows 7) Something like this: Win32_NetworkAdapter - WMI sample in Python but without using python-wmi... (more tricky)


Tue, 24 Oct 2017 15:59:08 GMT - Antoine Martin: milestone changed


Thu, 25 Jan 2018 07:15:34 GMT - Antoine Martin:

See also #619


Wed, 31 Jan 2018 16:51:36 GMT - Antoine Martin:

macos display-is-asleep detection added in r18239

Still TODO:


Thu, 01 Feb 2018 06:44:16 GMT - Antoine Martin:

Why is it such a mess on a linux desktop? We have both org.freedesktop.ScreenSaver and org.gnome.ScreenSaver (ignoring what KDE does for now..), you would guess that the former would be the new more standardized name and would be an alias for the other one, but no: only the latter one gives you signals on a gnome-shell desktop (..). Then to make things worse, triggering the screensaver with gnome-screensaver-command -a fires the ActiveChanged signal, but seemingly with the wrong value, and only once instead of twice (activate then deactivate). There will not be a "year of the Linux desktop", give up already.

win32 already had events for desktop lock and unlock since r10762 (see #901), we now add polling of screensaver status in r18242. (using the ISensLogon event interface directly using ctypes would be hard)


Thu, 01 Feb 2018 06:49:17 GMT - Antoine Martin:

As for getting network device information on win32, using wmi seemed like the right way of going about it, except we don't have wmi bindings with ctypes so we have to use the long winded way (as per ticket:173#comment:25) and then comtypes blows up:

from comtypes.client import CreateObject
o=CreateObject('WbemScripting.SWbemLocator')
s=o.ConnectServer('.', 'root\\cimv2')
res=s.ExecQuery('SELECT * FROM MSFT_NetAdapter');
print(res[0])
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/msys32/mingw32/lib/python2.7/site-packages/comtypes-1.1.4-py2.7.egg/comtypes/__init__.py", line 380, in __getitem__
    result = self.Item(*args)
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: unicode string expected instead of int instance

Even if it did work, it's not clear to me how we would be able to identify the network card that we are interested in ("GUID"? but which one is in use?). The equivalent wmic output for Win32_NetworkAdapter is not very helpful either:

$ wmic path Win32_NetworkAdapter
AdapterType     AdapterTypeId  AutoSense  Availability  Caption                                          ConfigManagerErrorCode  ConfigManagerUserConfig  CreationClassName     Description                           DeviceID  ErrorCleared  ErrorDescription  GUID                                    Index  InstallDate  Installed  InterfaceIndex  LastErrorCode  MACAddress         Manufacturer       MaxNumberControlled  MaxSpeed  Name                                  NetConnectionID        NetConnectionStatus  NetEnabled  NetworkAddresses  PermanentAddress  PhysicalAdapter  PNPDeviceID                                                   PowerManagementCapabilities  PowerManagementSupported  ProductName                           ServiceName   Speed       Status  StatusInfo  SystemCreationClassName  SystemName    TimeOfLastReset
                                          3             [00000000] WAN Miniport (SSTP)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (SSTP)                   0                                                                                 0                   TRUE       2                                                 Microsoft          0                              WAN Miniport (SSTP)                                                                                                               FALSE            ROOT\MS_SSTPMINIPORT\0000                                                                  FALSE                     WAN Miniport (SSTP)                   RasSstp                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000001] WAN Miniport (IKEv2)                  0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (IKEv2)                  1                                                                                 1                   TRUE       10                                                Microsoft          0                              WAN Miniport (IKEv2)                                                                                                              FALSE            ROOT\MS_AGILEVPNMINIPORT\0000                                                              FALSE                     WAN Miniport (IKEv2)                  RasAgileVpn                                   Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000002] WAN Miniport (L2TP)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (L2TP)                   2                                                                                 2                   TRUE       3                                                 Microsoft          0                              WAN Miniport (L2TP)                                                                                                               FALSE            ROOT\MS_L2TPMINIPORT\0000                                                                  FALSE                     WAN Miniport (L2TP)                   Rasl2tp                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000003] WAN Miniport (PPTP)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (PPTP)                   3                                                                                 3                   TRUE       4                                                 Microsoft          0                              WAN Miniport (PPTP)                                                                                                               FALSE            ROOT\MS_PPTPMINIPORT\0000                                                                  FALSE                     WAN Miniport (PPTP)                   PptpMiniport                                  Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000004] WAN Miniport (PPPOE)                  0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (PPPOE)                  4                                                                                 4                   TRUE       5                                                 Microsoft          0                              WAN Miniport (PPPOE)                                                                                                              FALSE            ROOT\MS_PPPOEMINIPORT\0000                                                                 FALSE                     WAN Miniport (PPPOE)                  RasPppoe                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000005] WAN Miniport (IPv6)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (IPv6)                   5                                                                                 5                   TRUE       6                                                 Microsoft          0                              WAN Miniport (IPv6)                                                                                                               FALSE            ROOT\MS_NDISWANIPV6\0000                                                                   FALSE                     WAN Miniport (IPv6)                   NdisWan                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000006] WAN Miniport (Network Monitor)        0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (Network Monitor)        6                                                                                 6                   TRUE       7                                                 Microsoft          0                              WAN Miniport (Network Monitor)                                                                                                    FALSE            ROOT\MS_NDISWANBH\0000                                                                     FALSE                     WAN Miniport (Network Monitor)        NdisWan                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000007] Intel(R) PRO/1000 MT Desktop Adapter  0                       FALSE                    Win32_NetworkAdapter  Intel(R) PRO/1000 MT Desktop Adapter  7                                         {97D5CC41-B8EA-4336-B147-F8227887A3A8}  7                   TRUE       11                             08:00:27:8B:8F:56  Intel              0                              Intel(R) PRO/1000 MT Desktop Adapter  Local Area Connection  2                    TRUE                                            TRUE             PCI\VEN_8086&DEV_100E&SUBSYS_001E8086&REV_02\3&267A616A&0&18                               FALSE                     Intel(R) PRO/1000 MT Desktop Adapter  E1G60         1000000000                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000008] WAN Miniport (IP)                     0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (IP)                     8                                                                                 8                   TRUE       8                                                 Microsoft          0                              WAN Miniport (IP)                                                                                                                 FALSE            ROOT\MS_NDISWANIP\0000                                                                     FALSE                     WAN Miniport (IP)                     NdisWan                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000009] Microsoft ISATAP Adapter              0                       FALSE                    Win32_NetworkAdapter  Microsoft ISATAP Adapter              9                                                                                 9                   TRUE       12                                                Microsoft          0                              Microsoft ISATAP Adapter                                                                                                          FALSE            ROOT\*ISATAP\0000                                                                          FALSE                     Microsoft ISATAP Adapter              tunnel        100000                          Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000010] RAS Async Adapter                                                                      Win32_NetworkAdapter  RAS Async Adapter                     10                                                                                10                  TRUE       9                                                                    0                              RAS Async Adapter                                                                                                                 FALSE                                                                                                       FALSE                     RAS Async Adapter                                                                   Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000011] Microsoft ISATAP Adapter              0                       FALSE                    Win32_NetworkAdapter  Microsoft ISATAP Adapter              11                                                                                11                  TRUE       13                                                Microsoft          0                              Microsoft ISATAP Adapter                                                                                                          FALSE            ROOT\*ISATAP\0001                                                                          FALSE                     Microsoft ISATAP Adapter              tunnel                                        Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000012] Microsoft Teredo Tunneling Adapter    0                       FALSE                    Win32_NetworkAdapter  Microsoft Teredo Tunneling Adapter    12                                                                                12                  TRUE       14                                                Microsoft          0                              Teredo Tunneling Pseudo-Interface                                                                                                 FALSE            ROOT\*TEREDO\0000                                                                          FALSE                     Microsoft Teredo Tunneling Adapter    tunnel        100000                          Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000013] Microsoft ISATAP Adapter              0                       FALSE                    Win32_NetworkAdapter  Microsoft ISATAP Adapter              13                                                                                13                  TRUE       15                                                Microsoft          0                              Microsoft ISATAP Adapter                                                                                                          FALSE            ROOT\*ISATAP\0002                                                                          FALSE                     Microsoft ISATAP Adapter              tunnel                                        Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000014] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      14                                                                                14                  TRUE       19                             08:00:27:8B:8F:56  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0000                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000015] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      15                                                                                15                  TRUE       18                             42:21:20:52:41:53  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0001                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000016] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      16                                                                                16                  TRUE       17                             3E:C2:20:52:41:53  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0002                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000017] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      17                                                                                17                  TRUE       16                             42:21:20:52:41:53  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0003                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420

What we know about:

$ ./Network_info.exe | head -n 7
Network interfaces found:
* {97D5CC41-B8EA-4336-B147-F8227887A3A8} (index=None)
* {E29AC6C2-7037-11DE-816D-806E6F6E6963} (index=None)
* {6EA7AA15-1A44-4AA4-AF09-3BBA667A284E} (index=None)
* {D054ED2E-6492-4002-BF0F-BDB357446D49} (index=None)
Gateways found:
* INET                            : [('192.168.1.1', '{97D5CC41-B8EA-4336-B147-F8227887A3A8}', True)]

Match the connection target with the network interface subnet? Fallback to gateway? Then find the "speed" from wmi..


Wed, 21 Mar 2018 18:21:14 GMT - Antoine Martin: owner, status changed

win32 support added in r18790. We should now get accurate network interface speed on all platforms, except macos... ie on win32 now:

$ ./Network_info.exe |& head -n 5
Network interfaces found:
* {97D5CC41-B8EA-4336-B147-F8227887A3A8} (index=None) (speed=1Gbps)
* {E29AC6C2-7037-11DE-816D-806E6F6E6963} (index=None)
* {6EA7AA15-1A44-4AA4-AF09-3BBA667A284E} (index=None)
* {D054ED2E-6492-4002-BF0F-BDB357446D49} (index=None)

(xpra/net/net_util.py doesn't show it on Linux - because we need an active connection to get the speed)

Or through xpra info (all supported platforms):

$ xpra info | grep connection-data.speed
client.connection-data.speed=100000000

As well as screensaver detection to slow down the screen refresh rate (just not on Linux..)

@maxmylyn: FYI, feel free to close.


Thu, 22 Mar 2018 19:32:16 GMT - J. Max Mena: status changed; resolution set

Noted and closing


Tue, 29 May 2018 15:12:44 GMT - Antoine Martin:

See also #1860, comtypes 32-bit error: #1899

Packet improvements: #1449.


Sat, 23 Jan 2021 04:58:47 GMT - migration script:

this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/540