-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (57 loc) · 1.62 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
package main
import (
"flag"
"log"
"net/http"
"strings"
_ "net/http/pprof"
"github.com/Jille/bindlink/linkmap"
"github.com/Jille/bindlink/multiplexer"
"github.com/Jille/bindlink/tundev"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
listenPort = flag.Int("listen_port", 0, "Listen for incoming connections on this port")
httpAddr = flag.String("http_listen_port", ":8080", "Listen on this address for stats")
targets = flag.String("targets", "", "Host:port pairs of direct endpoints to connect to")
proxies = flag.String("proxies", "", "Host:port pairs of proxy servers")
proxyTarget = flag.String("proxy_target", "", "Host:port pair to have proxy servers connect to")
)
func main() {
flag.Parse()
http.Handle("/metrics", promhttp.Handler())
go func() {
log.Fatal(http.ListenAndServe(*httpAddr, nil))
}()
isMaster := *listenPort > 0
tun, err := tundev.New(isMaster)
if err != nil {
log.Fatalf("Failed to create TUN device: %v", err)
}
mp := multiplexer.New()
lm := linkmap.New(mp)
if *listenPort > 0 {
if err := lm.StartListener(*listenPort); err != nil {
log.Fatalf("Failed to start listening socket: %v", err)
}
}
for _, p := range strings.Split(*targets, ",") {
if p == "" {
continue
}
if err := lm.InitiateLink(p); err != nil {
log.Fatalf("Failed to connect to peer %q: %v", p, err)
}
}
for _, p := range strings.Split(*proxies, ",") {
if p == "" {
continue
}
if err := lm.InitiateLinkOverSOCKS(p, *proxyTarget); err != nil {
log.Fatalf("Failed to connect to peer %q: %v", p, err)
}
}
mp.Start(tun.Send, lm.Send)
go tun.Run(mp.Send)
lm.Run()
}