router

package
v3.1.13+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2023 License: MIT, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config_DomainStrategy_name = map[int32]string{
	0: "AsIs",
	1: "UseIp",
	2: "IpIfNonMatch",
	3: "IpOnDemand",
}
View Source
var Config_DomainStrategy_value = map[string]int32{
	"AsIs":         0,
	"UseIp":        1,
	"IpIfNonMatch": 2,
	"IpOnDemand":   3,
}
View Source
var Domain_Type_name = map[int32]string{
	0: "Plain",
	1: "Regex",
	2: "Domain",
}
View Source
var Domain_Type_value = map[string]int32{
	"Plain":  0,
	"Regex":  1,
	"Domain": 2,
}

Functions

This section is empty.

Types

type AnyCondition

type AnyCondition []Condition

func NewAnyCondition

func NewAnyCondition() *AnyCondition

func (*AnyCondition) Add

func (v *AnyCondition) Add(cond Condition) *AnyCondition

func (*AnyCondition) Apply

func (v *AnyCondition) Apply(ctx context.Context) bool

func (*AnyCondition) Len

func (v *AnyCondition) Len() int

type CIDR

type CIDR struct {
	// IP address, should be either 4 or 16 bytes.
	Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3" json:"ip,omitempty"`
	// Number of leading ones in the network mask.
	Prefix               uint32   `protobuf:"varint,2,opt,name=prefix" json:"prefix,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

IP for routing decision, in CIDR form.

func (*CIDR) Descriptor

func (*CIDR) Descriptor() ([]byte, []int)

func (*CIDR) GetIp

func (m *CIDR) GetIp() []byte

func (*CIDR) GetPrefix

func (m *CIDR) GetPrefix() uint32

func (*CIDR) ProtoMessage

func (*CIDR) ProtoMessage()

func (*CIDR) Reset

func (m *CIDR) Reset()

func (*CIDR) String

func (m *CIDR) String() string

func (*CIDR) XXX_DiscardUnknown

func (m *CIDR) XXX_DiscardUnknown()

func (*CIDR) XXX_Marshal

func (m *CIDR) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CIDR) XXX_Merge

func (dst *CIDR) XXX_Merge(src proto.Message)

func (*CIDR) XXX_Size

func (m *CIDR) XXX_Size() int

func (*CIDR) XXX_Unmarshal

func (m *CIDR) XXX_Unmarshal(b []byte) error

type CIDRMatcher

type CIDRMatcher struct {
	// contains filtered or unexported fields
}

func NewCIDRMatcher

func NewCIDRMatcher(ip []byte, mask uint32, onSource bool) (*CIDRMatcher, error)

func (*CIDRMatcher) Apply

func (v *CIDRMatcher) Apply(ctx context.Context) bool

type CachableDomainMatcher

type CachableDomainMatcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCachableDomainMatcher

func NewCachableDomainMatcher() *CachableDomainMatcher

func (*CachableDomainMatcher) Add

func (m *CachableDomainMatcher) Add(domain *Domain) error

func (*CachableDomainMatcher) Apply

func (m *CachableDomainMatcher) Apply(ctx context.Context) bool

func (*CachableDomainMatcher) ApplyDomain

func (m *CachableDomainMatcher) ApplyDomain(domain string) bool

type Condition

type Condition interface {
	Apply(ctx context.Context) bool
}

type ConditionChan

type ConditionChan []Condition

func NewConditionChan

func NewConditionChan() *ConditionChan

func (*ConditionChan) Add

func (v *ConditionChan) Add(cond Condition) *ConditionChan

func (*ConditionChan) Apply

func (v *ConditionChan) Apply(ctx context.Context) bool

func (*ConditionChan) Len

func (v *ConditionChan) Len() int

type Config

type Config struct {
	DomainStrategy       Config_DomainStrategy `` /* 144-byte string literal not displayed */
	Rule                 []*RoutingRule        `protobuf:"bytes,2,rep,name=rule" json:"rule,omitempty"`
	XXX_NoUnkeyedLiteral struct{}              `json:"-"`
	XXX_unrecognized     []byte                `json:"-"`
	XXX_sizecache        int32                 `json:"-"`
}

func (*Config) Descriptor

func (*Config) Descriptor() ([]byte, []int)

func (*Config) GetDomainStrategy

func (m *Config) GetDomainStrategy() Config_DomainStrategy

func (*Config) GetRule

func (m *Config) GetRule() []*RoutingRule

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) Reset

func (m *Config) Reset()

func (*Config) String

func (m *Config) String() string

func (*Config) XXX_DiscardUnknown

func (m *Config) XXX_DiscardUnknown()

func (*Config) XXX_Marshal

func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Config) XXX_Merge

func (dst *Config) XXX_Merge(src proto.Message)

func (*Config) XXX_Size

func (m *Config) XXX_Size() int

func (*Config) XXX_Unmarshal

func (m *Config) XXX_Unmarshal(b []byte) error

type Config_DomainStrategy

type Config_DomainStrategy int32
const (
	// Use domain as is.
	Config_AsIs Config_DomainStrategy = 0
	// Always resolve IP for domains.
	Config_UseIp Config_DomainStrategy = 1
	// Resolve to IP if the domain doesn't match any rules.
	Config_IpIfNonMatch Config_DomainStrategy = 2
	// Resolve to IP if any rule requires IP matching.
	Config_IpOnDemand Config_DomainStrategy = 3
)

func (Config_DomainStrategy) EnumDescriptor

func (Config_DomainStrategy) EnumDescriptor() ([]byte, []int)

func (Config_DomainStrategy) String

func (x Config_DomainStrategy) String() string

type Domain

type Domain struct {
	// Domain matching type.
	Type Domain_Type `protobuf:"varint,1,opt,name=type,enum=com.core.app.router.Domain_Type" json:"type,omitempty"`
	// Domain value.
	Value                string   `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Domain for routing decision.

func (*Domain) Descriptor

func (*Domain) Descriptor() ([]byte, []int)

func (*Domain) GetType

func (m *Domain) GetType() Domain_Type

func (*Domain) GetValue

func (m *Domain) GetValue() string

func (*Domain) ProtoMessage

func (*Domain) ProtoMessage()

func (*Domain) Reset

func (m *Domain) Reset()

func (*Domain) String

func (m *Domain) String() string

func (*Domain) XXX_DiscardUnknown

func (m *Domain) XXX_DiscardUnknown()

func (*Domain) XXX_Marshal

func (m *Domain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Domain) XXX_Merge

func (dst *Domain) XXX_Merge(src proto.Message)

func (*Domain) XXX_Size

func (m *Domain) XXX_Size() int

func (*Domain) XXX_Unmarshal

func (m *Domain) XXX_Unmarshal(b []byte) error

type Domain_Type

type Domain_Type int32

Type of domain value.

const (
	// The value is used as is.
	Domain_Plain Domain_Type = 0
	// The value is used as a regular expression.
	Domain_Regex Domain_Type = 1
	// The value is a domain.
	Domain_Domain Domain_Type = 2
)

func (Domain_Type) EnumDescriptor

func (Domain_Type) EnumDescriptor() ([]byte, []int)

func (Domain_Type) String

func (x Domain_Type) String() string

type GeoIP

type GeoIP struct {
	CountryCode          string   `protobuf:"bytes,1,opt,name=country_code,json=countryCode" json:"country_code,omitempty"`
	Cidr                 []*CIDR  `protobuf:"bytes,2,rep,name=cidr" json:"cidr,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*GeoIP) Descriptor

func (*GeoIP) Descriptor() ([]byte, []int)

func (*GeoIP) GetCidr

func (m *GeoIP) GetCidr() []*CIDR

func (*GeoIP) GetCountryCode

func (m *GeoIP) GetCountryCode() string

func (*GeoIP) ProtoMessage

func (*GeoIP) ProtoMessage()

func (*GeoIP) Reset

func (m *GeoIP) Reset()

func (*GeoIP) String

func (m *GeoIP) String() string

func (*GeoIP) XXX_DiscardUnknown

func (m *GeoIP) XXX_DiscardUnknown()

func (*GeoIP) XXX_Marshal

func (m *GeoIP) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GeoIP) XXX_Merge

func (dst *GeoIP) XXX_Merge(src proto.Message)

func (*GeoIP) XXX_Size

func (m *GeoIP) XXX_Size() int

func (*GeoIP) XXX_Unmarshal

func (m *GeoIP) XXX_Unmarshal(b []byte) error

type GeoIPList

type GeoIPList struct {
	Entry                []*GeoIP `protobuf:"bytes,1,rep,name=entry" json:"entry,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*GeoIPList) Descriptor

func (*GeoIPList) Descriptor() ([]byte, []int)

func (*GeoIPList) GetEntry

func (m *GeoIPList) GetEntry() []*GeoIP

func (*GeoIPList) ProtoMessage

func (*GeoIPList) ProtoMessage()

func (*GeoIPList) Reset

func (m *GeoIPList) Reset()

func (*GeoIPList) String

func (m *GeoIPList) String() string

func (*GeoIPList) XXX_DiscardUnknown

func (m *GeoIPList) XXX_DiscardUnknown()

func (*GeoIPList) XXX_Marshal

func (m *GeoIPList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GeoIPList) XXX_Merge

func (dst *GeoIPList) XXX_Merge(src proto.Message)

func (*GeoIPList) XXX_Size

func (m *GeoIPList) XXX_Size() int

func (*GeoIPList) XXX_Unmarshal

func (m *GeoIPList) XXX_Unmarshal(b []byte) error

type GeoSite

type GeoSite struct {
	CountryCode          string    `protobuf:"bytes,1,opt,name=country_code,json=countryCode" json:"country_code,omitempty"`
	Domain               []*Domain `protobuf:"bytes,2,rep,name=domain" json:"domain,omitempty"`
	XXX_NoUnkeyedLiteral struct{}  `json:"-"`
	XXX_unrecognized     []byte    `json:"-"`
	XXX_sizecache        int32     `json:"-"`
}

func (*GeoSite) Descriptor

func (*GeoSite) Descriptor() ([]byte, []int)

func (*GeoSite) GetCountryCode

func (m *GeoSite) GetCountryCode() string

func (*GeoSite) GetDomain

func (m *GeoSite) GetDomain() []*Domain

func (*GeoSite) ProtoMessage

func (*GeoSite) ProtoMessage()

func (*GeoSite) Reset

func (m *GeoSite) Reset()

func (*GeoSite) String

func (m *GeoSite) String() string

func (*GeoSite) XXX_DiscardUnknown

func (m *GeoSite) XXX_DiscardUnknown()

func (*GeoSite) XXX_Marshal

func (m *GeoSite) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GeoSite) XXX_Merge

func (dst *GeoSite) XXX_Merge(src proto.Message)

func (*GeoSite) XXX_Size

func (m *GeoSite) XXX_Size() int

func (*GeoSite) XXX_Unmarshal

func (m *GeoSite) XXX_Unmarshal(b []byte) error

type GeoSiteList

type GeoSiteList struct {
	Entry                []*GeoSite `protobuf:"bytes,1,rep,name=entry" json:"entry,omitempty"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

func (*GeoSiteList) Descriptor

func (*GeoSiteList) Descriptor() ([]byte, []int)

func (*GeoSiteList) GetEntry

func (m *GeoSiteList) GetEntry() []*GeoSite

func (*GeoSiteList) ProtoMessage

func (*GeoSiteList) ProtoMessage()

func (*GeoSiteList) Reset

func (m *GeoSiteList) Reset()

func (*GeoSiteList) String

func (m *GeoSiteList) String() string

func (*GeoSiteList) XXX_DiscardUnknown

func (m *GeoSiteList) XXX_DiscardUnknown()

func (*GeoSiteList) XXX_Marshal

func (m *GeoSiteList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GeoSiteList) XXX_Merge

func (dst *GeoSiteList) XXX_Merge(src proto.Message)

func (*GeoSiteList) XXX_Size

func (m *GeoSiteList) XXX_Size() int

func (*GeoSiteList) XXX_Unmarshal

func (m *GeoSiteList) XXX_Unmarshal(b []byte) error

type IPv4Matcher

type IPv4Matcher struct {
	// contains filtered or unexported fields
}

func NewIPv4Matcher

func NewIPv4Matcher(ipnet *net.IPNetTable, onSource bool) *IPv4Matcher

func (*IPv4Matcher) Apply

func (v *IPv4Matcher) Apply(ctx context.Context) bool

type InboundTagMatcher

type InboundTagMatcher struct {
	// contains filtered or unexported fields
}

func NewInboundTagMatcher

func NewInboundTagMatcher(tags []string) *InboundTagMatcher

func (*InboundTagMatcher) Apply

func (v *InboundTagMatcher) Apply(ctx context.Context) bool

type NetworkMatcher

type NetworkMatcher struct {
	// contains filtered or unexported fields
}

func NewNetworkMatcher

func NewNetworkMatcher(network *net.NetworkList) *NetworkMatcher

func (*NetworkMatcher) Apply

func (v *NetworkMatcher) Apply(ctx context.Context) bool

type PlainDomainMatcher

type PlainDomainMatcher string

func NewPlainDomainMatcher

func NewPlainDomainMatcher(pattern string) PlainDomainMatcher

func (PlainDomainMatcher) Apply

func (v PlainDomainMatcher) Apply(domain string) bool

type PortMatcher

type PortMatcher struct {
	// contains filtered or unexported fields
}

func NewPortMatcher

func NewPortMatcher(portRange net.PortRange) *PortMatcher

func (*PortMatcher) Apply

func (v *PortMatcher) Apply(ctx context.Context) bool

type RegexpDomainMatcher

type RegexpDomainMatcher struct {
	// contains filtered or unexported fields
}

func NewRegexpDomainMatcher

func NewRegexpDomainMatcher(pattern string) (*RegexpDomainMatcher, error)

func (*RegexpDomainMatcher) Apply

func (v *RegexpDomainMatcher) Apply(domain string) bool

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router is an implementation of core.Router.

func NewRouter

func NewRouter(ctx context.Context, config *Config) (*Router, error)

NewRouter creates a new Router based on the given config.

func (*Router) Close

func (*Router) Close() error

Close implements common.Closable.

func (*Router) PickRoute

func (r *Router) PickRoute(ctx context.Context) (string, error)

PickRoute implements core.Router.

func (*Router) Start

func (*Router) Start() error

Start implements common.Runnable.

type RoutingRule

type RoutingRule struct {
	Tag                  string           `protobuf:"bytes,1,opt,name=tag" json:"tag,omitempty"`
	Domain               []*Domain        `protobuf:"bytes,2,rep,name=domain" json:"domain,omitempty"`
	Cidr                 []*CIDR          `protobuf:"bytes,3,rep,name=cidr" json:"cidr,omitempty"`
	PortRange            *net.PortRange   `protobuf:"bytes,4,opt,name=port_range,json=portRange" json:"port_range,omitempty"`
	NetworkList          *net.NetworkList `protobuf:"bytes,5,opt,name=network_list,json=networkList" json:"network_list,omitempty"`
	SourceCidr           []*CIDR          `protobuf:"bytes,6,rep,name=source_cidr,json=sourceCidr" json:"source_cidr,omitempty"`
	UserEmail            []string         `protobuf:"bytes,7,rep,name=user_email,json=userEmail" json:"user_email,omitempty"`
	InboundTag           []string         `protobuf:"bytes,8,rep,name=inbound_tag,json=inboundTag" json:"inbound_tag,omitempty"`
	XXX_NoUnkeyedLiteral struct{}         `json:"-"`
	XXX_unrecognized     []byte           `json:"-"`
	XXX_sizecache        int32            `json:"-"`
}

func (*RoutingRule) BuildCondition

func (rr *RoutingRule) BuildCondition() (Condition, error)

func (*RoutingRule) Descriptor

func (*RoutingRule) Descriptor() ([]byte, []int)

func (*RoutingRule) GetCidr

func (m *RoutingRule) GetCidr() []*CIDR

func (*RoutingRule) GetDomain

func (m *RoutingRule) GetDomain() []*Domain

func (*RoutingRule) GetInboundTag

func (m *RoutingRule) GetInboundTag() []string

func (*RoutingRule) GetNetworkList

func (m *RoutingRule) GetNetworkList() *net.NetworkList

func (*RoutingRule) GetPortRange

func (m *RoutingRule) GetPortRange() *net.PortRange

func (*RoutingRule) GetSourceCidr

func (m *RoutingRule) GetSourceCidr() []*CIDR

func (*RoutingRule) GetTag

func (m *RoutingRule) GetTag() string

func (*RoutingRule) GetUserEmail

func (m *RoutingRule) GetUserEmail() []string

func (*RoutingRule) ProtoMessage

func (*RoutingRule) ProtoMessage()

func (*RoutingRule) Reset

func (m *RoutingRule) Reset()

func (*RoutingRule) String

func (m *RoutingRule) String() string

func (*RoutingRule) XXX_DiscardUnknown

func (m *RoutingRule) XXX_DiscardUnknown()

func (*RoutingRule) XXX_Marshal

func (m *RoutingRule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RoutingRule) XXX_Merge

func (dst *RoutingRule) XXX_Merge(src proto.Message)

func (*RoutingRule) XXX_Size

func (m *RoutingRule) XXX_Size() int

func (*RoutingRule) XXX_Unmarshal

func (m *RoutingRule) XXX_Unmarshal(b []byte) error

type Rule

type Rule struct {
	Tag       string
	Condition Condition
}

func (*Rule) Apply

func (r *Rule) Apply(ctx context.Context) bool

type SubDomainMatcher

type SubDomainMatcher string

func NewSubDomainMatcher

func NewSubDomainMatcher(p string) SubDomainMatcher

func (SubDomainMatcher) Apply

func (m SubDomainMatcher) Apply(domain string) bool

type UserMatcher

type UserMatcher struct {
	// contains filtered or unexported fields
}

func NewUserMatcher

func NewUserMatcher(users []string) *UserMatcher

func (*UserMatcher) Apply

func (v *UserMatcher) Apply(ctx context.Context) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL