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 314ceb04b4
commit 6932c5e710

@ -387,7 +387,7 @@ AutoStartConnections()
for (i = 0; i < o.num_configs; i++) 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]); StartOpenVPN(&o.conn[i]);
} }
@ -529,6 +529,7 @@ ManagePersistent(HWND hwnd, UINT UNUSED msg, UINT_PTR id, DWORD UNUSED now)
* connect. * connect.
*/ */
o.conn[i].auto_connect = false; 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 */ 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; break;
} }
/* A timer to periodically tend to persistent connections */ /* A timer to periodically tend to persistent connections */
SetTimer(hwnd, 0, 10000, ManagePersistent); SetTimer(hwnd, 0, 100, ManagePersistent);
break; break;

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

@ -421,9 +421,13 @@ BuildFileList()
/* /*
* If no connections are active reset num_configs and rescan * If no connections are active reset num_configs and rescan
* to make a new list. Else we keep all current configs and * 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_configs = 0;
o.num_groups = 0; o.num_groups = 0;

Loading…
Cancel
Save