|
@ -2,53 +2,50 @@ package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"github.com/syndtr/goleveldb/leveldb" |
|
|
|
|
|
"time" |
|
|
"time" |
|
|
"github.com/vocdoni/dvote-relay/batch" |
|
|
"github.com/vocdoni/dvote-relay/batch" |
|
|
|
|
|
"github.com/vocdoni/dvote-relay/net" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var dbPath = "$HOME/.dvote/relay.db" |
|
|
var dbPath = "$HOME/.dvote/relay.db" |
|
|
var bdbPath = "$HOME/.dvote/batch.db" |
|
|
var bdbPath = "$HOME/.dvote/batch.db" |
|
|
var batchSeconds = 3 //seconds
|
|
|
|
|
|
|
|
|
var batchSeconds = 30 //seconds
|
|
|
|
|
|
var batchSize = 3 //packets
|
|
|
|
|
|
|
|
|
var err error |
|
|
var err error |
|
|
var db *leveldb.DB |
|
|
|
|
|
var bdb *leveldb.DB |
|
|
|
|
|
var batchTimer *time.Ticker |
|
|
var batchTimer *time.Ticker |
|
|
var batchSignal chan int |
|
|
|
|
|
|
|
|
var batchSignal chan bool |
|
|
|
|
|
var signal bool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setup() { |
|
|
func setup() { |
|
|
db, err = leveldb.OpenFile(dbPath, nil) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
defer db.Close() |
|
|
|
|
|
|
|
|
|
|
|
bdb, err = leveldb.OpenFile(bdbPath, nil) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
defer bdb.Close() |
|
|
|
|
|
|
|
|
|
|
|
batchTimer = time.NewTicker(time.Second * time.Duration(batchSeconds)) |
|
|
batchTimer = time.NewTicker(time.Second * time.Duration(batchSeconds)) |
|
|
//create batch signal channel
|
|
|
|
|
|
|
|
|
batchSignal = make(chan bool) |
|
|
|
|
|
|
|
|
|
|
|
batch.DBPath = dbPath |
|
|
|
|
|
batch.BDBPath = bdbPath |
|
|
|
|
|
batch.BatchSignal = batchSignal |
|
|
|
|
|
batch.BatchSize = batchSize |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
setup() |
|
|
setup() |
|
|
|
|
|
// batch.Setup()
|
|
|
fmt.Println("Entering main loop") |
|
|
fmt.Println("Entering main loop") |
|
|
|
|
|
go net.Listen("8080") |
|
|
for { |
|
|
for { |
|
|
select { |
|
|
select { |
|
|
case <- batchTimer.C: |
|
|
case <- batchTimer.C: |
|
|
fmt.Println("Timer triggered") |
|
|
fmt.Println("Timer triggered") |
|
|
fmt.Println(batch.Create(bdb)) |
|
|
|
|
|
|
|
|
fmt.Println(batch.Create()) |
|
|
//replace with chain link
|
|
|
//replace with chain link
|
|
|
case <- batchSignal: |
|
|
|
|
|
fmt.Println("Signal triggered") |
|
|
|
|
|
fmt.Println(batch.Create(bdb)) |
|
|
|
|
|
// case <- stopSignal:
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
|
case signal := <-batchSignal: |
|
|
|
|
|
if signal == true { |
|
|
|
|
|
fmt.Println("Signal triggered") |
|
|
|
|
|
fmt.Println(batch.Create()) |
|
|
|
|
|
} |
|
|
|
|
|
default: |
|
|
|
|
|
continue |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |