gateway

package
v0.90.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: AGPL-3.0 Imports: 49 Imported by: 0

Documentation

Overview

Package gateway provides the main API Gateway for the Orama Network. It orchestrates traffic between clients and various backend services including distributed caching (Olric), decentralized storage (IPFS), and serverless WebAssembly (WASM) execution. The gateway implements robust security through wallet-based cryptographic authentication and JWT lifecycle management.

Index

Constants

View Source
const (
	CtxKeyNamespaceOverride = ctxkeys.NamespaceOverride
)

Context keys for request-scoped values

Variables

View Source
var (
	BuildVersion = "dev"
	BuildCommit  = ""
	BuildTime    = ""
)

Build info (set via -ldflags at build time; defaults for dev)

Functions

This section is empty.

Types

type Config

type Config struct {
	ListenAddr      string
	ClientNamespace string
	BootstrapPeers  []string
	NodePeerID      string // The node's actual peer ID from its identity file

	// Optional DSN for rqlite database/sql driver, e.g. "http://localhost:4001"
	// If empty, defaults to "http://localhost:4001".
	RQLiteDSN string

	// HTTPS configuration
	EnableHTTPS bool   // Enable HTTPS with ACME (Let's Encrypt)
	DomainName  string // Domain name for HTTPS certificate
	TLSCacheDir string // Directory to cache TLS certificates (default: ~/.orama/tls-cache)

	// Olric cache configuration
	OlricServers []string      // List of Olric server addresses (e.g., ["localhost:3320"]). If empty, defaults to ["localhost:3320"]
	OlricTimeout time.Duration // Timeout for Olric operations (default: 10s)

	// IPFS Cluster configuration
	IPFSClusterAPIURL     string        // IPFS Cluster HTTP API URL (e.g., "http://localhost:9094"). If empty, gateway will discover from node configs
	IPFSAPIURL            string        // IPFS HTTP API URL for content retrieval (e.g., "http://localhost:5001"). If empty, gateway will discover from node configs
	IPFSTimeout           time.Duration // Timeout for IPFS operations (default: 60s)
	IPFSReplicationFactor int           // Replication factor for pins (default: 3)
	IPFSEnableEncryption  bool          // Enable client-side encryption before upload (default: true, discovered from node configs)
}

Config holds configuration for the gateway server

func (*Config) ValidateConfig added in v0.51.5

func (c *Config) ValidateConfig() []error

ValidateConfig performs comprehensive validation of gateway configuration. It returns aggregated errors, allowing the caller to print all issues at once.

type Dependencies added in v0.90.0

type Dependencies struct {
	// Client is the network client for P2P communication
	Client client.NetworkClient

	// RQLite database dependencies
	SQLDB     *sql.DB
	ORMClient rqlite.Client
	ORMHTTP   *rqlite.HTTPGateway

	// Olric distributed cache client
	OlricClient *olric.Client

	// IPFS storage client
	IPFSClient ipfs.IPFSClient

	// Serverless function engine components
	ServerlessEngine   *serverless.Engine
	ServerlessRegistry *serverless.Registry
	ServerlessInvoker  *serverless.Invoker
	ServerlessWSMgr    *serverless.WSManager
	ServerlessHandlers *serverlesshandlers.ServerlessHandlers

	// Authentication service
	AuthService *auth.Service
}

Dependencies holds all service clients and components required by the Gateway. This struct encapsulates external dependencies to support dependency injection and testability.

func NewDependencies added in v0.90.0

func NewDependencies(logger *logging.ColoredLogger, cfg *Config) (*Dependencies, error)

NewDependencies creates and initializes all gateway dependencies based on the provided configuration. It establishes connections to RQLite, Olric, IPFS, initializes the serverless engine, and creates the authentication service.

type ExpoPushMessage added in v0.72.0

type ExpoPushMessage struct {
	To       string                 `json:"to"`
	Title    string                 `json:"title"`
	Body     string                 `json:"body"`
	Data     map[string]interface{} `json:"data,omitempty"`
	Sound    string                 `json:"sound,omitempty"`
	Badge    int                    `json:"badge,omitempty"`
	Priority string                 `json:"priority,omitempty"`
	// iOS specific
	MutableContent bool   `json:"mutableContent,omitempty"`
	IosIcon        string `json:"iosIcon,omitempty"`
	// Android specific
	AndroidBigLargeIcon string `json:"androidBigLargeIcon,omitempty"`
	ChannelID           string `json:"channelId,omitempty"`
}

ExpoPushMessage represents a message to send via Expo

type ExpoTicket added in v0.72.0

type ExpoTicket struct {
	ID    string `json:"id"`
	Error string `json:"error,omitempty"`
}

ExpoTicket represents the response from Expo API

type Gateway

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

func New

func New(logger *logging.ColoredLogger, cfg *Config) (*Gateway, error)

New creates and initializes a new Gateway instance. It establishes all necessary service connections and dependencies.

func (*Gateway) Close

func (g *Gateway) Close()

Close gracefully shuts down the gateway and all its dependencies. It closes the serverless engine, network client, database connections, Olric cache client, and IPFS client in sequence.

func (*Gateway) Routes

func (g *Gateway) Routes() http.Handler

Routes returns the http.Handler with all routes and middleware configured

type HTTPGateway added in v0.72.0

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

HTTPGateway is the main reverse proxy router

func NewHTTPGateway added in v0.72.0

func NewHTTPGateway(logger *logging.ColoredLogger, cfg *config.HTTPGatewayConfig) (*HTTPGateway, error)

NewHTTPGateway creates a new HTTP reverse proxy gateway

func (*HTTPGateway) Router added in v0.72.0

func (hg *HTTPGateway) Router() chi.Router

Router returns the chi router for testing or extension

func (*HTTPGateway) Start added in v0.72.0

func (hg *HTTPGateway) Start(ctx context.Context) error

Start starts the HTTP gateway server

func (*HTTPGateway) Stop added in v0.72.0

func (hg *HTTPGateway) Stop() error

Stop gracefully stops the HTTP gateway server

type HTTPSGateway added in v0.72.0

type HTTPSGateway struct {
	*HTTPGateway
	// contains filtered or unexported fields
}

HTTPSGateway extends HTTPGateway with HTTPS/TLS support

func NewHTTPSGateway added in v0.72.0

func NewHTTPSGateway(logger *logging.ColoredLogger, cfg *config.HTTPGatewayConfig) (*HTTPSGateway, error)

NewHTTPSGateway creates a new HTTPS gateway with Let's Encrypt autocert

func (*HTTPSGateway) Start added in v0.72.0

func (g *HTTPSGateway) Start(ctx context.Context) error

Start starts both HTTP (for ACME) and HTTPS servers

func (*HTTPSGateway) Stop added in v0.72.0

func (g *HTTPSGateway) Stop() error

Stop gracefully stops both HTTP and HTTPS servers

type PresenceMember added in v0.90.0

type PresenceMember struct {
	MemberID string                 `json:"member_id"`
	JoinedAt int64                  `json:"joined_at"` // Unix timestamp
	Meta     map[string]interface{} `json:"meta,omitempty"`
	ConnID   string                 `json:"-"` // Internal: for tracking which connection
}

PresenceMember represents a member in a topic's presence list

type PushNotificationService added in v0.72.0

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

PushNotificationService handles sending push notifications via Expo

func NewPushNotificationService added in v0.72.0

func NewPushNotificationService(logger *zap.Logger) *PushNotificationService

NewPushNotificationService creates a new push notification service

func (*PushNotificationService) SendBulkNotifications added in v0.72.0

func (pns *PushNotificationService) SendBulkNotifications(
	ctx context.Context,
	expoPushTokens []string,
	title string,
	body string,
	data map[string]interface{},
	avatarURL string,
) []error

SendBulkNotifications sends notifications to multiple users

func (*PushNotificationService) SendNotification added in v0.72.0

func (pns *PushNotificationService) SendNotification(
	ctx context.Context,
	expoPushToken string,
	title string,
	body string,
	data map[string]interface{},
	avatarURL string,
) error

SendNotification sends a push notification via Expo

type TCPSNIGateway added in v0.72.0

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

TCPSNIGateway handles SNI-based TCP routing for services like RQLite Raft, IPFS, etc.

func NewTCPSNIGateway added in v0.72.0

func NewTCPSNIGateway(logger *logging.ColoredLogger, cfg *config.SNIConfig) (*TCPSNIGateway, error)

NewTCPSNIGateway creates a new TCP SNI-based gateway

func (*TCPSNIGateway) Start added in v0.72.0

func (g *TCPSNIGateway) Start(ctx context.Context) error

Start starts the TCP SNI gateway server

func (*TCPSNIGateway) Stop added in v0.72.0

func (g *TCPSNIGateway) Stop() error

Stop gracefully stops the TCP SNI gateway

Directories

Path Synopsis
handlers
auth
Package auth provides HTTP handlers for wallet-based authentication, JWT token management, and API key operations.
Package auth provides HTTP handlers for wallet-based authentication, JWT token management, and API key operations.

Jump to

Keyboard shortcuts

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