Maint: create OpenVPN runner in VPN run loop

This commit is contained in:
Quentin McGaw (desktop)
2021-08-19 14:45:57 +00:00
parent 3d8e61900b
commit 9218c7ef19
7 changed files with 48 additions and 26 deletions

View File

@@ -12,6 +12,10 @@ type Runner interface {
Run(ctx context.Context, done chan<- struct{})
}
type vpnRunner interface {
Run(ctx context.Context, errCh chan<- error, ready chan<- struct{})
}
func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
defer close(done)
@@ -26,7 +30,10 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
providerConf := provider.New(providerSettings.Name, allServers, time.Now)
serverName, err := setupOpenVPN(ctx, l.fw, l.openvpnConf, providerConf, VPNSettings.OpenVPN, providerSettings)
vpnRunner, serverName, err := setupOpenVPN(ctx, l.fw,
l.openvpnConf, providerConf,
VPNSettings.OpenVPN, providerSettings,
l.starter, l.logger)
if err != nil {
l.crashed(ctx, err)
continue
@@ -41,8 +48,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
waitError := make(chan error)
tunnelReady := make(chan struct{})
go l.openvpnConf.Run(openvpnCtx, waitError, tunnelReady,
l.logger, VPNSettings.OpenVPN)
go vpnRunner.Run(openvpnCtx, waitError, tunnelReady)
if err := l.waitForError(ctx, waitError); err != nil {
openvpnCancel()