hookChan loops to handle the message from the network
(channel chan *types.MsgPayload, stopCh chan bool)
| 99 | |
| 100 | // hookChan loops to handle the message from the network |
| 101 | func (this *MessageRouter) hookChan(channel chan *types.MsgPayload, |
| 102 | stopCh chan bool) { |
| 103 | for { |
| 104 | select { |
| 105 | case data, ok := <-channel: |
| 106 | if ok { |
| 107 | msgType := data.Payload.CmdType() |
| 108 | |
| 109 | handler, ok := this.msgHandlers[msgType] |
| 110 | if ok { |
| 111 | if msgType == msgCommon.TX_TYPE { |
| 112 | handler(data, this.p2p, this.pid) |
| 113 | } else { |
| 114 | go handler(data, this.p2p, this.pid) |
| 115 | } |
| 116 | } else { |
| 117 | log.Warn("unknown message handler for the msg: ", |
| 118 | msgType) |
| 119 | } |
| 120 | } |
| 121 | case <-stopCh: |
| 122 | return |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // Stop stops the message router's loop |
| 128 | func (this *MessageRouter) Stop() { |