Documentation ¶
Overview ¶
Package webtunnelserver is the server side of webtunnel; a websocket based VPN server. See examples for implementation.
Index ¶
- Variables
- type DNSForwarder
- type IPPam
- func (i *IPPam) AcquireIP(data any) (string, error)
- func (i *IPPam) AcquireSpecificIP(ip string, data any) error
- func (i *IPPam) DumpAllocations() map[string]*UserInfo
- func (i *IPPam) GetAllocatedCount() int
- func (i *IPPam) GetData(ip string) (any, error)
- func (i *IPPam) GetUserinfo(ip string) (UserInfo, error)
- func (i *IPPam) ReleaseIP(ip string) error
- func (i *IPPam) SetIPActiveWithUserInfo(ip, username, hostname string) error
- type Metrics
- type UserInfo
- type WebTunnelServer
- func (r *WebTunnelServer) DumpAllocations() map[string]*UserInfo
- func (r *WebTunnelServer) GetMetrics() *Metrics
- func (r *WebTunnelServer) PongHandler(ip string) func(string) error
- func (r *WebTunnelServer) ResetMetrics()
- func (r *WebTunnelServer) SetCustomHandler(endpoint string, h http.Handler) error
- func (r *WebTunnelServer) Start()
- func (r *WebTunnelServer) Stop()
Constants ¶
This section is empty.
Variables ¶
var InitTunnel = initializeTunnel
InitTunnel (Overridable) OS specific initialization.
var NewWaterInterface = wc.NewWaterInterface
NewWaterInterface (Overridable) New initialized water interface.
Functions ¶
This section is empty.
Types ¶
type DNSForwarder ¶
type DNSForwarder struct {
// contains filtered or unexported fields
}
DNSForwarder represents a DNS forwarder.
func NewDNSForwarder ¶
func NewDNSForwarder(ip string, port int) (*DNSForwarder, error)
NewDNSForwarder returns a new initialized DNS forwarder.
type IPPam ¶
type IPPam struct {
// contains filtered or unexported fields
}
IPPam represents a IP address mgmt struct
func (*IPPam) AcquireIP ¶
AcquireIP gets a free IP and marks the status as requested. SetIPactive should be called to make the IP active. data can be used to store any data associated with the IP.
func (*IPPam) AcquireSpecificIP ¶
AcquireSpecificIP acquires specific IP and marks it as in use.
func (*IPPam) DumpAllocations ¶
DumpAllocations returns the current IP mapping and user information
func (*IPPam) GetAllocatedCount ¶
GetAllocatedCount returns the number of allocated IPs.
func (*IPPam) GetUserinfo ¶
GetUserinfo returns the UnserInfo associated with the IP.
func (*IPPam) SetIPActiveWithUserInfo ¶
SetIPActiveWithUserInfo marks the IP as in use. IP is not considered active until this function is called. Also adds the username and hostname information associated with the IP connection.
type Metrics ¶
type Metrics struct { Users int // Total connected users. MaxUsers int // Maximum users supported by endpoint. Packets int // total packets. Bytes int // bytes pushed. }
Metrics is the system metrics structure.
type UserInfo ¶
type UserInfo struct {
// contains filtered or unexported fields
}
UserInfo represents the user information associated with an IP
type WebTunnelServer ¶
type WebTunnelServer struct { Error chan error // Channel to handle error from goroutine. // contains filtered or unexported fields }
WebTunnelServer represents a webtunnel server struct.
func NewWebTunnelServer ¶
func NewWebTunnelServer(serverIPPort, gwIP, tunNetmask, clientNetPrefix string, dnsIPs []string, routePrefix []string, secure bool, httpsKeyFile string, httpsCertFile string) (*WebTunnelServer, error)
NewWebTunnelServer returns an initialized webtunnel server.
serverIPPort: IP:Port to listen for websocket connections.
gwIP: TUN/TAP IP address of the server. Should be within clientNetPrefix (usually x.x.x.1).
tunNetmask: Network mask of the VPN network.
clientNetPrefix: Network prefix of the VPN network. (Used for IP address allocation)
dnsIPs: IP address of DNS servers (for client configuration)
routePrefix: Network prefix that the client should route via the tunnel.
secure: Start server in websocket secure.
httpsKeyFile: HTTPS Key File for secured connections.
httpsCertFile: HTTPS Cert file for secured connections.
func (*WebTunnelServer) DumpAllocations ¶
func (r *WebTunnelServer) DumpAllocations() map[string]*UserInfo
DumpAllocations returns IP allocations information. This can be called using a custom Handler for debuging purpose
func (*WebTunnelServer) GetMetrics ¶
func (r *WebTunnelServer) GetMetrics() *Metrics
GetMetrics returns the current server metrics.
func (*WebTunnelServer) PongHandler ¶
func (r *WebTunnelServer) PongHandler(ip string) func(string) error
PongHandler handles the pong messages from a client
func (*WebTunnelServer) ResetMetrics ¶
func (r *WebTunnelServer) ResetMetrics()
ResetMetrics resets the metrics on the server.
func (*WebTunnelServer) SetCustomHandler ¶
func (r *WebTunnelServer) SetCustomHandler(endpoint string, h http.Handler) error
SetCustomHandler sets any custom http end point handler. This should be called prior to Start.
func (*WebTunnelServer) Start ¶
func (r *WebTunnelServer) Start()
Start the webtunnel server. All processing functions are goroutines The user of Webtunnel must wait on the r.Error channel to know when the Server finished serving Either by catching an unrecoverable error or sending nil if ending gracefully.
func (*WebTunnelServer) Stop ¶
func (r *WebTunnelServer) Stop()
Stop the webtunnel server gracefully. All Websocket connections with peer will be terminated The tun interface handle will be closed
and this will eventually send nil to r.Error to let
the Server Caller that the whole serving process is ended