webtunnelserver

package
v0.0.0-...-9606b86 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package webtunnelserver is the server side of webtunnel; a websocket based VPN server. See examples for implementation.

Index

Constants

This section is empty.

Variables

View Source
var InitTunnel = initializeTunnel

InitTunnel (Overridable) OS specific initialization.

View Source
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.

func (*DNSForwarder) Start

func (d *DNSForwarder) Start()

Start starts the dns forwarder.

func (*DNSForwarder) Stop

func (d *DNSForwarder) Stop()

Stop stops the dns forwarder.

type IPPam

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

IPPam represents a IP address mgmt struct

func NewIPPam

func NewIPPam(prefix string) (*IPPam, error)

NewIPPam returns a new IPPam object.

func (*IPPam) AcquireIP

func (i *IPPam) AcquireIP(data any) (string, error)

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

func (i *IPPam) AcquireSpecificIP(ip string, data any) error

AcquireSpecificIP acquires specific IP and marks it as in use.

func (*IPPam) DumpAllocations

func (i *IPPam) DumpAllocations() map[string]*UserInfo

DumpAllocations returns the current IP mapping and user information

func (*IPPam) GetAllocatedCount

func (i *IPPam) GetAllocatedCount() int

GetAllocatedCount returns the number of allocated IPs.

func (*IPPam) GetData

func (i *IPPam) GetData(ip string) (any, error)

GetData returns the data associated with the IP.

func (*IPPam) GetUserinfo

func (i *IPPam) GetUserinfo(ip string) (UserInfo, error)

GetUserinfo returns the UnserInfo associated with the IP.

func (*IPPam) ReleaseIP

func (i *IPPam) ReleaseIP(ip string) error

ReleaseIP returns IP address back to pool.

func (*IPPam) SetIPActiveWithUserInfo

func (i *IPPam) SetIPActiveWithUserInfo(ip, username, hostname string) error

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

Jump to

Keyboard shortcuts

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