plugin/forward: add prefer_udp option (#1944)
* plugin/forward: add prefer_udp option * updated according to code review - fixed linter warning - removed metric parameter in Proxy.Connect()
This commit is contained in:
parent
7c41f2ce9f
commit
bc50901234
8 changed files with 115 additions and 43 deletions
|
@ -29,10 +29,10 @@ func TestProxyClose(t *testing.T) {
|
|||
p := NewProxy(s.Addr, nil)
|
||||
p.start(hcInterval)
|
||||
|
||||
go func() { p.Connect(ctx, state, false, false) }()
|
||||
go func() { p.Connect(ctx, state, true, false) }()
|
||||
go func() { p.Connect(ctx, state, false, false) }()
|
||||
go func() { p.Connect(ctx, state, true, false) }()
|
||||
go func() { p.Connect(ctx, state, options{}) }()
|
||||
go func() { p.Connect(ctx, state, options{forceTCP: true}) }()
|
||||
go func() { p.Connect(ctx, state, options{}) }()
|
||||
go func() { p.Connect(ctx, state, options{forceTCP: true}) }()
|
||||
|
||||
p.close()
|
||||
}
|
||||
|
@ -93,3 +93,30 @@ func TestProxyTLSFail(t *testing.T) {
|
|||
t.Fatal("Expected *not* to receive reply, but got one")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProtocolSelection(t *testing.T) {
|
||||
p := NewProxy("bad_address", nil)
|
||||
|
||||
stateUDP := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
|
||||
stateTCP := request.Request{W: &test.ResponseWriter{TCP: true}, Req: new(dns.Msg)}
|
||||
ctx := context.TODO()
|
||||
|
||||
go func() {
|
||||
p.Connect(ctx, stateUDP, options{})
|
||||
p.Connect(ctx, stateUDP, options{forceTCP: true})
|
||||
p.Connect(ctx, stateUDP, options{preferUDP: true})
|
||||
p.Connect(ctx, stateUDP, options{preferUDP: true, forceTCP: true})
|
||||
p.Connect(ctx, stateTCP, options{})
|
||||
p.Connect(ctx, stateTCP, options{forceTCP: true})
|
||||
p.Connect(ctx, stateTCP, options{preferUDP: true})
|
||||
p.Connect(ctx, stateTCP, options{preferUDP: true, forceTCP: true})
|
||||
}()
|
||||
|
||||
for i, exp := range []string{"udp", "tcp", "udp", "tcp", "tcp", "tcp", "udp", "tcp"} {
|
||||
proto := <-p.transport.dial
|
||||
p.transport.ret <- nil
|
||||
if proto != exp {
|
||||
t.Errorf("Unexpected protocol in case %d, expected %q, actual %q", i, exp, proto)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue