You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
967 B

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/vocdoni/dvote-relay/batch"
  6. "github.com/vocdoni/dvote-relay/net"
  7. )
  8. var dbPath = "$HOME/.dvote/relay.db"
  9. var bdbPath = "$HOME/.dvote/batch.db"
  10. var batchSeconds = 30 //seconds
  11. var batchSize = 3 //packets
  12. var err error
  13. var batchTimer *time.Ticker
  14. var batchSignal chan bool
  15. var signal bool
  16. func setup() {
  17. batchTimer = time.NewTicker(time.Second * time.Duration(batchSeconds))
  18. batchSignal = make(chan bool)
  19. batch.DBPath = dbPath
  20. batch.BDBPath = bdbPath
  21. batch.BatchSignal = batchSignal
  22. batch.BatchSize = batchSize
  23. }
  24. func main() {
  25. setup()
  26. // batch.Setup()
  27. fmt.Println("Entering main loop")
  28. go net.Listen("8080")
  29. for {
  30. select {
  31. case <- batchTimer.C:
  32. fmt.Println("Timer triggered")
  33. fmt.Println(batch.Create())
  34. //replace with chain link
  35. case signal := <-batchSignal:
  36. if signal == true {
  37. fmt.Println("Signal triggered")
  38. fmt.Println(batch.Create())
  39. }
  40. default:
  41. continue
  42. }
  43. }
  44. }