Documentation
¶
Index ¶
- Variables
- type Client
- type Conn
- func (c *Conn) Close() (err error)
- func (c *Conn) Closed() bool
- func (c *Conn) Dial(protocol string, target string) (pipe *ConnPipe, err error)
- func (c *Conn) DialContext(ctx context.Context, protocol string, target string) (pipe *ConnPipe, err error)
- func (c *Conn) Handle() (err error)
- func (c *Conn) Lock() (ok bool)
- func (c *Conn) Ping() (t time.Duration, err error)
- func (c *Conn) Status() ConnStatus
- func (c *Conn) Unlock() (ok bool)
- type ConnPipe
- type ConnStatus
- type Dialer
- type IPRule
- type IPRuleSet
- type RemoteDialError
- type RuleSetError
- type Server
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ( ErrIPBlocked = errors.New("IP is blocked") ErrNetworkUnreachable = errors.New("Network unreachable") // network is not support ErrHostUnreachable = errors.New("Host unreachable") )
var DefaultTransport http.RoundTripper = &http.Transport{ Proxy: nil, DialContext: (&net.Dialer{ Timeout: 10 * time.Second, KeepAlive: 20 * time.Second, }).DialContext, ForceAttemptHTTP2: true, MaxIdleConns: 30, IdleConnTimeout: 30 * time.Second, TLSHandshakeTimeout: 6 * time.Second, ExpectContinueTimeout: 1 * time.Second, }
var (
ErrIllegalStatus = errors.New("Illegal status error")
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Logger logger.Logger // wpn.Client.Transport will override wpn.Client.WebsocketOpts.HTTPClient.Transport if that is nil // Default value is wpn.DefaultTransport Transport http.RoundTripper WebsocketOpts *websocket.DialOptions IdleTimeout time.Duration MaxIdleConn int // contains filtered or unexported fields }
func (*Client) DialContext ¶
type Conn ¶
type Conn struct { PingInterval time.Duration Dialer Dialer // If the function is not `nil`, and it returned false, the incoming connection will be blocked OnCheckIncoming func(protocol string, target string) bool // contains filtered or unexported fields }
func (*Conn) Close ¶
return the latest error cause the connection closed
or the close handshake error (maybe nil) if there are no error during the connection is open
func (*Conn) Dial ¶
`DialContext` will only success if `status` is `StatusIdle` or `StatusLocked` `Conn.Handle` must be called concurrently with `DialContext`
func (*Conn) DialContext ¶
func (c *Conn) DialContext(ctx context.Context, protocol string, target string) (pipe *ConnPipe, err error)
`DialContext` will only success if `status` is `StatusIdle` or `StatusLocked` `Conn.Handle` must be called concurrently with `DialContext`
func (*Conn) Ping ¶
`Ping` will ping the remote point, return the time used and possible error If an error occured during ping, the connection will be automaticly closed The connection can ping with any status
func (*Conn) Status ¶
func (c *Conn) Status() ConnStatus
type ConnPipe ¶
func (*ConnPipe) AfterClose ¶
func (p *ConnPipe) AfterClose() <-chan struct{}
func (*ConnPipe) RemoteAddr ¶
type ConnStatus ¶
type ConnStatus byte
const ( // The connection is idle StatusIdle ConnStatus = 0x00 // The connection is used for packet based internet, such as IP, UDP StatusPacket ConnStatus = 0x01 // The connection is used for stream based internet, such as TCP StatusStream ConnStatus = 0x02 // The connection is locked for later use StatusLocked ConnStatus = 0xfe // The connection is closed StatusClosed ConnStatus = 0xff )
type IPRule ¶
type IPRule struct { // An IP prefix, such as `192.168.0.1/24` or `::1/128` Prefix netip.Prefix // whether allow or not allow the prefix Not bool }
func ParseIPRule ¶
func (IPRule) Contains ¶
Check if an IP match the rule. it will unmap the IP that passed in. for example, `127.0.0.1/8` contains `::ffff::127.1.2.3` note that it won't unmap the prefix, so `::ffff::127.0.0.1/104` doesn't contains `127.0.0.1`
func (*IPRule) MarshalText ¶
func (*IPRule) UnmarshalText ¶
Parse an IP rule from text Empty bytes is not ok. It will return io.EOF if the text's length is zero
type IPRuleSet ¶
type IPRuleSet struct {
// contains filtered or unexported fields
}
IPRuleSet is a list of IPRule.
func NewIPRuleSetFrom ¶
Create a rule set from a slice of rules. It's the invoker's responsibility to ensure the rules are only exists once in the slice.
func ReadIPRuleSet ¶
Read rule set from a text reader. `IPRuleSet.UnmarshalText` will be called
func (*IPRuleSet) Add ¶
Add a rule to the rule set. If the rule is already exists in the rule set, the method will do nothing and return false. Otherwise, the new rule will be append to the end, and return true. Rule conflict won't be detect
func (*IPRuleSet) Contains ¶
Check if an address is in the rule set or not. It will always return false if *IPRuleSet is nil.
Multiple include rules (Not == false) use `or (||)` operation. Multiple exclude rules (Not == true) use `and (&&)` operation. Exclude rules will always have the highest priority.
func (*IPRuleSet) MarshalText ¶
func (*IPRuleSet) Rules ¶
Return the IP rule slice of the rule set. Operation on the slice it returns is not recommend and it's undefined. It will always return a nil slice if *IPRuleSet is nil.
func (*IPRuleSet) UnmarshalText ¶
Parse a IPRuleSet file. each line will trim spaces before parse. empty line or line starts with hash sign ('#') will be ignored. During unmarshalling, the error lines will be skipped,
the errors will be returned after wrapped with `RuleSetError` and `errors.Join`.
type RemoteDialError ¶
type RemoteDialError struct {
Message string
}
func (*RemoteDialError) Error ¶
func (e *RemoteDialError) Error() string
type RuleSetError ¶
func (*RuleSetError) Error ¶
func (e *RuleSetError) Error() string
func (*RuleSetError) Unwrap ¶
func (e *RuleSetError) Unwrap() error
type Server ¶
type StatusError ¶
type StatusError struct {
Status ConnStatus
}
func (*StatusError) Error ¶
func (e *StatusError) Error() string