-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdispatch.go
63 lines (55 loc) · 1.99 KB
/
dispatch.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
// Copyright 2016 F. Alan Jones. All rights reserved.
// Use of this source code is governed by a Mozilla
// license that can be found in the LICENSE file.
package ketch
import (
"github.com/Sirupsen/logrus"
"github.com/watercraft/ketch/msg"
)
// dispatchIncomingMsgs dispatches messages from incoming channel
func (k *Ketch) dispatchIncomingMsgs() {
for {
// Pull message from channel; blocking
myMsg := <-k.incomingMsgCh
k.log.WithFields(Locate(logrus.Fields{
"msg": myMsg,
})).Info("Dispatch")
// Dispatch message
var outMsgs msg.MsgList
k.Lock()
k.GetUptime()
switch myMsg.GetCommon().Type {
case msg.MsgTypeEpochSetupReq:
k.onEpochSetupReq(myMsg.(*msg.MsgEpochSetupReq), &outMsgs)
case msg.MsgTypeEpochSetupResp:
k.onEpochSetupResp(myMsg.(*msg.MsgEpochSetupResp))
case msg.MsgTypeEpochOpenReq:
k.onEpochOpenReq(myMsg.(*msg.MsgEpochOpenReq), &outMsgs)
case msg.MsgTypeEpochOpenResp:
k.onEpochOpenResp(myMsg.(*msg.MsgEpochOpenResp))
case msg.MsgTypeEpochCloseReq:
k.onEpochCloseReq(myMsg.(*msg.MsgEpochCloseReq), &outMsgs)
case msg.MsgTypeEpochCloseResp:
k.onEpochCloseResp(myMsg.(*msg.MsgEpochCloseResp))
case msg.MsgTypeEpochRevokeReq:
k.onEpochRevokeReq(myMsg.(*msg.MsgEpochRevokeReq), &outMsgs)
case msg.MsgTypeEpochRevokeResp:
k.onEpochRevokeResp(myMsg.(*msg.MsgEpochRevokeResp))
case msg.MsgTypeLeasePrepareReq:
k.onLeasePrepareReq(myMsg.(*msg.MsgLeasePrepareReq), &outMsgs)
case msg.MsgTypeLeasePrepareResp:
k.onLeasePrepareResp(myMsg.(*msg.MsgLeasePrepareResp), &outMsgs)
case msg.MsgTypeLeaseProposeReq:
k.onLeaseProposeReq(myMsg.(*msg.MsgLeaseProposeReq), &outMsgs)
case msg.MsgTypeLeaseProposeResp:
k.onLeaseProposeResp(myMsg.(*msg.MsgLeaseProposeResp))
case msg.MsgTypeReplicaCreateReq:
k.onReplicaCreateReq(myMsg.(*msg.MsgReplicaCreateReq), &outMsgs)
case msg.MsgTypeReplicaCreateResp:
k.onReplicaCreateResp(myMsg.(*msg.MsgReplicaCreateResp))
}
k.Unlock()
// Send response messages
k.sendMsgs(outMsgs)
}
}