Documentation
¶
Overview ¶
Package network implements the CROM P2P networking layer using libp2p.
The network is sovereign: only peers that share the same Codebook BuildHash can communicate. This is enforced at the protocol level via a handshake on /crom/auth/1.0.
Index ¶
- Constants
- Variables
- func GenerateIdentity() error
- func IsPeerTrusted(peerIDStr string) bool
- func LoadIdentity() (crypto.PrivKey, error)
- func ReceiveChunks(tempPath string, outPath string, manifest *cromsync.ChunkManifest, ...) (int64, error)
- func StreamChunks(localPath, codebookPath, encryptionKey string, indices []uint32, ...) error
- func TrustPeer(peerIDStr string) error
- type AnnounceMsg
- type CromFECEngine
- type CromNode
- func (n *CromNode) Addrs() []string
- func (n *CromNode) AnnounceFile(ctx context.Context, filename string, originalSize uint64, chunkCount uint32) error
- func (n *CromNode) AuthenticatePeer(ctx context.Context, pid peer.ID) error
- func (n *CromNode) Context() context.Context
- func (n *CromNode) IsAuthenticated(pid peer.ID) bool
- func (n *CromNode) PeerID() peer.ID
- func (n *CromNode) ProposeUniversalPattern(ctx context.Context, hash string, payload []byte, weight uint32, ...) error
- func (n *CromNode) SetupDHT(bootstrapAddrs []string, private bool) error
- func (n *CromNode) Stop() error
- type GossipManager
- type Identity
- type ProposeChunkMsg
- type SyncProtocol
Constants ¶
const ( // AuthProtocol is the protocol ID for the sovereignty handshake. AuthProtocol = "/crom/auth/2.0" // AuthTimeout is the maximum time allowed for the handshake. AuthTimeout = 10 * time.Second )
const ( MsgSyncReq byte = 0x01 // Request a manifest for a specific original file hash (or filename) MsgManifest byte = 0x02 // The serialized ChunkManifest MsgDiffReq byte = 0x03 // Request missing chunks (payload is array of indices) MsgChunkData byte = 0x04 // Raw delta payload MsgError byte = 0xFF // Error message )
Message Types
const (
// SyncProtocolID is the identifier for the CROM manifest exchange protocol.
SyncProtocolID = "/crom/sync/1.0"
)
Variables ¶
var DefaultBootstrapPeers = []string{
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
}
DefaultBootstrapPeers returns the default set of IPFS bootstrap peers. In a real private network, these would be dedicated bootstrap nodes for CROM.
Functions ¶
func GenerateIdentity ¶
func GenerateIdentity() error
GenerateIdentity creates a new Ed25519 keypair for libp2p
func IsPeerTrusted ¶
IsPeerTrusted checks if a peer is in the Web of Trust
func LoadIdentity ¶
LoadIdentity loads the libp2p private key from disk
func ReceiveChunks ¶
func ReceiveChunks(tempPath string, outPath string, manifest *cromsync.ChunkManifest, missingIndices []uint32, s network.Stream, codebookPath string, encryptionKey string) (int64, error)
ReceiveChunks reads streamed deltas and rebuilds the .crom file, taking the chunks it already has from the local version. It returns the bytes read from the network.
Types ¶
type AnnounceMsg ¶
type AnnounceMsg struct {
Type string `json:"type"` // "NEW_FILE" or "CODEBOOK_UPDATE"
Filename string `json:"filename"` // Basename of the .crom file
OriginalSize uint64 `json:"original_size"` // Size of the original uncompressed file
ChunkCount uint32 `json:"chunk_count"` // Total chunks
Sender string `json:"sender"` // Peer ID of the announcer
}
AnnounceMsg represents a GossipSub message announcing a new or updated file.
type CromFECEngine ¶
CromFECEngine provides Forward Error Correction using Reed-Solomon style mathematical matrices. This layer shields Kademlia Bitswap in LEO-Satellite or 4G Android connections: Missing P2P TCP chunks are RECONSTRUCTED algebraically instead of draining radio battery by re-asking peers.
func NewFECEngine ¶
func NewFECEngine(dataShards, parityShards int) *CromFECEngine
NewFECEngine launches the Erasure Coding mathematical grid protector.
func (*CromFECEngine) Encode ¶
func (fec *CromFECEngine) Encode(chunk []byte) ([][]byte, [][]byte, error)
Encode generates mathematical parity shards (Polynomials) for a given raw chunk payload.
func (*CromFECEngine) Reconstruct ¶
func (fec *CromFECEngine) Reconstruct(shards [][]byte) ([]byte, error)
Reconstruct validates and mathematically reconstructs missing data shards utilizing active Parity Shards via Vandermonde matrix parsing.
type CromNode ¶
type CromNode struct {
Host host.Host
DHT *dht.IpfsDHT
PubSub *pubsub.PubSub
CodebookHash [32]byte // SHA-256 BuildHash — defines the network partition
DataDir string // Directory containing local .crom files
EncKey string // AES passphrase for encrypted files
CodebookPath string // Path to the .cromdb file
// contains filtered or unexported fields
}
CromNode is the main P2P node for the CROM network.
func NewCromNode ¶
func NewCromNode(codebookPath string, listenPort int, dataDir string, encKey string) (*CromNode, error)
NewCromNode creates and starts a libp2p host bound to the given codebook. The node identity (Ed25519 keypair) is persisted in dataDir/peer.key.
func (*CromNode) AnnounceFile ¶
func (n *CromNode) AnnounceFile(ctx context.Context, filename string, originalSize uint64, chunkCount uint32) error
AnnounceFile publishes a NEW_FILE message to the network.
func (*CromNode) AuthenticatePeer ¶
AuthenticatePeer initiates the handshake with a remote peer. Must be called after establishing a connection before any other protocol.
func (*CromNode) IsAuthenticated ¶
IsAuthenticated reports whether the peer proved it holds the same brain.
func (*CromNode) ProposeUniversalPattern ¶
func (n *CromNode) ProposeUniversalPattern(ctx context.Context, hash string, payload []byte, weight uint32, signature []byte) error
ProposeUniversalPattern publishes a PROPOSE_CHUNK message to federate learning.
type GossipManager ¶
type GossipManager struct {
// contains filtered or unexported fields
}
GossipManager handles pubsub operations for the node.
type Identity ¶
type Identity struct {
PrivKeyBytes []byte `json:"privKey"`
PubKeyBytes []byte `json:"pubKey"`
PeerID string `json:"peerID"`
}
Identity struct stores the keys locally
type ProposeChunkMsg ¶
type ProposeChunkMsg struct {
Type string `json:"type"` // "PROPOSE_CHUNK"
Hash string `json:"hash"` // Hash of the chunk
Payload []byte `json:"payload"` // Raw chunk data
Weight uint32 `json:"weight"` // Recurrency score
Signature []byte `json:"signature"` // Ed25519 signature of the sender
Sender string `json:"sender"` // Peer ID
}
ProposeChunkMsg represents a federated learning proposal for a universal chunk.
type SyncProtocol ¶
type SyncProtocol struct {
// BytesReceived counts what the last RequestSync read from the network.
BytesReceived int64
// contains filtered or unexported fields
}
SyncProtocol handles manifest exchange and chunk transfers.
func NewSyncProtocol ¶
func NewSyncProtocol(node *CromNode) *SyncProtocol
NewSyncProtocol registers the sync stream handler.
func (*SyncProtocol) RequestSync ¶
RequestSync is called proactively by a node to download a file from a remote peer. Flow: 0. Codebook Handshake (hash exchange, download if mismatch) 1. Sends SYNC_REQ 2. Receives MANIFEST 3. Diff against local (if file exists) or request all chunks 4. Send DIFF_REQ with missing indices 5. Receive CHUNK_DATA stream and rebuild