|
|
@@ -1,6 +1,11 @@
|
|
1
|
1
|
package modules
|
|
2
|
2
|
|
|
3
|
|
-import "encoding/json"
|
|
|
3
|
+import (
|
|
|
4
|
+ "encoding/json"
|
|
|
5
|
+ "net"
|
|
|
6
|
+ "os"
|
|
|
7
|
+ "time"
|
|
|
8
|
+)
|
|
4
|
9
|
|
|
5
|
10
|
//import "strconv"
|
|
6
|
11
|
//*****메세지 타입 상수화
|
|
|
@@ -59,19 +64,40 @@ type KeyShareMsg struct {
|
|
59
|
64
|
key string
|
|
60
|
65
|
}
|
|
61
|
66
|
|
|
|
67
|
+func NewKeyShareMsg(message Message,key string) *KeyShareMsg {
|
|
|
68
|
+ addrs,err:=net.InterfaceAddrs()
|
|
|
69
|
+ var ipaddr string
|
|
|
70
|
+ if err !=nil{
|
|
|
71
|
+ os.Stderr.WriteString("Oops: "+err.Error()+"\n")
|
|
|
72
|
+ os.Exit(1)
|
|
|
73
|
+ }
|
|
|
74
|
+ for _,a:=range addrs{
|
|
|
75
|
+ if ipnet, ok:=a.(*net.IPNet); ok && !ipnet.IP.IsLoopback(){
|
|
|
76
|
+ ipaddr=ipnet.IP.String()
|
|
|
77
|
+ }
|
|
|
78
|
+ }
|
|
|
79
|
+ t := time.Now().String()
|
|
|
80
|
+ return &KeyShareMsg{Message{
|
|
|
81
|
+ from: ipaddr,
|
|
|
82
|
+ version: "1",
|
|
|
83
|
+ time: t,
|
|
|
84
|
+ kind: KSM,
|
|
|
85
|
+ },key}
|
|
|
86
|
+}
|
|
|
87
|
+
|
|
62
|
88
|
//전달할 내용을 담은 메세지
|
|
63
|
89
|
type PublishMsg struct {
|
|
64
|
90
|
Message
|
|
65
|
|
- topic []int64 //대주제
|
|
66
|
|
- value []int64 //topic의 세부적인 내용
|
|
67
|
|
- content []int64 // 내용
|
|
|
91
|
+ topic string //대주제
|
|
|
92
|
+ value string //topic의 세부적인 내용
|
|
|
93
|
+ content string // 내용
|
|
68
|
94
|
}
|
|
69
|
95
|
|
|
70
|
96
|
//구독 정보를 담은 메세지
|
|
71
|
97
|
type SubscriptionMsg struct {
|
|
72
|
98
|
Message
|
|
73
|
|
- topic []int64 //대주제
|
|
74
|
|
- value []int64 //피연산자
|
|
|
99
|
+ topic string //대주제
|
|
|
100
|
+ value string //피연산자
|
|
75
|
101
|
operator []string //연산자
|
|
76
|
102
|
isAlpha bool // 범위연산인지 단순비교연산인지 구분 가능하게 함
|
|
77
|
103
|
}
|
|
|
@@ -81,11 +107,102 @@ type RegisterMsg struct {
|
|
81
|
107
|
Message
|
|
82
|
108
|
}
|
|
83
|
109
|
|
|
|
110
|
+
|
|
|
111
|
+
|
|
84
|
112
|
//Microservice 탈퇴 메세지(없앰)
|
|
85
|
113
|
type WithdrawMsg struct {
|
|
86
|
114
|
Message
|
|
87
|
115
|
}
|
|
88
|
116
|
|
|
|
117
|
+//생성자
|
|
|
118
|
+func NewPublishMsg(message Message, topic string, value string, content string) *PublishMsg {
|
|
|
119
|
+ addrs,err:=net.InterfaceAddrs()
|
|
|
120
|
+ var ipaddr string
|
|
|
121
|
+ if err !=nil{
|
|
|
122
|
+ os.Stderr.WriteString("Oops: "+err.Error()+"\n")
|
|
|
123
|
+ os.Exit(1)
|
|
|
124
|
+ }
|
|
|
125
|
+ for _,a:=range addrs{
|
|
|
126
|
+ if ipnet, ok:=a.(*net.IPNet); ok && !ipnet.IP.IsLoopback(){
|
|
|
127
|
+ ipaddr=ipnet.IP.String()
|
|
|
128
|
+ }
|
|
|
129
|
+ }
|
|
|
130
|
+ t := time.Now().String()
|
|
|
131
|
+ return &PublishMsg{Message{
|
|
|
132
|
+ from: ipaddr,
|
|
|
133
|
+ version: "1",
|
|
|
134
|
+ time: t,
|
|
|
135
|
+ kind: PM,
|
|
|
136
|
+ },topic,value,content}
|
|
|
137
|
+}
|
|
|
138
|
+
|
|
|
139
|
+func NewSubscriptionMsg(message Message,topic string, value string, operator []string, isAlpha bool) *SubscriptionMsg {
|
|
|
140
|
+ addrs,err:=net.InterfaceAddrs()
|
|
|
141
|
+ var ipaddr string
|
|
|
142
|
+ if err !=nil{
|
|
|
143
|
+ os.Stderr.WriteString("Oops: "+err.Error()+"\n")
|
|
|
144
|
+ os.Exit(1)
|
|
|
145
|
+ }
|
|
|
146
|
+ for _,a:=range addrs{
|
|
|
147
|
+ if ipnet, ok:=a.(*net.IPNet); ok && !ipnet.IP.IsLoopback(){
|
|
|
148
|
+ ipaddr=ipnet.IP.String()
|
|
|
149
|
+ }
|
|
|
150
|
+ }
|
|
|
151
|
+ t := time.Now().String()
|
|
|
152
|
+ return &SubscriptionMsg{Message{
|
|
|
153
|
+ from: ipaddr,
|
|
|
154
|
+ version: "1",
|
|
|
155
|
+ time: t,
|
|
|
156
|
+ kind: SM,
|
|
|
157
|
+ },topic,value,operator,isAlpha}
|
|
|
158
|
+
|
|
|
159
|
+}
|
|
|
160
|
+
|
|
|
161
|
+func NewRegisterMsg(message Message) *RegisterMsg {
|
|
|
162
|
+ addrs,err:=net.InterfaceAddrs()
|
|
|
163
|
+ var ipaddr string
|
|
|
164
|
+ if err !=nil{
|
|
|
165
|
+ os.Stderr.WriteString("Oops: "+err.Error()+"\n")
|
|
|
166
|
+ os.Exit(1)
|
|
|
167
|
+ }
|
|
|
168
|
+ for _,a:=range addrs{
|
|
|
169
|
+ if ipnet, ok:=a.(*net.IPNet); ok && !ipnet.IP.IsLoopback(){
|
|
|
170
|
+ ipaddr=ipnet.IP.String()
|
|
|
171
|
+ }
|
|
|
172
|
+ }
|
|
|
173
|
+ t := time.Now().String()
|
|
|
174
|
+ return &RegisterMsg{Message{
|
|
|
175
|
+ from: ipaddr,
|
|
|
176
|
+ version: "1",
|
|
|
177
|
+ time: t,
|
|
|
178
|
+ kind: RM,
|
|
|
179
|
+ }}
|
|
|
180
|
+}
|
|
|
181
|
+
|
|
|
182
|
+func NewWithdrawMsg(message Message) *WithdrawMsg {
|
|
|
183
|
+ addrs,err:=net.InterfaceAddrs()
|
|
|
184
|
+ var ipaddr string
|
|
|
185
|
+ if err !=nil{
|
|
|
186
|
+ os.Stderr.WriteString("Oops: "+err.Error()+"\n")
|
|
|
187
|
+ os.Exit(1)
|
|
|
188
|
+ }
|
|
|
189
|
+ for _,a:=range addrs{
|
|
|
190
|
+ if ipnet, ok:=a.(*net.IPNet); ok && !ipnet.IP.IsLoopback(){
|
|
|
191
|
+ ipaddr=ipnet.IP.String()
|
|
|
192
|
+ }
|
|
|
193
|
+ }
|
|
|
194
|
+ t := time.Now().String()
|
|
|
195
|
+ return &WithdrawMsg{Message{
|
|
|
196
|
+ from: ipaddr,
|
|
|
197
|
+ version: "1",
|
|
|
198
|
+ time: t,
|
|
|
199
|
+ kind: WM,
|
|
|
200
|
+ }}
|
|
|
201
|
+}
|
|
|
202
|
+
|
|
|
203
|
+
|
|
|
204
|
+
|
|
|
205
|
+
|
|
89
|
206
|
//**************************
|
|
90
|
207
|
|
|
91
|
208
|
func (msg *KeyGenMsg) ConvertToJson() ([]byte, error) {
|