forked from dedis/cothority_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
52 lines (44 loc) · 1.29 KB
/
api.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
package template
/*
The api.go defines the methods that can be called from the outside. Most
of the methods will take a roster so that the service knows which nodes
it should work with.
This part of the service runs on the client or the app.
*/
import (
"gopkg.in/dedis/onet.v1"
"gopkg.in/dedis/onet.v1/log"
"gopkg.in/dedis/onet.v1/network"
)
// ServiceName is used for registration on the onet.
const ServiceName = "Template"
// Client is a structure to communicate with the CoSi
// service
type Client struct {
*onet.Client
}
// NewClient instantiates a new cosi.Client
func NewClient() *Client {
return &Client{Client: onet.NewClient(ServiceName)}
}
// Clock will return the time in seconds it took to run the protocol.
func (c *Client) Clock(r *onet.Roster) (*ClockResponse, onet.ClientError) {
dst := r.RandomServerIdentity()
log.Lvl4("Sending message to", dst)
reply := &ClockResponse{}
err := c.SendProtobuf(dst, &ClockRequest{r}, reply)
if err != nil {
return nil, err
}
return reply, nil
}
// Count will return the number of times `Clock` has been called on this
// service-node.
func (c *Client) Count(si *network.ServerIdentity) (int, error) {
reply := &CountResponse{}
err := c.SendProtobuf(si, &CountRequest{}, reply)
if err != nil {
return -1, err
}
return reply.Count, nil
}