-
Notifications
You must be signed in to change notification settings - Fork 4
/
chat.go
37 lines (30 loc) · 951 Bytes
/
chat.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
package dht
import (
"github.com/curltech/go-colla-node/p2p/chain/action"
"github.com/curltech/go-colla-node/p2p/chain/handler"
"github.com/curltech/go-colla-node/p2p/msgtype"
)
type chatAction struct {
action.BaseAction
}
var ChatAction chatAction
/**
在chain目录下的采用自定义protocol "/chain"的方式自己实现的功能
*/
func (this *chatAction) Chat(peerId string, data interface{}, targetPeerId string, targetConnectSessionId string) (interface{}, error) {
chainMessage := this.PrepareSend(peerId, data, targetPeerId)
chainMessage.TargetConnectSessionId = targetConnectSessionId
response, err := this.Send(chainMessage)
if err != nil {
return nil, err
}
if response != nil {
return response.Payload, nil
}
return nil, nil
}
func init() {
ChatAction = chatAction{}
ChatAction.MsgType = msgtype.CHAT
handler.RegistChainMessageHandler(msgtype.CHAT, ChatAction.Send, ChatAction.Receive, ChatAction.Response)
}