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 ¶
- Variables
- func NewPeerCache(store *storage.Store) network.PeerCache
- type AckEvent
- type AutoNATStatus
- type CachedPeer
- type ChatEvent
- type ConnectResult
- type ConnectionEvent
- type DCUtRStatus
- type DHTPeer
- type DHTStatus
- type DialAttempt
- type DownloadProgress
- type DownloadResult
- type Event
- type Friend
- 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) 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) ListFriends(ctx context.Context) ([]Friend, 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) 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 Published
- type PublishedFile
- type PublishedSkip
- type RelayProviderStatus
- type RelayReservation
- type ResourceStatus
- type SendResult
- type Status
- type StoredMessage
Constants ¶
This section is empty.
Variables ¶
var ( ErrFriendNotFound = storage.ErrFriendNotFound ErrFriendNameTaken = storage.ErrFriendNameTaken ErrFriendPendingOutbox = storage.ErrFriendPendingOutbox )
Friend sentinel errors are stable API-facing aliases for the storage errors.
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 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 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 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)) (DownloadResult, error)
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) ListFriends ¶
ListFriends is the API-facing alias for Friends.
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. 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.
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.
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 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
}
SendResult is the outcome of one SendChat call. Acked is true only when a matching ACK was received and its ACK state was persisted.
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
}
Status is a point-in-time view of the running node.