Flag-compatible IP type

This commit is contained in:
Tim Hockin
2014-10-03 21:34:30 -07:00
parent a0bb739609
commit 0ad0a247c4
10 changed files with 74 additions and 28 deletions

View File

@@ -276,7 +276,8 @@ func logTimeout(err error) bool {
return false
}
func newProxySocket(protocol api.Protocol, host string, port int) (proxySocket, error) {
func newProxySocket(protocol api.Protocol, ip net.IP, port int) (proxySocket, error) {
host := ip.String()
switch strings.ToUpper(string(protocol)) {
case "TCP":
listener, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
@@ -304,12 +305,12 @@ type Proxier struct {
loadBalancer LoadBalancer
mu sync.Mutex // protects serviceMap
serviceMap map[string]*serviceInfo
address string
address net.IP
}
// NewProxier returns a new Proxier given a LoadBalancer and an
// address on which to listen
func NewProxier(loadBalancer LoadBalancer, address string) *Proxier {
func NewProxier(loadBalancer LoadBalancer, address net.IP) *Proxier {
return &Proxier{
loadBalancer: loadBalancer,
serviceMap: make(map[string]*serviceInfo),

View File

@@ -144,7 +144,7 @@ func TestTCPProxy(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "TCP", 0)
if err != nil {
@@ -162,7 +162,7 @@ func TestUDPProxy(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "UDP", time.Second)
if err != nil {
@@ -189,7 +189,7 @@ func TestTCPProxyStop(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "TCP", 0)
if err != nil {
@@ -217,7 +217,7 @@ func TestUDPProxyStop(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "UDP", time.Second)
if err != nil {
@@ -245,7 +245,7 @@ func TestTCPProxyUpdateDelete(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "TCP", 0)
if err != nil {
@@ -272,7 +272,7 @@ func TestUDPProxyUpdateDelete(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "UDP", time.Second)
if err != nil {
@@ -299,7 +299,7 @@ func TestTCPProxyUpdateDeleteUpdate(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "TCP", 0)
if err != nil {
@@ -331,7 +331,7 @@ func TestUDPProxyUpdateDeleteUpdate(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "UDP", time.Second)
if err != nil {
@@ -363,7 +363,7 @@ func TestTCPProxyUpdatePort(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "TCP", 0)
if err != nil {
@@ -408,7 +408,7 @@ func TestUDPProxyUpdatePort(t *testing.T) {
},
})
p := NewProxier(lb, "127.0.0.1")
p := NewProxier(lb, net.ParseIP("127.0.0.1"))
proxyPort, err := p.addServiceOnUnusedPort("echo", "UDP", time.Second)
if err != nil {