Documentation
¶
Overview ¶
Package node orchestrates identity, config, storage, network and protocol. It is the only package that composes the base modules; it never reimplements their policies.
Index ¶
- Constants
- Variables
- func NewPeerCache(store *storage.Store) network.PeerCache
- type AckEvent
- type AutoNATStatus
- type CachedPeer
- type ChatEvent
- type ConnectResult
- type ConnectionEvent
- type Conversation
- type ConversationPage
- type DCUtRStatus
- type DHTPeer
- type DHTStatus
- type DialAttempt
- type DownloadOptions
- type DownloadProgress
- type DownloadResult
- type Event
- type Friend
- type HumanOutboundPage
- type HumanOutboundPeer
- type MessagePage
- type MessageRetention
- type NetworkStatus
- type Node
- func (n *Node) AddPeer(ctx context.Context, multiaddr string) (network.PeerEntry, error)
- func (n *Node) CancelOutbox(ctx context.Context, messageID string) error
- func (n *Node) Connect(ctx context.Context, peerID, multiaddr string) (ConnectResult, error)
- func (n *Node) ConnectListedPeer(ctx context.Context, peerID string, addrs []string) (ConnectResult, error)
- func (n *Node) DHTFindPeer(ctx context.Context, peerID string) (network.DHTPeer, error)
- func (n *Node) DHTStatus() network.DHTStatus
- func (n *Node) Disconnect(ctx context.Context, peerID string) error
- func (n *Node) Download(ctx context.Context, peerID, remotePath string, ...) (DownloadResult, error)
- func (n *Node) DownloadPeerFile(ctx context.Context, peerID, path string, progress func(DownloadProgress), ...) (DownloadResult, error)
- func (n *Node) DownloadWithOptions(ctx context.Context, peerID, remotePath string, ...) (DownloadResult, error)
- func (n *Node) FetchManifest(ctx context.Context, peerID string, offset, limit int) (PeerManifest, error)
- func (n *Node) Friends(ctx context.Context) ([]Friend, error)
- func (n *Node) GetPeerFriends(ctx context.Context, peerID string) (PeerFriends, error)
- func (n *Node) GetPeerManifest(ctx context.Context, peerID string, offset, limit int) (PeerManifest, error)
- func (n *Node) GetPeerProfile(ctx context.Context, peerID string) (PeerProfile, error)
- func (n *Node) ListConversations(ctx context.Context, before string, limit int) (ConversationPage, error)
- func (n *Node) ListDiscoveries(ctx context.Context, before string, limit int, familiarOnly bool) (PublicDiscoveryPage, error)
- func (n *Node) ListFriends(ctx context.Context) ([]Friend, error)
- func (n *Node) ListHumanOutboundPeers(ctx context.Context, before string, limit int) (HumanOutboundPage, error)
- func (n *Node) ListMessages(ctx context.Context, peerID, before string, limit int) (MessagePage, error)
- func (n *Node) ListOutbox(ctx context.Context, limit int) ([]OutboxEntry, error)
- func (n *Node) Outbox(ctx context.Context, limit int) ([]OutboxEntry, OutboxStats, error)
- func (n *Node) OutboxStats(ctx context.Context) (OutboxStats, error)
- func (n *Node) PausePeer(ctx context.Context, peerID string) error
- func (n *Node) Peers(ctx context.Context) ([]PeerStatus, error)
- func (n *Node) Published(ctx context.Context) (Published, error)
- func (n *Node) RecentMessages(ctx context.Context, limit int) ([]StoredMessage, error)
- func (n *Node) RelayProvider() network.RelayProviderStatus
- func (n *Node) RelayReservations() []network.RelayReservation
- func (n *Node) RemoveFriend(ctx context.Context, peerID string, cancelPending bool) (bool, int, error)
- func (n *Node) ResumePeer(ctx context.Context, pid peer.ID) error
- func (n *Node) SendChat(ctx context.Context, peerIDStr, multiaddrStr, text string) (SendResult, error)
- func (n *Node) SendChatOrigin(ctx context.Context, peerIDStr, multiaddrStr, text, origin, requestID string) (SendResult, error)
- func (n *Node) SetFriendDescription(ctx context.Context, peerID, description string) (Friend, error)
- func (n *Node) SetFriendName(ctx context.Context, peerID, name string) (Friend, error)
- func (n *Node) Start(ctx context.Context) error
- func (n *Node) Status(ctx context.Context) (Status, error)
- func (n *Node) Stop(context.Context) error
- func (n *Node) Subscribe(ctx context.Context) (<-chan Event, func(), error)
- func (n *Node) SyncFriends(ctx context.Context) (bool, error)
- func (n *Node) ViewFriends(ctx context.Context, peerID string) (PeerFriends, error)
- func (n *Node) ViewProfile(ctx context.Context, peerID string) (PeerProfile, error)
- type Options
- type OutboxEntry
- type OutboxStats
- type PeerEntry
- type PeerFriend
- type PeerFriends
- type PeerManifest
- type PeerProfile
- type PeerStatus
- type PublicDiscovery
- type PublicDiscoveryPage
- type Published
- type PublishedFile
- type PublishedSkip
- type RelayProviderStatus
- type RelayReservation
- type ResourceStatus
- type SendResult
- type Status
- type StoredMessage
Constants ¶
const ( OriginHuman = storage.OriginHuman OriginAgent = storage.OriginAgent OriginUnknown = storage.OriginUnknown )
Local send provenance values. They are an operator model, not strong auth.
const ( DeliveryPending = storage.DeliveryPending DeliveryAcked = storage.DeliveryAcked DeliveryFailed = storage.DeliveryFailed DeliveryCancelled = storage.DeliveryCancelled DeliveryUnknown = storage.DeliveryUnknown DeliveryReceived = storage.DeliveryReceived )
Delivery states exposed by the local API.
Variables ¶
var ( ErrFriendNotFound = storage.ErrFriendNotFound ErrFriendNameTaken = storage.ErrFriendNameTaken ErrFriendPendingOutbox = storage.ErrFriendPendingOutbox )
Friend sentinel errors are stable API-facing aliases for the storage errors.
var ErrInvalidCursor = storage.ErrInvalidCursor
ErrInvalidCursor reports a malformed message or conversation cursor.
Functions ¶
Types ¶
type AutoNATStatus ¶
type AutoNATStatus = network.AutoNATStatus
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type CachedPeer ¶
type CachedPeer = network.CachedPeer
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type ChatEvent ¶
type ChatEvent struct {
MessageID string
FromPeerID string
FromNodeID string
Text string
Duplicate bool
Accepted bool
}
ChatEvent reports an inbound chat message.
type ConnectResult ¶
type ConnectResult struct {
PeerID string
Transport string
Route string
RelayPeerID string
Direct bool
Limited bool
RemoteMultiaddr string
Reused bool
RequestedTransport string
TransportChanged bool
Source string
Attempts []network.DialAttempt
Note string
}
ConnectResult is the outcome of an explicit dial or a peer-ID dial.
type ConnectionEvent ¶
type ConnectionEvent struct {
PeerID string
Direction string
Transport string
Route string
RelayPeerID string
RemoteMultiaddr string
Kind string // "connected" or "disconnected"
Direct bool
Limited bool
}
ConnectionEvent reports a connection change.
type Conversation ¶
type Conversation struct {
PeerID string
LastMessageID string
Direction string
Preview string
LastAt time.Time
DeliveryStatus string
Origin string
MessageCount int
}
Conversation is one Peer's latest retained message.
type ConversationPage ¶
type ConversationPage struct {
Conversations []Conversation
NextBefore string
HasMore bool
Retention MessageRetention
}
ConversationPage is one keyset page of conversation summaries.
type DCUtRStatus ¶
type DCUtRStatus = network.DCUtRStatus
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type DHTPeer ¶
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type DHTStatus ¶
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type DialAttempt ¶
type DialAttempt = network.DialAttempt
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type DownloadOptions ¶
DownloadOptions controls optional evidence recording for one download.
type DownloadProgress ¶
type DownloadResult ¶
type Event ¶
type Event struct {
At time.Time
Chat *ChatEvent
Ack *AckEvent
Connection *ConnectionEvent
}
Event is one local-API notification.
type Friend ¶
type Friend struct {
PeerID string
Name string
Addrs []string
Description string
ManuallyConnected bool
RelayCapable bool
DHTCapable bool
Paused bool
FirstSeen time.Time
LastInteraction time.Time
}
Friend is the node-facing friend view. Names/descriptions are local only.
type HumanOutboundPage ¶
type HumanOutboundPage struct {
Peers []HumanOutboundPeer
NextBefore string
HasMore bool
}
HumanOutboundPage is one keyset page of durable human-outbound relations.
type HumanOutboundPeer ¶
type HumanOutboundPeer struct {
PeerID string
FirstAt time.Time
LastAt time.Time
// PagingRowID and PagingSnapshotID are opaque keyset positions for the
// stable relation snapshot. They are not serialized as public relation data.
PagingRowID int64
PagingSnapshotID int64
}
HumanOutboundPeer is one durable human-outbound relation.
type MessagePage ¶
type MessagePage struct {
Messages []StoredMessage
NextBefore string
HasMore bool
Retention MessageRetention
}
MessagePage is one keyset page of retained messages, newest first.
type MessageRetention ¶
MessageRetention describes currently retained rows, not pruned history.
type NetworkStatus ¶
type NetworkStatus struct {
Reachability string
AutoNAT network.AutoNATStatus
DCUtR network.DCUtRStatus
Relays []network.RelayReservation
RelayProvider network.RelayProviderStatus
DHT network.DHTStatus
Resources network.ResourceStatus
PeerCache []network.CachedPeer
UPNP bool
NATPMP bool
STUN bool
}
NetworkStatus groups G2 diagnostics. Cached addresses are never online.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is the running node orchestration.
func (*Node) CancelOutbox ¶
CancelOutbox cancels one pending entry; terminal entries are rejected.
func (*Node) Connect ¶
Connect dials a peer by explicit multiaddr or, when only a Peer ID is given, through resolved PeerStore/cache/DHT candidates.
func (*Node) ConnectListedPeer ¶
func (*Node) DHTFindPeer ¶
DHTFindPeer performs a real DHT lookup with a cache fallback source label.
func (*Node) Disconnect ¶
Disconnect closes all connections to a peer (test-only API).
func (*Node) Download ¶
func (n *Node) Download(ctx context.Context, peerID, remotePath string, progress func(DownloadProgress)) (DownloadResult, error)
func (*Node) DownloadPeerFile ¶
func (n *Node) DownloadPeerFile(ctx context.Context, peerID, path string, progress func(DownloadProgress), options DownloadOptions) (DownloadResult, error)
DownloadPeerFile is the API-facing variant used by Agent tools that may explicitly record acquisition evidence.
func (*Node) DownloadWithOptions ¶
func (n *Node) DownloadWithOptions(ctx context.Context, peerID, remotePath string, progress func(DownloadProgress), options DownloadOptions) (DownloadResult, error)
DownloadWithOptions downloads one manifest file and optionally records the successful acquisition as private discovery evidence. Only Agent tool callers opt in; a manual TUI download, a directory scan or merely listing a manifest does not become a Feed recommendation.
func (*Node) FetchManifest ¶
func (*Node) GetPeerFriends ¶
func (*Node) GetPeerManifest ¶
func (n *Node) GetPeerManifest(ctx context.Context, peerID string, offset, limit int) (PeerManifest, error)
API-facing aliases use explicit Get names.
func (*Node) GetPeerProfile ¶
func (*Node) ListConversations ¶
func (n *Node) ListConversations(ctx context.Context, before string, limit int) (ConversationPage, error)
ListConversations returns one summary per Peer from retained messages.
func (*Node) ListDiscoveries ¶
func (n *Node) ListDiscoveries(ctx context.Context, before string, limit int, familiarOnly bool) (PublicDiscoveryPage, error)
ListDiscoveries returns the private discovery index page. It is served only on the local API; the remote content protocol does not expose it.
func (*Node) ListFriends ¶
ListFriends is the API-facing alias for Friends.
func (*Node) ListHumanOutboundPeers ¶
func (n *Node) ListHumanOutboundPeers(ctx context.Context, before string, limit int) (HumanOutboundPage, error)
ListHumanOutboundPeers returns the durable stage-6 relation page.
func (*Node) ListMessages ¶
func (n *Node) ListMessages(ctx context.Context, peerID, before string, limit int) (MessagePage, error)
ListMessages returns one Peer's retained messages with a stable cursor.
func (*Node) ListOutbox ¶
ListOutbox returns durable outbox entries newest first.
func (*Node) Outbox ¶
func (n *Node) Outbox(ctx context.Context, limit int) ([]OutboxEntry, OutboxStats, error)
Outbox returns the durable outbox page and accounting in one call for the local API.
func (*Node) OutboxStats ¶
func (n *Node) OutboxStats(ctx context.Context) (OutboxStats, error)
OutboxStats returns bounded outbox accounting.
func (*Node) PausePeer ¶
PausePeer persists a pause, stops local relay/auto-relay work and closes the current connection. It intentionally does not create a friend row.
func (*Node) Peers ¶
func (n *Node) Peers(ctx context.Context) ([]PeerStatus, error)
Peers returns live connections plus cached hints (Online=false).
func (*Node) Published ¶
Published forces a fresh local scan and returns what is published, what was skipped and when friends.json was last written. It stays on the local API.
func (*Node) RecentMessages ¶
RecentMessages returns persisted messages newest first.
func (*Node) RelayProvider ¶
func (n *Node) RelayProvider() network.RelayProviderStatus
RelayProvider returns the optional relay provider quotas.
func (*Node) RelayReservations ¶
func (n *Node) RelayReservations() []network.RelayReservation
RelayReservations returns real Relay v2 client reservation states.
func (*Node) RemoveFriend ¶
func (n *Node) RemoveFriend(ctx context.Context, peerID string, cancelPending bool) (bool, int, error)
RemoveFriend deletes a friend row; pending outbox requires explicit cancel.
func (*Node) ResumePeer ¶
ResumePeer clears a pause (explicit connect/chat).
func (*Node) SendChat ¶
func (n *Node) SendChat(ctx context.Context, peerIDStr, multiaddrStr, text string) (SendResult, error)
SendChat persists an outbound message, sends it and records a matching ACK. It is the legacy internal entry and records unknown provenance; shells use SendChatOrigin with an explicit human/agent origin.
func (*Node) SendChatOrigin ¶
func (n *Node) SendChatOrigin(ctx context.Context, peerIDStr, multiaddrStr, text, origin, requestID string) (SendResult, error)
SendChatOrigin persists an outbound message with local provenance and an optional idempotency key, sends it and records a matching ACK. Transport/ACK failures are returned in SendResult with Acked=false, not as a local RPC error; only invalid input and local persistence errors are errors. A non-empty requestID maps to one deterministic message ID per Peer: replaying it returns the persisted state and never creates or sends a second message.
func (*Node) SetFriendDescription ¶
func (n *Node) SetFriendDescription(ctx context.Context, peerID, description string) (Friend, error)
SetFriendDescription replaces a description for an existing friend.
func (*Node) SetFriendName ¶
SetFriendName replaces a name for an existing friend. An empty name clears the local label; non-empty names keep the existing syntax/uniqueness rules in storage. This never changes any remotely published profile.
func (*Node) Start ¶
Start launches the network subsystems, then registers the chat protocol and connection notifiee.
func (*Node) Status ¶
Status returns a point-in-time view. Cached peer hints are listed with Online=false; they are never reported as reachable.
func (*Node) SyncFriends ¶
SyncFriends regenerates public/friends.json immediately.
func (*Node) ViewFriends ¶
func (*Node) ViewProfile ¶
type Options ¶
type Options struct {
DataDir string
Version string
Config config.Config
Identity *identity.Identity
Store *storage.Store
Network *network.Network
Logger *slog.Logger
TestAPI bool
Supervised bool
}
Options constructs a Node. The Node takes ownership of Store and Network and closes them on Stop; the caller keeps ownership of Identity and its lock.
type OutboxEntry ¶
type OutboxEntry struct {
MessageID string
PeerID string
Text string
Multiaddr string
Status string
Attempts int
Bytes int
LastError string
CreatedAt time.Time
ExpiresAt time.Time
NextAttemptAt time.Time
UpdatedAt time.Time
}
OutboxEntry is one durable unacknowledged outbound message.
type OutboxStats ¶
OutboxStats is the bounded outbox accounting view.
type PeerEntry ¶
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type PeerFriend ¶
type PeerFriends ¶
type PeerFriends struct {
PeerID string
Friends []PeerFriend
Limited bool
}
type PeerManifest ¶
type PeerProfile ¶
type PeerStatus ¶
type PeerStatus struct {
PeerID string
Addrs []string
Sources []string
Direction string
Transport string
Route string
RelayPeerID string
Direct bool
Limited bool
Paused bool
Online bool
OpenedAt time.Time
}
PeerStatus is one current connection or cached hint.
type PublicDiscovery ¶
type PublicDiscovery struct {
ID int64
PeerID string
Path string
SHA256 string
SizeBytes int64
FetchedAt time.Time
Source string
}
PublicDiscovery is one successful Agent acquisition from a remote public manifest, with the exact path, hash, time and local acquisition source.
type PublicDiscoveryPage ¶
type PublicDiscoveryPage struct {
Discoveries []PublicDiscovery
NextBefore string
HasMore bool
}
PublicDiscoveryPage is one keyset page of discovery evidence.
type Published ¶
type Published struct {
Files []PublishedFile
Skipped []PublishedSkip
GeneratedAt time.Time
// FriendsSyncedAt is the mtime of friends.json, i.e. when its contents last
// changed, not the last time friends were synced.
FriendsSyncedAt time.Time
}
Published is the local-only /published view. It is never served over the remote content HTTP routes.
type PublishedFile ¶
PublishedFile is one file in the local public manifest.
type PublishedSkip ¶
PublishedSkip is one local path omitted from the public manifest.
type RelayProviderStatus ¶
type RelayProviderStatus = network.RelayProviderStatus
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type RelayReservation ¶
type RelayReservation = network.RelayReservation
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type ResourceStatus ¶
type ResourceStatus = network.ResourceStatus
G2 public type aliases keep the local API dependent on node, not on network internals directly.
type SendResult ¶
type SendResult struct {
MessageID string
Acked bool
AckMessageID string
ACKID string
Route string
Transport string
RelayPeerID string
RemoteMultiaddr string
Reused bool
Source string
Attempts []network.DialAttempt
Note string
Error string
OutboxStatus string
DeliveryStatus string
Replayed bool
RequestID string
}
SendResult is the outcome of one SendChat call. Acked is true only when a matching ACK was received and its ACK state was persisted. DeliveryStatus is the durable history state and outlives the outbox row.
type Status ¶
type Status struct {
PeerID string
NodeID string
ListenAddrs []string
AdvertisedAddrs []string
Version string
ProtocolVersion string
StartedAt time.Time
Peers []PeerStatus
Connections []network.ConnInfo
TestAPI bool
Supervised bool
DataDir string
GoVersion string
Network NetworkStatus
ContentWarnings []string
MaxChatTextBytes int
MaxStoredMessages int
}
Status is a point-in-time view of the running node.
type StoredMessage ¶
type StoredMessage struct {
MessageID string
PeerID string
Direction string
Text string
Acked bool
CreatedAt time.Time
AckedAt time.Time
Origin string
DeliveryStatus string
DeliveryError string
DeliveryUpdatedAt time.Time
ClientRequestID string
}
StoredMessage is a persisted message view.