Compare commits

...

4 Commits

Author SHA1 Message Date
ginuerzh
abc73f2ca2 update router interface 2023-11-19 16:14:03 +08:00
ginuerzh
6b01698ea9 add router interface 2023-11-19 14:20:35 +08:00
ginuerzh
486f2cee61 add traffic limiter option for handler 2023-11-18 18:25:40 +08:00
ginuerzh
a916f04016 update ingress interface 2023-11-13 20:38:50 +08:00
4 changed files with 78 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/go-gost/core/bypass"
"github.com/go-gost/core/chain"
"github.com/go-gost/core/limiter/rate"
"github.com/go-gost/core/limiter/traffic"
"github.com/go-gost/core/logger"
"github.com/go-gost/core/metadata"
)
@ -18,6 +19,7 @@ type Options struct {
Auth *url.Userinfo
Auther auth.Authenticator
RateLimiter rate.RateLimiter
Limiter traffic.TrafficLimiter
TLSConfig *tls.Config
Logger logger.Logger
Service string
@ -55,6 +57,12 @@ func RateLimiterOption(limiter rate.RateLimiter) Option {
}
}
func TrafficLimiterOption(limiter traffic.TrafficLimiter) Option {
return func(opts *Options) {
opts.Limiter = limiter
}
}
func TLSConfigOption(tlsConfig *tls.Config) Option {
return func(opts *Options) {
opts.TLSConfig = tlsConfig

View File

@ -2,15 +2,20 @@ package ingress
import "context"
type GetOptions struct{}
type Options struct{}
type GetOption func(opts *GetOptions)
type Option func(opts *Options)
type SetOptions struct{}
type SetOption func(opts *SetOptions)
type Rule struct {
// Hostname is the hostname match pattern, e.g. example.com, *.example.org or .example.com.
Hostname string
// Endpoint is the tunnel ID for the hostname.
Endpoint string
}
type Ingress interface {
Get(ctx context.Context, host string, opts ...GetOption) string
Set(ctx context.Context, host, endpoint string, opts ...SetOption)
// SetRule adds or updates a rule for the ingress.
SetRule(ctx context.Context, rule *Rule, opts ...Option) bool
// GetRule queries a rule by host.
GetRule(ctx context.Context, host string, opts ...Option) *Rule
}

View File

@ -10,7 +10,40 @@ type Limiter interface {
Set(n int)
}
type TrafficLimiter interface {
In(key string) Limiter
Out(key string) Limiter
type Options struct {
Network string
Addr string
Client string
Src string
}
type Option func(opts *Options)
func NetworkOption(network string) Option {
return func(opts *Options) {
opts.Network = network
}
}
func AddrOption(addr string) Option {
return func(opts *Options) {
opts.Addr = addr
}
}
func ClientOption(client string) Option {
return func(opts *Options) {
opts.Client = client
}
}
func SrcOption(src string) Option {
return func(opts *Options) {
opts.Src = src
}
}
type TrafficLimiter interface {
In(ctx context.Context, key string, opts ...Option) Limiter
Out(ctx context.Context, key string, opts ...Option) Limiter
}

22
router/router.go Normal file
View File

@ -0,0 +1,22 @@
package router
import (
"context"
"net"
)
type Options struct{}
type Option func(opts *Options)
type Route struct {
// Net is the destination network, e.g. 192.168.0.0/16, 172.10.10.0/24.
Net *net.IPNet
// Gateway is the gateway for the destination network.
Gateway net.IP
}
type Router interface {
// GetRoute queries a route by destination IP address.
GetRoute(ctx context.Context, dst net.IP, opts ...Option) *Route
}