Skip to content

Commit

Permalink
Retry wg conf in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
zachhuff386 committed Apr 3, 2020
1 parent bd5af58 commit 1f3e3ef
Showing 1 changed file with 67 additions and 30 deletions.
97 changes: 67 additions & 30 deletions service/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2087,15 +2087,27 @@ func (p *Profile) confWgLinuxQuick() (err error) {
p.wgQuickLock.Lock()
defer p.wgQuickLock.Unlock()

_, _ = utils.ExecOutput(
p.wgQuickPath, "down", p.Iface,
)
for i := 0; i < 3; i++ {
_, _ = utils.ExecOutput(
p.wgQuickPath, "down", p.Iface,
)

if i == 0 {
time.Sleep(100 * time.Millisecond)
} else {
time.Sleep(500 * time.Millisecond)
}

_, err = utils.ExecOutputLogged(
nil,
p.wgQuickPath,
"up", p.Iface,
)
if err == nil {
break
}
}

_, err = utils.ExecOutputLogged(
nil,
p.wgQuickPath,
"up", p.Iface,
)
if err != nil {
return
}
Expand All @@ -2107,15 +2119,28 @@ func (p *Profile) confWgMac() (err error) {
p.wgQuickLock.Lock()
defer p.wgQuickLock.Unlock()

_, _ = utils.ExecOutput(
p.wgQuickPath, "down", p.Iface,
)
output := ""
for i := 0; i < 3; i++ {
_, _ = utils.ExecOutput(
p.wgQuickPath, "down", p.Iface,
)

if i == 0 {
time.Sleep(100 * time.Millisecond)
} else {
time.Sleep(500 * time.Millisecond)
}

output, err = utils.ExecOutputLogged(
nil,
p.wgQuickPath,
"up", p.Iface,
)
if err == nil {
break
}
}

output, err := utils.ExecOutputLogged(
nil,
p.wgQuickPath,
"up", p.Iface,
)
if err != nil {
return
}
Expand All @@ -2142,21 +2167,33 @@ func (p *Profile) confWgMac() (err error) {
}

func (p *Profile) confWgWin() (err error) {
p.wgQuickLock.Lock()
_, _ = utils.ExecOutput(
"sc.exe", "stop", fmt.Sprintf("WireGuardTunnel$%s", p.Iface),
)
time.Sleep(100 * time.Millisecond)
_, _ = utils.ExecOutput(
"sc.exe", "delete", fmt.Sprintf("WireGuardTunnel$%s", p.Iface),
)
p.wgQuickLock.Unlock()
for i := 0; i < 3; i++ {
p.wgQuickLock.Lock()
_, _ = utils.ExecOutput(
"sc.exe", "stop", fmt.Sprintf("WireGuardTunnel$%s", p.Iface),
)
time.Sleep(100 * time.Millisecond)
_, _ = utils.ExecOutput(
"sc.exe", "delete", fmt.Sprintf("WireGuardTunnel$%s", p.Iface),
)
p.wgQuickLock.Unlock()

if i == 0 {
time.Sleep(100 * time.Millisecond)
} else {
time.Sleep(500 * time.Millisecond)
}

_, err = utils.ExecOutputLogged(
nil,
WgWinPath,
"/installtunnelservice", p.wgConfPth,
)
if err == nil {
break
}
}

_, err = utils.ExecOutputLogged(
nil,
WgWinPath,
"/installtunnelservice", p.wgConfPth,
)
if err != nil {
return
}
Expand Down

0 comments on commit 1f3e3ef

Please sign in to comment.