Quellcode durchsuchen

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

master
kidjung vor 4 Jahren
Ursprung
Commit
8d118c5f59
3 geänderte Dateien mit 46 neuen und 26 gelöschten Zeilen
  1. 41
    6
      src/broker/modules/init.go
  2. 0
    11
      src/broker/modules/matching.go
  3. 5
    9
      src/broker/modules/subscription.go

+ 41
- 6
src/broker/modules/init.go Datei anzeigen

117
 	return nil
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
 //Recieve - MM가 msg전달 받음
161
 //Recieve - MM가 msg전달 받음
136
 	case PM: //Publish msg
170
 	case PM: //Publish msg
137
 		log.Println("PM received")
171
 		log.Println("PM received")
138
 		fmt.Println("PM: ", msg)
172
 		fmt.Println("PM: ", msg)
139
-		moscato.queue.push(msg.(PublishMsg))
173
+		moscato.queue.push(moscato.preProcessMsg(msg))
140
 
174
 
141
 	case SM: //Subscription msg
175
 	case SM: //Subscription msg
142
 		fmt.Println("SM: ", msg)
176
 		fmt.Println("SM: ", msg)
143
-		moscato.SubscriptionManager.addSubscription(msg)
177
+		moscato.SubscriptionManager.addSubscription(moscato.preProcessMsg(msg))
144
 
178
 
145
 	case RM: //Register msg
179
 	case RM: //Register msg
146
 		log.Println("RM received")
180
 		log.Println("RM received")
217
 
251
 
218
 	//go routine -> matching 동작
252
 	//go routine -> matching 동작
219
 	go moscato.Matching()
253
 	go moscato.Matching()
254
+	go moscato.SendWithEncrypt()
220
 
255
 
221
 	//go moscato.CheckQueue()
256
 	//go moscato.CheckQueue()
222
 
257
 

+ 0
- 11
src/broker/modules/matching.go Datei anzeigen

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

+ 5
- 9
src/broker/modules/subscription.go Datei anzeigen

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

Laden…
Abbrechen
Speichern