forked from Amdyes233/stream
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
97 lines (74 loc) · 2.01 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
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
96
97
package main
import (
"flag"
"log"
"runtime"
"time"
"github.com/aiocloud/stream/api"
"github.com/aiocloud/stream/dns"
"github.com/aiocloud/stream/mitm"
)
var (
Path string
)
func main() {
flag.StringVar(&Path, "c", "/etc/stream.json", "Path")
flag.Parse()
if err := api.Load(Path); err != nil {
log.Fatalf("[Stream] api.Load: %v", err)
}
if err := api.UpdateIPv4(); err != nil {
log.Printf("[Stream] api.UpdateIPv4: %v", err)
}
if err := api.UpdateIPv6(); err != nil {
log.Printf("[Stream] api.UpdateIPv6: %v", err)
}
if api.CurrentIPv4 == "" && api.CurrentIPv6 == "" {
log.Fatalln("[Stream] Get current ip address failed")
}
if err := api.UpdateRule(); err != nil {
log.Fatalf("[Stream] Update rule failed: %v", err)
}
api.Run()
dns.Run()
for _, i := range api.StreamData.TCP.TLS {
go mitm.ListenTLS(i)
}
for _, i := range api.StreamData.TCP.HTTP {
go mitm.ListenHTTP(i)
}
go UpdateIP()
go UpdateRule()
log.Printf("[Stream] IPv4: %s IPv6: %s", api.CurrentIPv4, api.CurrentIPv6)
log.Println("[Stream] Started")
for {
time.Sleep(time.Minute * 10)
runtime.GC()
stats := new(runtime.MemStats)
runtime.ReadMemStats(stats)
log.Printf("[Stream][GC] CPU Fraction %f", stats.GCCPUFraction)
log.Printf("[Stream][GC] Obtained %dMB", stats.Sys/1024/1024)
log.Printf("[Stream][GC] Assigned %dMB", stats.Alloc/1024/1024)
log.Printf("[Stream][GC] Routine %d", runtime.NumGoroutine())
}
}
func UpdateIP() {
for {
time.Sleep(time.Second * 120)
if err := api.UpdateIPv4(); err != nil {
log.Printf("[Stream] api.UpdateIPv4: %v", err)
}
if err := api.UpdateIPv6(); err != nil {
log.Printf("[Stream] api.UpdateIPv6: %v", err)
}
log.Printf("[Stream] IPv4: %s IPv6: %s", api.CurrentIPv4, api.CurrentIPv6)
}
}
func UpdateRule() {
for {
time.Sleep(time.Second * 86400)
if err := api.UpdateRule(); err != nil {
log.Printf("[Stream] Update rule failed: %v", err)
}
}
}