-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientMain.go
More file actions
95 lines (80 loc) · 2 KB
/
clientMain.go
File metadata and controls
95 lines (80 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
)
func main() {
startTime = time.Now()
//loadSavedStats()
go func() {
err := restoreBinaryName()
if err != nil {
fmt.Println(err.Error())
}
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
flag.StringVar(&tunnelServerAddress, "serverAddr", "m45sci.xyz:30000", "server:port")
flag.StringVar(&clientAddress, "clientAddr", "127.0.0.1", "address for this proxy")
flag.BoolVar(&debugLog, "debugLog", false, "debug logging")
flag.BoolVar(&verboseDebug, "verboseDebug", false, "full debug logging")
flag.Parse()
if verboseDebug {
//Verbose also enables debug
debugLog = true
}
if publicClientFlag == "true" {
//Convert ldflag to bool
publicMode = true
}
startLog()
go autoRotateLogs()
showANSILogo()
doLog("[START] goRelay client started: %v", version)
if publicMode {
didUpdate, err := CheckUpdate()
if err != nil {
doLog("CheckUpdate: %v", err)
}
if didUpdate {
os.Exit(0)
}
}
go tunnelHandler()
go cleanEphemeralMaps()
<-sigs
doLog("[QUIT] relayClient Shutting down.")
}
func restoreBinaryName() error {
// 1) Locate current executable
exePath, err := os.Executable()
if err != nil {
return fmt.Errorf("cannot find executable path: %w", err)
}
dir := filepath.Dir(exePath)
base := filepath.Base(exePath) // e.g. "update_binary.exe" or "myprog"
ext := filepath.Ext(base) // e.g. ".exe" or ""
// 2) Check if it's the updater name
nameOnly := strings.TrimSuffix(base, ext)
if nameOnly != "update_binary" {
// nothing to do
//fmt.Println("not an update")
return nil
}
// 3) Compute the target name
targetName := "M45-Relay-Client" + ext
targetPath := filepath.Join(dir, targetName)
// Sleep, just in case
time.Sleep(time.Second * 2)
// 4) Perform rename
if err := os.Rename(exePath, targetPath); err != nil {
return fmt.Errorf("failed to rename %q to %q: %w", exePath, targetPath, err)
}
return nil
}