send

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTimeout          = "timeout"
	ErrorInvalidRequest   = "invalid_request"
	ErrorInternal         = "internal_error"
	ErrorNotFound         = "not_found"
	ErrorPermissionDenied = "permission_denied"
	PollURL               = "/api/v1/send/poll?x-syft-request-id=%s&x-syft-url=%s&x-syft-from=%s&x-syft-raw=%t"
)

Error constants

Variables

View Source
var (
	ErrPollTimeout      = errors.New("poll timeout")
	ErrRequestNotFound  = errors.New("request not found")
	ErrPermissionDenied = errors.New("permission denied")
)
View Source
var (
	ErrMsgNotFound = errors.New("message not found")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Error     string `json:"error"`
	Message   string `json:"message"`
	RequestID string `json:"request_id,omitempty"`
}

APIError represents a standardized error response

type APIResponse

type APIResponse struct {
	RequestID string      `json:"request_id"`
	Data      interface{} `json:"data,omitempty"`
	Message   string      `json:"message,omitempty"`
}

APIResponse represents a standardized success response

type BlobMsgStore

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

func (*BlobMsgStore) DeleteMsg

func (m *BlobMsgStore) DeleteMsg(ctx context.Context, path string) error

func (*BlobMsgStore) GetMsg

func (m *BlobMsgStore) GetMsg(ctx context.Context, path string) (io.ReadCloser, error)

func (*BlobMsgStore) StoreMsg

func (m *BlobMsgStore) StoreMsg(ctx context.Context, path string, msgBytes []byte) error

type Config

type Config struct {
	DefaultTimeout      time.Duration
	MaxTimeout          time.Duration
	ObjectPollInterval  time.Duration
	RequestCheckTimeout time.Duration
	MaxBodySize         int64
}

Config holds the service configuration

type Headers

type Headers map[string]string

type MessageDispatcher

type MessageDispatcher interface {
	Dispatch(datasite string, msg *syftmsg.Message) bool
}

Message dispatch interface for dispatching messages to users

func NewWSMsgDispatcher

func NewWSMsgDispatcher(hub *ws.WebsocketHub) MessageDispatcher

type MessageRequest

type MessageRequest struct {
	SyftURL      utils.SyftBoxURL `form:"x-syft-url" binding:"required"`  // Binds to the syft url using UnmarshalParam
	From         string           `form:"x-syft-from" binding:"required"` // The sender of the message
	Timeout      int              `form:"timeout" binding:"gte=0"`        // The timeout for the request in milliseconds
	AsRaw        bool             `form:"x-syft-raw" default:"false"`     // If true, the request body will be read and sent as is
	Method       string           // Will be set from request method
	Headers      Headers          // Will be set from request headers
	SuffixSender bool             `form:"suffix-sender" default:"false"` // If true, the sender prefix will be added to the request
}

MessageRequest represents the request for sending a message

func (*MessageRequest) BindHeaders

func (h *MessageRequest) BindHeaders(ctx *gin.Context)

type PollInfo

type PollInfo struct {
	PollURL string `json:"poll_url"`
}

type PollObjectRequest

type PollObjectRequest struct {
	RequestID string           `form:"x-syft-request-id" binding:"required"`
	From      string           `form:"x-syft-from" binding:"required"`
	SyftURL   utils.SyftBoxURL `form:"x-syft-url" binding:"required"`
	Timeout   int              `form:"timeout,omitempty" binding:"gte=0"` // Timeout in milliseconds
	UserAgent string           `form:"user-agent,omitempty"`
	AsRaw     bool             `form:"x-syft-raw" default:"false"` // If true, the request body will be read and sent as is
}

PollObjectRequest represents the request for polling

type PollResult

type PollResult struct {
	Status    int
	RequestID string
	Response  map[string]interface{}
}

PollResult represents the result of a poll operation

type PollStatus

type PollStatus string
const (
	PollStatusPending  PollStatus = "pending"
	PollStatusComplete PollStatus = "complete"
)

type RPCMsgStore

type RPCMsgStore interface {
	StoreMsg(ctx context.Context, path string, msgBytes []byte) error
	GetMsg(ctx context.Context, path string) (io.ReadCloser, error)
	DeleteMsg(ctx context.Context, path string) error
}

Message store interface for storing and retrieving messages

func NewBlobMsgStore

func NewBlobMsgStore(blob *blob.BlobService) RPCMsgStore

type SendHandler

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

SendHandler handles HTTP requests for sending messages

func New

func New(msgDispatcher MessageDispatcher, msgStore RPCMsgStore, acl *acl.ACLService) *SendHandler

New creates a new send handler

func (*SendHandler) PollForResponse

func (h *SendHandler) PollForResponse(ctx *gin.Context)

PollForResponse handles polling for a response

func (*SendHandler) SendMsg

func (h *SendHandler) SendMsg(ctx *gin.Context)

SendMsg handles sending a message

type SendResult

type SendResult struct {
	Status    int
	RequestID string
	PollURL   string
	Response  map[string]interface{}
}

SendResult represents the result of a send operation

type SendService

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

SendService handles the business logic for message sending and polling

func NewSendService

func NewSendService(dispatch MessageDispatcher, store RPCMsgStore, acl *acl.ACLService, cfg *Config) *SendService

NewSendService creates a new send service

func (*SendService) GetConfig

func (s *SendService) GetConfig() *Config

GetConfig returns the current service configuration settings.

func (*SendService) PollForResponse

func (s *SendService) PollForResponse(ctx context.Context, req *PollObjectRequest) (*PollResult, error)

PollForResponse retrieves a response for a previously sent request. It supports both new (user-partitioned) and legacy (shared) storage formats and includes ACL permission checking for security.

func (*SendService) SendMessage

func (s *SendService) SendMessage(ctx context.Context, req *MessageRequest, bodyBytes []byte) (*SendResult, error)

SendMessage processes an HTTP request and converts it to an RPC message for delivery. It handles both online (WebSocket) and offline (polling) scenarios, with ACL permission checking and support for user-partitioned storage via the suffix-sender feature.

type SendServiceInterface

type SendServiceInterface interface {
	SendMessage(ctx context.Context, req *MessageRequest, bodyBytes []byte) (*SendResult, error)
	PollForResponse(ctx context.Context, req *PollObjectRequest) (*PollResult, error)

	GetConfig() *Config
	// contains filtered or unexported methods
}

SendServiceInterface defines the interface for the send service

type WSMsgDispatcher

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

func (*WSMsgDispatcher) Dispatch

func (m *WSMsgDispatcher) Dispatch(datasite string, msg *syftmsg.Message) bool

Jump to

Keyboard shortcuts

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