-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
56 lines (50 loc) · 1.32 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
package main
import (
"fmt"
"os"
"time"
)
const VERSION string = "1.2.1"
func main() {
fmt.Printf("Gole v%s\n", VERSION)
conf := ParseConfig(os.Args)
switch conf.getMode() {
case "tcp":
fmt.Printf("tunnel mode: TCP\n")
fmt.Printf("operation: %s\n", conf.getOp())
PrintDbgf("%v\n", conf.(*TCPConfig))
case "udp":
fmt.Printf("tunnel mode: UDP\n")
fmt.Printf("tunnel protocol: %s\n", conf.(*UDPConfig).Proto)
fmt.Printf("operation: %s\n", conf.getOp())
PrintDbgf("%v\n", conf.(*UDPConfig))
default:
fmt.Printf("not implemented\n")
os.Exit(1)
}
// punch hole
fmt.Println("====================")
fmt.Printf("punching holes: [local]%s ---> [remote]%s\n", conf.LocalAddr(), conf.RemoteAddr())
conn, err := Punch(conf)
if err != nil {
perror("Failed to punch hole.", err)
os.Exit(1)
}
fmt.Printf("punched through\n")
time.Sleep(50)
fmt.Printf("%s %s\n", conn.LocalAddr(), conf.RemoteAddr())
if conf.getOp() == "holepunch" {
os.Exit(0)
}
// create tunnel
fmt.Println("====================")
fmt.Printf("creating tunnel: [local]%s <--> [remote]%s\n", conn.LocalAddr(), conf.RemoteAddr())
if conf.getOp() == "client" {
fmt.Println("starting client ...")
StartClient(conn, conf)
} else if conf.getOp() == "server" {
fmt.Println("starting server ...")
StartServer(conn, conf)
}
fmt.Printf("Done\n")
}