proxy: add a multiplexing server frontend

On a Hyper-V system we can only register one listening endpoint (with
a GUID), so we need to accept connections, read a header and then
start the proxy.

If the binary has argv[0] == "proxy-vsockd" then run this new frontend.

Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
David Scott
2016-05-17 22:14:59 +01:00
parent be3e256015
commit 5090fd9599
7 changed files with 240 additions and 77 deletions

View File

@@ -35,10 +35,10 @@ func NewTCPProxy(listener net.Listener, backendAddr *net.TCPAddr) (*TCPProxy, er
}, nil
}
func (proxy *TCPProxy) clientLoop(client Conn, quit chan bool) {
backend, err := net.DialTCP("tcp", nil, proxy.backendAddr)
func HandleTCPConnection(client Conn, backendAddr *net.TCPAddr, quit chan bool) {
backend, err := net.DialTCP("tcp", nil, backendAddr)
if err != nil {
logrus.Printf("Can't forward traffic to backend tcp/%v: %s\n", proxy.backendAddr, err)
logrus.Printf("Can't forward traffic to backend tcp/%v: %s\n", backendAddr, err)
client.Close()
return
}
@@ -89,7 +89,7 @@ func (proxy *TCPProxy) Run() {
logrus.Printf("Stopping proxy on tcp/%v for tcp/%v (%s)", proxy.frontendAddr, proxy.backendAddr, err)
return
}
go proxy.clientLoop(client.(Conn), quit)
go HandleTCPConnection(client.(Conn), proxy.backendAddr, quit)
}
}