瀏覽代碼

[plus]comment

master
jaehoon_kim 4 年之前
父節點
當前提交
fa1e2dd636
共有 1 個文件被更改,包括 23 次插入29 次删除
  1. 23
    29
      src/broker/modules/message.go

+ 23
- 29
src/broker/modules/message.go 查看文件

2
 
2
 
3
 import "encoding/json"
3
 import "encoding/json"
4
 
4
 
5
-//import "strconv"
6
 //*****메세지 타입 상수화
5
 //*****메세지 타입 상수화
7
 const (
6
 const (
8
-	KGM = 1 + iota
9
-	KSM
10
-	PM
11
-	SM
12
-	RM
13
-	WM
7
+	KGM = 1 + iota	//KeyGenMessage
8
+	KSM	//KeyShareMessage
9
+	PM	//PublishMessage
10
+	SM	//SubscriptionMessage
11
+	RM	//RegisterMessage
12
+	WM	//WithdrawMessage
14
 )
13
 )
15
 
14
 
16
 //*****메세지 틀*****
15
 //*****메세지 틀*****
17
-
18
 type Message struct {
16
 type Message struct {
19
-	From    string //ip주소
20
-	Version string
21
-	Time    string
22
-	Kind    int //종류
17
+	From    string	//메세지 만든 주체의 Ip주소
18
+	Version string	//메세지 버전
19
+	Time    string	//메세지 만든 시간
20
+	Kind    int		//메세지 종류
23
 }
21
 }
24
 
22
 
25
 type MsgUnit interface {
23
 type MsgUnit interface {
26
-	// ConvertToJson - send 전 json형식으로 바꾸는 함수
27
-	ConvertToJson() ([]byte, error)
28
-	//JsontoMsg
29
-	//JsontoMsg()(msg MsgUnit)
30
-	// CheckType - Message의 타입을 알려줌
31
-	CheckType() int
24
+	ConvertToJson() ([]byte, error)	//메세지를 JSON형식으로 바꿔주는 멤버함수
25
+	CheckType() int	//메세지의 종류를 반환하는 함수
32
 }
26
 }
33
 
27
 
34
 //*****각 메세지 형식 및 정의**********
28
 //*****각 메세지 형식 및 정의**********
48
 //전달할 내용을 담은 메세지
42
 //전달할 내용을 담은 메세지
49
 type PublishMsg struct {
43
 type PublishMsg struct {
50
 	Message
44
 	Message
51
-	Topic   []int64 //대주제
52
-	Value   []int64 //topic의 세부적인 내용
53
-	Content []int64 // 내용
45
+	Topic   []int64 //대주제	ex)soccer
46
+	Value   []int64 //topic의 세부적인 내용 ex)ManCity or 40
47
+	Content []int64 //내용 ex)오늘 케빈 데 브라위너가 골을 넣었다
54
 }
48
 }
55
 
49
 
56
 //구독 정보를 담은 메세지
50
 //구독 정보를 담은 메세지
57
 type SubscriptionMsg struct {
51
 type SubscriptionMsg struct {
58
 	Message
52
 	Message
59
-	Topic    []int64  //대주제
60
-	Value    []int64  //피연산자
61
-	Operator []string //연산자
62
-	IsAlpha  bool     //value가 숫자인지 문자열인지
53
+	Topic    []int64  //대주제 ex)soccer
54
+	Value    []int64  //피연산자 ex)Mancity or 20 40
55
+	Operator []string //연산자	ex) ==, < && >
56
+	IsAlpha  bool     //value가 숫자인지 문자열인지, 문자열이면 단순비교, 숫자이면 범위연산
63
 }
57
 }
64
 
58
 
65
 //Microservice 등록 메세지
59
 //Microservice 등록 메세지
73
 	Message
67
 	Message
74
 }
68
 }
75
 
69
 
76
-//**************************
77
-
70
+//******ConverToJson을 메세지 종류별로 실행가능하게 구현******
78
 func (msg KeyGenMsg) ConvertToJson() ([]byte, error) {
71
 func (msg KeyGenMsg) ConvertToJson() ([]byte, error) {
79
 	js := msg
72
 	js := msg
80
 	jsonBytes, err := json.Marshal(js)
73
 	jsonBytes, err := json.Marshal(js)
111
 	return jsonBytes, err
104
 	return jsonBytes, err
112
 }
105
 }
113
 
106
 
107
+//CheckType함수 구현
114
 func (msg Message) CheckType() int {
108
 func (msg Message) CheckType() int {
115
-	return msg.Kind
109
+	return msg.Kind	//메세지 멤버변수 Kind 리턴
116
 }
110
 }
117
 
111
 
118
 //KeyGenMsg 생성자
112
 //KeyGenMsg 생성자
119
 func NewKeyGenMsg(table *MStable) *KeyGenMsg {
113
 func NewKeyGenMsg(table *MStable) *KeyGenMsg {
120
 	m := &KeyGenMsg{}
114
 	m := &KeyGenMsg{}
121
-	for _, value := range table.NodeTable {
115
+	for _, value := range table.NodeTable { // MicroService테이블에서 ip주소를 다 가져와서 iptable에 넣음
122
 		m.iptable = append(m.iptable, value.GetIpaddr())
116
 		m.iptable = append(m.iptable, value.GetIpaddr())
123
 	}
117
 	}
124
 	return m
118
 	return m

Loading…
取消
儲存