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.

65 lines
1.5 KiB

  1. package coordinator
  2. import (
  3. "github.com/hermeznetwork/hermez-node/common"
  4. "github.com/hermeznetwork/hermez-node/log"
  5. )
  6. type ServerProofInterface interface {
  7. CalculateProof(zkInputs *common.ZKInputs) error
  8. GetProof(stopCh chan bool) (*Proof, error)
  9. }
  10. // ServerProof contains the data related to a ServerProof
  11. type ServerProof struct {
  12. // TODO
  13. URL string
  14. Available bool
  15. }
  16. func NewServerProof(URL string) *ServerProof {
  17. return &ServerProof{URL: URL}
  18. }
  19. // CalculateProof sends the *common.ZKInputs to the ServerProof to compute the
  20. // Proof
  21. func (p *ServerProof) CalculateProof(zkInputs *common.ZKInputs) error {
  22. return nil
  23. }
  24. // GetProof retreives the Proof from the ServerProof
  25. func (p *ServerProof) GetProof(stopCh chan bool) (*Proof, error) {
  26. return nil, nil
  27. }
  28. // ServerProofPool contains the multiple ServerProof
  29. type ServerProofPool struct {
  30. pool chan ServerProofInterface
  31. }
  32. func NewServerProofPool(maxServerProofs int) *ServerProofPool {
  33. return &ServerProofPool{
  34. pool: make(chan ServerProofInterface, maxServerProofs),
  35. }
  36. }
  37. func (p *ServerProofPool) Add(serverProof ServerProofInterface) {
  38. p.pool <- serverProof
  39. }
  40. // Get returns the available ServerProof
  41. func (p *ServerProofPool) Get(stopCh chan bool) (ServerProofInterface, error) {
  42. select {
  43. case <-stopCh:
  44. log.Info("ServerProofPool.Get stopped")
  45. return nil, ErrStop
  46. default:
  47. select {
  48. case <-stopCh:
  49. log.Info("ServerProofPool.Get stopped")
  50. return nil, ErrStop
  51. case serverProof := <-p.pool:
  52. return serverProof, nil
  53. }
  54. }
  55. }