Skip to content

Commit

Permalink
Minor improvements (#831)
Browse files Browse the repository at this point in the history
* replace usage of WithScheme to WithSchemeID; add more docs
  • Loading branch information
emmanuelm41 committed Oct 15, 2021
1 parent 7af9e77 commit 794b3c7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 25 deletions.
2 changes: 2 additions & 0 deletions chain/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/drand/kyber"
)

// Verifier allows verifying the beacons signature based on a scheme.
type Verifier struct {
// scheme holds a set of values the verifying process will use to act in specific ways, regarding signature verification, etc
scheme scheme.Scheme
}

Expand Down
17 changes: 5 additions & 12 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ type clientConfig struct {
fullVerify bool
// insecure indicates the root of trust does not need to be present.
insecure bool
// scheme
// scheme holds a set of values the client will use to act in specific ways, regarding signature verification, etc
scheme scheme.Scheme
// cache size - how large of a cache to keep locally.
cacheSize int
Expand Down Expand Up @@ -227,19 +227,12 @@ func Insecurely() Option {
}
}

// WithScheme
func WithScheme(sch scheme.Scheme) Option {
return func(cfg *clientConfig) error {
cfg.scheme = sch
return nil
}
}

// WithSchemeID
// WithSchemeID allows user to set a scheme using its ID. The scheme
// is used to customize some behaviors inside the client
func WithSchemeID(schID string) Option {
return func(cfg *clientConfig) error {
sch, ok := scheme.GetSchemeByID(schID)
if !ok {
sch, err := scheme.GetSchemeByIDWithDefault(schID)
if err != nil {
return fmt.Errorf("scheme is not valid")
}

Expand Down
12 changes: 6 additions & 6 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestClientMultiple(t *testing.T) {
var e error
c, e = client.New(
client.From(http.ForURLs([]string{"http://" + addr1, "http://" + addr2}, chainInfo.Hash())...),
client.WithScheme(sch),
client.WithSchemeID(sch.ID),
client.WithChainHash(chainInfo.Hash()))

if e != nil {
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestClientCache(t *testing.T) {
var c client.Client
var e error
c, e = client.New(client.From(http.ForURLs([]string{"http://" + addr1}, chainInfo.Hash())...),
client.WithScheme(sch),
client.WithSchemeID(sch.ID),
client.WithChainHash(chainInfo.Hash()), client.WithCacheSize(1))

if e != nil {
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestClientWithoutCache(t *testing.T) {
var e error
c, e = client.New(
client.From(http.ForURLs([]string{"http://" + addr1}, chainInfo.Hash())...),
client.WithScheme(sch),
client.WithSchemeID(sch.ID),
client.WithChainHash(chainInfo.Hash()),
client.WithCacheSize(0))

Expand Down Expand Up @@ -162,7 +162,7 @@ func TestClientWithWatcher(t *testing.T) {
var err error
c, err = client.New(
client.WithChainInfo(info),
client.WithScheme(sch),
client.WithSchemeID(sch.ID),
client.WithWatcher(watcherCtor),
)

Expand Down Expand Up @@ -250,7 +250,7 @@ func TestClientAutoWatch(t *testing.T) {
client.From(client.MockClientWithInfo(chainInfo)),
client.WithChainHash(chainInfo.Hash()),
client.WithWatcher(watcherCtor),
client.WithScheme(sch),
client.WithSchemeID(sch.ID),
client.WithAutoWatch(),
)

Expand Down Expand Up @@ -314,7 +314,7 @@ func TestClientAutoWatchRetry(t *testing.T) {
client.WithAutoWatch(),
client.WithAutoWatchRetry(time.Second),
client.WithCacheSize(len(results)),
client.WithScheme(sch),
client.WithSchemeID(sch.ID),
)

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions client/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

type Opts struct {
strict bool

// scheme holds a set of values the verifying process will use to act in specific ways, regarding signature verification, etc
scheme scheme.Scheme
}

Expand Down
2 changes: 1 addition & 1 deletion client/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func mockClientWithVerifiableResults(n int) (client.Client, []mock.Result, error
client.WithChainInfo(info),
client.WithVerifiedResult(&results[0]),
client.WithFullChainVerification(),
client.WithScheme(sch),
client.WithSchemeID(sch.ID),
)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/lib/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func Create(c *cli.Context, withInstrumentation bool, opts ...client.Option) (cl
return nil, fmt.Errorf("scheme %s given is invalid", c.String(SchemeFlag.Name))
}

opts = append(opts, client.WithScheme(schemeFound))
opts = append(opts, client.WithSchemeID(schemeFound.ID))

clients = append(clients, buildHTTPClients(c, &info, hash, withInstrumentation)...)

Expand Down
6 changes: 1 addition & 5 deletions demo/node/node_subprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,7 @@ func (n *NodeProc) RunDKG(nodes, thr int, timeout string, leader bool, leaderAdd
args = append(args, pair("--threshold", strconv.Itoa(thr))...)
args = append(args, pair("--timeout", timeout)...)
args = append(args, pair("--period", n.period)...)

// TODO The momento master supports this new flag, we will be able to remove this
if n.scheme.DecouplePrevSig {
args = append(args, pair("--scheme", n.scheme.ID)...)
}
args = append(args, pair("--scheme", n.scheme.ID)...)

// make genesis time offset
args = append(args, pair("--beacon-delay", strconv.Itoa(beaconOffset))...)
Expand Down

0 comments on commit 794b3c7

Please sign in to comment.