mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move proxy into pkg
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
6dd1bb9eb0
commit
8c39db8f96
9 changed files with 25 additions and 25 deletions
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/pkg/iptables"
|
"github.com/dotcloud/docker/pkg/iptables"
|
||||||
"github.com/dotcloud/docker/proxy"
|
"github.com/dotcloud/docker/pkg/proxy"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@ package portmapper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/pkg/iptables"
|
"github.com/dotcloud/docker/pkg/iptables"
|
||||||
"github.com/dotcloud/docker/proxy"
|
"github.com/dotcloud/docker/pkg/proxy"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package proxy
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -49,7 +48,8 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
|
||||||
to.CloseRead()
|
to.CloseRead()
|
||||||
event <- written
|
event <- written
|
||||||
}
|
}
|
||||||
utils.Debugf("Forwarding traffic between tcp/%v and tcp/%v", client.RemoteAddr(), backend.RemoteAddr())
|
|
||||||
|
log.Printf("Forwarding traffic between tcp/%v and tcp/%v", client.RemoteAddr(), backend.RemoteAddr())
|
||||||
go broker(client, backend)
|
go broker(client, backend)
|
||||||
go broker(backend, client)
|
go broker(backend, client)
|
||||||
|
|
||||||
|
@ -71,17 +71,17 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
|
||||||
client.Close()
|
client.Close()
|
||||||
backend.Close()
|
backend.Close()
|
||||||
done:
|
done:
|
||||||
utils.Debugf("%v bytes transferred between tcp/%v and tcp/%v", transferred, client.RemoteAddr(), backend.RemoteAddr())
|
log.Printf("%v bytes transferred between tcp/%v and tcp/%v", transferred, client.RemoteAddr(), backend.RemoteAddr())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *TCPProxy) Run() {
|
func (proxy *TCPProxy) Run() {
|
||||||
quit := make(chan bool)
|
quit := make(chan bool)
|
||||||
defer close(quit)
|
defer close(quit)
|
||||||
utils.Debugf("Starting proxy on tcp/%v for tcp/%v", proxy.frontendAddr, proxy.backendAddr)
|
log.Printf("Starting proxy on tcp/%v for tcp/%v", proxy.frontendAddr, proxy.backendAddr)
|
||||||
for {
|
for {
|
||||||
client, err := proxy.listener.Accept()
|
client, err := proxy.listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Debugf("Stopping proxy on tcp/%v for tcp/%v (%v)", proxy.frontendAddr, proxy.backendAddr, err.Error())
|
log.Printf("Stopping proxy on tcp/%v for tcp/%v (%v)", proxy.frontendAddr, proxy.backendAddr, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go proxy.clientLoop(client.(*net.TCPConn), quit)
|
go proxy.clientLoop(client.(*net.TCPConn), quit)
|
|
@ -2,9 +2,9 @@ package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -66,7 +66,7 @@ func (proxy *UDPProxy) replyLoop(proxyConn *net.UDPConn, clientAddr *net.UDPAddr
|
||||||
proxy.connTrackLock.Lock()
|
proxy.connTrackLock.Lock()
|
||||||
delete(proxy.connTrackTable, *clientKey)
|
delete(proxy.connTrackTable, *clientKey)
|
||||||
proxy.connTrackLock.Unlock()
|
proxy.connTrackLock.Unlock()
|
||||||
utils.Debugf("Done proxying between udp/%v and udp/%v", clientAddr.String(), proxy.backendAddr.String())
|
log.Printf("Done proxying between udp/%v and udp/%v", clientAddr.String(), proxy.backendAddr.String())
|
||||||
proxyConn.Close()
|
proxyConn.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -92,24 +92,24 @@ func (proxy *UDPProxy) replyLoop(proxyConn *net.UDPConn, clientAddr *net.UDPAddr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i += written
|
i += written
|
||||||
utils.Debugf("Forwarded %v/%v bytes to udp/%v", i, read, clientAddr.String())
|
log.Printf("Forwarded %v/%v bytes to udp/%v", i, read, clientAddr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *UDPProxy) Run() {
|
func (proxy *UDPProxy) Run() {
|
||||||
readBuf := make([]byte, UDPBufSize)
|
readBuf := make([]byte, UDPBufSize)
|
||||||
utils.Debugf("Starting proxy on udp/%v for udp/%v", proxy.frontendAddr, proxy.backendAddr)
|
log.Printf("Starting proxy on udp/%v for udp/%v", proxy.frontendAddr, proxy.backendAddr)
|
||||||
for {
|
for {
|
||||||
read, from, err := proxy.listener.ReadFromUDP(readBuf)
|
read, from, err := proxy.listener.ReadFromUDP(readBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// NOTE: Apparently ReadFrom doesn't return
|
// NOTE: Apparently ReadFrom doesn't return
|
||||||
// ECONNREFUSED like Read do (see comment in
|
// ECONNREFUSED like Read do (see comment in
|
||||||
// UDPProxy.replyLoop)
|
// UDPProxy.replyLoop)
|
||||||
if utils.IsClosedError(err) {
|
if isClosedError(err) {
|
||||||
utils.Debugf("Stopping proxy on udp/%v for udp/%v (socket was closed)", proxy.frontendAddr, proxy.backendAddr)
|
log.Printf("Stopping proxy on udp/%v for udp/%v (socket was closed)", proxy.frontendAddr, proxy.backendAddr)
|
||||||
} else {
|
} else {
|
||||||
utils.Errorf("Stopping proxy on udp/%v for udp/%v (%v)", proxy.frontendAddr, proxy.backendAddr, err.Error())
|
log.Printf("Stopping proxy on udp/%v for udp/%v (%v)", proxy.frontendAddr, proxy.backendAddr, err.Error())
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ func (proxy *UDPProxy) Run() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
i += written
|
i += written
|
||||||
utils.Debugf("Forwarded %v/%v bytes to udp/%v", i, read, proxy.backendAddr.String())
|
log.Printf("Forwarded %v/%v bytes to udp/%v", i, read, proxy.backendAddr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,3 +150,13 @@ func (proxy *UDPProxy) Close() {
|
||||||
|
|
||||||
func (proxy *UDPProxy) FrontendAddr() net.Addr { return proxy.frontendAddr }
|
func (proxy *UDPProxy) FrontendAddr() net.Addr { return proxy.frontendAddr }
|
||||||
func (proxy *UDPProxy) BackendAddr() net.Addr { return proxy.backendAddr }
|
func (proxy *UDPProxy) BackendAddr() net.Addr { return proxy.backendAddr }
|
||||||
|
|
||||||
|
func isClosedError(err error) bool {
|
||||||
|
/* This comparison is ugly, but unfortunately, net.go doesn't export errClosing.
|
||||||
|
* See:
|
||||||
|
* http://golang.org/src/pkg/net/net.go
|
||||||
|
* https://code.google.com/p/go/issues/detail?id=4337
|
||||||
|
* https://groups.google.com/forum/#!msg/golang-nuts/0_aaCvBmOcM/SptmDyX1XJMJ
|
||||||
|
*/
|
||||||
|
return strings.HasSuffix(err.Error(), "use of closed network connection")
|
||||||
|
}
|
|
@ -879,16 +879,6 @@ func ShellQuoteArguments(args []string) string {
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsClosedError(err error) bool {
|
|
||||||
/* This comparison is ugly, but unfortunately, net.go doesn't export errClosing.
|
|
||||||
* See:
|
|
||||||
* http://golang.org/src/pkg/net/net.go
|
|
||||||
* https://code.google.com/p/go/issues/detail?id=4337
|
|
||||||
* https://groups.google.com/forum/#!msg/golang-nuts/0_aaCvBmOcM/SptmDyX1XJMJ
|
|
||||||
*/
|
|
||||||
return strings.HasSuffix(err.Error(), "use of closed network connection")
|
|
||||||
}
|
|
||||||
|
|
||||||
func PartParser(template, data string) (map[string]string, error) {
|
func PartParser(template, data string) (map[string]string, error) {
|
||||||
// ip:public:private
|
// ip:public:private
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in a new issue