mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
log: show proxy info in log, via PROXY
This commit is contained in:
1 parent
edcb21236a
commit
d6d706b5ee
17 files changed
+124
-110
No files matched your search
+15
-10
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/nadoo/glider/proxy"
|
||||
)
|
||||
|
||||
// TLS struct
|
||||
// TLS struct.
|
||||
type TLS struct {
|
||||
dialer proxy.Dialer
|
||||
proxy proxy.Proxy
|
||||
@@ -34,7 +34,7 @@ func init() {
|
||||
proxy.RegisterServer("tls", NewTLSServer)
|
||||
}
|
||||
|
||||
// NewTLS returns a tls proxy struct
|
||||
// NewTLS returns a tls proxy struct.
|
||||
func NewTLS(s string, d proxy.Dialer, p proxy.Proxy) (*TLS, error) {
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
@@ -70,7 +70,7 @@ func NewTLS(s string, d proxy.Dialer, p proxy.Proxy) (*TLS, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// NewTLSDialer returns a tls proxy dialer
|
||||
// NewTLSDialer returns a tls proxy dialer.
|
||||
func NewTLSDialer(s string, d proxy.Dialer) (proxy.Dialer, error) {
|
||||
p, err := NewTLS(s, d, nil)
|
||||
if err != nil {
|
||||
@@ -87,7 +87,7 @@ func NewTLSDialer(s string, d proxy.Dialer) (proxy.Dialer, error) {
|
||||
return p, err
|
||||
}
|
||||
|
||||
// NewTLSServer returns a tls transport layer before the real server
|
||||
// NewTLSServer returns a tls transport layer before the real server.
|
||||
func NewTLSServer(s string, p proxy.Proxy) (proxy.Server, error) {
|
||||
transport := strings.Split(s, ",")
|
||||
|
||||
@@ -121,7 +121,7 @@ func NewTLSServer(s string, p proxy.Proxy) (proxy.Server, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// ListenAndServe .
|
||||
// ListenAndServe listens on server's addr and serves connections.
|
||||
func (s *TLS) ListenAndServe() {
|
||||
l, err := net.Listen("tcp", s.addr)
|
||||
if err != nil {
|
||||
@@ -143,7 +143,7 @@ func (s *TLS) ListenAndServe() {
|
||||
}
|
||||
}
|
||||
|
||||
// Serve serves requests
|
||||
// Serve serves a connection.
|
||||
func (s *TLS) Serve(c net.Conn) {
|
||||
// we know the internal server will close the connection after serve
|
||||
// defer c.Close()
|
||||
@@ -154,10 +154,15 @@ func (s *TLS) Serve(c net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
// Addr returns forwarder's address
|
||||
func (s *TLS) Addr() string { return s.addr }
|
||||
// Addr returns forwarder's address.
|
||||
func (s *TLS) Addr() string {
|
||||
if s.addr == "" {
|
||||
return s.dialer.Addr()
|
||||
}
|
||||
return s.addr
|
||||
}
|
||||
|
||||
// Dial connects to the address addr on the network net via the proxy
|
||||
// Dial connects to the address addr on the network net via the proxy.
|
||||
func (s *TLS) Dial(network, addr string) (net.Conn, error) {
|
||||
cc, err := s.dialer.Dial("tcp", s.addr)
|
||||
if err != nil {
|
||||
@@ -170,7 +175,7 @@ func (s *TLS) Dial(network, addr string) (net.Conn, error) {
|
||||
return c, err
|
||||
}
|
||||
|
||||
// DialUDP connects to the given address via the proxy
|
||||
// DialUDP connects to the given address via the proxy.
|
||||
func (s *TLS) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) {
|
||||
return nil, nil, errors.New("tls client does not support udp now")
|
||||
}
|
||||
Reference in new issue
Block a user