natholepunch

package module
v0.0.0-...-3d58c26 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StopHPClient

func StopHPClient(l *zap.Logger, serverIP, serverPort, localID string)

Teardown client class

Types

type ClientData

type ClientData struct {
	RemoteID  string `json:"remote_addr"`
	LocalIP   string `json:"local_addr"`
	LocalPort string `json:"local_port"`
	LocalID   string `json:"local_ID"`
}

ClientData contents all data about client to be stored on the server

type ConnectRequest

type ConnectRequest struct {
	LocalID  string `json:"local_id"`
	RemoteID string `json:"remote_id"` // fif empty, flag to whether client is idle and wants online client listing from server
}

ConnectRequest decribes message from client to server, contents requested and local clients ID

type ConnectResponse

type ConnectResponse struct {
	RemoteIP   string `json:"local_addr"`
	RemotePort string `json:"remote_port"`
}

ConnectResponse decribes message from server to client, contents requested client address

type HPClient

type HPClient struct {

	// Connections and response
	Conn *net.UDPConn
	R    *ConnectResponse

	RemoteID string
	// Client map from HPServer
	ClientList map[string]ClientData
	// UI update hook
	UIupdate       *bool
	ClientUIStage2 *bool
	UIupdateCListB []byte
	//todo: Tunnel info & udptunnel command channel
	TunnelMan *tunnel.TunnelManager
	// contains filtered or unexported fields
}

Define the Hole Punch client struct

func NewHPClient

func NewHPClient(l *zap.Logger, timeout time.Duration, serverAddr, serverPort, localID, remoteID string, UIupdate, ClientUIStage2 *bool, TunnelMan *tunnel.TunnelManager) *HPClient

Initialises a pointer to a new HPClient struct

func (*HPClient) InitiatePunch

func (c *HPClient) InitiatePunch(client string)

Contact info exchange server, perform hole punch and test connection with ping

func (*HPClient) REconnect

func (c *HPClient) REconnect() (*net.UDPAddr, error)

REconnect allows to manually send reconnect signal, returns new remote addr and port

func (*HPClient) Run

func (c *HPClient) Run() error

Main logic

type HPServer

type HPServer struct {
	// Client list
	sync.RWMutex
	ClientList map[string]ClientData

	// UI update hook
	UIupdate *bool

	ConnLogC chan string
	// contains filtered or unexported fields
}

Define the Hole Punch Server struct

func NewHPServer

func NewHPServer(l *zap.Logger, ConnLogC chan string, UIupdate *bool) *HPServer

Initialises a pointer to a new HPServer struct

func (*HPServer) Serve

func (s *HPServer) Serve(serverPort string) error

start serving and reply to client requests

Jump to

Keyboard shortcuts

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