node

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: 37 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 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

View Source
const (
	OriginHuman   = storage.OriginHuman
	OriginAgent   = storage.OriginAgent
	OriginUnknown = storage.OriginUnknown
)

Local send provenance values. They are an operator model, not strong auth.

View Source
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

View Source
var (
	ErrFriendNotFound      = storage.ErrFriendNotFound
	ErrFriendNameTaken     = storage.ErrFriendNameTaken
	ErrFriendPendingOutbox = storage.ErrFriendPendingOutbox
)

Friend sentinel errors are stable API-facing aliases for the storage errors.

View Source
var ErrInvalidCursor = storage.ErrInvalidCursor

ErrInvalidCursor reports a malformed message or conversation cursor.

Functions

func NewPeerCache

func NewPeerCache(store *storage.Store) network.PeerCache

NewPeerCache adapts the SQLite store to the network package's small hint cache interface. It is not a second runtime address source.

Types

type AckEvent

type AckEvent struct {
	MessageID string
	PeerID    string
	Accepted  bool
	Error     string
}

AckEvent reports an ACK observed by this node.

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

type DHTPeer = network.DHTPeer

G2 public type aliases keep the local API dependent on node, not on network internals directly.

type DHTStatus

type DHTStatus = network.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

type DownloadOptions struct {
	RecordDiscovery bool
	DiscoverySource string
}

DownloadOptions controls optional evidence recording for one download.

type DownloadProgress

type DownloadProgress struct {
	Phase    string
	Path     string
	Received int64
	Total    int64
	Direct   bool
}

type DownloadResult

type DownloadResult struct {
	PeerID    string
	Path      string
	LocalPath string
	Size      int64
	SHA256    string
	Resumed   bool
	Direct    bool
	// Discovery evidence is set only when the caller explicitly requested it.
	DiscoveryID       int64
	DiscoveryRecorded bool
	DiscoveryError    string
}

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

type MessageRetention struct {
	RetainedMessages int
	OldestAt         time.Time
	MaxMessages      int
}

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 New

func New(opts Options) (*Node, error)

New validates dependencies and constructs the node.

func (*Node) AddPeer

func (n *Node) AddPeer(ctx context.Context, multiaddr string) (network.PeerEntry, error)

AddPeer performs a manual peer add via the local API.

func (*Node) CancelOutbox

func (n *Node) CancelOutbox(ctx context.Context, messageID string) error

CancelOutbox cancels one pending entry; terminal entries are rejected.

func (*Node) Connect

func (n *Node) Connect(ctx context.Context, peerID, multiaddr string) (ConnectResult, error)

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 (n *Node) ConnectListedPeer(ctx context.Context, peerID string, addrs []string) (ConnectResult, error)

func (*Node) DHTFindPeer

func (n *Node) DHTFindPeer(ctx context.Context, peerID string) (network.DHTPeer, error)

DHTFindPeer performs a real DHT lookup with a cache fallback source label.

func (*Node) DHTStatus

func (n *Node) DHTStatus() network.DHTStatus

DHTStatus returns DHT diagnostics.

func (*Node) Disconnect

func (n *Node) Disconnect(ctx context.Context, peerID string) error

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 (n *Node) FetchManifest(ctx context.Context, peerID string, offset, limit int) (PeerManifest, error)

func (*Node) Friends

func (n *Node) Friends(ctx context.Context) ([]Friend, error)

Friends lists local friend rows.

func (*Node) GetPeerFriends

func (n *Node) GetPeerFriends(ctx context.Context, peerID string) (PeerFriends, error)

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 (n *Node) GetPeerProfile(ctx context.Context, peerID string) (PeerProfile, error)

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

func (n *Node) ListFriends(ctx context.Context) ([]Friend, error)

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

func (n *Node) ListOutbox(ctx context.Context, limit int) ([]OutboxEntry, error)

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

func (n *Node) PausePeer(ctx context.Context, peerID string) error

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

func (n *Node) Published(ctx context.Context) (Published, error)

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

func (n *Node) RecentMessages(ctx context.Context, limit int) ([]StoredMessage, error)

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

func (n *Node) ResumePeer(ctx context.Context, pid peer.ID) error

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

func (n *Node) SetFriendName(ctx context.Context, peerID, name string) (Friend, error)

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

func (n *Node) Start(ctx context.Context) error

Start launches the network subsystems, then registers the chat protocol and connection notifiee.

func (*Node) Status

func (n *Node) Status(ctx context.Context) (Status, error)

Status returns a point-in-time view. Cached peer hints are listed with Online=false; they are never reported as reachable.

func (*Node) Stop

func (n *Node) Stop(context.Context) error

Stop unregisters notifications and closes the network and storage.

func (*Node) Subscribe

func (n *Node) Subscribe(ctx context.Context) (<-chan Event, func(), error)

Subscribe returns a buffered event channel and a cancel function.

func (*Node) SyncFriends

func (n *Node) SyncFriends(ctx context.Context) (bool, error)

SyncFriends regenerates public/friends.json immediately.

func (*Node) ViewFriends

func (n *Node) ViewFriends(ctx context.Context, peerID string) (PeerFriends, error)

func (*Node) ViewProfile

func (n *Node) ViewProfile(ctx context.Context, peerID string) (PeerProfile, error)

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

type OutboxStats struct {
	Pending      int
	Acked        int
	Failed       int
	Cancelled    int
	PendingBytes int64
}

OutboxStats is the bounded outbox accounting view.

type PeerEntry

type PeerEntry = network.PeerEntry

G2 public type aliases keep the local API dependent on node, not on network internals directly.

type PeerFriend

type PeerFriend struct {
	Name        string
	PeerID      string
	Addrs       []string
	Description string
}

type PeerFriends

type PeerFriends struct {
	PeerID  string
	Friends []PeerFriend
	Limited bool
}

type PeerManifest

type PeerManifest struct {
	Version   int
	PeerID    string
	Generated time.Time
	Entries   []content.Entry
	Total     int
	Limited   bool
}

type PeerProfile

type PeerProfile struct {
	PeerID string
	Name   string
	Text   string
	Files  []string
	Found  bool
}

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

type PublishedFile struct {
	Path string
	Size int64
}

PublishedFile is one file in the local public manifest.

type PublishedSkip

type PublishedSkip struct {
	Path   string
	Reason string
}

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.

Jump to

Keyboard shortcuts

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