Add Fleet Torrent erasure extension with shard DHT and gossip.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Content-addressed shard DHT on seeder agents with subnet_primary_seeder election, cross-subnet fleet_torrent_gossip, BGP swarm magnets, C2 torrent manifest, and k-of-n peer fetch with C2 fallback.
This commit is contained in:
67
server/internal/atlas/fleet_gossip.go
Normal file
67
server/internal/atlas/fleet_gossip.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package atlas
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Fleet gossip kinds — shard DHT advertisements relayed fleet-wide (not LAN-only).
|
||||
const (
|
||||
FleetGossipHaveShard = "have_shard"
|
||||
FleetGossipHealthy = "healthy"
|
||||
FleetGossipKnowNode = "know_node"
|
||||
)
|
||||
|
||||
// FleetGossipRecord is one peer advertisement in the fleet torrent DHT.
|
||||
type FleetGossipRecord struct {
|
||||
Kind string `json:"kind"`
|
||||
AgentID string `json:"agent_id,omitempty"`
|
||||
Subnet string `json:"subnet,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
ShardIndex int `json:"shard_index,omitempty"`
|
||||
ShardHash string `json:"shard_hash,omitempty"`
|
||||
TargetAgentID string `json:"target_agent_id,omitempty"`
|
||||
Healthy bool `json:"healthy,omitempty"`
|
||||
FetchURL string `json:"fetch_url,omitempty"`
|
||||
}
|
||||
|
||||
// NormalizeFleetGossipRecord validates and trims one fleet gossip record.
|
||||
func NormalizeFleetGossipRecord(r FleetGossipRecord) (FleetGossipRecord, bool) {
|
||||
r.Kind = strings.TrimSpace(strings.ToLower(r.Kind))
|
||||
r.AgentID = strings.TrimSpace(r.AgentID)
|
||||
r.Subnet = strings.TrimSpace(r.Subnet)
|
||||
r.Token = strings.TrimSpace(r.Token)
|
||||
r.ShardHash = strings.TrimSpace(strings.ToLower(r.ShardHash))
|
||||
r.TargetAgentID = strings.TrimSpace(r.TargetAgentID)
|
||||
r.FetchURL = strings.TrimSpace(r.FetchURL)
|
||||
switch r.Kind {
|
||||
case FleetGossipHaveShard:
|
||||
if r.AgentID == "" || r.Token == "" || r.ShardHash == "" {
|
||||
return FleetGossipRecord{}, false
|
||||
}
|
||||
case FleetGossipHealthy:
|
||||
if r.AgentID == "" {
|
||||
return FleetGossipRecord{}, false
|
||||
}
|
||||
case FleetGossipKnowNode:
|
||||
if r.AgentID == "" || r.TargetAgentID == "" {
|
||||
return FleetGossipRecord{}, false
|
||||
}
|
||||
default:
|
||||
return FleetGossipRecord{}, false
|
||||
}
|
||||
return r, true
|
||||
}
|
||||
|
||||
// NormalizeFleetGossipRecords drops invalid records while preserving order.
|
||||
func NormalizeFleetGossipRecords(in []FleetGossipRecord) []FleetGossipRecord {
|
||||
if len(in) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]FleetGossipRecord, 0, len(in))
|
||||
for _, r := range in {
|
||||
if norm, ok := NormalizeFleetGossipRecord(r); ok {
|
||||
out = append(out, norm)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
16
server/internal/atlas/fleet_gossip_test.go
Normal file
16
server/internal/atlas/fleet_gossip_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package atlas
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeFleetGossipRecords(t *testing.T) {
|
||||
in := []FleetGossipRecord{
|
||||
{Kind: FleetGossipHaveShard, AgentID: "a", Token: "tok", ShardHash: "abc"},
|
||||
{Kind: "bogus"},
|
||||
{Kind: FleetGossipHealthy, AgentID: "b", Healthy: true},
|
||||
{Kind: FleetGossipKnowNode, AgentID: "a", TargetAgentID: "c"},
|
||||
}
|
||||
out := NormalizeFleetGossipRecords(in)
|
||||
if len(out) != 3 {
|
||||
t.Fatalf("got %d records", len(out))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user