Documentation ¶
Overview ¶
Package comm is responsible for sharing logic to handle communication between a server and clients.
Index ¶
- Constants
- 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(log *logger.Logger, req *ssh.Request, err error)
- func ReplySuccessJSON(log *logger.Logger, req *ssh.Request, resp interface{})
- func SendRequestAndGetResponse(conn ssh.Conn, reqType string, req, successRespDest interface{}, ...) error
- func SendRequestWithTimeout(parentCtx context.Context, conn ssh.Conn, name string, wantReply bool, ...) (bool, []byte, error)
- func WithRetry[R any](retryAbleFn func() (result R, err error), canRetryFn retryCheckerFn, ...) (result R, err error)
- type CheckPortRequest
- type CheckPortResponse
- type CheckTunnelAllowedRequest
- type CheckTunnelAllowedResponse
- type ClientError
- type RunCmdResponse
- type TimeoutError
- type UDPChannel
- type UDPMessage
Constants ¶
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" )
const DefaultMaxRetryAttempts = 3
const DefaultRetryWaitJitterMilliSeconds = 500
Variables ¶
This section is empty.
Functions ¶
func ReplyError ¶
ReplyError sends a failure response with a given error message if not nil to a given request.
func ReplySuccessJSON ¶
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 ¶
Types ¶
type CheckPortRequest ¶
func DecodeCheckPortRequest ¶
func DecodeCheckPortRequest(b []byte) (*CheckPortRequest, error)
type CheckPortResponse ¶
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 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