api

package
v0.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 34 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.

The default transport is a 0600 Unix domain socket with a 0600 token file. An explicit opt-in mode serves the same authenticated Connect-RPC API only on a per-run ephemeral TCP listener bound to literal 127.0.0.1, protected by a per-run bearer token and a pinned per-run TLS certificate. There is no automatic fallback between the two modes. 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 = "4"
)

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)
	SendChatOrigin(ctx context.Context, peerID, multiaddr, text, origin, requestID string) (node.SendResult, error)
	RecentMessages(ctx context.Context, limit int) ([]node.StoredMessage, error)
	ListMessages(ctx context.Context, peerID, before string, limit int) (node.MessagePage, error)
	ListConversations(ctx context.Context, before string, limit int) (node.ConversationPage, error)
	ListHumanOutboundPeers(ctx context.Context, before string, limit int) (node.HumanOutboundPage, 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)
	ListDiscoveries(ctx context.Context, before string, limit int, familiarOnly bool) (node.PublicDiscoveryPage, 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), options node.DownloadOptions) (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 Options

type Options struct {
	// EnableTCP serves only the opt-in loopback TCP transport. It never starts
	// the Unix socket, and a caller cannot silently fall back to either mode.
	EnableTCP bool
}

Options selects the local API transport. The zero value preserves the Unix domain socket default.

type Server

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

Server serves the Connect-RPC API over the selected local transport.

func NewServer

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

NewServer prepares the default Unix-socket API server.

func NewServerWithOptions

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

NewServerWithOptions prepares the API server for the explicitly selected transport. Unix mode ensures the 0600 UDS token file exists; TCP mode does not read or create that token, because its bearer token is per-run and lives only in the protected discovery document.

func (*Server) Close

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

Close shuts the selected listener down and removes its discovery artifact.

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) ListConversations

ListConversations implements the per-Peer conversation summary query.

func (*Server) ListDiscoveries

ListDiscoveries returns the local, private acquisition index. Rows exist only after an Agent tool successfully fetched a manifest file with evidence recording requested.

func (*Server) ListFriends

ListFriends implements the ListFriends RPC.

func (*Server) ListHumanOutboundPeers

ListHumanOutboundPeers exposes the durable stage-6 relation.

func (*Server) ListMessages

ListMessages implements the stable per-Peer keyset query.

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 serves the explicitly selected transport. TCP mode is mutually exclusive with the Unix socket; a stale discovery document is removed before the new per-run document is published.

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 endpoint reads and writes the protected local-TCP API discovery document.
Package endpoint reads and writes the protected local-TCP API discovery document.
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