Documentation
¶
Overview ¶
coherence.go — 3-layer coherence validation for constellation nodes.
Validates the integrity of a node's event ledger:
- Hash chain integrity (event[i].prior_hash == hash(event[i-1]))
- Schema validation (required fields present, valid timestamps)
- Temporal monotonicity (timestamps non-decreasing, sequences contiguous)
constellation.go — Trust scoring and identity conflict detection.
Trust is tracked per-peer via exponential moving average (EMA) of heartbeat consistency. Thresholds: trusted >= 0.7, pending >= 0.4, suspect >= 0.2, rejected < 0.2.
gitstore.go — In-process git repository for event storage.
Uses go-git/v5 to manage a bare git repo where events are committed as individual JSON files under events/{seq:08d}.json. The tree hash of the events/ directory serves as the node's state fingerprint for mutual verification.
heartbeat.go — Background heartbeat ticker and peer communication.
Every 5 seconds: generate a simulated event, append to ledger, commit to git, sign the state snapshot, POST to all known peers.
identity.go — ECDSA P-256 identity for constellation nodes.
Adapted from apps/cogos/bep_tls.go. Simplified to just key operations: generate, load, sign, verify, and NodeID derivation (SHA-256 of pubkey DER).
ledger.go — Hash-chained event ledger for constellation nodes.
Adapted from apps/cogos-v3/ledger.go. Events are canonicalized (RFC 8785), hashed (SHA-256), and chained via prior_hash fields.
node.go — Constellation node lifecycle.
A Node holds its identity (ECDSA keypair), git-backed event store, peer registry, and coherence state. It manages startup (init repo, load/generate keys) and graceful shutdown.
protocol.go — HTTP handlers for inter-node communication.
Endpoints:
POST /heartbeat — receive peer heartbeat GET /peers — list peers + trust state POST /challenge — request event range verification POST /join — new node announces itself GET /health — self coherence check GET /state — full dump for testing
run.go — Constellation Protocol PoC CLI entry point.
Subcommands:
node — Start a constellation node inject — Inject an event into a running node tamper — Corrupt an event in a node's git store status — Query a node's state and peer trust
Index ¶
- Constants
- func CanonicalizeEvent(payload *EventPayload) ([]byte, error)
- func FormatNodeID(nodeID string) string
- func HashEvent(canonicalBytes []byte) string
- func PublicKeyFromDER(der []byte) (*ecdsa.PublicKey, error)
- func RegisterHandlers(mux *http.ServeMux, node *Node)
- func Run()
- func SaveIdentity(id *NodeIdentity, dir string) error
- func TrustLevel(score float64) string
- func Verify(pubKey *ecdsa.PublicKey, data, signature []byte) bool
- func VerifyHeartbeat(hb *Heartbeat) (bool, *ecdsa.PublicKey, error)
- type CoherenceCheck
- type CoherenceReport
- type EventEnvelope
- type EventMetadata
- type EventPayload
- type GitStore
- func (gs *GitStore) AppendEvent(envelope *EventEnvelope) error
- func (gs *GitStore) CommitHash() (string, error)
- func (gs *GitStore) CorruptEvent(seq int64) error
- func (gs *GitStore) LastEvent() (*EventEnvelope, error)
- func (gs *GitStore) ReadEventRange(startSeq, endSeq int64) ([]*EventEnvelope, error)
- func (gs *GitStore) TreeHash() (string, error)
- type Heartbeat
- type HeartbeatRunner
- type Node
- type NodeIdentity
- type NodeState
- type PeerRegistry
- func (pr *PeerRegistry) AddPeer(addr string)
- func (pr *PeerRegistry) AllPeers() []*PeerState
- func (pr *PeerRegistry) GetByID(nodeID string) *PeerState
- func (pr *PeerRegistry) GetPeer(addr string) *PeerState
- func (pr *PeerRegistry) ProcessHeartbeat(addr string, hb *Heartbeat, pubKey *ecdsa.PublicKey) error
- func (pr *PeerRegistry) Summarize() []PeerSummary
- type PeerState
- type PeerSummary
Constants ¶
const ( TrustThresholdTrusted = 0.7 TrustThresholdPending = 0.4 TrustThresholdSuspect = 0.2 EMADecay = 0.8 IdentityConflictWindow = 30 * time.Second MaxDriftBeforeChallenge = 2 )
Trust thresholds.
Variables ¶
This section is empty.
Functions ¶
func CanonicalizeEvent ¶
func CanonicalizeEvent(payload *EventPayload) ([]byte, error)
CanonicalizeEvent produces RFC 8785 canonical JSON for an event payload.
func FormatNodeID ¶
FormatNodeID returns a short form of the node ID (first 12 hex chars).
func PublicKeyFromDER ¶
PublicKeyFromDER parses an ECDSA public key from DER bytes.
func RegisterHandlers ¶
RegisterHandlers wires up the HTTP mux for a node.
func SaveIdentity ¶
func SaveIdentity(id *NodeIdentity, dir string) error
SaveIdentity writes the private key to disk as PEM.
func TrustLevel ¶
TrustLevel returns a human-readable trust label.
Types ¶
type CoherenceCheck ¶
type CoherenceCheck struct {
Layer string `json:"layer"`
Pass bool `json:"pass"`
Detail string `json:"detail,omitempty"`
}
CoherenceCheck is the result of a single validation layer.
type CoherenceReport ¶
type CoherenceReport struct {
Pass bool `json:"pass"`
Checks []CoherenceCheck `json:"checks"`
Timestamp string `json:"timestamp"`
}
CoherenceReport is the result of validating a node's ledger.
func ValidateCoherence ¶
func ValidateCoherence(events []*EventEnvelope) *CoherenceReport
ValidateCoherence runs all 3 validation layers on a set of events.
type EventEnvelope ¶
type EventEnvelope struct {
HashedPayload EventPayload `json:"hashed_payload"`
Metadata EventMetadata `json:"metadata"`
}
EventEnvelope is the on-disk event shape committed to the git store.
type EventMetadata ¶
EventMetadata is NOT included in the hash.
type EventPayload ¶
type EventPayload struct {
Type string `json:"type"`
Timestamp string `json:"timestamp"`
NodeID string `json:"node_id"`
PriorHash string `json:"prior_hash,omitempty"`
Data map[string]interface{} `json:"data,omitempty"`
}
EventPayload is the content that gets canonicalized and hashed.
type GitStore ¶
type GitStore struct {
// contains filtered or unexported fields
}
GitStore wraps an on-disk git repository for event storage.
func NewGitStore ¶
NewGitStore initializes a new git repository at the given path.
func (*GitStore) AppendEvent ¶
func (gs *GitStore) AppendEvent(envelope *EventEnvelope) error
AppendEvent writes an event to events/{seq:08d}.json and commits it.
func (*GitStore) CommitHash ¶
CommitHash returns the current HEAD commit hash.
func (*GitStore) CorruptEvent ¶
CorruptEvent overwrites an event file with tampered data (for testing).
func (*GitStore) LastEvent ¶
func (gs *GitStore) LastEvent() (*EventEnvelope, error)
LastEvent returns the most recent event, or nil if none.
func (*GitStore) ReadEventRange ¶
func (gs *GitStore) ReadEventRange(startSeq, endSeq int64) ([]*EventEnvelope, error)
ReadEventRange returns events from startSeq to endSeq (inclusive).
type Heartbeat ¶
type Heartbeat struct {
NodeID string `json:"node_id"`
ListenAddr string `json:"listen_addr"` // sender's listening address
TreeHash string `json:"tree_hash"`
Seq int64 `json:"seq"`
LastHash string `json:"last_hash"`
Timestamp string `json:"timestamp"`
PublicKey string `json:"public_key"` // base64-encoded DER
Signature string `json:"signature"` // base64-encoded ASN.1
}
Heartbeat is the signed state snapshot sent to peers.
type HeartbeatRunner ¶
type HeartbeatRunner struct {
// contains filtered or unexported fields
}
HeartbeatRunner manages the background heartbeat loop.
func NewHeartbeatRunner ¶
func NewHeartbeatRunner(node *Node, interval time.Duration) *HeartbeatRunner
NewHeartbeatRunner creates a heartbeat runner.
type Node ¶
type Node struct {
Name string
Identity *NodeIdentity
Store *GitStore
Peers *PeerRegistry
Port int
DataDir string
Hostname string // externally reachable hostname (default: localhost)
// contains filtered or unexported fields
}
Node is a self-referentially closed unit in the constellation.
func (*Node) AppendEvent ¶
AppendEvent creates a new event and commits it to the git store.
func (*Node) CurrentState ¶
CurrentState returns the node's current state snapshot.
func (*Node) ListenAddr ¶
ListenAddr returns the externally reachable address for this node.
func (*Node) SelfCheck ¶
func (n *Node) SelfCheck() (*CoherenceReport, error)
SelfCheck runs coherence validation on the node's own ledger.
type NodeIdentity ¶
type NodeIdentity struct {
PrivateKey *ecdsa.PrivateKey
PublicKey *ecdsa.PublicKey
NodeID string // hex-encoded SHA-256 of DER-encoded public key
}
NodeIdentity holds the ECDSA keypair and derived node ID.
func GenerateIdentity ¶
func GenerateIdentity() (*NodeIdentity, error)
GenerateIdentity creates a new ECDSA P-256 keypair and derives the NodeID.
func LoadIdentity ¶
func LoadIdentity(dir string) (*NodeIdentity, error)
LoadIdentity reads an ECDSA private key from disk.
func (*NodeIdentity) MarshalPublicKey ¶
func (id *NodeIdentity) MarshalPublicKey() ([]byte, error)
MarshalPublicKey returns the DER-encoded public key.
type NodeState ¶
type NodeState struct {
NodeID string `json:"node_id"`
Name string `json:"name"`
Seq int64 `json:"seq"`
LastHash string `json:"last_hash"`
TreeHash string `json:"tree_hash"`
}
NodeState is the snapshot sent in heartbeats.
type PeerRegistry ¶
type PeerRegistry struct {
// contains filtered or unexported fields
}
PeerRegistry manages the set of known peers.
func NewPeerRegistry ¶
func NewPeerRegistry() *PeerRegistry
NewPeerRegistry creates an empty registry.
func (*PeerRegistry) AddPeer ¶
func (pr *PeerRegistry) AddPeer(addr string)
AddPeer registers a peer address (identity learned on first heartbeat).
func (*PeerRegistry) AllPeers ¶
func (pr *PeerRegistry) AllPeers() []*PeerState
AllPeers returns all peer states.
func (*PeerRegistry) GetByID ¶
func (pr *PeerRegistry) GetByID(nodeID string) *PeerState
GetByID returns the state for a node ID.
func (*PeerRegistry) GetPeer ¶
func (pr *PeerRegistry) GetPeer(addr string) *PeerState
GetPeer returns the state for a peer address.
func (*PeerRegistry) ProcessHeartbeat ¶
ProcessHeartbeat updates peer state based on a received heartbeat. Returns an error if an identity conflict is detected.
func (*PeerRegistry) Summarize ¶
func (pr *PeerRegistry) Summarize() []PeerSummary
Summarize returns a JSON-friendly summary of all peers.
type PeerState ¶
type PeerState struct {
NodeID string `json:"node_id"`
Addr string `json:"addr"`
PublicKey *ecdsa.PublicKey `json:"-"`
PublicDER []byte `json:"public_key_der,omitempty"`
LastSeq int64 `json:"last_seq"`
LastHash string `json:"last_hash"`
TreeHash string `json:"tree_hash"`
Trust float64 `json:"trust"`
DriftCount int `json:"drift_count"`
LastSeen time.Time `json:"last_seen"`
Rejected bool `json:"rejected"`
}
PeerState tracks a remote peer's last known state and trust.
type PeerSummary ¶
type PeerSummary struct {
NodeID string `json:"node_id"`
Addr string `json:"addr"`
Seq int64 `json:"seq"`
Trust float64 `json:"trust"`
TrustLevel string `json:"trust_level"`
DriftCount int `json:"drift_count"`
LastSeen string `json:"last_seen"`
Rejected bool `json:"rejected,omitempty"`
}
PeerSummary is the JSON-friendly view of a peer.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
constellation
command
cmd/constellation/main.go — Thin entry point for go install support.
|
cmd/constellation/main.go — Thin entry point for go install support. |