comm

package
v0.0.0-...-7578c0e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package comm is responsible for sharing logic to handle communication between a server and clients.

Index

Constants

View Source
const (
	// RequestTypeCheckPort request types sent by server to clients
	RequestTypeCheckPort            = "check_port"
	RequestTypeRunCmd               = "run_cmd"
	RequestTypeRefreshUpdatesStatus = "refresh_updates_status"
	RequestTypePutCapabilities      = "put_capabilities"
	RequestTypeCheckTunnelAllowed   = "check_tunnel_allowed"

	RequestTypeUpdateClientAttributes = "update_client_metadata"

	// RequestTypeCmdResult request types sent by clients to server
	RequestTypeCmdResult       = "cmd_result"
	RequestTypeUpdatesStatus   = "updates_status"
	RequestTypeSaveMeasurement = "save_measurement"
	RequestTypeUpload          = "upload"
	RequestTypeIPAddresses     = "ip_addresses"

	// RequestTypePing request types understood on both sides, client and server
	RequestTypePing = "ping"
)
View Source
const DefaultMaxRetryAttempts = 3
View Source
const DefaultRetryWaitJitterMilliSeconds = 500

Variables

This section is empty.

Functions

func PingConnectionWithTimeout

func PingConnectionWithTimeout(ctx context.Context, conn ssh.Conn, timeout time.Duration, l *logger.Logger) (ok bool, response []byte, rtt time.Duration, err error)

func ReplyError

func ReplyError(log *logger.Logger, req *ssh.Request, err error)

ReplyError sends a failure response with a given error message if not nil to a given request.

func ReplySuccessJSON

func ReplySuccessJSON(log *logger.Logger, req *ssh.Request, resp interface{})

ReplySuccessJSON sends a success response with a given value as JSON to a given request. Response expected to be a value that can be encoded into JSON, otherwise - a failure will be replied.

func SendRequestAndGetResponse

func SendRequestAndGetResponse(conn ssh.Conn, reqType string, req, successRespDest interface{}, l *logger.Logger) error

SendRequestAndGetResponse sends a given request, parses a returned response and stores a success result in a given destination value. Returns an error on a failure response or if an error happen. Error will be ClientError type if the error is a client error. Both request and response are expected to be JSON.

func SendRequestWithTimeout

func SendRequestWithTimeout(parentCtx context.Context, conn ssh.Conn, name string, wantReply bool, payload []byte, timeout time.Duration, l *logger.Logger) (bool, []byte, error)

func WithRetry

func WithRetry[R any](retryAbleFn func() (result R, err error), canRetryFn retryCheckerFn, minRetryWaitDuration time.Duration, label string, l *logger.Logger) (result R, err error)

Types

type CheckPortRequest

type CheckPortRequest struct {
	HostPort string
	Timeout  time.Duration
}

func DecodeCheckPortRequest

func DecodeCheckPortRequest(b []byte) (*CheckPortRequest, error)

type CheckPortResponse

type CheckPortResponse struct {
	Open   bool
	ErrMsg string
}

type CheckTunnelAllowedRequest

type CheckTunnelAllowedRequest struct {
	Remote string
}

type CheckTunnelAllowedResponse

type CheckTunnelAllowedResponse struct {
	IsAllowed bool
}

type ClientError

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

func NewClientError

func NewClientError(err error) *ClientError

func (*ClientError) Error

func (e *ClientError) Error() string

type RunCmdResponse

type RunCmdResponse struct {
	Pid       int
	StartedAt time.Time
}

type TimeoutError

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

type UDPChannel

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

func NewUDPChannel

func NewUDPChannel(rw io.ReadWriter) *UDPChannel

func (*UDPChannel) Decode

func (c *UDPChannel) Decode() (*net.UDPAddr, []byte, error)

func (*UDPChannel) Encode

func (c *UDPChannel) Encode(addr *net.UDPAddr, data []byte) error

type UDPMessage

type UDPMessage struct {
	Addr *net.UDPAddr
	Data []byte
}

Jump to

Keyboard shortcuts

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