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:
49
server/internal/erasure/torrent_test.go
Normal file
49
server/internal/erasure/torrent_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package erasure
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBuildTorrentManifestMagnet(t *testing.T) {
|
||||
p := DefaultParams()
|
||||
hashes := []string{"aa", "bb", "cc", "dd", "ee", "ff"}
|
||||
m, err := BuildTorrentManifest("http://c2:8989", "deadbeef", "abc123", 1024, p, hashes)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m.SwarmMagnet == "" || m.ManifestURL == "" {
|
||||
t.Fatalf("manifest=%+v", m)
|
||||
}
|
||||
if len(m.ShardManifestURLs) != 6 {
|
||||
t.Fatalf("urls=%d", len(m.ShardManifestURLs))
|
||||
}
|
||||
if m.Shards[0].URL != "http://c2:8989/api/v1/public/erasure-shard/deadbeef/0" {
|
||||
t.Fatalf("shard url=%q", m.Shards[0].URL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwarmMagnetLink(t *testing.T) {
|
||||
m := SwarmMagnetLink("tok12345678", "deadbeef")
|
||||
if m == "" || !contains(m, "urn:aetherforge:erasure:tok12345678") {
|
||||
t.Fatalf("magnet=%q", m)
|
||||
}
|
||||
}
|
||||
|
||||
func contains(s, sub string) bool {
|
||||
return len(s) >= len(sub) && (s == sub || len(sub) == 0 || indexOf(s, sub) >= 0)
|
||||
}
|
||||
|
||||
func indexOf(s, sub string) int {
|
||||
for i := 0; i+len(sub) <= len(s); i++ {
|
||||
if s[i:i+len(sub)] == sub {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func TestShardContentHash(t *testing.T) {
|
||||
h1 := ShardContentHash([]byte("shard-a"))
|
||||
h2 := ShardContentHash([]byte("shard-b"))
|
||||
if h1 == h2 || len(h1) != 64 {
|
||||
t.Fatalf("hash=%q", h1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user