Selaa lähdekoodia

[plus]comment

master
jaehoon_kim 4 vuotta sitten
vanhempi
commit
fa1e2dd636
1 muutettua tiedostoa jossa 23 lisäystä ja 29 poistoa
  1. 23
    29
      src/broker/modules/message.go

+ 23
- 29
src/broker/modules/message.go Näytä tiedosto

@@ -2,33 +2,27 @@ package modules
2 2
 
3 3
 import "encoding/json"
4 4
 
5
-//import "strconv"
6 5
 //*****메세지 타입 상수화
7 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 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 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,18 +42,18 @@ type KeyShareMsg struct {
48 42
 //전달할 내용을 담은 메세지
49 43
 type PublishMsg struct {
50 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 51
 type SubscriptionMsg struct {
58 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 59
 //Microservice 등록 메세지
@@ -73,8 +67,7 @@ type WithdrawMsg struct {
73 67
 	Message
74 68
 }
75 69
 
76
-//**************************
77
-
70
+//******ConverToJson을 메세지 종류별로 실행가능하게 구현******
78 71
 func (msg KeyGenMsg) ConvertToJson() ([]byte, error) {
79 72
 	js := msg
80 73
 	jsonBytes, err := json.Marshal(js)
@@ -111,14 +104,15 @@ func (msg WithdrawMsg) ConvertToJson() ([]byte, error) {
111 104
 	return jsonBytes, err
112 105
 }
113 106
 
107
+//CheckType함수 구현
114 108
 func (msg Message) CheckType() int {
115
-	return msg.Kind
109
+	return msg.Kind	//메세지 멤버변수 Kind 리턴
116 110
 }
117 111
 
118 112
 //KeyGenMsg 생성자
119 113
 func NewKeyGenMsg(table *MStable) *KeyGenMsg {
120 114
 	m := &KeyGenMsg{}
121
-	for _, value := range table.NodeTable {
115
+	for _, value := range table.NodeTable { // MicroService테이블에서 ip주소를 다 가져와서 iptable에 넣음
122 116
 		m.iptable = append(m.iptable, value.GetIpaddr())
123 117
 	}
124 118
 	return m

Loading…
Peruuta
Tallenna