/
round_5.go
78 lines (68 loc) · 1.83 KB
/
round_5.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
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (C) 2020-2021 AnySwap Ltd. All rights reserved.
* Copyright (C) 2020-2021 haijun.cai@anyswap.exchange
*
* This library is free software; you can redistribute it and/or
* modify it under the Apache License, Version 2.0.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package keygen
import (
"errors"
"github.com/RWAValueRouter/FastMulThreshold-DSA/smpc-lib/smpc"
)
// Start broacast cfsBBytes
func (round *round5) Start() error {
if round.started {
return errors.New("ed,round already started")
}
round.number = 5
round.started = true
round.ResetOK()
curIndex, err := round.GetDNodeIDIndex(round.dnodeid)
if err != nil {
return err
}
kg := &KGRound5Message{
KGRoundMessage: new(KGRoundMessage),
CfsBBytes: round.temp.cfsBBytes,
}
kg.SetFromID(round.dnodeid)
kg.SetFromIndex(curIndex)
round.temp.kgRound5Messages[curIndex] = kg
round.out <- kg
//fmt.Printf("========= round5 start success ==========\n")
return nil
}
// CanAccept is it legal to receive this message
func (round *round5) CanAccept(msg smpc.Message) bool {
if _, ok := msg.(*KGRound5Message); ok {
return msg.IsBroadcast()
}
return false
}
// Update is the message received and ready for the next round?
func (round *round5) Update() (bool, error) {
for j, msg := range round.temp.kgRound5Messages {
if round.ok[j] {
continue
}
if msg == nil || !round.CanAccept(msg) {
return false, nil
}
round.ok[j] = true
}
return true, nil
}
// NextRound enter next round
func (round *round5) NextRound() smpc.Round {
round.started = false
return &round6{round}
}