core

package
v0.0.0-...-4937328 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

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

func ComputePeerListHash(peerIDs []string) []byte

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

func NewCore() (*Core, error)

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

func (c *Core) BindNewPeer(syncPhrase string) error

BindNewPeer discovers and authorizes a new replica peer using the sync phrase

func (*Core) DB

func (c *Core) DB() *database.EndershareDB

DB returns the database instance

func (*Core) GetNodeID

func (c *Core) GetNodeID() string

GetNodeID returns this node's peer ID as a string

func (*Core) GetOtherPeerIDs

func (c *Core) GetOtherPeerIDs() []string

func (*Core) GetPeerStatus

func (c *Core) GetPeerStatus(peerID string) (isOnline bool, lastSeen time.Time)

GetPeerStatus returns whether a peer is currently connected and when it was last seen

func (*Core) IsMaster

func (c *Core) IsMaster() bool

IsMaster returns true if this node has the master private key

func (*Core) PublishDataUpdate

func (c *Core) PublishDataUpdate(action string, key, value []byte, size int64, hash []byte) error

PublishDataUpdate creates and broadcasts a data update (ADD or DELETE)

func (*Core) PublishPeerUpdate

func (c *Core) PublishPeerUpdate(action string, peerID string, addrs []string) error

PublishPeerUpdate creates and broadcasts a peer update (ADD or REMOVE)

func (*Core) ReplacePeers

func (c *Core) ReplacePeers(peers []peer.AddrInfo)

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

func (c *Core) RequestMetadata(from peer.ID, hashes [][]byte) ([]MetadataEntry, error)

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

func (c *Core) RequestTreeBucketHashes(from peer.ID, numBuckets int) [][]byte

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

func (*Core) Storage

func (c *Core) Storage() *storage.Storage

Storage returns the storage instance for file operations

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 PeerUpdate struct {
	Action    string   `json:"action"` // "ADD" or "REMOVE"
	PeerID    string   `json:"peer_id"`
	Addresses []string `json:"addresses,omitempty"` // Only for ADD
}

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"`
}

Jump to

Keyboard shortcuts

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