check: stop checking when protocol not supported

This commit is contained in:
nadoo committed 2020-11-26 19:21:27 +08:00
1 parent 6820644073
commit 98ce20b295
9 files changed
+69 -122

No files matched your search

+4
View File
@@ -6,6 +6,10 @@ import (
"strings"
)
var (
ErrNotSupported = errors.New("not supported")
)
// Dialer is used to create connection.
type Dialer interface {
TCPDialer
+2 -25
View File
@@ -1,7 +1,6 @@
package tcp
import (
"errors"
"net"
"net/url"
"strings"
@@ -12,10 +11,9 @@ import (
// TCP struct.
type TCP struct {
addr string
dialer proxy.Dialer
proxy proxy.Proxy
server proxy.Server
addr string
}
func init() {
@@ -47,19 +45,6 @@ func NewTCPDialer(s string, d proxy.Dialer) (proxy.Dialer, error) {
// NewTCPServer returns a tcp transport layer before the real server.
func NewTCPServer(s string, p proxy.Proxy) (proxy.Server, error) {
// transport := strings.Split(s, ",")
// prepare transport listener
// TODO: check here
// if len(transport) < 2 {
// return nil, errors.New("[tcp] malformd listener:" + s)
// }
// t.server, err = proxy.ServerFromURL(transport[1], p)
// if err != nil {
// return nil, err
// }
return NewTCP(s, nil, p)
}
@@ -87,14 +72,6 @@ func (s *TCP) ListenAndServe() {
// Serve serves a connection.
func (s *TCP) Serve(c net.Conn) {
// we know the internal server will close the connection after serve
// defer c.Close()
if s.server != nil {
s.server.Serve(c)
return
}
defer c.Close()
if c, ok := c.(*net.TCPConn); ok {
@@ -135,5 +112,5 @@ func (s *TCP) Dial(network, addr string) (net.Conn, error) {
// DialUDP connects to the given address via the proxy.
func (s *TCP) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
return nil, nil, errors.New("tcp client does not support udp now")
return nil, nil, proxy.ErrNotSupported
}
+2 -2
View File
@@ -1,6 +1,7 @@
package udp
import (
"fmt"
"net"
"net/url"
"sync"
@@ -15,7 +16,6 @@ type UDP struct {
addr string
dialer proxy.Dialer
proxy proxy.Proxy
server proxy.Server
}
func init() {
@@ -120,7 +120,7 @@ func (s *UDP) Addr() string {
// Dial connects to the address addr on the network net via the proxy.
func (s *UDP) Dial(network, addr string) (net.Conn, error) {
return s.dialer.Dial("udp", s.addr)
return nil, fmt.Errorf("can not dial tcp via udp dialer: %w", proxy.ErrNotSupported)
}
// DialUDP connects to the given address via the proxy.