Documentation ¶
Index ¶
- Variables
- type Config
- type Conn
- func (c *Conn) AsyncWritePacket(p Packet, timeout time.Duration) (err error)
- func (c *Conn) Close()
- func (c *Conn) Do()
- func (c *Conn) GetClientAddr() string
- func (c *Conn) GetExtraData() interface{}
- func (c *Conn) GetRawConn() net.Conn
- func (c *Conn) IsClosed() bool
- func (c *Conn) PutExtraData(data interface{})
- func (c *Conn) WritePacket(p Packet) (err error)
- type ConnCallback
- type Packet
- type Protocol
- type ProxyConn
- func (p *ProxyConn) Close() error
- func (p *ProxyConn) LocalAddr() net.Addr
- func (p *ProxyConn) Read(b []byte) (int, error)
- func (p *ProxyConn) RemoteAddr() net.Addr
- func (p *ProxyConn) SetDeadline(t time.Time) error
- func (p *ProxyConn) SetReadDeadline(t time.Time) error
- func (p *ProxyConn) SetWriteDeadline(t time.Time) error
- func (p *ProxyConn) Write(b []byte) (int, error)
- type ProxyListener
- type Server
- func (s *Server) Start(listener *net.TCPListener, acceptTimeout time.Duration)
- func (s *Server) StartProxyTcp(addr string, acceptTimeout time.Duration)
- func (s *Server) StartProxyV2Tcp(addr string, acceptTimeout time.Duration)
- func (s *Server) StartProxyV2Ws(addr string, path string)
- func (s *Server) StartTcp(addr string, acceptTimeout time.Duration)
- func (s *Server) StartWs(addr string, path string)
- func (s *Server) Stop()
- type SourceChecker
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnClosing = errors.New("use of closed network connection") ErrWriteBlocking = errors.New("write packet was blocking") ErrReadBlocking = errors.New("read packet was blocking") )
Error type
var (
ErrInvalidUpstream = errors.New("upstream connection address not trusted for PROXY information")
)
var PROXY_HEADERS = []string{"X-Forwarded-For", "Proxy-Client-IP", "WL-Proxy-Client-IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR"}
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn exposes a set of callbacks for the various events that occur on a connection
func (*Conn) AsyncWritePacket ¶
AsyncWritePacket async writes a packet, this method will never block
func (*Conn) GetClientAddr ¶
GetClientAddr returns the raw net.TCPConn peer client address
func (*Conn) GetExtraData ¶
func (c *Conn) GetExtraData() interface{}
GetExtraData gets the extra data from the Conn
func (*Conn) GetRawConn ¶
GetRawConn returns the raw net.TCPConn from the Conn
func (*Conn) PutExtraData ¶
func (c *Conn) PutExtraData(data interface{})
PutExtraData puts the extra data with the Conn
func (*Conn) WritePacket ¶
type ConnCallback ¶
type ConnCallback interface { // OnConnect is called when the connection was accepted, // If the return value of false is closed OnConnect(*Conn) bool // OnMessage is called when the connection receives a packet, // If the return value of false is closed OnMessage(*Conn, Packet) bool // OnClose is called when the connection closed OnClose(*Conn) }
ConnCallback is an interface of methods that are used as callbacks on a connection
type ProxyConn ¶
type ProxyConn struct {
// contains filtered or unexported fields
}
Conn is used to wrap and underlying connection which may be speaking the Proxy Protocol. If it is, the RemoteAddr() will return the address of the client instead of the proxy address.
func NewConn ¶
NewConn is used to wrap a net.Conn that may be speaking the proxy protocol into a proxyproto.Conn
func (*ProxyConn) Read ¶
Read is check for the proxy protocol header when doing the initial scan. If there is an error parsing the header, it is returned and the socket is closed.
func (*ProxyConn) RemoteAddr ¶
RemoteAddr returns the address of the client if the proxy protocol is being used, otherwise just returns the address of the socket peer. If there is an error parsing the header, the address of the client is not returned, and the socket is closed. Once implication of this is that the call could block if the client is slow. Using a Deadline is recommended if this is called before Read()
type ProxyListener ¶
type ProxyListener struct { Listener *net.TCPListener ProxyHeaderTimeout time.Duration SourceCheck SourceChecker }
Listener is used to wrap an underlying listener, whose connections may be using the HAProxy Proxy Protocol (version 1). If the connection is using the protocol, the RemoteAddr() will return the correct client address.
Optionally define ProxyHeaderTimeout to set a maximum time to receive the Proxy Protocol Header. Zero means no timeout.
func (*ProxyListener) AcceptTCP ¶
func (p *ProxyListener) AcceptTCP() (net.Conn, error)
Accept waits for and returns the next connection to the listener.
func (*ProxyListener) Addr ¶
func (p *ProxyListener) Addr() net.Addr
Addr returns the underlying listener's network address.
func (*ProxyListener) Close ¶
func (p *ProxyListener) Close() error
Close closes the underlying listener.
func (*ProxyListener) SetDeadline ¶
func (p *ProxyListener) SetDeadline(t time.Time) error
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(config *Config, callback ConnCallback, protocol Protocol) *Server
NewServer creates a server
func (*Server) Start ¶
func (s *Server) Start(listener *net.TCPListener, acceptTimeout time.Duration)
Start starts service
func (*Server) StartProxyTcp ¶
func (*Server) StartProxyV2Tcp ¶
func (*Server) StartProxyV2Ws ¶
type SourceChecker ¶
SourceChecker can be used to decide whether to trust the PROXY info or pass the original connection address through. If set, the connecting address is passed in as an argument. If the function returns an error due to the source being disallowed, it should return ErrInvalidUpstream.
Behavior is as follows: * If error is not nil, the call to Accept() will fail. If the reason for triggering this failure is due to a disallowed source, it should return ErrInvalidUpstream. * If bool is true, the PROXY-set address is used. * If bool is false, the connection's remote address is used, rather than the address claimed in the PROXY info.