Browse Source

Change the logic of releasing persistent connections in OnHold

(i)
State is changed to detached before auto-starting
so that OnHold() will see state = resuming and keep the hold.

State is set to disconnected instead of detached on detach
so that manual starts will release the hold automatically.

End result: While connecting automatically, do not release if
management-hold is on. But while started manually, release
from hold so that connection can complete without further
user action.

In normal use of automatic service, one would not add management
hold into the config. However, if the user disconnects the connection
the GUI puts it on hold, and we do not want to auto-start it after a
lock-unlock or some other automatic action.

(ii)
Also, currently, for persistent connections, the status
window is not shown automatically which feels unnatural in
real use. Instead, popup the status window when connection
is manually initiated. Its not popped up when automatically
attached to or if silent_connection is on.

Only persistent connections are affected by the change.

fixup: config file list is not recreated from scratch when
enable_persistent == 2 (auto attach mode) to avoid losing info
such as auto_connect = false on detached connections.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/519/head
Selva Nair 2 years ago
parent
commit
6932c5e710
  1. 5
      main.c
  2. 13
      openvpn.c
  3. 8
      openvpn_config.c

5
main.c

@ -387,7 +387,7 @@ AutoStartConnections()
for (i = 0; i < o.num_configs; i++)
{
if (o.conn[i].auto_connect)
if (o.conn[i].auto_connect && !(o.conn[i].flags & FLAG_DAEMON_PERSISTENT))
StartOpenVPN(&o.conn[i]);
}
@ -529,6 +529,7 @@ ManagePersistent(HWND hwnd, UINT UNUSED msg, UINT_PTR id, DWORD UNUSED now)
* connect.
*/
o.conn[i].auto_connect = false;
o.conn[i].state = detached; /* this is required to retain management-hold on re-attach */
StartOpenVPN(&o.conn[i]); /* attach to the management i/f */
}
}
@ -617,7 +618,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
break;
}
/* A timer to periodically tend to persistent connections */
SetTimer(hwnd, 0, 10000, ManagePersistent);
SetTimer(hwnd, 0, 100, ManagePersistent);
break;

13
openvpn.c

@ -1347,7 +1347,6 @@ OnStop(connection_t *c, UNUSED char *msg)
if (c->flags & FLAG_DAEMON_PERSISTENT)
{
/* user initiated disconnection -- stay detached and do not auto-reconnect */
c->state = detached;
c->auto_connect = false;
}
CheckAndSetTrayIcon();
@ -1358,7 +1357,7 @@ OnStop(connection_t *c, UNUSED char *msg)
case onhold:
/* stop triggered while on hold -- possibly the daemon exited. Treat same as detaching */
case detaching:
c->state = detached;
c->state = disconnected;
CheckAndSetTrayIcon();
SendMessage(c->hwndStatus, WM_CLOSE, 0, 0);
break;
@ -2136,9 +2135,13 @@ ThreadOpenVPNStatus(void *p)
wait_event = c->hProcess;
}
/* For persistent connections, popup the status win only if we're in manual mode */
if (o.silent_connection == 0 && ((c->flags & FLAG_DAEMON_PERSISTENT) == 0 || o.enable_persistent == 1))
ShowWindow(c->hwndStatus, SW_SHOW);
/* For persistent connections, popup the status win only if we're connecting manually */
BOOL show_status_win = (o.silent_connection == 0);
if ((c->flags & FLAG_DAEMON_PERSISTENT) && c->state == resuming)
{
show_status_win = false;
}
ShowWindow(c->hwndStatus, show_status_win ? SW_SHOW : SW_HIDE);
/* Load echo msg histroy from registry */
echo_msg_load(c);

8
openvpn_config.c

@ -421,9 +421,13 @@ BuildFileList()
/*
* If no connections are active reset num_configs and rescan
* to make a new list. Else we keep all current configs and
* rescan to add any new one's found
* rescan to add any new one's found.
* Do the same when persistent connections are in auto-attach mode,
* to avoid over-writing their status info such as auto_connect=false
* after manual detach.
*/
if (!o.num_groups || CountConnState(disconnected) == o.num_configs)
if (!o.num_groups
|| (CountConnState(disconnected) == o.num_configs && o.enable_persistent != 2))
{
o.num_configs = 0;
o.num_groups = 0;

Loading…
Cancel
Save