-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (57 loc) · 1.44 KB
/
main.go
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
package main
import (
"crypto/sha256"
"flag"
"log"
"os"
"regexp"
"stargazer/transport-pipe/client"
"stargazer/transport-pipe/color"
"stargazer/transport-pipe/server"
"strconv"
)
func main() {
log.SetOutput(color.NewWriter(os.Stderr))
mode := flag.String("mode", "client", "Set the type (client/server)")
address := flag.String("address", "127.0.0.1", "Enter an IP address / URL")
bufSize := flag.String("b", "1M", "Enter a buffer size")
password := flag.String("password", "pass", "Server / Client password")
flag.Parse()
_password := *password
// Sanitize buffer size
re := regexp.MustCompile("[0-9]+")
units := []string{"K", "M", "G"}
unit := (*bufSize)[len(*bufSize)-1:]
value, valErr := strconv.Atoi(re.FindAllString(*bufSize, -1)[0])
if valErr != nil {
log.Panicln("Wrong -b")
}
bufferSize := value
if !re.Match([]byte(unit)) {
for _, v := range units {
bufferSize *= 1024
if v == unit {
break
}
}
}
log.Printf("Buffer size %d", bufferSize)
switch *mode {
case "client":
if cErr := client.StartClient(address, bufferSize, _password); cErr != nil {
log.Panicln(cErr.Error())
}
log.Println("Successfully Read")
case "server":
if sErr := server.StartServer(bufferSize, _password); sErr != nil {
log.Panicln(sErr.Error())
}
default:
log.Println("Wrong type (client/server)")
}
}
func String2Hash(str string) string {
h := sha256.New()
h.Write([]byte(str))
return string(h.Sum(nil))
}