|
@ -1,21 +1,23 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
|
|
|
"time" |
|
|
|
|
|
"encoding/gob" |
|
|
|
|
|
"bytes" |
|
|
"bytes" |
|
|
"os" |
|
|
|
|
|
|
|
|
"encoding/gob" |
|
|
"flag" |
|
|
"flag" |
|
|
|
|
|
"fmt" |
|
|
|
|
|
"os" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/vocdoni/go-dvote/batch" |
|
|
"github.com/vocdoni/go-dvote/batch" |
|
|
"github.com/vocdoni/go-dvote/net" |
|
|
|
|
|
"github.com/vocdoni/go-dvote/db" |
|
|
|
|
|
"github.com/vocdoni/go-dvote/data" |
|
|
"github.com/vocdoni/go-dvote/data" |
|
|
|
|
|
"github.com/vocdoni/go-dvote/db" |
|
|
|
|
|
"github.com/vocdoni/go-dvote/net" |
|
|
|
|
|
"github.com/vocdoni/go-dvote/types" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var dbPath = "~/.dvote/relay.db" |
|
|
var dbPath = "~/.dvote/relay.db" |
|
|
var batchSeconds = 10 //seconds
|
|
|
var batchSeconds = 10 //seconds
|
|
|
var batchSize = 3 //packets
|
|
|
|
|
|
|
|
|
var batchSize = 3 //packets
|
|
|
|
|
|
|
|
|
var err error |
|
|
var err error |
|
|
var batchTimer *time.Ticker |
|
|
var batchTimer *time.Ticker |
|
@ -23,7 +25,6 @@ var batchSignal chan bool |
|
|
var signal bool |
|
|
var signal bool |
|
|
var transportType net.TransportID |
|
|
var transportType net.TransportID |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
|
|
|
|
|
|
db, err := db.NewLevelDbStorage(dbPath, false) |
|
|
db, err := db.NewLevelDbStorage(dbPath, false) |
|
@ -40,25 +41,26 @@ func main() { |
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
transportType = net.TransportIDFromString(transportIDString) |
|
|
transportType = net.TransportIDFromString(transportIDString) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
batchTimer = time.NewTicker(time.Second * time.Duration(batchSeconds)) |
|
|
batchTimer = time.NewTicker(time.Second * time.Duration(batchSeconds)) |
|
|
batchSignal = make(chan bool) |
|
|
batchSignal = make(chan bool) |
|
|
|
|
|
|
|
|
batch.BatchSignal = batchSignal |
|
|
batch.BatchSignal = batchSignal |
|
|
batch.BatchSize = batchSize |
|
|
batch.BatchSize = batchSize |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("Entering main loop") |
|
|
fmt.Println("Entering main loop") |
|
|
transport, err := net.Init(transportType) |
|
|
transport, err := net.Init(transportType) |
|
|
|
|
|
listenerOutput := make(chan types.Message, 10) |
|
|
|
|
|
listenerErrors := make(chan error) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
os.Exit(1) |
|
|
os.Exit(1) |
|
|
} |
|
|
} |
|
|
go transport.Listen() |
|
|
|
|
|
|
|
|
go transport.Listen(listenerOutput, listenerErrors) |
|
|
|
|
|
go batch.Recieve(listenerOutput) |
|
|
for { |
|
|
for { |
|
|
select { |
|
|
select { |
|
|
case <- batchTimer.C: |
|
|
|
|
|
|
|
|
case <-batchTimer.C: |
|
|
fmt.Println("Timer triggered") |
|
|
fmt.Println("Timer triggered") |
|
|
// fmt.Println(batch.Create())
|
|
|
|
|
|
|
|
|
// fmt.Println(batch.Create())
|
|
|
//replace with chain link
|
|
|
//replace with chain link
|
|
|
case signal := <-batchSignal: |
|
|
case signal := <-batchSignal: |
|
|
if signal == true { |
|
|
if signal == true { |
|
@ -78,6 +80,8 @@ func main() { |
|
|
//fmt.Println(b)
|
|
|
//fmt.Println(b)
|
|
|
batch.Compact(ns) |
|
|
batch.Compact(ns) |
|
|
} |
|
|
} |
|
|
|
|
|
case listenError := <-listenerErrors: |
|
|
|
|
|
fmt.Println(listenError) |
|
|
default: |
|
|
default: |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|