// newConn creates a new connection which will handle the PROXY protocol. It
// will return nil if the remote IP does not match the allowable CIDR ranges.
//
// This is basically a copy of `Listener.Accept` from the proxyprotocol package.
newConn creates a new connection which will handle the PROXY protocol. It
will return nil if the remote IP does not match the allowable CIDR ranges.

This is basically a copy of `Listener.Accept` from the proxyprotocol package.
// newConn creates a new connection which will handle the PROXY protocol . It // will return nil if the remote IP does not match the allowable CIDR ranges . // // This is basically a copy of ` Listener . Accept ` from the proxyprotocol package .
func (h *Handler) newConn(cx *layer4.Connection) *proxyprotocol.Conn {
	nc := func(t time.Duration) *proxyprotocol.Conn {
		if t == 0 {
			return proxyprotocol.NewConn(cx, time.Time{})
		}
		return proxyprotocol.NewConn(cx, time.Now().Add(t))
	}
	if len(h.rules) == 0 {
		return nc(time.Duration(h.Timeout))
	}
	var remoteIP net.IP
	switch r := cx.RemoteAddr().(type) {
	case *net.TCPAddr:
		remoteIP = r.IP
	case *net.UDPAddr:
		remoteIP = r.IP
	default:
		return nil
	}
	for _, r := range h.rules {
		if r.Subnet.Contains(remoteIP) {
			return nc(r.Timeout)
		}
	}
	return nil
}
func ( h * Handler ) newConn ( cx * layer4 . Connection ) * proxyprotocol . Conn { nc := func ( t time . Duration ) * proxyprotocol . Conn { if t == 0 { return proxyprotocol . NewConn ( cx , time . Time { } ) } return proxyprotocol . NewConn ( cx , time . Now ( ) . Add ( t ) ) } if len ( h . rules ) == 0 { return nc ( time . Duration ( h . Timeout ) ) } var remoteIP net . IP switch r := cx . RemoteAddr ( ) . ( type ) { case * net . TCPAddr : remoteIP = r . IP case * net . UDPAddr : remoteIP = r . IP default : return nil } for _ , r := range h . rules { if r . Subnet . Contains ( remoteIP ) { return nc ( r . Timeout ) } } return nil }
newConn creates a new connection which will handle the PROXY protocol.
newConn creates a new connection which will handle the PROXY protocol .