api

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api implements the local Connect-RPC API over a Unix domain socket.

The API is never served on TCP or UDP. Authentication is a bearer token in a 0600 file plus the 0600 socket; test-only RPCs are unavailable unless the daemon was started with --enable-test-api.

Index

Constants

View Source
const (
	// SocketFileName is the UDS path inside the data directory.
	SocketFileName = paths.SocketFileName
	// TokenFileName is the bearer token path inside the data directory.
	TokenFileName = paths.TokenFileName
	// APIVersion is the local API contract version reported by Status. Plugin
	// shells compare it against their expected version and ask for a restart
	// or upgrade on mismatch instead of failing individual RPCs.
	APIVersion = "2"
)

Variables

This section is empty.

Functions

func EnsureToken

func EnsureToken(dataDir string) (string, error)

EnsureToken loads or creates the 0600 bearer token.

func SocketPath

func SocketPath(dataDir string) string

SocketPath returns <dataDir>/api.sock.

func TokenPath

func TokenPath(dataDir string) string

TokenPath returns <dataDir>/api.token.

Types

type Backend

type Backend interface {
	Status(ctx context.Context) (node.Status, error)
	Connect(ctx context.Context, peerID, multiaddr string) (node.ConnectResult, error)
	SendChat(ctx context.Context, peerID, multiaddr, text string) (node.SendResult, error)
	RecentMessages(ctx context.Context, limit int) ([]node.StoredMessage, error)
	Outbox(ctx context.Context, limit int) ([]node.OutboxEntry, node.OutboxStats, error)
	CancelOutbox(ctx context.Context, messageID string) error
	Subscribe(ctx context.Context) (<-chan node.Event, func(), error)

	Peers(ctx context.Context) ([]node.PeerStatus, error)
	RelayReservations() []node.RelayReservation
	RelayProvider() node.RelayProviderStatus
	AddPeer(ctx context.Context, multiaddr string) (node.PeerEntry, error)
	DHTStatus() node.DHTStatus
	DHTFindPeer(ctx context.Context, peerID string) (node.DHTPeer, error)
	ListFriends(ctx context.Context) ([]node.Friend, error)
	SetFriendName(ctx context.Context, peerID, name string) (node.Friend, error)
	SetFriendDescription(ctx context.Context, peerID, description string) (node.Friend, error)
	RemoveFriend(ctx context.Context, peerID string, cancelPending bool) (bool, int, error)
	SyncFriends(ctx context.Context) (bool, error)
	Published(ctx context.Context) (node.Published, error)
	GetPeerManifest(ctx context.Context, peerID string, offset, limit int) (node.PeerManifest, error)
	GetPeerProfile(ctx context.Context, peerID string) (node.PeerProfile, error)
	GetPeerFriends(ctx context.Context, peerID string) (node.PeerFriends, error)
	DownloadPeerFile(ctx context.Context, peerID, path string, progress func(node.DownloadProgress)) (node.DownloadResult, error)
	ConnectListedPeer(ctx context.Context, peerID string, addrs []string) (node.ConnectResult, error)
	Disconnect(ctx context.Context, peerID string) error
	PausePeer(ctx context.Context, peerID string) error
}

Backend is the node surface used by the local API.

type Server

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

Server serves the Connect-RPC API over UDS.

func NewServer

func NewServer(backend Backend, dataDir string, testAPI bool, logger *slog.Logger) (*Server, error)

NewServer prepares the API server and ensures the 0600 token file exists.

func (*Server) Close

func (s *Server) Close(ctx context.Context) error

Close shuts the API down and removes the socket.

func (*Server) Connect

Connect implements the Connect RPC.

func (*Server) ConnectListedPeer

ConnectListedPeer implements the ConnectListedPeer RPC.

func (*Server) DhtAddPeer

DhtAddPeer implements the DhtAddPeer RPC.

func (*Server) DhtFindPeer

DhtFindPeer implements the DhtFindPeer RPC.

func (*Server) DhtStatus

DhtStatus implements the DhtStatus RPC.

func (*Server) DisconnectPeer

DisconnectPeer implements the normal, token-authenticated DisconnectPeer RPC.

func (*Server) DownloadPeerFile

DownloadPeerFile implements the server-streaming DownloadPeerFile RPC.

func (*Server) Errors

func (s *Server) Errors() <-chan error

Errors reports an unexpected serve failure.

func (*Server) Events

Events implements the server-streaming Events RPC.

func (*Server) GetPeerFriends

GetPeerFriends implements the GetPeerFriends RPC.

func (*Server) GetPeerProfile

GetPeerProfile implements the GetPeerProfile RPC.

func (*Server) ListFriends

ListFriends implements the ListFriends RPC.

func (*Server) OutboxCancel

OutboxCancel implements the durable outbox cancellation RPC.

func (*Server) Peers

Peers implements the Peers RPC.

func (*Server) Published

GetPeerManifest implements the GetPeerManifest RPC. Published lists the local public manifest after a forced scan.

func (*Server) RecentMessages

RecentMessages implements the RecentMessages RPC.

func (*Server) RelayStatus

RelayStatus implements the RelayStatus RPC.

func (*Server) RemoveFriend

RemoveFriend implements the RemoveFriend RPC.

func (*Server) SendChat

SendChat implements the SendChat RPC.

func (*Server) SetFriendDescription

SetFriendDescription implements the SetFriendDescription RPC.

func (*Server) SetFriendName

SetFriendName implements the SetFriendName RPC.

func (*Server) Shutdown

Shutdown implements the normal, token-authenticated graceful-stop RPC.

func (*Server) ShutdownRequests

func (s *Server) ShutdownRequests() <-chan struct{}

ShutdownRequests reports token-authenticated Shutdown RPCs. The daemon owns the actual stop sequence so the API can finish writing the response first.

func (*Server) Start

func (s *Server) Start(_ context.Context) error

Start listens on the Unix socket, applies 0600 and serves the API.

func (*Server) Status

Status implements the Status RPC.

func (*Server) SyncFriends

SyncFriends implements the SyncFriends RPC.

func (*Server) TestDisconnectPeer

TestDisconnectPeer implements the test-only disconnect RPC.

func (*Server) TestPing

TestPing implements the test-only TestPing RPC.

Directories

Path Synopsis
Package client is a Connect-RPC client for the local Raminga API.
Package client is a Connect-RPC client for the local Raminga API.
Package paths centralizes the local API file names so the server and the CLI client agree without the client importing the server package (which would pull node internals into the thin client).
Package paths centralizes the local API file names so the server and the CLI client agree without the client importing the server package (which would pull node internals into the thin client).

Jump to

Keyboard shortcuts

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