-
Notifications
You must be signed in to change notification settings - Fork 0
/
round_5.go
83 lines (70 loc) · 1.97 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
79
80
81
82
83
/*
* 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 signing
import (
"errors"
"fmt"
"github.com/deltaswapio/gsmpc/smpc-lib/smpc"
)
// Start broacast DSB
func (round *round5) Start() error {
if round.started {
fmt.Printf("============================= ed sign,round5.start fail ===============================\n")
return errors.New("round already started")
}
round.number = 5
round.started = true
round.ResetOK()
curIndex, err := round.GetDNodeIDIndex(round.kgid)
if err != nil {
return err
}
srm := &SignRound5Message{
SignRoundMessage: new(SignRoundMessage),
DSB: round.temp.DSB,
}
srm.SetFromID(round.kgid)
srm.SetFromIndex(curIndex)
round.temp.signRound5Messages[curIndex] = srm
round.out <- srm
//fmt.Printf("============= ed sign,round5.start success, current node id = %v =============\n", round.kgid)
return nil
}
// CanAccept is it legal to receive this message
func (round *round5) CanAccept(msg smpc.Message) bool {
if _, ok := msg.(*SignRound5Message); 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.signRound5Messages {
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}
}