|
|
@@ -126,7 +126,6 @@ func (moscato *Moscato) preProcessMsg(originalMsg MsgUnit) MsgUnit {
|
|
126
|
126
|
for index := 0; index < len(pubMsg.Value); index++ {
|
|
127
|
127
|
pubMsg.Value[index] = pubMsg.Value[index] - moscato.SecureManager.GetNodeKey(pubMsg.From)
|
|
128
|
128
|
}
|
|
129
|
|
- fmt.Println("preprocess : ", pubMsg)
|
|
130
|
129
|
return pubMsg
|
|
131
|
130
|
} else if originalMsg.CheckType() == SM {
|
|
132
|
131
|
subMsg := originalMsg.(SubscriptionMsg)
|
|
|
@@ -136,26 +135,25 @@ func (moscato *Moscato) preProcessMsg(originalMsg MsgUnit) MsgUnit {
|
|
136
|
135
|
for index := 0; index < len(subMsg.Value); index++ {
|
|
137
|
136
|
subMsg.Value[index] = subMsg.Value[index] - moscato.SecureManager.GetNodeKey(subMsg.From)
|
|
138
|
137
|
}
|
|
139
|
|
- fmt.Println("preprocess : ", subMsg)
|
|
140
|
138
|
return subMsg
|
|
141
|
139
|
}
|
|
142
|
140
|
return nil
|
|
143
|
141
|
}
|
|
144
|
142
|
|
|
145
|
143
|
func (moscato *Moscato) SendWithEncrypt() MsgUnit {
|
|
146
|
|
- mt := <-moscato.SendQueue
|
|
147
|
|
- fmt.Println(mt)
|
|
148
|
|
- if mt.err == nil {
|
|
149
|
|
- for index := 0; index < len(mt.subList); index++ {
|
|
150
|
|
- tmpNode := mt.subList[index]
|
|
151
|
|
- tmpNodeIpAddr, _ := moscato.MicroServiceManager.GetIpaddr(tmpNode)
|
|
152
|
|
- fmt.Println("before reEnc: ", mt.pubMsg)
|
|
153
|
|
- moscato.SecureManager.ReEncPubMsg(mt.pubMsg.(PublishMsg), tmpNode)
|
|
154
|
|
- fmt.Println("after reEnc: ", mt.pubMsg)
|
|
155
|
|
- moscato.Send2MS(tmpNodeIpAddr, mt.pubMsg)
|
|
|
144
|
+ for {
|
|
|
145
|
+ mt := <-moscato.SendQueue
|
|
|
146
|
+ fmt.Println(mt)
|
|
|
147
|
+ if mt.err == nil {
|
|
|
148
|
+ for index := 0; index < len(mt.subList); index++ {
|
|
|
149
|
+ tmpNode := mt.subList[index]
|
|
|
150
|
+ tmpNodeIpAddr, _ := moscato.MicroServiceManager.GetIpaddr(tmpNode)
|
|
|
151
|
+ moscato.SecureManager.ReEncPubMsg(mt.pubMsg.(PublishMsg), tmpNode)
|
|
|
152
|
+ moscato.Send2MS(tmpNodeIpAddr, mt.pubMsg)
|
|
|
153
|
+ }
|
|
156
|
154
|
}
|
|
|
155
|
+ return nil
|
|
157
|
156
|
}
|
|
158
|
|
- return nil
|
|
159
|
157
|
}
|
|
160
|
158
|
|
|
161
|
159
|
//Recieve - MM가 msg전달 받음
|
|
|
@@ -171,10 +169,14 @@ func (moscato *Moscato) Receive(msg MsgUnit) (MsgUnit, error) {
|
|
171
|
169
|
log.Println("PM received")
|
|
172
|
170
|
fmt.Println("PM: ", msg)
|
|
173
|
171
|
moscato.queue.push(moscato.preProcessMsg(msg))
|
|
|
172
|
+ fmt.Println("pushed")
|
|
174
|
173
|
|
|
175
|
174
|
case SM: //Subscription msg
|
|
176
|
|
- fmt.Println("SM: ", msg)
|
|
177
|
|
- moscato.SubscriptionManager.addSubscription(moscato.preProcessMsg(msg))
|
|
|
175
|
+ err := moscato.SubscriptionManager.addSubscription(moscato.preProcessMsg(msg))
|
|
|
176
|
+ if err != nil {
|
|
|
177
|
+ println(err)
|
|
|
178
|
+ //return nil, err
|
|
|
179
|
+ }
|
|
178
|
180
|
|
|
179
|
181
|
case RM: //Register msg
|
|
180
|
182
|
log.Println("RM received")
|
|
|
@@ -200,6 +202,7 @@ func (moscato *Moscato) Receive(msg MsgUnit) (MsgUnit, error) {
|
|
200
|
202
|
|
|
201
|
203
|
case WM: //Withdraw msg
|
|
202
|
204
|
moscato.MicroServiceManager.RemoveMicroservice(msg.(WithdrawMsg).From)
|
|
|
205
|
+ moscato.SecureManager.RemoveSecureKey(msg.(WithdrawMsg).From)
|
|
203
|
206
|
|
|
204
|
207
|
default:
|
|
205
|
208
|
return nil, errors.New("Message type Error: Not registered message type")
|
|
|
@@ -250,8 +253,14 @@ func (moscato *Moscato) Run() {
|
|
250
|
253
|
}
|
|
251
|
254
|
|
|
252
|
255
|
//go routine -> matching 동작
|
|
253
|
|
- go moscato.Matching()
|
|
254
|
|
- go moscato.SendWithEncrypt()
|
|
|
256
|
+ go func() {
|
|
|
257
|
+ for {
|
|
|
258
|
+ msg := moscato.queue.pop(true)
|
|
|
259
|
+ fmt.Println(msg)
|
|
|
260
|
+ go moscato.Matching(msg)
|
|
|
261
|
+ go moscato.SendWithEncrypt()
|
|
|
262
|
+ }
|
|
|
263
|
+ }()
|
|
255
|
264
|
|
|
256
|
265
|
//go moscato.CheckQueue()
|
|
257
|
266
|
|