Skip to content

Commit 06aa1a4

Browse files
committed
RobustSolitonDistribution
1 parent 902bda2 commit 06aa1a4

File tree

7 files changed

+38
-28
lines changed

7 files changed

+38
-28
lines changed

StartNodes.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ rm -rf output
99
mkdir output
1010

1111
# Number of regular nodes to start
12-
NUM_NODES=10
12+
NUM_NODES=41
1313
PORT_BASE=4007
1414
BOOTSTRAP_PORT_BASE=4001
15-
BOOTSTRAP_NODES=1
15+
BOOTSTRAP_NODES=4
1616
BOOTSTRAP_READY_TIMEOUT=30
1717
IP_BASE="127.0.0."
1818
CODING_METHOD="RS"

cmd/main.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func main() {
187187
config.StartTime = time.Now()
188188
fmt.Println("Broadcasting chunks...")
189189

190-
originalFilePath := "test.txt"
190+
originalFilePath := "eth_transactions.json"
191191
originalData, err := os.ReadFile(originalFilePath)
192192
if err != nil {
193193
fmt.Printf("Node %s failed to read original data file: %v\n", *nodeID, err)
@@ -251,16 +251,16 @@ func main() {
251251
receivedFromKey := fmt.Sprintf("%s-%d", pi.ID.String(), index)
252252
origSender, senderOk := config.ReceivedFrom.Load(receivedFromKey)
253253

254-
for _, peerInfo := range config.ConnectedPeers {
255-
if peerInfo.ID != pi.ID && peerInfo.ID.String() != *nodeID && (senderOk && origSender.(string) == config.Node1ID.String()) {
256-
chunkKey := fmt.Sprintf("%s-%d", peerInfo.ID.String(), index)
254+
for i := 0; i < config.ExpectedChunks; i++ {
255+
if config.ConnectedPeers[i].ID != pi.ID && config.ConnectedPeers[i].ID.String() != *nodeID && (senderOk && origSender.(string) == config.Node1ID.String()) {
256+
chunkKey := fmt.Sprintf("%s-%d", config.ConnectedPeers[i].ID.String(), index)
257257
if _, ok := config.SentChunks.Load(chunkKey); !ok {
258-
fmt.Printf("Sending chunk %d to %s\n", index, peerInfo.ID.String())
259-
handlers.SendChunk(context.Background(), h, peerInfo, index, chunk)
258+
fmt.Printf("Sending chunk %d to %s\n", index, config.ConnectedPeers[i].ID.String())
259+
handlers.SendChunk(context.Background(), h, config.ConnectedPeers[i], index, chunk)
260260
config.SentChunks.Store(chunkKey, struct{}{})
261261
time.Sleep(50 * time.Millisecond)
262262
} else {
263-
fmt.Printf("Chunk %d already sent to %s\n", index, peerInfo.ID.String())
263+
fmt.Printf("Chunk %d already sent to %s\n", index, config.ConnectedPeers[i].ID.String())
264264
}
265265
}
266266
}

config/config.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"flag"
5+
"math"
56
"sync"
67
"time"
78

@@ -18,31 +19,35 @@ type NodeData struct {
1819

1920
// Must change respected to the codign method
2021
const (
21-
ExpectedChunks = 60
22+
ExpectedChunks = 27
2223
)
2324

2425
// Reed-Solomon parameters
2526
const (
26-
DataShards = 55
27+
DataShards = 100
2728
ParityShards = 10
2829
)
2930

3031
// Luby-Transform parameters
3132
const (
32-
LTSourceBlocks = 50
33-
LTEncodedBlockCount = 65
34-
RandomSeed = 42
33+
LTSourceBlocks = 3
34+
RandomSeed = 42
35+
)
36+
37+
var (
38+
c = 2.0
39+
LTEncodedBlockCount = int(c*math.Sqrt(float64(LTSourceBlocks))) + LTSourceBlocks
3540
)
3641

3742
const (
3843
RaptorSourceBlocks = 10
39-
RaptorEncodedBlockCount = 15
44+
RaptorEncodedBlockCount = 12
4045
)
4146

4247
var (
4348
NodeID string
4449
CodingMethod string
45-
Nodes = 10
50+
Nodes = 30
4651
ReceivedChunks = sync.Map{}
4752
SentChunks = sync.Map{}
4853
NodeMutex = sync.Mutex{}
@@ -56,5 +61,5 @@ var (
5661
ChunksRecByNode = make([][]byte, DataShards+ParityShards)
5762
ReadyCounter = 0
5863
StartTime time.Time
59-
OriginalLength = 29283680
64+
OriginalLength = 188762857
6065
)

lt/ltcodec.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ import (
44
"bytes"
55
"encoding/binary"
66
"fmt"
7+
"math"
78
"math/rand"
89

910
"github.com/xm0onh/AVID-go/config"
1011
gofountain "github.com/xm0onh/AVID-go/gofountain"
1112
)
1213

13-
var degree = gofountain.SolitonDistribution(config.LTSourceBlocks)
14+
// var degree = gofountain.SolitonDistribution(config.LTSourceBlocks)
1415

1516
// var eps = 0.1 // Adjust the epsilon parameter as needed
1617
// var degree = onlineSolitonDistribution(eps)
1718

18-
// var n = config.LTSourceBlocks // Number of source blocks
19-
// var c = 0.1
20-
// var m = int(c * math.Sqrt(float64(n))) // Calculated number of redundant blocks
21-
// var delta = 0.01 // Failure probability
19+
var n = config.LTSourceBlocks // Number of source blocks
20+
var c = 1.5
21+
var m = int(c * math.Sqrt(float64(n))) // Number of encoded blocks
2222

23-
// var degree = robustSolitonDistribution(n, m, delta)
23+
var delta = 0.01 // Failure probability
24+
25+
var degree = gofountain.RobustSolitonDistribution(n, m, delta)
2426

2527
var random = rand.New(rand.NewSource(config.RandomSeed))
2628
var codec = gofountain.NewLubyCodec(config.LTSourceBlocks, random, degree)
2729

2830
func LTEncode(data string) ([][]byte, error) {
29-
31+
fmt.Println(config.LTEncodedBlockCount)
3032
encodedBlockIDs := make([]int64, config.LTEncodedBlockCount)
3133
for i := range encodedBlockIDs {
3234
encodedBlockIDs[i] = int64(i)

lt/ltcodec_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestLTEncodeDecode(t *testing.T) {
1414
// Specify the file path
15-
filePath := "../test.txt"
15+
filePath := "../eth_transactions.json"
1616

1717
// Open the file
1818
file, err := os.Open(filePath)
@@ -32,11 +32,12 @@ func TestLTEncodeDecode(t *testing.T) {
3232

3333
encodeTimeStart := time.Now()
3434
chunks, err := LTEncode(string(originalData))
35+
fmt.Println("Size of each chunk in byte", len(chunks[0]))
3536
fmt.Println("Time taken - Encode: ", time.Since(encodeTimeStart))
3637

3738
assert.NoError(t, err, "LTEncode should not return an error")
3839
assert.NotEmpty(t, chunks, "Encoded chunks should not be empty")
39-
assert.Equal(t, config.LTEncodedBlockCount, len(chunks), "Number of encoded chunks should match LTEncodedBlockCount")
40+
// assert.Equal(t, config.LTEncodedBlockCount, len(chunks), "Number of encoded chunks should match LTEncodedBlockCount")
4041

4142
// Decode the encoded data
4243

raptor/raptor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestRaptorEncodeDecode(t *testing.T) {
1414
// Specify the file path
15-
filePath := "../test.txt"
15+
filePath := "../eth_transactions.json"
1616

1717
// Open the file
1818
file, err := os.Open(filePath)

rs/rs_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestRSEncodeDecode(t *testing.T) {
13-
filePath := "../test.txt"
13+
filePath := "../eth_transactions.json"
1414

1515
// Open the file
1616
file, err := os.Open(filePath)
@@ -27,6 +27,8 @@ func TestRSEncodeDecode(t *testing.T) {
2727
encodeTimeStart := time.Now()
2828
shards, err := RSEncode(string(originalData))
2929
fmt.Println("Time taken - Encode: ", time.Since(encodeTimeStart))
30+
31+
fmt.Println("size of each shard in byte", len(shards))
3032
assert.NoError(t, err, "RSEncode should not return an error")
3133
shards[1] = nil
3234
// fmt.Println("Shards", shards)

0 commit comments

Comments
 (0)