Documentation
¶
Index ¶
- Constants
- func BindMain(syncPhrase string)
- func ComputePeerListHash(peerIDs []string) []byte
- func PeerMain(initMode bool)
- func VerifySignedUpdate(signedUpdate SignedUpdate, publicKey ed25519.PublicKey) bool
- type Core
- func (c *Core) BindNewPeer(syncPhrase string) error
- func (c *Core) DB() *database.EndershareDB
- func (c *Core) GetNodeID() string
- func (c *Core) GetOtherPeerIDs() []string
- func (c *Core) GetPeerStatus(peerID string) (isOnline bool, lastSeen time.Time)
- func (c *Core) IsMaster() bool
- func (c *Core) PublishDataUpdate(action string, key, value []byte, size int64, hash []byte) error
- func (c *Core) PublishPeerUpdate(action string, peerID string, addrs []string) error
- func (c *Core) ReplacePeers(peers []peer.AddrInfo)
- func (c *Core) RequestDataBucketHashes(from peer.ID, bucketIndices []int, numBuckets int) (map[int][][]byte, error)
- func (c *Core) RequestLatestUpdate()
- func (c *Core) RequestMetadata(from peer.ID, hashes [][]byte) ([]MetadataEntry, error)
- func (c *Core) RequestPeerList(peerID peer.ID) ([]PeerInfoResponse, error)
- func (c *Core) RequestTreeBucketHashes(from peer.ID, numBuckets int) [][]byte
- func (c *Core) StartBinding(ctx context.Context, onComplete func(info *p2p.ClientInfo)) (string, error)
- func (c *Core) Storage() *storage.Storage
- type DataBucketHashesRequest
- type DataBucketHashesResponse
- type DataUpdate
- type FileDataRequest
- type MetadataEntry
- type PeerInfoResponse
- type PeerUpdate
- type SignedUpdate
- type TreeBucketHashesRequest
- type Update
Constants ¶
const FILE_STREAM_CHUNK_SIZE = 64 * 1024
Variables ¶
This section is empty.
Functions ¶
func BindMain ¶
func BindMain(syncPhrase string)
BindMain (CLI only) is called by a master node to authorize a new replica peer
func ComputePeerListHash ¶
ComputePeerListHash creates a BLAKE3 hash of sorted peer IDs
func PeerMain ¶
func PeerMain(initMode bool)
PeerMain (CLI only) is the unified entry point for all nodes (both master and replica)
func VerifySignedUpdate ¶
func VerifySignedUpdate(signedUpdate SignedUpdate, publicKey ed25519.PublicKey) bool
VerifySignedUpdate verifies the signature over the canonical update bytes
Types ¶
type Core ¶
type Core struct {
OnDataUpdated func() // Called when data is synced from another device
// contains filtered or unexported fields
}
func NewCore ¶
NewCore creates and initializes a Core instance for use with the UI. It starts the P2P node and background sync but does not block.
func NewCoreForBinding ¶
func NewCoreForBinding(db *database.EndershareDB, keys *crypto.CryptoKeys) (*Core, error)
NewCoreForBinding creates a Core instance for replica binding (no master keys yet)
func (*Core) BindNewPeer ¶
BindNewPeer discovers and authorizes a new replica peer using the sync phrase
func (*Core) GetOtherPeerIDs ¶
func (*Core) GetPeerStatus ¶
GetPeerStatus returns whether a peer is currently connected and when it was last seen
func (*Core) PublishDataUpdate ¶
PublishDataUpdate creates and broadcasts a data update (ADD or DELETE)
func (*Core) PublishPeerUpdate ¶
PublishPeerUpdate creates and broadcasts a peer update (ADD or REMOVE)
func (*Core) ReplacePeers ¶
ReplacePeers updates the P2P node's in-memory peer map
func (*Core) RequestDataBucketHashes ¶
func (c *Core) RequestDataBucketHashes(from peer.ID, bucketIndices []int, numBuckets int) (map[int][][]byte, error)
RequestDataBucketHashes requests data entry hashes for multiple buckets from a peer
func (*Core) RequestLatestUpdate ¶
func (c *Core) RequestLatestUpdate()
RequestLatestUpdate sends a request to all peers for their latest update
func (*Core) RequestMetadata ¶
RequestMetadata requests metadata for a list of hashes from a peer Returns partial results if peer closes stream early (missing hash)
func (*Core) RequestPeerList ¶
func (c *Core) RequestPeerList(peerID peer.ID) ([]PeerInfoResponse, error)
RequestPeerList requests the full peer list from a connected peer
func (*Core) RequestTreeBucketHashes ¶
RequestTreeBucketHashes requests merkle tree bucket hashes from a peer
func (*Core) StartBinding ¶
func (c *Core) StartBinding(ctx context.Context, onComplete func(info *p2p.ClientInfo)) (string, error)
StartBinding starts the binding process for a replica node Returns the 4-word sync phrase and calls onComplete when binding finishes
type DataBucketHashesRequest ¶
type DataBucketHashesRequest struct {
BucketIndices []int `json:"bucket_indices"`
NumBuckets int `json:"num_buckets"`
}
DataBucketHashesRequest requests data entry hashes for multiple buckets
type DataBucketHashesResponse ¶
type DataBucketHashesResponse struct {
BucketIndex int `json:"bucket_index"`
Hashes [][]byte `json:"hashes"`
}
DataBucketHashesResponse contains hashes for a specific bucket
type DataUpdate ¶
type DataUpdate struct {
Action string `json:"action"` // "ADD", "MODIFY", "DELETE"
Key []byte `json:"key"`
Value []byte `json:"value,omitempty"` // File hash for files, nil for folders
Size int64 `json:"size,omitempty"` // Size of file, 0 for folders
Hash []byte `json:"hash,omitempty"` // For ADD/MODIFY, omitted for DELETE
}
type FileDataRequest ¶
type FileDataRequest struct {
FileHash []byte `json:"file_hash"`
Offset int64 `json:"offset"`
Length int64 `json:"length"`
}
FileDataRequest requests file data with offset support
type MetadataEntry ¶
type MetadataEntry struct {
Hash []byte `json:"hash"`
Key []byte `json:"key"`
Value []byte `json:"value"`
Size int64 `json:"size"`
}
MetadataEntry represents a data table entry for protocol response
type PeerInfoResponse ¶
type PeerInfoResponse struct {
PeerID string `json:"peer_id"`
Addresses []string `json:"addresses"`
}
PeerInfoResponse represents peer information for protocol response
type PeerUpdate ¶
type SignedUpdate ¶
type SignedUpdate struct {
UpdateBytes []byte `json:"update_bytes"` // Canonical JSON bytes of the update
Signature []byte `json:"signature"`
}
func SignUpdate ¶
func SignUpdate(update Update, privateKey ed25519.PrivateKey) (SignedUpdate, error)
func (*SignedUpdate) GetUpdate ¶
func (s *SignedUpdate) GetUpdate() (Update, error)
GetUpdate unmarshals the Update from SignedUpdate.UpdateBytes
type TreeBucketHashesRequest ¶
type TreeBucketHashesRequest struct {
NumBuckets int `json:"num_buckets"`
}
TreeBucketHashesRequest requests merkle tree bucket hashes
type Update ¶
type Update struct {
UpdateID uint64 `json:"update_id"`
PeerListHash []byte `json:"peer_list_hash"`
PrevPeerListHash []byte `json:"prev_peer_list_hash"`
DataHash []byte `json:"data_hash"`
PrevDataHash []byte `json:"prev_data_hash"`
NumBuckets int `json:"num_buckets"`
UpdateDataType string `json:"update_data_type"` // "PEER" or "DATA"
UpdateData interface{} `json:"update_data"`
Timestamp int64 `json:"timestamp"`
}