|
|
@@ -39,29 +39,22 @@ func New(addr int, heartbeat, election tick) *Node {
|
|
|
heartbeat: heartbeat,
|
|
|
election: election,
|
|
|
addr: addr,
|
|
|
+ sm: newStateMachine(addr, []int{addr}),
|
|
|
}
|
|
|
|
|
|
return n
|
|
|
}
|
|
|
|
|
|
-// Propose asynchronously proposes data be applied to the underlying state machine.
|
|
|
-func (n *Node) Propose(data []byte) {
|
|
|
- m := Message{Type: msgProp, Entries: []Entry{{Data: data}}}
|
|
|
- n.Step(m)
|
|
|
-}
|
|
|
-
|
|
|
func Dictate(n *Node) *Node {
|
|
|
- n.sm = newStateMachine(n.addr, []int{n.addr})
|
|
|
n.Step(Message{Type: msgHup})
|
|
|
n.Step(n.newConfMessage(configAdd, &Config{NodeId: n.addr}))
|
|
|
return n
|
|
|
}
|
|
|
|
|
|
-func (n *Node) Start() {
|
|
|
- if n.sm != nil {
|
|
|
- panic("node is started")
|
|
|
- }
|
|
|
- n.sm = newStateMachine(n.addr, nil)
|
|
|
+// Propose asynchronously proposes data be applied to the underlying state machine.
|
|
|
+func (n *Node) Propose(data []byte) {
|
|
|
+ m := Message{Type: msgProp, Entries: []Entry{{Data: data}}}
|
|
|
+ n.Step(m)
|
|
|
}
|
|
|
|
|
|
func (n *Node) Add(addr int) {
|