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.

53 lines
989 B

  1. package net
  2. import (
  3. "errors"
  4. "github.com/vocdoni/go-dvote/types"
  5. )
  6. type Transport interface {
  7. Listen(reciever chan<- types.Message, errors chan<- error)
  8. Send(msg []byte, errors chan<- error)
  9. Init() error
  10. }
  11. type TransportID int
  12. const (
  13. PubSub TransportID = iota + 1
  14. PSS
  15. )
  16. func TransportIDFromString(i string) TransportID {
  17. switch i {
  18. case "PubSub":
  19. return PubSub
  20. case "PSS":
  21. return PSS
  22. default:
  23. return -1
  24. }
  25. }
  26. func Init(t TransportID) (Transport, error) {
  27. switch t {
  28. case PubSub:
  29. p := new(PubSubHandle)
  30. defaultConnection := new(types.Connection)
  31. defaultConnection.Topic = "vocdoni_testing"
  32. p.c = defaultConnection
  33. p.Init()
  34. return p, nil
  35. case PSS:
  36. p := new(PSSHandle)
  37. defaultConnection := new(types.Connection)
  38. defaultConnection.Topic = "vocdoni_testing"
  39. defaultConnection.Key = ""
  40. defaultConnection.Kind = "sym"
  41. p.c = defaultConnection
  42. p.Init()
  43. return p, nil
  44. default:
  45. return nil, errors.New("Bad transport type specification")
  46. }
  47. }