/
default_service.go
68 lines (62 loc) 路 2.02 KB
/
default_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package net
import (
"context"
"github.com/dedis/drand/protobuf/dkg"
"github.com/dedis/drand/protobuf/drand"
)
// Default service implements the Service interface with methods that returns empty messages.
// Default service is useful mainly for testing, where you want to implement only a specific functionality of a Service.
// To use : depending on which server you want to test, define a struct that implemants BeaconServer, RandomnessServer or DkgServer
// and instanciate defaultService with &DefaultService{<your struct>}.
type DefaultService struct {
B drand.BeaconServer
R drand.RandomnessServer
I drand.InfoServer
D dkg.DkgServer
}
func (s *DefaultService) Public(c context.Context, in *drand.PublicRandRequest) (*drand.PublicRandResponse, error) {
if s.R == nil {
return &drand.PublicRandResponse{}, nil
} else {
return s.R.Public(c, in)
}
}
func (s *DefaultService) Private(c context.Context, in *drand.PrivateRandRequest) (*drand.PrivateRandResponse, error) {
if s.R == nil {
return &drand.PrivateRandResponse{}, nil
} else {
return s.R.Private(c, in)
}
}
func (s *DefaultService) DistKey(c context.Context, in *drand.DistKeyRequest) (*drand.DistKeyResponse, error) {
if s.I == nil {
return &drand.DistKeyResponse{}, nil
} else {
return s.I.DistKey(c, in)
}
}
func (s *DefaultService) Setup(c context.Context, in *dkg.DKGPacket) (*dkg.DKGResponse, error) {
if s.D != nil {
return s.D.Setup(c, in)
}
return &dkg.DKGResponse{}, nil
}
func (s *DefaultService) Reshare(c context.Context, in *dkg.ResharePacket) (*dkg.ReshareResponse, error) {
if s.D != nil {
return s.D.Reshare(c, in)
}
return &dkg.ReshareResponse{}, nil
}
func (s *DefaultService) NewBeacon(c context.Context, in *drand.BeaconRequest) (*drand.BeaconResponse, error) {
if s.B == nil {
return &drand.BeaconResponse{}, nil
} else {
return s.B.NewBeacon(c, in)
}
}
func (s *DefaultService) Home(c context.Context, in *drand.HomeRequest) (*drand.HomeResponse, error) {
if s.I == nil {
return &drand.HomeResponse{}, nil
}
return s.I.Home(c, in)
}