p2p

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Protocol IDs for different sync operations
	ManifestProtocolID   = "/sietch/manifest/1.0.0"
	ManifestProtocolIDv0 = "/sietch/manifest/0.9.0" // Fallback version
	ChunkProtocolID      = "/sietch/chunk/1.0.0"
	KeyExchangeProtocol  = "/sietch/key-exchange/1.0.0"
	AuthProtocol         = "/sietch/auth/1.0.0"

	// RSA encryption chunk size (must be smaller than key size to account for padding)
	RSAChunkSize = 256 // For 2048-bit keys
)

Variables

This section is empty.

Functions

func CreateLibp2pHost

func CreateLibp2pHost(port int) (host.Host, error)

CreateLibp2pHost creates a new libp2p host listening on the specified port. If port is 0, the system will choose an available port.

Types

type Factory

type Factory struct{}

func NewFactory

func NewFactory() *Factory

NewFactory creates a new discovery factory

func (*Factory) CreateDHT

func (f *Factory) CreateDHT(ctx context.Context, h host.Host, bootstrapAddrs []multiaddr.Multiaddr) (config.Discovery, error)

CreateDHT creates a DHT-based discovery service

func (*Factory) CreateMDNS

func (f *Factory) CreateMDNS(h host.Host) (config.Discovery, error)

CreateMDNS creates an mDNS discovery service

type MDNSDiscovery

type MDNSDiscovery struct {
	// contains filtered or unexported fields
}

MDNSDiscovery implements the config.Discovery interface using mDNS

func NewMDNSDiscovery

func NewMDNSDiscovery(h host.Host) (*MDNSDiscovery, error)

NewMDNSDiscovery creates a new mDNS discovery service

func (*MDNSDiscovery) DiscoveredPeers

func (m *MDNSDiscovery) DiscoveredPeers() <-chan peer.AddrInfo

DiscoveredPeers returns channel of found peers

func (*MDNSDiscovery) GetPeerChan

func (m *MDNSDiscovery) GetPeerChan() chan peer.AddrInfo

GetPeerChan returns the peer channel for notifee configuration

func (*MDNSDiscovery) SetService

func (m *MDNSDiscovery) SetService(service mdns.Service)

SetService sets the mDNS service

func (*MDNSDiscovery) Start

func (m *MDNSDiscovery) Start(ctx context.Context) error

Start initiates the discovery process

func (*MDNSDiscovery) Stop

func (m *MDNSDiscovery) Stop() error

Stop halts the discovery process

type MdnsNotifee

type MdnsNotifee struct {
	// contains filtered or unexported fields
}

mdnsNotifee gets notified when new peers are discovered via mDNS

func (*MdnsNotifee) HandlePeerFound

func (n *MdnsNotifee) HandlePeerFound(pi peer.AddrInfo)

HandlePeerFound implements the mdns.Notifee interface

type PeerInfo

type PeerInfo struct {
	ID           peer.ID
	PublicKey    *rsa.PublicKey
	Fingerprint  string
	Name         string
	TrustedSince time.Time
}

PeerInfo contains information about a trusted peer

type SyncResult

type SyncResult struct {
	FileCount          int
	ChunksTransferred  int
	ChunksDeduplicated int
	BytesTransferred   int64
	Duration           time.Duration
}

SyncResult contains statistics about a sync operation

type SyncService

type SyncService struct {
	Verbose bool // Enable verbose debug output
	// contains filtered or unexported fields
}

SyncService handles vault synchronization

func NewSecureSyncService

func NewSecureSyncService(
	h host.Host,
	vm *config.Manager,
	privateKey *rsa.PrivateKey,
	publicKey *rsa.PublicKey,
	rsaConfig *config.RSAConfig,
) (*SyncService, error)

NewSecureSyncService creates a new secure sync service with RSA key support

func NewSyncService

func NewSyncService(h host.Host, vm *config.Manager) (*SyncService, error)

NewSyncService creates a new sync service

func (*SyncService) AddTrustedPeer

func (s *SyncService) AddTrustedPeer(ctx context.Context, peerID peer.ID) error

AddTrustedPeer adds a peer to the trusted peers list and saves to config

func (*SyncService) GetPeerFingerprint

func (s *SyncService) GetPeerFingerprint(peerID peer.ID) (string, error)

GetPeerFingerprint returns the fingerprint of a peer's public key

func (*SyncService) HasPeer

func (s *SyncService) HasPeer(id peer.ID) bool

HasPeer returns true if peer is already in trustedPeers map

func (*SyncService) RegisterProtocols

func (s *SyncService) RegisterProtocols(ctx context.Context)

RegisterProtocols sets up all protocol handlers

func (*SyncService) SetTrustAllPeers

func (s *SyncService) SetTrustAllPeers(trustAll bool)

SetTrustAllPeers sets whether to automatically trust all peers

func (*SyncService) StoreChunk

func (s *SyncService) StoreChunk(hash string, data []byte, encryptedHash string) error

StoreChunk stores a chunk and handles the relationship between regular and encrypted hashes

func (*SyncService) SyncWithPeer

func (s *SyncService) SyncWithPeer(ctx context.Context, peerID peer.ID) (*SyncResult, error)

SyncWithPeer performs a sync operation with a specific peer

func (*SyncService) VerifyAndExchangeKeys

func (s *SyncService) VerifyAndExchangeKeys(ctx context.Context, peerID peer.ID) (bool, error)

VerifyAndExchangeKeys performs key exchange with a peer

Jump to

Keyboard shortcuts

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