Просмотр исходного кода

[fix] matching re-encryption 동작 수정

master
kidjung 4 лет назад
Родитель
Сommit
a892562359
3 измененных файлов: 43 добавлений и 19 удалений
  1. 26
    17
      src/broker/modules/init.go
  2. 2
    2
      src/broker/modules/matching.go
  3. 15
    0
      src/broker/modules/secure.go

+ 26
- 17
src/broker/modules/init.go Просмотреть файл

126
 		for index := 0; index < len(pubMsg.Value); index++ {
126
 		for index := 0; index < len(pubMsg.Value); index++ {
127
 			pubMsg.Value[index] = pubMsg.Value[index] - moscato.SecureManager.GetNodeKey(pubMsg.From)
127
 			pubMsg.Value[index] = pubMsg.Value[index] - moscato.SecureManager.GetNodeKey(pubMsg.From)
128
 		}
128
 		}
129
-		fmt.Println("preprocess : ", pubMsg)
130
 		return pubMsg
129
 		return pubMsg
131
 	} else if originalMsg.CheckType() == SM {
130
 	} else if originalMsg.CheckType() == SM {
132
 		subMsg := originalMsg.(SubscriptionMsg)
131
 		subMsg := originalMsg.(SubscriptionMsg)
136
 		for index := 0; index < len(subMsg.Value); index++ {
135
 		for index := 0; index < len(subMsg.Value); index++ {
137
 			subMsg.Value[index] = subMsg.Value[index] - moscato.SecureManager.GetNodeKey(subMsg.From)
136
 			subMsg.Value[index] = subMsg.Value[index] - moscato.SecureManager.GetNodeKey(subMsg.From)
138
 		}
137
 		}
139
-		fmt.Println("preprocess : ", subMsg)
140
 		return subMsg
138
 		return subMsg
141
 	}
139
 	}
142
 	return nil
140
 	return nil
143
 }
141
 }
144
 
142
 
145
 func (moscato *Moscato) SendWithEncrypt() MsgUnit {
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
 //Recieve - MM가 msg전달 받음
159
 //Recieve - MM가 msg전달 받음
171
 		log.Println("PM received")
169
 		log.Println("PM received")
172
 		fmt.Println("PM: ", msg)
170
 		fmt.Println("PM: ", msg)
173
 		moscato.queue.push(moscato.preProcessMsg(msg))
171
 		moscato.queue.push(moscato.preProcessMsg(msg))
172
+		fmt.Println("pushed")
174
 
173
 
175
 	case SM: //Subscription msg
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
 	case RM: //Register msg
181
 	case RM: //Register msg
180
 		log.Println("RM received")
182
 		log.Println("RM received")
200
 
202
 
201
 	case WM: //Withdraw msg
203
 	case WM: //Withdraw msg
202
 		moscato.MicroServiceManager.RemoveMicroservice(msg.(WithdrawMsg).From)
204
 		moscato.MicroServiceManager.RemoveMicroservice(msg.(WithdrawMsg).From)
205
+		moscato.SecureManager.RemoveSecureKey(msg.(WithdrawMsg).From)
203
 
206
 
204
 	default:
207
 	default:
205
 		return nil, errors.New("Message type Error: Not registered message type")
208
 		return nil, errors.New("Message type Error: Not registered message type")
250
 	}
253
 	}
251
 
254
 
252
 	//go routine -> matching 동작
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
 	//go moscato.CheckQueue()
265
 	//go moscato.CheckQueue()
257
 
266
 

+ 2
- 2
src/broker/modules/matching.go Просмотреть файл

12
 }
12
 }
13
 
13
 
14
 // Matching -> Return (list of IP addresses of matched subs, Pub Msg, error)
14
 // Matching -> Return (list of IP addresses of matched subs, Pub Msg, error)
15
-func (moscato *Moscato) Matching() {
16
-	msg := moscato.queue.pop(true)
15
+func (moscato *Moscato) Matching(msg MsgUnit) {
16
+	//msg := moscato.queue.pop(true)
17
 	topic := msg.(PublishMsg).Topic
17
 	topic := msg.(PublishMsg).Topic
18
 	value := msg.(PublishMsg).Value
18
 	value := msg.(PublishMsg).Value
19
 	sub_mng := moscato.SubscriptionManager
19
 	sub_mng := moscato.SubscriptionManager

+ 15
- 0
src/broker/modules/secure.go Просмотреть файл

2
 
2
 
3
 import (
3
 import (
4
 	"fmt"
4
 	"fmt"
5
+	"log"
5
 	"strconv"
6
 	"strconv"
6
 )
7
 )
7
 
8
 
21
 	GetNodeKey(nodeName string) int64
22
 	GetNodeKey(nodeName string) int64
22
 	ReEncrypt(fromKey int64, toKey int64, target []int64) []int64
23
 	ReEncrypt(fromKey int64, toKey int64, target []int64) []int64
23
 	ReEncPubMsg(fromPubMsg PublishMsg, nodeName string) *PublishMsg
24
 	ReEncPubMsg(fromPubMsg PublishMsg, nodeName string) *PublishMsg
25
+	RemoveSecureKey(nodeName string) bool
24
 	//CompareTopic(topic1 []int64, topic2 []int64) int
26
 	//CompareTopic(topic1 []int64, topic2 []int64) int
25
 	//CompareDigit(topic1 int64, topic2 int64) int
27
 	//CompareDigit(topic1 int64, topic2 int64) int
26
 	//CompareAlpha(topic1 []int64, topic2 []int64) int
28
 	//CompareAlpha(topic1 []int64, topic2 []int64) int
79
 	return toPubMsg
81
 	return toPubMsg
80
 }
82
 }
81
 
83
 
84
+func (sc *Security) RemoveSecureKey(nodeName string) bool {
85
+	//삭제 전 존재여부 확인
86
+	_, exists := sc.KeyMap[nodeName]
87
+
88
+	if exists {
89
+		delete(sc.KeyMap, nodeName)
90
+		log.Println("[" + nodeName + "] : delete Key successful")
91
+		return true
92
+	} else {
93
+		return false
94
+	}
95
+}
96
+
82
 /**
97
 /**
83
 Compare 함수들은 같으면 0 다르면 -1 (비교가 필요한 경우 오름차순 1 내림차순 -1)
98
 Compare 함수들은 같으면 0 다르면 -1 (비교가 필요한 경우 오름차순 1 내림차순 -1)
84
 */
99
 */

Загрузка…
Отмена
Сохранить