fixed bug, code now is able to broadcast to all nodes

pull/1/head
alok 7 years ago
parent 3a11c6779e
commit 08d9375b75
  1. 45
      README.md
  2. 33
      node.go

@ -9,45 +9,16 @@ https://github.com/lightningnetwork/lnd
https://docs.google.com/document/d/1u-8C9MiEUYPA7QC1Ekg7Cg-yL09ArZIxxyUtCUF9Wp0/edit
#Done
* fan-out
#TODO
#DEBUG
```
0
1
2
3
4
5
6
Leader has sent message gmwjgsapga to 1
7
Leader has sent message gmwjgsapga to 1
Leader has sent message gmwjgsapga to 4
Leader has sent message gmwjgsapga to 6
Leader has sent message gmwjgsapga to 7
Leader has sent message gmwjgsapga to 2
Leader has sent message gmwjgsapga to 1
Leader has sent message gmwjgsapga to 5
8
Leader has sent message gmwjgsapga to 2
9
Leader has sent message gmwjgsapga to 1
Leader has sent message tlmodylumg to 2
Leader has sent message tlmodylumg to 8
Leader has sent message tlmodylumg to 1
Leader has sent message tlmodylumg to 2
Leader has sent message tlmodylumg to 8
Leader has sent message tlmodylumg to 7
Leader has sent message tlmodylumg to 1
Leader has sent message qimgegmgkb to 3
Leader has sent message uqdiwwmnpp to 2
Leader has sent message uqdiwwmnpp to 2
Leader has sent message uqdiwwmnpp to 3
Leader has sent message tlmodylumg to 2
Leader has sent message uqdiwwmnpp to 8
Leader has sent message tlmodylumg to 1
```
* implement block of transactions, instead of individual generators
* instead of _consume_ used leader.send function
* understand when the program terminates and why we don't end up writing all the txns
* simplify code, if it might be a overkill
https://gist.github.com/rushilgupta/228dfdf379121cb9426d5e90d34c5b96

@ -3,6 +3,7 @@ package main
import (
"fmt"
"math/rand"
"time"
)
type Node struct {
@ -35,6 +36,12 @@ func (n Node) send(cin <-chan string, id int) {
}
}
func consume(cin <-chan string, id int) {
for msg := range cin {
fmt.Printf("Leader has sent message %s to %d\n", msg, id)
}
}
func (n Node) receive() {
fmt.Printf("Node: %d received message\n", n.ip)
}
@ -78,6 +85,7 @@ func TxnGenerator(numOfTxns int, lenOfRandomString int) <-chan string {
go func() {
for i := 0; i < numOfTxns; i++ {
out <- randomString(lenOfRandomString)
time.Sleep(2 * time.Second)
}
close(out)
}()
@ -86,9 +94,9 @@ func TxnGenerator(numOfTxns int, lenOfRandomString int) <-chan string {
func main() {
var (
isLeader Node
//isLeader Node
numOfTxns = 1000
numOfTxnsInBlock = 10
numOfNodes = 10
N = make([]Node, 10)
lenOfRandomString = 10
node_ips = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
@ -96,20 +104,15 @@ func main() {
for i := range node_ips {
m := pickLeader(i)
N[i] = m
if m.leader {
isLeader = m
}
// if m.leader {
// isLeader := m
// }
}
txnqueue := TxnGenerator(numOfTxns, lenOfRandomString)
blockFullOfTxns := BufferedTxnQueueWithFanOut(txnqueue, numOfTxnsInBlock)
for num := range blockFullOfTxns {
fmt.Println(num)
txn := blockFullOfTxns[num]
for i, m := range N {
if !m.leader {
go isLeader.send(txn, i)
}
Txns := BufferedTxnQueueWithFanOut(txnqueue, numOfNodes)
for num := range Txns {
txn := Txns[num]
go consume(txn,num)
}
}
time.Sleep(60 * time.Second)
}

Loading…
Cancel
Save