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
- func EnsureToken(dataDir string) (string, error)
- func SocketPath(dataDir string) string
- func TokenPath(dataDir string) string
- type Backend
- type Options
- type Server
- func (s *Server) Close(ctx context.Context) error
- func (s *Server) Connect(ctx context.Context, req *connect.Request[apiv1.ConnectRequest]) (*connect.Response[apiv1.ConnectResponse], error)
- func (s *Server) ConnectListedPeer(ctx context.Context, req *connect.Request[apiv1.ConnectListedPeerRequest]) (*connect.Response[apiv1.ConnectListedPeerResponse], error)
- func (s *Server) DhtAddPeer(ctx context.Context, req *connect.Request[apiv1.DhtAddPeerRequest]) (*connect.Response[apiv1.DhtAddPeerResponse], error)
- func (s *Server) DhtFindPeer(ctx context.Context, req *connect.Request[apiv1.DhtFindPeerRequest]) (*connect.Response[apiv1.DhtFindPeerResponse], error)
- func (s *Server) DhtStatus(_ context.Context, _ *connect.Request[apiv1.DhtStatusRequest]) (*connect.Response[apiv1.DhtStatusResponse], error)
- func (s *Server) DisconnectPeer(ctx context.Context, req *connect.Request[apiv1.DisconnectPeerRequest]) (*connect.Response[apiv1.DisconnectPeerResponse], error)
- func (s *Server) DownloadPeerFile(ctx context.Context, req *connect.Request[apiv1.DownloadPeerFileRequest], ...) error
- func (s *Server) Errors() <-chan error
- func (s *Server) Events(ctx context.Context, _ *connect.Request[apiv1.EventsRequest], ...) error
- func (s *Server) GetPeerFriends(ctx context.Context, req *connect.Request[apiv1.GetPeerFriendsRequest]) (*connect.Response[apiv1.GetPeerFriendsResponse], error)
- func (s *Server) GetPeerManifest(ctx context.Context, req *connect.Request[apiv1.GetPeerManifestRequest]) (*connect.Response[apiv1.GetPeerManifestResponse], error)
- func (s *Server) GetPeerProfile(ctx context.Context, req *connect.Request[apiv1.GetPeerProfileRequest]) (*connect.Response[apiv1.GetPeerProfileResponse], error)
- func (s *Server) ListConversations(ctx context.Context, req *connect.Request[apiv1.ListConversationsRequest]) (*connect.Response[apiv1.ListConversationsResponse], error)
- func (s *Server) ListDiscoveries(ctx context.Context, req *connect.Request[apiv1.ListDiscoveriesRequest]) (*connect.Response[apiv1.ListDiscoveriesResponse], error)
- func (s *Server) ListFriends(ctx context.Context, _ *connect.Request[apiv1.ListFriendsRequest]) (*connect.Response[apiv1.ListFriendsResponse], error)
- func (s *Server) ListHumanOutboundPeers(ctx context.Context, req *connect.Request[apiv1.ListHumanOutboundPeersRequest]) (*connect.Response[apiv1.ListHumanOutboundPeersResponse], error)
- func (s *Server) ListMessages(ctx context.Context, req *connect.Request[apiv1.ListMessagesRequest]) (*connect.Response[apiv1.ListMessagesResponse], error)
- func (s *Server) OutboxCancel(ctx context.Context, req *connect.Request[apiv1.OutboxCancelRequest]) (*connect.Response[apiv1.OutboxCancelResponse], error)
- func (s *Server) OutboxList(ctx context.Context, req *connect.Request[apiv1.OutboxListRequest]) (*connect.Response[apiv1.OutboxListResponse], error)
- func (s *Server) Peers(ctx context.Context, req *connect.Request[apiv1.PeersRequest]) (*connect.Response[apiv1.PeersResponse], error)
- func (s *Server) Published(ctx context.Context, _ *connect.Request[apiv1.PublishedRequest]) (*connect.Response[apiv1.PublishedResponse], error)
- func (s *Server) RecentMessages(ctx context.Context, req *connect.Request[apiv1.RecentMessagesRequest]) (*connect.Response[apiv1.RecentMessagesResponse], error)
- func (s *Server) RelayStatus(_ context.Context, _ *connect.Request[apiv1.RelayStatusRequest]) (*connect.Response[apiv1.RelayStatusResponse], error)
- func (s *Server) RemoveFriend(ctx context.Context, req *connect.Request[apiv1.RemoveFriendRequest]) (*connect.Response[apiv1.RemoveFriendResponse], error)
- func (s *Server) SendChat(ctx context.Context, req *connect.Request[apiv1.SendChatRequest]) (*connect.Response[apiv1.SendChatResponse], error)
- func (s *Server) SetFriendDescription(ctx context.Context, req *connect.Request[apiv1.SetFriendDescriptionRequest]) (*connect.Response[apiv1.SetFriendDescriptionResponse], error)
- func (s *Server) SetFriendName(ctx context.Context, req *connect.Request[apiv1.SetFriendNameRequest]) (*connect.Response[apiv1.SetFriendNameResponse], error)
- func (s *Server) Shutdown(_ context.Context, _ *connect.Request[apiv1.ShutdownRequest]) (*connect.Response[apiv1.ShutdownResponse], error)
- func (s *Server) ShutdownRequests() <-chan struct{}
- func (s *Server) Start(_ context.Context) error
- func (s *Server) Status(ctx context.Context, _ *connect.Request[apiv1.StatusRequest]) (*connect.Response[apiv1.StatusResponse], error)
- func (s *Server) SyncFriends(ctx context.Context, _ *connect.Request[apiv1.SyncFriendsRequest]) (*connect.Response[apiv1.SyncFriendsResponse], error)
- func (s *Server) TestDisconnectPeer(ctx context.Context, req *connect.Request[apiv1.TestDisconnectPeerRequest]) (*connect.Response[apiv1.TestDisconnectPeerResponse], error)
- func (s *Server) TestPing(_ context.Context, req *connect.Request[apiv1.TestPingRequest]) (*connect.Response[apiv1.TestPingResponse], error)
Constants ¶
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 ¶
EnsureToken loads or creates the 0600 bearer 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 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) Connect ¶
func (s *Server) Connect(ctx context.Context, req *connect.Request[apiv1.ConnectRequest]) (*connect.Response[apiv1.ConnectResponse], error)
Connect implements the Connect RPC.
func (*Server) ConnectListedPeer ¶
func (s *Server) ConnectListedPeer(ctx context.Context, req *connect.Request[apiv1.ConnectListedPeerRequest]) (*connect.Response[apiv1.ConnectListedPeerResponse], error)
ConnectListedPeer implements the ConnectListedPeer RPC.
func (*Server) DhtAddPeer ¶
func (s *Server) DhtAddPeer(ctx context.Context, req *connect.Request[apiv1.DhtAddPeerRequest]) (*connect.Response[apiv1.DhtAddPeerResponse], error)
DhtAddPeer implements the DhtAddPeer RPC.
func (*Server) DhtFindPeer ¶
func (s *Server) DhtFindPeer(ctx context.Context, req *connect.Request[apiv1.DhtFindPeerRequest]) (*connect.Response[apiv1.DhtFindPeerResponse], error)
DhtFindPeer implements the DhtFindPeer RPC.
func (*Server) DhtStatus ¶
func (s *Server) DhtStatus(_ context.Context, _ *connect.Request[apiv1.DhtStatusRequest]) (*connect.Response[apiv1.DhtStatusResponse], error)
DhtStatus implements the DhtStatus RPC.
func (*Server) DisconnectPeer ¶
func (s *Server) DisconnectPeer(ctx context.Context, req *connect.Request[apiv1.DisconnectPeerRequest]) (*connect.Response[apiv1.DisconnectPeerResponse], error)
DisconnectPeer implements the normal, token-authenticated DisconnectPeer RPC.
func (*Server) DownloadPeerFile ¶
func (s *Server) DownloadPeerFile(ctx context.Context, req *connect.Request[apiv1.DownloadPeerFileRequest], stream *connect.ServerStream[apiv1.DownloadPeerFileResponse]) error
DownloadPeerFile implements the server-streaming DownloadPeerFile RPC.
func (*Server) Events ¶
func (s *Server) Events(ctx context.Context, _ *connect.Request[apiv1.EventsRequest], stream *connect.ServerStream[apiv1.EventsResponse]) error
Events implements the server-streaming Events RPC.
func (*Server) GetPeerFriends ¶
func (s *Server) GetPeerFriends(ctx context.Context, req *connect.Request[apiv1.GetPeerFriendsRequest]) (*connect.Response[apiv1.GetPeerFriendsResponse], error)
GetPeerFriends implements the GetPeerFriends RPC.
func (*Server) GetPeerManifest ¶
func (*Server) GetPeerProfile ¶
func (s *Server) GetPeerProfile(ctx context.Context, req *connect.Request[apiv1.GetPeerProfileRequest]) (*connect.Response[apiv1.GetPeerProfileResponse], error)
GetPeerProfile implements the GetPeerProfile RPC.
func (*Server) ListConversations ¶
func (s *Server) ListConversations(ctx context.Context, req *connect.Request[apiv1.ListConversationsRequest]) (*connect.Response[apiv1.ListConversationsResponse], error)
ListConversations implements the per-Peer conversation summary query.
func (*Server) ListDiscoveries ¶
func (s *Server) ListDiscoveries(ctx context.Context, req *connect.Request[apiv1.ListDiscoveriesRequest]) (*connect.Response[apiv1.ListDiscoveriesResponse], error)
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 ¶
func (s *Server) ListFriends(ctx context.Context, _ *connect.Request[apiv1.ListFriendsRequest]) (*connect.Response[apiv1.ListFriendsResponse], error)
ListFriends implements the ListFriends RPC.
func (*Server) ListHumanOutboundPeers ¶
func (s *Server) ListHumanOutboundPeers(ctx context.Context, req *connect.Request[apiv1.ListHumanOutboundPeersRequest]) (*connect.Response[apiv1.ListHumanOutboundPeersResponse], error)
ListHumanOutboundPeers exposes the durable stage-6 relation.
func (*Server) ListMessages ¶
func (s *Server) ListMessages(ctx context.Context, req *connect.Request[apiv1.ListMessagesRequest]) (*connect.Response[apiv1.ListMessagesResponse], error)
ListMessages implements the stable per-Peer keyset query.
func (*Server) OutboxCancel ¶
func (s *Server) OutboxCancel(ctx context.Context, req *connect.Request[apiv1.OutboxCancelRequest]) (*connect.Response[apiv1.OutboxCancelResponse], error)
OutboxCancel implements the durable outbox cancellation RPC.
func (*Server) OutboxList ¶
func (*Server) Peers ¶
func (s *Server) Peers(ctx context.Context, req *connect.Request[apiv1.PeersRequest]) (*connect.Response[apiv1.PeersResponse], error)
Peers implements the Peers RPC.
func (*Server) Published ¶
func (s *Server) Published(ctx context.Context, _ *connect.Request[apiv1.PublishedRequest]) (*connect.Response[apiv1.PublishedResponse], error)
GetPeerManifest implements the GetPeerManifest RPC. Published lists the local public manifest after a forced scan.
func (*Server) RecentMessages ¶
func (s *Server) RecentMessages(ctx context.Context, req *connect.Request[apiv1.RecentMessagesRequest]) (*connect.Response[apiv1.RecentMessagesResponse], error)
RecentMessages implements the RecentMessages RPC.
func (*Server) RelayStatus ¶
func (s *Server) RelayStatus(_ context.Context, _ *connect.Request[apiv1.RelayStatusRequest]) (*connect.Response[apiv1.RelayStatusResponse], error)
RelayStatus implements the RelayStatus RPC.
func (*Server) RemoveFriend ¶
func (s *Server) RemoveFriend(ctx context.Context, req *connect.Request[apiv1.RemoveFriendRequest]) (*connect.Response[apiv1.RemoveFriendResponse], error)
RemoveFriend implements the RemoveFriend RPC.
func (*Server) SendChat ¶
func (s *Server) SendChat(ctx context.Context, req *connect.Request[apiv1.SendChatRequest]) (*connect.Response[apiv1.SendChatResponse], error)
SendChat implements the SendChat RPC.
func (*Server) SetFriendDescription ¶
func (s *Server) SetFriendDescription(ctx context.Context, req *connect.Request[apiv1.SetFriendDescriptionRequest]) (*connect.Response[apiv1.SetFriendDescriptionResponse], error)
SetFriendDescription implements the SetFriendDescription RPC.
func (*Server) SetFriendName ¶
func (s *Server) SetFriendName(ctx context.Context, req *connect.Request[apiv1.SetFriendNameRequest]) (*connect.Response[apiv1.SetFriendNameResponse], error)
SetFriendName implements the SetFriendName RPC.
func (*Server) Shutdown ¶
func (s *Server) Shutdown(_ context.Context, _ *connect.Request[apiv1.ShutdownRequest]) (*connect.Response[apiv1.ShutdownResponse], error)
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 ¶
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 ¶
func (s *Server) Status(ctx context.Context, _ *connect.Request[apiv1.StatusRequest]) (*connect.Response[apiv1.StatusResponse], error)
Status implements the Status RPC.
func (*Server) SyncFriends ¶
func (s *Server) SyncFriends(ctx context.Context, _ *connect.Request[apiv1.SyncFriendsRequest]) (*connect.Response[apiv1.SyncFriendsResponse], error)
SyncFriends implements the SyncFriends RPC.
func (*Server) TestDisconnectPeer ¶
func (s *Server) TestDisconnectPeer(ctx context.Context, req *connect.Request[apiv1.TestDisconnectPeerRequest]) (*connect.Response[apiv1.TestDisconnectPeerResponse], error)
TestDisconnectPeer implements the test-only disconnect 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). |