Procházet zdrojové kódy

[add] 매칭, re-encryption, 마이크로서비스 send 완료

master
kidjung před 4 roky
rodič
revize
8d118c5f59

+ 41
- 6
src/broker/modules/init.go Zobrazit soubor

@@ -117,11 +117,45 @@ func (receiver Receiver) MmReceive(args Args, reply *Reply) error {
117 117
 	return nil
118 118
 }
119 119
 
120
-func (moscato *Moscato) CheckQueue() MsgUnit {
121
-	for {
122
-		pmMsg := moscato.queue.pop(true)
123
-		fmt.Println("queue popped : ", pmMsg)
120
+func (moscato *Moscato) preProcessMsg(originalMsg MsgUnit) MsgUnit {
121
+	if originalMsg.CheckType() == PM {
122
+		pubMsg := originalMsg.(PublishMsg)
123
+		for index := 0; index < len(pubMsg.Topic); index++ {
124
+			pubMsg.Topic[index] = pubMsg.Topic[index] - moscato.SecureManager.GetNodeKey(pubMsg.From)
125
+		}
126
+		for index := 0; index < len(pubMsg.Value); index++ {
127
+			pubMsg.Value[index] = pubMsg.Value[index] - moscato.SecureManager.GetNodeKey(pubMsg.From)
128
+		}
129
+		fmt.Println("preprocess : ", pubMsg)
130
+		return pubMsg
131
+	} else if originalMsg.CheckType() == SM {
132
+		subMsg := originalMsg.(SubscriptionMsg)
133
+		for index := 0; index < len(subMsg.Topic); index++ {
134
+			subMsg.Topic[index] = subMsg.Topic[index] - moscato.SecureManager.GetNodeKey(subMsg.From)
135
+		}
136
+		for index := 0; index < len(subMsg.Value); index++ {
137
+			subMsg.Value[index] = subMsg.Value[index] - moscato.SecureManager.GetNodeKey(subMsg.From)
138
+		}
139
+		fmt.Println("preprocess : ", subMsg)
140
+		return subMsg
124 141
 	}
142
+	return nil
143
+}
144
+
145
+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)
156
+		}
157
+	}
158
+	return nil
125 159
 }
126 160
 
127 161
 //Recieve - MM가 msg전달 받음
@@ -136,11 +170,11 @@ func (moscato *Moscato) Receive(msg MsgUnit) (MsgUnit, error) {
136 170
 	case PM: //Publish msg
137 171
 		log.Println("PM received")
138 172
 		fmt.Println("PM: ", msg)
139
-		moscato.queue.push(msg.(PublishMsg))
173
+		moscato.queue.push(moscato.preProcessMsg(msg))
140 174
 
141 175
 	case SM: //Subscription msg
142 176
 		fmt.Println("SM: ", msg)
143
-		moscato.SubscriptionManager.addSubscription(msg)
177
+		moscato.SubscriptionManager.addSubscription(moscato.preProcessMsg(msg))
144 178
 
145 179
 	case RM: //Register msg
146 180
 		log.Println("RM received")
@@ -217,6 +251,7 @@ func (moscato *Moscato) Run() {
217 251
 
218 252
 	//go routine -> matching 동작
219 253
 	go moscato.Matching()
254
+	go moscato.SendWithEncrypt()
220 255
 
221 256
 	//go moscato.CheckQueue()
222 257
 

+ 0
- 11
src/broker/modules/matching.go Zobrazit soubor

@@ -3,7 +3,6 @@ package modules
3 3
 import (
4 4
 	"errors"
5 5
 	_ "errors"
6
-	"fmt"
7 6
 	"github.com/juliangruber/go-intersect"
8 7
 	"reflect"
9 8
 )
@@ -19,10 +18,6 @@ func (moscato *Moscato) Matching() {
19 18
 	value := msg.(PublishMsg).Value
20 19
 	sub_mng := moscato.SubscriptionManager
21 20
 
22
-	fmt.Println("matchßing st")
23
-
24
-	fmt.Println("value = ", value)
25
-
26 21
 	// listß
27 22
 	ret := make([]string, 0)
28 23
 
@@ -146,8 +141,6 @@ func (moscato *Moscato) Matching() {
146 141
 			valPtr = valPtr.next
147 142
 		}
148 143
 
149
-		//fmt.Println("hi")
150
-
151 144
 		// Add the intersection IP address of two sets (large and small) to the return list
152 145
 		hash := intersect.Hash(small, big)
153 146
 		list := reflect.ValueOf(hash)
@@ -157,10 +150,6 @@ func (moscato *Moscato) Matching() {
157 150
 			ret = append(ret, ip)
158 151
 		}
159 152
 
160
-		fmt.Println("Big =", big)
161
-		fmt.Println("small =", small)
162
-
163
-		fmt.Println("matching: ", ret)
164 153
 		moscato.MatchingManager.match_count++
165 154
 		moscato.SendQueue <- myType{ret, msg, nil}
166 155
 	}

+ 5
- 9
src/broker/modules/subscription.go Zobrazit soubor

@@ -2,7 +2,6 @@ package modules
2 2
 
3 3
 import (
4 4
 	"errors"
5
-	"fmt"
6 5
 )
7 6
 
8 7
 type sub_manager struct {
@@ -40,9 +39,6 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
40 39
 	subnumber := 0
41 40
 	// * 1. Mapping incoming IP address to sub #
42 41
 
43
-	fmt.Println("add sub st")
44
-	fmt.Println("sub val", value)
45
-
46 42
 	if len(manager.emptylist) == 0 {
47 43
 		subnumber = manager.count_sub
48 44
 		manager.ip2sub[msg.(SubscriptionMsg).From] = append(manager.ip2sub[msg.(SubscriptionMsg).From], manager.count_sub)
@@ -89,18 +85,18 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
89 85
 
90 86
 		// For compound expressions bounded by '&&' and '||'
91 87
 		// (ex) { (234 < x) && (x <= 1293) } , { (234 < x) || ( x < 1293) }
92
-		logical_operator := operator[2]
88
+		logical_operator := operator[1]
93 89
 
94 90
 		// Find ValueNode = (namelist[name].list.val == Value)
95 91
 		valptr1 := nameptr.list.getValueNodePos([]int64{value[0]})
96
-		valptr2 := nameptr.list.getValueNodePos([]int64{value[2]})
92
+		valptr2 := nameptr.list.getValueNodePos([]int64{value[1]})
97 93
 
98 94
 		if valptr1 == nil {
99 95
 			nameptr.list.addValueNode([]int64{value[0]})
100 96
 			valptr1 = nameptr.list.tail
101 97
 		}
102 98
 		if valptr2 == nil {
103
-			nameptr.list.addValueNode([]int64{value[2]})
99
+			nameptr.list.addValueNode([]int64{value[1]})
104 100
 			valptr2 = nameptr.list.tail
105 101
 		}
106 102
 
@@ -111,12 +107,12 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
111 107
 			// If they are enclosed in '&&' -> Insert Value to range_operator_list
112 108
 			manager.israngesub[subnumber] = true
113 109
 			valptr1.insertSub(operator[0], subnumber, false)
114
-			valptr2.insertSub(operator[4], subnumber, false)
110
+			valptr2.insertSub(operator[2], subnumber, false)
115 111
 
116 112
 		} else {
117 113
 			// if they are enclosed in '||' -> Insert Value to single_operator_list
118 114
 			valptr1.insertSub(operator[0], subnumber, true)
119
-			valptr2.insertSub(operator[4], subnumber, true)
115
+			valptr2.insertSub(operator[2], subnumber, true)
120 116
 		}
121 117
 
122 118
 		return nil // addSubscription ok

Načítá se…
Zrušit
Uložit