MCPcopy Create free account
hub / github.com/celzero/midway / main

Function main

main.go:20–104  ·  view source on GitHub ↗

Adopted from: github.com/inetaf/tcpproxy/blob/be3ee21/tcpproxy.go

()

Source from the content-addressed store, hash-verified

18
19// Adopted from: github.com/inetaf/tcpproxy/blob/be3ee21/tcpproxy.go
20func main() {
21 portmap := map[string]string{
22 "h11": ":80",
23 "tls": ":443",
24 "dot": ":853",
25 "flydoh": ":1443",
26 "flydot": ":1853",
27 "echo": ":5000",
28 "ppecho": ":5001",
29 }
30 if !env.Sudo() {
31 portmap["tls"] = ":8443"
32 portmap["dot"] = ":8853"
33 portmap["h11"] = ":8080"
34 }
35
36 totallisteners := len(portmap)
37 hold := barrier(totallisteners)
38
39 // cleartext http1.x on port 80
40 t80, err := net.Listen("tcp", portmap["h11"])
41 ko(err)
42 fmt.Println("started: pptcp-server on port ", portmap["h11"])
43 pp80 := &proxyproto.Listener{Listener: t80}
44
45 // tcp-tls (http2 / http1.1) on port 443
46 t443, err := net.Listen("tcp", portmap["tls"])
47 ko(err)
48 fmt.Println("started: pptcp-server on port ", portmap["tls"])
49 pp443 := &proxyproto.Listener{Listener: t443}
50
51 // tcp-tls (DNS over TLS) on port 853
52 t853, err := net.Listen("tcp", portmap["dot"])
53 ko(err)
54 fmt.Println("started: pptcp-server on port ", portmap["dot"])
55 pp853 := &proxyproto.Listener{Listener: t853}
56
57 // fly terminated tls (http2 and http1.1) on port 1443
58 t1443, err := net.Listen("tcp", portmap["flydoh"])
59 ko(err)
60 fmt.Println("started: pptcp-server on port ", portmap["flydoh"])
61 pp1443 := &proxyproto.Listener{Listener: t1443}
62
63 // fly terminated tls (DNS over TLS) on port 1853
64 t1853, err := net.Listen("tcp", portmap["flydot"])
65 ko(err)
66 fmt.Println("started: pptcp-server on port ", portmap["flydot"])
67 pp1853 := &proxyproto.Listener{Listener: t1853}
68
69 // ref: fly.io/docs/app-guides/udp-and-tcp/
70 u5000, err := net.ListenPacket("udp", "fly-global-services:5000")
71 if err != nil {
72 log.Println(err)
73 if pc5000, err := net.ListenPacket("udp", portmap["echo"]); err != nil {
74 ko(err)
75 } else {
76 u5000 = pc5000
77 }

Callers

nothing calls this directly

Calls 13

SudoFunction · 0.92
NewDohStubFunction · 0.92
UpstreamDohFunction · 0.92
StartPPFunction · 0.92
StartPPWithDoHFunction · 0.92
StartPPWithDoTFunction · 0.92
StartPPWithDoHCleartextFunction · 0.92
StartPPWithDoTCleartextFunction · 0.92
EchoUDPFunction · 0.92
EchoTCPFunction · 0.92
EchoPPFunction · 0.92
barrierFunction · 0.85

Tested by

no test coverage detected