server

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TunnelStatusUnknown = ""
	TunnelStatusOpen    = "OPEN"
	TunnelStatusClosed  = "CLOSED"

	ConnStatusUnknown      = ""
	ConnStatusConnected    = "CONNECTED"
	ConnStatusDisconnected = "DISCONNECTED"
)

Variables

This section is empty.

Functions

func PreProcess

func PreProcess[T any](handler func(*gin.Context, T)) gin.HandlerFunc

Types

type AccessToken

type AccessToken string

AccessToken = {tunnelID}_{random string}

func (AccessToken) TunnelID

func (token AccessToken) TunnelID() string

type Authorizer

type Authorizer interface {
	Pluggable
	// Login the service and return your credentials.
	Login(http.ResponseWriter, *http.Request)
	// Logout the server.
	Logout(http.ResponseWriter, *http.Request)
	// HasAuth Check if the request has the credentials and make sure that
	// the credentials are authorized to access the resource.
	HasAuth(*http.Request) error
}

Authorizer is an interface that allow to change the functions related to authentication.

type CloseTunnelRequest

type CloseTunnelRequest struct {
	Delete   bool   `form:"delete" json:"delete"`
	TunnelID string `form:"tunnelId" json:"tunnelId"`
}

func (CloseTunnelRequest) Validate

func (request CloseTunnelRequest) Validate() error

type CloseTunnelResponse

type CloseTunnelResponse struct {
}

type ConnStatus

type ConnStatus string

type Connection

type Connection struct {
	ID                 ConnectionID
	Rev                uint
	TunnelID           string
	Mode               aws.Mode
	Status             ConnStatus
	InterServerNetwork string // for scaling
	InterServerAddress string // for scaling
	LastUpdatedAt      time.Time
}

func (Connection) GetKey

func (connection Connection) GetKey() ConnectionID

func (Connection) GetRev

func (connection Connection) GetRev() uint

func (Connection) SetRev

func (connection Connection) SetRev(rev uint)

type ConnectionID

type ConnectionID string

ConnectionID = {tunnelID}_{random string}

func (ConnectionID) TunnelID

func (connectionID ConnectionID) TunnelID() string

type ConnectionSearchOptions

type ConnectionSearchOptions struct {
	TunnelID string
}

type DebugListRequest

type DebugListRequest struct {
}

func (DebugListRequest) Validate

func (request DebugListRequest) Validate() error

type DebugListTunnel

type DebugListTunnel struct {
	Tunnel      Tunnel       `json:"tunnel"`
	Connections []Connection `json:"connections"`
}

type DebugSendRequest

type DebugSendRequest struct {
	TunnelID            string           `form:"tunnelId" json:"tunnelId"`
	Mode                aws.Mode         `form:"mode" json:"mode"`
	StreamID            int32            `form:"streamID" json:"streamID"`
	Type                aws.Message_Type `form:"type" json:"type"`
	Ignorable           bool             `form:"ignorable" json:"ignorable"`
	ServiceID           string           `form:"serviceID" json:"serviceID"`
	AvailableServiceIds []string         `form:"serviceIDs" json:"serviceIDs"`
	Payload             []byte           `form:"payload" json:"payload"`
}

func (DebugSendRequest) Validate

func (request DebugSendRequest) Validate() error

type DescribeTunnelConnectionState

type DescribeTunnelConnectionState struct {
	Status        ConnStatus `json:"status"`
	LastUpdatedAt time.Time  `json:"lastUpdatedAt"`
}

type DescribeTunnelRequest

type DescribeTunnelRequest struct {
	TunnelID string `form:"tunnelId" json:"tunnelId"`
}

func (DescribeTunnelRequest) Validate

func (request DescribeTunnelRequest) Validate() error

type DescribeTunnelResponse

type DescribeTunnelResponse struct {
	TunnelID       string                        `json:"tunnelId"`
	ThingName      string                        `json:"thingName"`
	TimeoutMinutes uint                          `json:"timeoutMinutes"`
	Payload        string                        `json:"payload"`
	Status         TunnelStatus                  `json:"status"`
	DstConnState   DescribeTunnelConnectionState `json:"destinationConnectionState"`
	SrcConnState   DescribeTunnelConnectionState `json:"sourceConnectionState"`
	LastUpdatedAt  time.Time                     `json:"lastUpdatedAt"`
	CreatedAt      time.Time                     `json:"createdAt"`
}

type IDTokenGen

type IDTokenGen struct {
	TunnelIDDigit     uint
	TokenDigit        uint
	ConnectionIDDigit uint
}

func (*IDTokenGen) GenerateID

func (idTokenGen *IDTokenGen) GenerateID(digit uint) (string, error)

func (*IDTokenGen) NewConnectionID

func (idTokenGen *IDTokenGen) NewConnectionID(tunnelID string) (ConnectionID, error)

func (*IDTokenGen) NewIDTokens

func (idTokenGen *IDTokenGen) NewIDTokens() (IDTokens, error)

func (*IDTokenGen) NewToken

func (idTokenGen *IDTokenGen) NewToken(tunnelID string) (AccessToken, error)

func (*IDTokenGen) NewTunnelID

func (idTokenGen *IDTokenGen) NewTunnelID() (string, error)

type IDTokens

type IDTokens struct {
	TunnelID         string
	SourceToken      AccessToken
	DestinationToken AccessToken
}

type ListTunnelsRequest

type ListTunnelsRequest struct {
}

func (ListTunnelsRequest) Validate

func (request ListTunnelsRequest) Validate() error

type ListTunnelsResponse

type ListTunnelsResponse struct {
	Tunnels []ListTunnelsTunnel `json:"tunnelSummaries"`
}

type ListTunnelsTunnel

type ListTunnelsTunnel struct {
	ID            string       `json:"tunnelId"`
	Status        TunnelStatus `json:"status"`
	ThingName     string       `json:"thingName"`
	LastUpdatedAt time.Time    `json:"lastUpdatedAt"`
}

type MemoryStore

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

MemoryStore is an structure that implements Store interface. This structure stores information in memory. This structure cannot be used to spread across multiple servers.

func (*MemoryStore) AddConnection

func (store *MemoryStore) AddConnection(connection Connection) error

func (*MemoryStore) AddTunnel

func (store *MemoryStore) AddTunnel(tunnel Tunnel) error

func (*MemoryStore) DeleteConnection

func (store *MemoryStore) DeleteConnection(connectionID ConnectionID) error

func (*MemoryStore) DeleteTunnel

func (store *MemoryStore) DeleteTunnel(tunnelID string) error

func (*MemoryStore) GetConnection

func (store *MemoryStore) GetConnection(connectionID ConnectionID) (Connection, error)

func (*MemoryStore) GetConnections

func (store *MemoryStore) GetConnections(options ConnectionSearchOptions) ([]Connection, error)

func (*MemoryStore) GetTunnel

func (store *MemoryStore) GetTunnel(tunnelID string) (Tunnel, error)

func (*MemoryStore) GetTunnels

func (store *MemoryStore) GetTunnels(options TunnelSearchOptions) ([]Tunnel, error)

func (*MemoryStore) Init

func (store *MemoryStore) Init() error

func (*MemoryStore) UpdateConnection

func (store *MemoryStore) UpdateConnection(connection Connection) error

func (*MemoryStore) UpdateTunnel

func (store *MemoryStore) UpdateTunnel(tunnel Tunnel) error

type NilAuthorizer

type NilAuthorizer struct {
}

NilAuthorizer is an interface that implements Authorizer. NilAuthorizer does not authenticate. It is used only for development purposes.

func (*NilAuthorizer) HasAuth

func (auth *NilAuthorizer) HasAuth(*http.Request) error

func (*NilAuthorizer) Init

func (auth *NilAuthorizer) Init() error

func (*NilAuthorizer) Login

func (auth *NilAuthorizer) Login(writer http.ResponseWriter, request *http.Request)

func (*NilAuthorizer) Logout

func (auth *NilAuthorizer) Logout(writer http.ResponseWriter, request *http.Request)

type NilNotifier

type NilNotifier struct {
}

NilNotifier is an interface that implements Notifier. NilNotifier does not notify any device.

func (*NilNotifier) Init

func (notifier *NilNotifier) Init() error

func (*NilNotifier) Notify

func (notifier *NilNotifier) Notify(tunnel Tunnel) error

type Notifier

type Notifier interface {
	Pluggable
	// Notify the device of tunnel information.
	// This method is triggered when the tunnel is opened.
	Notify(Tunnel) error
}

Notifier is an interface to notify the device that the tunnel has opened and its token.

type OpenTunnelRequest

type OpenTunnelRequest struct {
	Services       []string `form:"services" json:"services"`
	ThingName      string   `form:"thingName" json:"thingName"`
	TimeoutMinutes uint     `form:"timeoutMinutes" json:"timeoutMinutes"`
	Payload        string   `form:"payload" json:"payload"`
}

func (OpenTunnelRequest) Validate

func (request OpenTunnelRequest) Validate() error

type OpenTunnelResponse

type OpenTunnelResponse struct {
	TunnelID         string      `json:"tunnelId"`
	DestinationToken AccessToken `json:"destinationAccessToken"`
	SourceToken      AccessToken `json:"sourceAccessToken"`
}

type Peer

type Peer struct {
	ConnectionID ConnectionID
	ClientToken  string
	NumOfConn    int
}

type Pluggable

type Pluggable interface {
	// Init is always executed only once before it is used.
	Init() error
}

Pluggable is an interface that indicates that the structure is pluggable.

type Services

type Services struct {
	IDTokenGen         *IDTokenGen
	NeedAuth           bool
	InterServerNetwork string
	InterServerAddress string
	Auth               Authorizer
	Store              Store
	Notifier           Notifier
	// contains filtered or unexported fields
}

func (*Services) AuthFilter

func (svc *Services) AuthFilter(ctx *gin.Context)

func (*Services) CloseTunnel

func (svc *Services) CloseTunnel(ctx *gin.Context, args CloseTunnelRequest)

CloseTunnel close tunnel and disconnect from both localproxy. Executing this method does not immediately disconnect from both localproxy. Example:

curl -v -s -X PUT -d 'tunnelId=<tunnelID>' http://localhost:18080/tunnel/close

func (*Services) DebugListTunnels

func (svc *Services) DebugListTunnels(ctx *gin.Context, args DebugListRequest)

DebugListTunnels returns list of tunnel information. Example:

curl -s http://localhost:18080/debug/tunnel/list

func (*Services) DebugSendToPeer

func (svc *Services) DebugSendToPeer(ctx *gin.Context, args DebugSendRequest)

DebugSendToPeer send message to localproxy. You can interrupt and send a message to a specific peer. Example:

curl -s -X POST -d 'tunnelId=<tunnelID>' -d 'mode=source' -d 'type=4' http://localhost:18080/debug/tunnel/send

func (*Services) DescribeTunnel

func (svc *Services) DescribeTunnel(ctx *gin.Context, args DescribeTunnelRequest)

DescribeTunnel returns detail tunnel information. Example:

curl -s http://localhost:18080/tunnel/describe?tunnelId=<tunnelID>

func (*Services) ListTunnels

func (svc *Services) ListTunnels(ctx *gin.Context, args ListTunnelsRequest)

ListTunnels returns list of tunnel information. Example:

curl -s http://localhost:18080/tunnel/list

func (*Services) Login

func (svc *Services) Login(ctx *gin.Context)

func (*Services) Logout

func (svc *Services) Logout(ctx *gin.Context)

func (*Services) OpenTunnel

func (svc *Services) OpenTunnel(ctx *gin.Context, args OpenTunnelRequest)

OpenTunnel creates a new tunnel and returns client access tokens. These tokens are used by the localproxy as credentials when connecting. Example:

curl -s -X POST -H "Content-Type: application/json" -d '{"services": ["SSH", "RDP"], "thingName": "device1"}' http://localhost:18080/tunnel/open
curl -s -X POST -d 'thingName=device' -d 'services=SSH' -d 'services=RDP' http://localhost:18080/tunnel/open

func (*Services) Start

func (svc *Services) Start() error

func (*Services) TunnelConnect

func (svc *Services) TunnelConnect(ctx *gin.Context, args TunnelConnectArgs)

TunnelConnect is a WebAPI for localproxy to connect and establish a network tunnel.

type Store

type Store interface {
	Pluggable
	GetTunnel(tunndlID string) (Tunnel, error)
	GetTunnels(options TunnelSearchOptions) ([]Tunnel, error)
	AddTunnel(tunnel Tunnel) error
	UpdateTunnel(tunnel Tunnel) error
	DeleteTunnel(tunndlID string) error
	GetConnection(connectionID ConnectionID) (Connection, error)
	GetConnections(options ConnectionSearchOptions) ([]Connection, error)
	AddConnection(connection Connection) error
	UpdateConnection(connection Connection) error
	DeleteConnection(connectionID ConnectionID) error
}

Store is an interface for storing and retrieving data.

type Tunnel

type Tunnel struct {
	ID               string
	Rev              uint
	SourceToken      AccessToken
	SourcePeer       *Peer
	DestinationToken AccessToken
	DestinationPeer  *Peer
	Services         []string
	ThingName        string
	TimeoutMinutes   uint
	Payload          string
	LifetimeAt       time.Time
	CreatedAt        time.Time
	LastUpdatedAt    time.Time
}

func (Tunnel) GetKey

func (tunnel Tunnel) GetKey() string

func (Tunnel) GetRev

func (tunnel Tunnel) GetRev() uint

func (Tunnel) Open

func (tunnel Tunnel) Open() bool

func (Tunnel) Peer

func (tunnel Tunnel) Peer(mode aws.Mode) *Peer

func (Tunnel) SetRev

func (tunnel Tunnel) SetRev(rev uint)

func (Tunnel) Status

func (tunnel Tunnel) Status() TunnelStatus

func (Tunnel) Token

func (tunnel Tunnel) Token(mode aws.Mode) AccessToken

type TunnelConnectArgs

type TunnelConnectArgs struct {
	Mode         aws.Mode    `form:"local-proxy-mode"`
	Subprotocols []string    `header:"Sec-WebSocket-Protocol"`
	AccessToken  AccessToken `header:"access-token"`
	ClientToken  string      `header:"client-token"`
}

func (TunnelConnectArgs) Validate

func (request TunnelConnectArgs) Validate() error

type TunnelSearchOptions

type TunnelSearchOptions struct {
}

type TunnelStatus

type TunnelStatus string

type Validatable

type Validatable interface {
	Validate() error
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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