network

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

internal/network/connectivity.go

internal/network/discovery.go

internal/network/onboarding.go

internal/network/reverseproxy.go

internal/network/tunnel.go

Index

Constants

This section is empty.

Variables

View Source
var ComponentRoutes = map[string]int{
	"api":     3000,
	"web":     3000,
	"db":      5050,
	"mongo":   8081,
	"storage": 9001,
	"ai":      11434,
	"cache":   8001,
	"queue":   8002,
}

ComponentRoutes maps component names to their default ports

Functions

func DetectRunningServices added in v0.2.0

func DetectRunningServices(cfg *config.Config) map[string]int

DetectRunningServices checks which services are actually running

func IsProviderReady

func IsProviderReady(provider string) bool

IsProviderReady checks if a specific provider is ready to use

func SaveTunnelInfo

func SaveTunnelInfo(projectName string, info *TunnelInfo) error

SaveTunnelInfo saves tunnel information to disk

Types

type CloudflareTunnel

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

CloudflareTunnel implementation

func NewCloudflareTunnel

func NewCloudflareTunnel(cfg *config.TunnelConfig) (*CloudflareTunnel, error)

NewCloudflareTunnel creates a new Cloudflare tunnel provider

func (*CloudflareTunnel) Connect

func (ct *CloudflareTunnel) Connect(ctx context.Context, port int) (string, error)

Connect establishes a Cloudflare tunnel

func (*CloudflareTunnel) Disconnect

func (ct *CloudflareTunnel) Disconnect() error

Disconnect stops the Cloudflare tunnel

func (*CloudflareTunnel) GetProviderName

func (ct *CloudflareTunnel) GetProviderName() string

GetProviderName returns "cloudflare"

func (*CloudflareTunnel) GetURL

func (ct *CloudflareTunnel) GetURL() string

GetURL returns the tunnel URL

func (*CloudflareTunnel) IsPersistent

func (ct *CloudflareTunnel) IsPersistent() bool

IsPersistent returns true if using named tunnel

type ConnectionInfo

type ConnectionInfo struct {
	ProjectName string              `json:"project_name"`
	Status      string              `json:"status"`
	LocalURLs   map[string]string   `json:"local_urls"`
	NetworkURLs map[string][]string `json:"network_urls"`
	MDNSURLs    map[string]string   `json:"mdns_urls"`
	TunnelURLs  map[string]string   `json:"tunnel_urls"`
	GeneratedAt time.Time           `json:"generated_at"`
}

ConnectionInfo represents all connection information

type ConnectivityManager

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

ConnectivityManager manages all connectivity features

func NewConnectivityManager

func NewConnectivityManager(cfg *config.Config) (*ConnectivityManager, error)

NewConnectivityManager creates a new connectivity manager

func (*ConnectivityManager) GetConnectionInfo

func (cm *ConnectivityManager) GetConnectionInfo() (*ConnectionInfo, error)

GetConnectionInfo returns all connection information

func (*ConnectivityManager) GetMobileConfig

func (cm *ConnectivityManager) GetMobileConfig() (*MobileConfig, error)

GetMobileConfig returns configuration for mobile apps

func (*ConnectivityManager) RegisterService

func (cm *ConnectivityManager) RegisterService(name string, port int)

RegisterService registers a service port

func (*ConnectivityManager) Start

func (cm *ConnectivityManager) Start(ctx context.Context) error

Start starts all connectivity services

func (*ConnectivityManager) Stop

func (cm *ConnectivityManager) Stop() error

Stop stops all connectivity services

func (*ConnectivityManager) TestConnectivity

func (cm *ConnectivityManager) TestConnectivity(url string) (*ConnectivityTest, error)

TestConnectivity tests connectivity to a URL

type ConnectivityTest

type ConnectivityTest struct {
	URL             string        `json:"url"`
	Success         bool          `json:"success"`
	HTTPStatus      string        `json:"http_status"`
	HTTPLatency     time.Duration `json:"http_latency"`
	WebSocketStatus string        `json:"websocket_status"`
	Error           string        `json:"error,omitempty"`
	TestedAt        time.Time     `json:"tested_at"`
}

ConnectivityTest represents a connectivity test result

type MobileConfig

type MobileConfig struct {
	ProjectName string                    `json:"project_name"`
	UpdatedAt   time.Time                 `json:"updated_at"`
	Endpoints   map[string]MobileEndpoint `json:"endpoints"`
	EnvFormat   string                    `json:"env_format"`
}

MobileConfig represents configuration for mobile apps

func (*MobileConfig) ToJSON

func (mc *MobileConfig) ToJSON() (string, error)

ToJSON returns JSON representation

type MobileEndpoint

type MobileEndpoint struct {
	Primary   string `json:"primary"`   // The URL to use
	Local     string `json:"local"`     // localhost URL
	Network   string `json:"network"`   // LAN IP URL
	Public    string `json:"public"`    // Tunnel URL
	WebSocket string `json:"websocket"` // WebSocket URL
}

MobileEndpoint represents an endpoint configuration

type MultiTunnelProxy added in v0.2.0

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

MultiTunnelProxy manages multiple service routing through a single tunnel

func NewMultiTunnelProxy added in v0.2.0

func NewMultiTunnelProxy(prefix string) *MultiTunnelProxy

NewMultiTunnelProxy creates a new multi-service tunnel proxy

func (*MultiTunnelProxy) AddService added in v0.2.0

func (mtp *MultiTunnelProxy) AddService(name string, port int)

AddService adds a service to the proxy

func (*MultiTunnelProxy) GetProxyPort added in v0.2.0

func (mtp *MultiTunnelProxy) GetProxyPort() int

GetProxyPort returns the proxy port

func (*MultiTunnelProxy) GetServiceURLs added in v0.2.0

func (mtp *MultiTunnelProxy) GetServiceURLs(baseTunnelURL string) map[string]string

GetServiceURLs returns the public URLs for all services

func (*MultiTunnelProxy) Start added in v0.2.0

func (mtp *MultiTunnelProxy) Start() error

Start starts the reverse proxy server

func (*MultiTunnelProxy) Stop added in v0.2.0

func (mtp *MultiTunnelProxy) Stop() error

Stop stops the reverse proxy server

type NetworkDiscovery

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

NetworkDiscovery handles local network discovery and mDNS

func NewNetworkDiscovery

func NewNetworkDiscovery() *NetworkDiscovery

NewNetworkDiscovery creates a new network discovery instance

func (*NetworkDiscovery) DiscoverServices

func (n *NetworkDiscovery) DiscoverServices(timeout time.Duration) ([]ServiceInfo, error)

DiscoverServices discovers other LocalCloud services on the network

func (*NetworkDiscovery) GetLocalIPs

func (n *NetworkDiscovery) GetLocalIPs() ([]string, error)

GetLocalIPs returns all valid local IP addresses

func (*NetworkDiscovery) GetNetworkURLs

func (n *NetworkDiscovery) GetNetworkURLs(projectName string, services map[string]int) (map[string][]string, error)

GetNetworkURLs returns all possible network URLs for services

func (*NetworkDiscovery) StartMDNS

func (n *NetworkDiscovery) StartMDNS(projectName string, services map[string]int) error

StartMDNS starts mDNS service advertisement

func (*NetworkDiscovery) StopMDNS

func (n *NetworkDiscovery) StopMDNS()

StopMDNS stops the mDNS server

type NgrokTunnel

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

NgrokTunnel implementation

func NewNgrokTunnel

func NewNgrokTunnel(cfg *config.TunnelConfig) (*NgrokTunnel, error)

NewNgrokTunnel creates a new Ngrok tunnel provider

func (*NgrokTunnel) Connect

func (nt *NgrokTunnel) Connect(ctx context.Context, port int) (string, error)

Connect establishes an Ngrok tunnel

func (*NgrokTunnel) Disconnect

func (nt *NgrokTunnel) Disconnect() error

Disconnect stops the Ngrok tunnel

func (*NgrokTunnel) GetProviderName

func (nt *NgrokTunnel) GetProviderName() string

GetProviderName returns "ngrok"

func (*NgrokTunnel) GetURL

func (nt *NgrokTunnel) GetURL() string

GetURL returns the tunnel URL

func (*NgrokTunnel) IsPersistent

func (nt *NgrokTunnel) IsPersistent() bool

IsPersistent returns true if using custom domain

type ServiceConfig added in v0.2.0

type ServiceConfig struct {
	Name        string `json:"name"`
	Port        int    `json:"port"`
	Path        string `json:"path,omitempty"`         // Optional path prefix
	Subdomain   string `json:"subdomain,omitempty"`    // Optional subdomain
	HealthCheck string `json:"health_check,omitempty"` // Health check endpoint
}

ServiceConfig represents configuration for a tunneled service

type ServiceInfo

type ServiceInfo struct {
	Name    string
	Host    string
	Port    int
	IPs     []net.IP
	TxtData []string
}

ServiceInfo represents discovered service information

func (ServiceInfo) ParseTxtData

func (s ServiceInfo) ParseTxtData() map[string]string

ParseTxtData parses TXT record data into a map

type TunnelInfo

type TunnelInfo struct {
	Provider    string    `json:"provider"`
	URL         string    `json:"url"`
	TunnelID    string    `json:"tunnel_id,omitempty"`
	Domain      string    `json:"domain,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	LastStarted time.Time `json:"last_started"`
}

TunnelInfo represents tunnel information for persistence

func LoadTunnelInfo

func LoadTunnelInfo(projectName string) (*TunnelInfo, error)

LoadTunnelInfo loads tunnel information from disk

type TunnelManager

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

TunnelManager manages tunnel connections

func NewTunnelManager

func NewTunnelManager(cfg *config.ConnectivityConfig) (*TunnelManager, error)

NewTunnelManager creates a new tunnel manager

func (*TunnelManager) Connect

func (tm *TunnelManager) Connect(ctx context.Context, port int) (string, error)

Connect establishes a tunnel connection

func (*TunnelManager) Disconnect

func (tm *TunnelManager) Disconnect() error

Disconnect closes the tunnel

func (*TunnelManager) GetProviderName

func (tm *TunnelManager) GetProviderName() string

GetProviderName returns the active provider name

func (*TunnelManager) GetURL

func (tm *TunnelManager) GetURL() string

GetURL returns the current tunnel URL

type TunnelOnboarding

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

TunnelOnboarding handles first-time tunnel setup

func NewTunnelOnboarding

func NewTunnelOnboarding() *TunnelOnboarding

NewTunnelOnboarding creates a new onboarding helper

func (*TunnelOnboarding) CheckAndSetup

func (t *TunnelOnboarding) CheckAndSetup() (string, error)

CheckAndSetup checks if tunnel provider is ready and sets it up if needed

func (*TunnelOnboarding) GetConfiguredProvider

func (t *TunnelOnboarding) GetConfiguredProvider() string

GetConfiguredProvider returns the configured provider after onboarding

type TunnelProvider

type TunnelProvider interface {
	Connect(ctx context.Context, port int) (string, error)
	Disconnect() error
	GetURL() string
	IsPersistent() bool
	GetProviderName() string
}

TunnelProvider interface for different tunnel implementations

Jump to

Keyboard shortcuts

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