common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseTunnel

func CloseTunnel(client *ClientHub, content []byte)

func ConvertToMessage

func ConvertToMessage(mt MessageType, content []byte) []byte

func Error

func Error(c *websocket.Conn, hub *ClientHub)

func GenerateCloseTunnelMsg

func GenerateCloseTunnelMsg(id uuid.UUID) []byte

func GeneratePing

func GeneratePing() []byte

func GeneratePong

func GeneratePong() []byte

func HandleDataReceive

func HandleDataReceive(client *ClientHub, msg []byte)

func HandleMetrics

func HandleMetrics(client *ClientHub) int

func MarshalObject

func MarshalObject(o any) ([]byte, error)

func Reader

func Reader(c *websocket.Conn, hub *ClientHub)

func TunnelError

func TunnelError(client *ClientHub, connID uuid.UUID)

func TunnelReader

func TunnelReader(client *ClientHub, connID uuid.UUID)

Take information from the TCP connection specified by connID and send it to the client application via websockets. This is "reading" from the TCP connection and dropping the information into the channels

func TunnelWriter

func TunnelWriter(client *ClientHub, connID uuid.UUID)

func UnmarshalObject

func UnmarshalObject(data []byte, v any) error

func Writer

func Writer(c *websocket.Conn, hub *ClientHub)

Types

type Client

type Client struct {
	ClientID    uuid.UUID `gorm:"type:uuid;primaryKey"`
	Secret      string    `gorm:"size:64;primaryKey"`
	Type        string
	DisplayName string
}

type ClientHub

type ClientHub struct {
	Reader  chan []byte
	Writer  chan []byte
	Control chan int

	Tunnels     []Tunnel                            // Tunnels the client is sending to the server
	ActiveConns map[uuid.UUID](IunctioActiveTunnel) // Active network connections the
	LoginID     uuid.UUID                           // The UUID used for logging in
	Hostname    string                              // The hostname
	Namespace   string                              // What k8s namespace to put this in
	CloseChan   chan os.Signal                      // Used to close client

	// Metrics
	MetricsChan   chan []*io_prometheus_client.MetricFamily
	MetricsServer *http.Server
	MetricsPort   int
}

This is a struct to hold information about the client that is connected to the server. This should have information about the client connection itself and any tunnels/connections that are available. This allows the server to safely discard resources in the case of a client disconnect.

func NewClientHub

func NewClientHub() *ClientHub

func (ClientHub) Gather

func (client ClientHub) Gather() ([]*io_prometheus_client.MetricFamily, error)

type IunctioActiveTunnel

type IunctioActiveTunnel struct {
	Id             uuid.UUID   // The UUID of the tunnel
	Conn           net.Conn    // The network connection
	Reader         chan []byte // The channel that will send data to the other end of this tcp socket
	Control        chan []byte
	ThreadsRunning bool
}

This struct contains members that describe an active tunnel connection and associated data. This includes the net.Conn structure, required channels, and more.

func NewIunctioActiveTunnel

func NewIunctioActiveTunnel(conn net.Conn) *IunctioActiveTunnel

type IunctioClient

type IunctioClient struct {
	gorm.Model
	IunctioClientLogin `gorm:"embedded"`
	Namespace          string // What k8s namespace to put this in
}

type IunctioClientLogin

type IunctioClientLogin struct {
	ClientID uuid.UUID // The ID to sign in with
	Secret   string    // The secret ID for the client
	Hostname string    // The hostname
}

type LoggerStub

type LoggerStub struct {
}

func (LoggerStub) Log

func (l LoggerStub) Log(keyvals ...interface{}) error

This function is called each time a metric is requested from each processor. It will produce a lot of output if you add anything here

type Message

type Message struct {
	Type    MessageType
	Content []byte
}

type MessageType

type MessageType int
const (
	TunnelMessageType MessageType = iota
	AdminMessageType

	RequestAuthenticationMsgType
	ResponseCredentialsMsgType
	ResponseAuthenticationSuccessMsgType

	RequestTunnelDescriptionsMsgType
	ResponseTunnelDescriptionsMsgType

	RequestTunnelInitMsgType
	ResponseTunnelInitMsgType // Basically yeah or nah

	RequestTunnelCloseMsgType
	ResponseTunnelCloseMsgType

	TunnelDataMsgType // Either direction

	PingDataMsgType
	PongDataMsgType
	RequestMetricsMsgType        // For metrics, Server asking client
	ResponseMetricsReportMsgType // For metrics, client responding to server

	ClientGoodbyeMessageType
)

type Tunnel

type Tunnel struct {
	IPAddr       netip.Addr
	Port         int
	SessionID    string
	Listener     net.Listener
	ListenerPort int
	Control      chan int
}

type TunnelData

type TunnelData struct {
	Data string //base64 encoded
	Id   uuid.UUID
}

type TunnelInit

type TunnelInit struct {
	IPAddr netip.Addr `json:"ip_addr"`
	Port   int        `json:"port"`
}

type TunnelStart

type TunnelStart struct {
	IPAddr netip.Addr
	Port   int
	Id     uuid.UUID
}

Jump to

Keyboard shortcuts

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