Compare commits
No commits in common. "8e4fc06cf1b7f87db24b04712b990baddfb53082" and "bf3b76a273061effd0e24c613cd0732035450c28" have entirely different histories.
8e4fc06cf1
...
bf3b76a273
@ -2,11 +2,8 @@ package admission
|
||||
|
||||
import "context"
|
||||
|
||||
type Options struct{}
|
||||
type Option func(opts *Options)
|
||||
|
||||
type Admission interface {
|
||||
Admit(ctx context.Context, addr string, opts ...Option) bool
|
||||
Admit(ctx context.Context, addr string) bool
|
||||
}
|
||||
|
||||
type admissionGroup struct {
|
||||
@ -19,9 +16,9 @@ func AdmissionGroup(admissions ...Admission) Admission {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *admissionGroup) Admit(ctx context.Context, addr string, opts ...Option) bool {
|
||||
func (p *admissionGroup) Admit(ctx context.Context, addr string) bool {
|
||||
for _, admission := range p.admissions {
|
||||
if admission != nil && !admission.Admit(ctx, addr, opts...) {
|
||||
if admission != nil && !admission.Admit(ctx, addr) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
10
auth/auth.go
10
auth/auth.go
@ -2,13 +2,9 @@ package auth
|
||||
|
||||
import "context"
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
// Authenticator is an interface for user authentication.
|
||||
type Authenticator interface {
|
||||
Authenticate(ctx context.Context, user, password string, opts ...Option) (id string, ok bool)
|
||||
Authenticate(ctx context.Context, user, password string) (id string, ok bool)
|
||||
}
|
||||
|
||||
type authenticatorGroup struct {
|
||||
@ -21,7 +17,7 @@ func AuthenticatorGroup(authers ...Authenticator) Authenticator {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string, opts ...Option) (string, bool) {
|
||||
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string) (string, bool) {
|
||||
if len(p.authers) == 0 {
|
||||
return "", false
|
||||
}
|
||||
@ -30,7 +26,7 @@ func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password st
|
||||
continue
|
||||
}
|
||||
|
||||
if id, ok := auther.Authenticate(ctx, user, password, opts...); ok {
|
||||
if id, ok := auther.Authenticate(ctx, user, password); ok {
|
||||
return id, ok
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import "context"
|
||||
|
||||
type Options struct {
|
||||
Host string
|
||||
Path string
|
||||
}
|
||||
|
||||
type Option func(opts *Options)
|
||||
@ -15,12 +14,6 @@ func WithHostOpton(host string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func WithPathOption(path string) Option {
|
||||
return func(opts *Options) {
|
||||
opts.Path = path
|
||||
}
|
||||
}
|
||||
|
||||
// Bypass is a filter of address (IP or domain).
|
||||
type Bypass interface {
|
||||
// Contains reports whether the bypass includes addr.
|
||||
|
@ -17,11 +17,6 @@ type HTTPNodeSettings struct {
|
||||
type TLSNodeSettings struct {
|
||||
ServerName string
|
||||
Secure bool
|
||||
Options struct {
|
||||
MinVersion string
|
||||
MaxVersion string
|
||||
CipherSuites []string
|
||||
}
|
||||
}
|
||||
|
||||
type NodeOptions struct {
|
||||
@ -31,9 +26,7 @@ type NodeOptions struct {
|
||||
HostMapper hosts.HostMapper
|
||||
Metadata metadata.Metadata
|
||||
Host string
|
||||
Network string
|
||||
Protocol string
|
||||
Path string
|
||||
HTTP *HTTPNodeSettings
|
||||
TLS *TLSNodeSettings
|
||||
Auther auth.Authenticator
|
||||
@ -71,24 +64,12 @@ func HostNodeOption(host string) NodeOption {
|
||||
}
|
||||
}
|
||||
|
||||
func NetworkNodeOption(network string) NodeOption {
|
||||
return func(o *NodeOptions) {
|
||||
o.Network = network
|
||||
}
|
||||
}
|
||||
|
||||
func ProtocolNodeOption(protocol string) NodeOption {
|
||||
return func(o *NodeOptions) {
|
||||
o.Protocol = protocol
|
||||
}
|
||||
}
|
||||
|
||||
func PathNodeOption(path string) NodeOption {
|
||||
return func(o *NodeOptions) {
|
||||
o.Path = path
|
||||
}
|
||||
}
|
||||
|
||||
func MetadataNodeOption(md metadata.Metadata) NodeOption {
|
||||
return func(o *NodeOptions) {
|
||||
o.Metadata = md
|
||||
|
@ -14,7 +14,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 128)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -23,7 +23,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 512)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -32,7 +32,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 1024)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -41,7 +41,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 2048)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -50,7 +50,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 4096)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -59,7 +59,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 8192)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -68,7 +68,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 16*1024)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -77,7 +77,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 32*1024)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -86,7 +86,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 64*1024)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -95,7 +95,7 @@ var (
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
b := make([]byte, 65*1024)
|
||||
return b
|
||||
return &b
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -103,20 +103,21 @@ var (
|
||||
)
|
||||
|
||||
// Get returns a buffer of specified size.
|
||||
func Get(size int) []byte {
|
||||
func Get(size int) *[]byte {
|
||||
for i := range pools {
|
||||
if size <= pools[i].size {
|
||||
b := pools[i].pool.Get().([]byte)
|
||||
return b[:size]
|
||||
b := pools[i].pool.Get().(*[]byte)
|
||||
*b = (*b)[:size]
|
||||
return b
|
||||
}
|
||||
}
|
||||
b := make([]byte, size)
|
||||
return b
|
||||
return &b
|
||||
}
|
||||
|
||||
func Put(b []byte) {
|
||||
func Put(b *[]byte) {
|
||||
for i := range pools {
|
||||
if cap(b) == pools[i].size {
|
||||
if cap(*b) == pools[i].size {
|
||||
pools[i].pool.Put(b)
|
||||
}
|
||||
}
|
||||
|
@ -47,13 +47,6 @@ func (d *NetDialer) Dial(ctx context.Context, network, addr string) (conn net.Co
|
||||
log = logger.Default()
|
||||
}
|
||||
|
||||
switch network {
|
||||
case "unix":
|
||||
netd := net.Dialer{}
|
||||
return netd.DialContext(ctx, network, addr)
|
||||
default:
|
||||
}
|
||||
|
||||
deadline := time.Now().Add(timeout)
|
||||
ifces := strings.Split(d.Interface, ",")
|
||||
for _, ifce := range ifces {
|
||||
|
@ -37,7 +37,7 @@ func (c *conn) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
|
||||
case bb := <-c.rc:
|
||||
n = copy(b, bb)
|
||||
c.SetIdle(false)
|
||||
bufpool.Put(bb)
|
||||
bufpool.Put(&bb)
|
||||
|
||||
case <-c.closed:
|
||||
err = net.ErrClosed
|
||||
|
@ -33,14 +33,12 @@ func NewListener(conn net.PacketConn, cfg *ListenConfig) net.Listener {
|
||||
}
|
||||
|
||||
ln := &listener{
|
||||
conn: conn,
|
||||
cqueue: make(chan net.Conn, cfg.Backlog),
|
||||
closed: make(chan struct{}),
|
||||
errChan: make(chan error, 1),
|
||||
config: cfg,
|
||||
}
|
||||
if cfg.KeepAlive {
|
||||
ln.connPool = newConnPool(cfg.TTL).WithLogger(cfg.Logger)
|
||||
conn: conn,
|
||||
cqueue: make(chan net.Conn, cfg.Backlog),
|
||||
connPool: newConnPool(cfg.TTL).WithLogger(cfg.Logger),
|
||||
closed: make(chan struct{}),
|
||||
errChan: make(chan error, 1),
|
||||
config: cfg,
|
||||
}
|
||||
go ln.listenLoop()
|
||||
|
||||
@ -71,7 +69,7 @@ func (ln *listener) listenLoop() {
|
||||
|
||||
b := bufpool.Get(ln.config.ReadBufferSize)
|
||||
|
||||
n, raddr, err := ln.conn.ReadFrom(b)
|
||||
n, raddr, err := ln.conn.ReadFrom(*b)
|
||||
if err != nil {
|
||||
ln.errChan <- err
|
||||
close(ln.errChan)
|
||||
@ -84,7 +82,7 @@ func (ln *listener) listenLoop() {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := c.WriteQueue(b[:n]); err != nil {
|
||||
if err := c.WriteQueue((*b)[:n]); err != nil {
|
||||
ln.config.Logger.Warn("data discarded: ", err)
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,6 @@ func (p *connPool) WithLogger(logger logger.Logger) *connPool {
|
||||
}
|
||||
|
||||
func (p *connPool) Get(key any) (c *conn, ok bool) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
|
||||
v, ok := p.m.Load(key)
|
||||
if ok {
|
||||
c, ok = v.(*conn)
|
||||
@ -41,25 +37,14 @@ func (p *connPool) Get(key any) (c *conn, ok bool) {
|
||||
}
|
||||
|
||||
func (p *connPool) Set(key any, c *conn) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.m.Store(key, c)
|
||||
}
|
||||
|
||||
func (p *connPool) Delete(key any) {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
p.m.Delete(key)
|
||||
}
|
||||
|
||||
func (p *connPool) Close() {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-p.closed:
|
||||
return
|
||||
|
13
hop/hop.go
13
hop/hop.go
@ -9,9 +9,8 @@ import (
|
||||
type SelectOptions struct {
|
||||
Network string
|
||||
Addr string
|
||||
Protocol string
|
||||
Host string
|
||||
Path string
|
||||
Protocol string
|
||||
}
|
||||
|
||||
type SelectOption func(*SelectOptions)
|
||||
@ -28,21 +27,15 @@ func AddrSelectOption(addr string) SelectOption {
|
||||
}
|
||||
}
|
||||
|
||||
func ProtocolSelectOption(protocol string) SelectOption {
|
||||
return func(o *SelectOptions) {
|
||||
o.Protocol = protocol
|
||||
}
|
||||
}
|
||||
|
||||
func HostSelectOption(host string) SelectOption {
|
||||
return func(o *SelectOptions) {
|
||||
o.Host = host
|
||||
}
|
||||
}
|
||||
|
||||
func PathSelectOption(path string) SelectOption {
|
||||
func ProtocolSelectOption(protocol string) SelectOption {
|
||||
return func(o *SelectOptions) {
|
||||
o.Path = path
|
||||
o.Protocol = protocol
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,7 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
// HostMapper is a mapping from hostname to IP.
|
||||
type HostMapper interface {
|
||||
Lookup(ctx context.Context, network, host string, opts ...Option) ([]net.IP, bool)
|
||||
Lookup(ctx context.Context, network, host string) ([]net.IP, bool)
|
||||
}
|
||||
|
@ -2,15 +2,6 @@ package ingress
|
||||
|
||||
import "context"
|
||||
|
||||
type GetOptions struct{}
|
||||
|
||||
type GetOption func(opts *GetOptions)
|
||||
|
||||
type SetOptions struct{}
|
||||
|
||||
type SetOption func(opts *SetOptions)
|
||||
|
||||
type Ingress interface {
|
||||
Get(ctx context.Context, host string, opts ...GetOption) string
|
||||
Set(ctx context.Context, host, endpoint string, opts ...SetOption)
|
||||
Get(ctx context.Context, host string) string
|
||||
}
|
||||
|
@ -4,20 +4,8 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type RecordOptions struct {
|
||||
Metadata any
|
||||
}
|
||||
|
||||
type RecordOption func(opts *RecordOptions)
|
||||
|
||||
func MetadataReocrdOption(md any) RecordOption {
|
||||
return func(opts *RecordOptions) {
|
||||
opts.Metadata = md
|
||||
}
|
||||
}
|
||||
|
||||
type Recorder interface {
|
||||
Record(ctx context.Context, b []byte, opts ...RecordOption) error
|
||||
Record(ctx context.Context, b []byte) error
|
||||
}
|
||||
|
||||
type RecorderObject struct {
|
||||
|
@ -10,12 +10,8 @@ var (
|
||||
ErrInvalid = errors.New("invalid resolver")
|
||||
)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
type Resolver interface {
|
||||
// Resolve returns a slice of the host's IPv4 and IPv6 addresses.
|
||||
// The network should be 'ip', 'ip4' or 'ip6', default network is 'ip'.
|
||||
Resolve(ctx context.Context, network, host string, opts ...Option) ([]net.IP, error)
|
||||
Resolve(ctx context.Context, network, host string) ([]net.IP, error)
|
||||
}
|
||||
|
25
sd/sd.go
25
sd/sd.go
@ -1,25 +0,0 @@
|
||||
package sd
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Option func(opts *Options)
|
||||
|
||||
type Service struct {
|
||||
ID string
|
||||
Name string
|
||||
Node string
|
||||
Network string
|
||||
Address string
|
||||
}
|
||||
|
||||
// SD is the service discovery interface.
|
||||
type SD interface {
|
||||
Register(ctx context.Context, service *Service, opts ...Option) error
|
||||
Deregister(ctx context.Context, service *Service) error
|
||||
Renew(ctx context.Context, service *Service) error
|
||||
Get(ctx context.Context, name string) ([]*Service, error)
|
||||
}
|
Loading…
Reference in New Issue
Block a user