Maint: minor Openvpn loop simplifications
This commit is contained in:
@@ -4,9 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (l *Loop) crashed(ctx context.Context, err error) {
|
||||||
|
l.signalOrSetStatus(constants.Crashed)
|
||||||
|
l.logAndWait(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Loop) signalOrSetStatus(status models.LoopStatus) {
|
func (l *Loop) signalOrSetStatus(status models.LoopStatus) {
|
||||||
if l.userTrigger {
|
if l.userTrigger {
|
||||||
l.userTrigger = false
|
l.userTrigger = false
|
||||||
|
|||||||
@@ -32,40 +32,32 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
var err error
|
var err error
|
||||||
if openVPNSettings.Config == "" {
|
if openVPNSettings.Config == "" {
|
||||||
connection, err = providerConf.GetOpenVPNConnection(providerSettings.ServerSelection)
|
connection, err = providerConf.GetOpenVPNConnection(providerSettings.ServerSelection)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
l.signalOrSetStatus(constants.Crashed)
|
lines = providerConf.BuildConf(connection, l.username, openVPNSettings)
|
||||||
l.logAndWait(ctx, err)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
lines = providerConf.BuildConf(connection, l.username, openVPNSettings)
|
|
||||||
} else {
|
} else {
|
||||||
lines, connection, err = l.processCustomConfig(openVPNSettings)
|
lines, connection, err = l.processCustomConfig(openVPNSettings)
|
||||||
if err != nil {
|
}
|
||||||
l.signalOrSetStatus(constants.Crashed)
|
if err != nil {
|
||||||
l.logAndWait(ctx, err)
|
l.crashed(ctx, err)
|
||||||
continue
|
continue
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := l.conf.WriteConfig(lines); err != nil {
|
if err := l.conf.WriteConfig(lines); err != nil {
|
||||||
l.signalOrSetStatus(constants.Crashed)
|
l.crashed(ctx, err)
|
||||||
l.logAndWait(ctx, err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if openVPNSettings.User != "" {
|
if openVPNSettings.User != "" {
|
||||||
err := l.conf.WriteAuthFile(
|
err := l.conf.WriteAuthFile(openVPNSettings.User, openVPNSettings.Password)
|
||||||
openVPNSettings.User, openVPNSettings.Password)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.signalOrSetStatus(constants.Crashed)
|
l.crashed(ctx, err)
|
||||||
l.logAndWait(ctx, err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := l.fw.SetVPNConnection(ctx, connection); err != nil {
|
if err := l.fw.SetVPNConnection(ctx, connection); err != nil {
|
||||||
l.signalOrSetStatus(constants.Crashed)
|
l.crashed(ctx, err)
|
||||||
l.logAndWait(ctx, err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +67,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
openvpnCtx, openVPNSettings.Version, openVPNSettings.Flags)
|
openvpnCtx, openVPNSettings.Version, openVPNSettings.Flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
openvpnCancel()
|
openvpnCancel()
|
||||||
l.signalOrSetStatus(constants.Crashed)
|
l.crashed(ctx, err)
|
||||||
l.logAndWait(ctx, err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user