Przeglądaj źródła

[fix] matching re-encryption 동작 수정

master
kidjung 4 lat temu
rodzic
commit
a892562359

+ 26
- 17
src/broker/modules/init.go Wyświetl plik

@@ -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
 

+ 2
- 2
src/broker/modules/matching.go Wyświetl plik

@@ -12,8 +12,8 @@ type match_manager struct {
12 12
 }
13 13
 
14 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 17
 	topic := msg.(PublishMsg).Topic
18 18
 	value := msg.(PublishMsg).Value
19 19
 	sub_mng := moscato.SubscriptionManager

+ 15
- 0
src/broker/modules/secure.go Wyświetl plik

@@ -2,6 +2,7 @@ package modules
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"log"
5 6
 	"strconv"
6 7
 )
7 8
 
@@ -21,6 +22,7 @@ type SecurityManager interface {
21 22
 	GetNodeKey(nodeName string) int64
22 23
 	ReEncrypt(fromKey int64, toKey int64, target []int64) []int64
23 24
 	ReEncPubMsg(fromPubMsg PublishMsg, nodeName string) *PublishMsg
25
+	RemoveSecureKey(nodeName string) bool
24 26
 	//CompareTopic(topic1 []int64, topic2 []int64) int
25 27
 	//CompareDigit(topic1 int64, topic2 int64) int
26 28
 	//CompareAlpha(topic1 []int64, topic2 []int64) int
@@ -79,6 +81,19 @@ func (sc Security) ReEncPubMsg(fromPubMsg PublishMsg, nodeName string) *PublishM
79 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 98
 Compare 함수들은 같으면 0 다르면 -1 (비교가 필요한 경우 오름차순 1 내림차순 -1)
84 99
 */

Ładowanie…
Anuluj
Zapisz