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