-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (48 loc) · 1.06 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
package main
import (
"flag"
"fmt"
"net"
"github.com/golang/glog"
)
var (
version = "unknown"
buildTime = "unknown"
bindAddr string
bufferSize int
upstreamRules UpstreamRuleList
showVersion bool
)
func init() {
flag.IntVar(&bufferSize, "buffersize", 4096, "buffer size for first read")
flag.StringVar(&bindAddr, "bind", "localhost:1080", "bind address")
flag.Var(&upstreamRules, "upstream", "list of upstream rules")
flag.BoolVar(&showVersion, "version", false, "show version")
}
func main() {
flag.Parse()
if showVersion {
fmt.Printf("emissary version: %s\n", version)
fmt.Printf("build time: %s\n", buildTime)
} else {
if len(upstreamRules) == 0 {
flag.PrintDefaults()
} else {
listener, err := net.Listen("tcp", bindAddr)
if err != nil {
glog.Fatalln(err)
}
defer listener.Close()
glog.Infof("listening on %s", listener.Addr().String())
for {
conn, err := listener.Accept()
defer conn.Close()
if err != nil {
panic(err)
}
go upstreamRules.HandleConn(conn, bufferSize)
}
}
}
return
}