-
Notifications
You must be signed in to change notification settings - Fork 1
/
dtc.go
46 lines (41 loc) · 1.19 KB
/
dtc.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
package main
import "C"
import (
"fmt"
"sync"
"github.com/niclabs/dtc/v3/config"
"github.com/niclabs/dtc/v3/network"
"github.com/spf13/viper"
)
func init() {
viper.SetConfigName("dtc-config")
viper.AddConfigPath("./")
viper.AddConfigPath("$HOME/.dtc")
viper.AddConfigPath("/etc/dtc/")
if err := viper.ReadInConfig(); err != nil {
panic(fmt.Errorf("config file problem %v", err))
}
}
// DTC represents the Distributed Threshold Criptography library. It manages on its own the nodes, and exposes a simple API to use it.
type DTC struct {
sync.Mutex
Connection network.Connection // The messenger DTC uses to communicate with the nodes.
Threshold uint16 // The threshold defined in the model.
Nodes uint16 // The total number of nodes used.
}
// NewDTC creates a new and ready DTC struct. It connects automatically to its nodes.
func NewDTC(config config.DTCConfig) (*DTC, error) {
connection, err := NewConnection(config.MessagingType)
if err != nil {
return nil, err
}
dtc := &DTC{
Threshold: config.Threshold,
Nodes: config.NodesNumber,
Connection: connection,
}
if err = connection.Open(); err != nil {
return nil, err
}
return dtc, nil
}