Skip to content

Commit

Permalink
Launcher: When connecting to an announced server, the ip to connect t…
Browse files Browse the repository at this point in the history
…o now properly checks it is our server (and not just any https server) and use of loopback interface is prioritized. Fixes #28
  • Loading branch information
luskaner committed Aug 14, 2024
1 parent 297a463 commit ac29795
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
1 change: 1 addition & 0 deletions launcher-common/executor/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package executor
49 changes: 23 additions & 26 deletions launcher/internal/cmdUtils/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ import (
)

func selectBestServerIp(ips []string) (ok bool, ip string) {
var successIps []string
var successIps []net.IP

for _, curIp := range ips {
if server.CheckConnectionFromServer(curIp, true) {
successIps = append(successIps, curIp)
if server.LanServer(curIp, true) {
parsedIp := net.ParseIP(curIp)
if parsedIp.IsLoopback() {
return true, curIp
}
successIps = append(successIps, net.ParseIP(curIp).To4())
}
}

Expand All @@ -28,36 +32,29 @@ func selectBestServerIp(ips []string) (ok bool, ip string) {
}

ok = true
ip = successIps[0]
ip = successIps[0].String()
interfaces, err := net.Interfaces()

if countSuccessIps > 1 {
interfaces, err := net.Interfaces()
if err != nil {
return
}

var addrs []net.Addr
for _, i := range interfaces {
addrs, err = i.Addrs()
if err != nil {
return
continue
}
var successIpsParsed []net.IP
for _, curIp := range successIps {
successIpsParsed = append(successIpsParsed, net.ParseIP(curIp).To4())
}

var addrs []net.Addr
for _, i := range interfaces {
addrs, err = i.Addrs()
if err != nil {
for _, addr := range addrs {
v, addrOk := addr.(*net.IPNet)
if !addrOk {
continue
}
for _, addr := range addrs {
v, addrOk := addr.(*net.IPNet)
if !addrOk {
continue
}

for _, curIp := range successIpsParsed {
if v.Contains(curIp) {
ip = curIp.String()
return
}
for _, curIp := range successIps {
if v.Contains(curIp) {
ip = curIp.String()
return
}
}
}
Expand Down

0 comments on commit ac29795

Please sign in to comment.