|
|
@@ -8,10 +8,10 @@ type sub_manager struct {
|
|
8
|
8
|
list topicList
|
|
9
|
9
|
|
|
10
|
10
|
/* Manage sub# */
|
|
11
|
|
- count_sub int // Subscription #
|
|
|
11
|
+ count_sub int // Subscription #
|
|
12
|
12
|
emptylist []int // To administrate sub #
|
|
13
|
13
|
ip2sub map[string][]int // ip2sub[ip] = sub# ...
|
|
14
|
|
- sub2ip map[int]string // sub2ip[sub#] = ip
|
|
|
14
|
+ sub2ip map[int]string // sub2ip[sub#] = ip
|
|
15
|
15
|
sub2node map[int][]*valueNode // sub2node[sub#] = node_addr ...
|
|
16
|
16
|
israngesub map[int]bool // To manage when deleted
|
|
17
|
17
|
}
|
|
|
@@ -41,14 +41,15 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
|
|
41
|
41
|
// * 1. Mapping incoming IP address to sub #
|
|
42
|
42
|
|
|
43
|
43
|
if len(manager.emptylist) == 0 {
|
|
44
|
|
- manager.ip2sub[msg.(*SubscriptionMsg).From] = append(manager.ip2sub[msg.(*SubscriptionMsg).From], manager.count_sub)
|
|
45
|
44
|
subnumber = manager.count_sub
|
|
|
45
|
+ manager.ip2sub[msg.(*SubscriptionMsg).from] = append(manager.ip2sub[msg.(*SubscriptionMsg).from], manager.count_sub)
|
|
|
46
|
+ manager.sub2ip[subnumber] = msg.(*SubscriptionMsg).from
|
|
46
|
47
|
manager.count_sub++
|
|
47
|
48
|
} else {
|
|
48
|
|
- subidx := manager.emptylist[len(manager.emptylist)-1]
|
|
|
49
|
+ subnumber := manager.emptylist[len(manager.emptylist)-1]
|
|
49
|
50
|
manager.emptylist = manager.emptylist[:len(manager.emptylist)-1]
|
|
50
|
|
- manager.ip2sub[msg.(*SubscriptionMsg).From] = append(manager.ip2sub[msg.(*SubscriptionMsg).From], subidx)
|
|
51
|
|
- subnumber = subidx
|
|
|
51
|
+ manager.ip2sub[msg.(*SubscriptionMsg).from] = append(manager.ip2sub[msg.(*SubscriptionMsg).from], subnumber)
|
|
|
52
|
+ manager.sub2ip[subnumber] = msg.(*SubscriptionMsg).from
|
|
52
|
53
|
}
|
|
53
|
54
|
|
|
54
|
55
|
nameptr := manager.list.head
|
|
|
@@ -70,7 +71,7 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
|
|
70
|
71
|
nameptr = manager.list.tail
|
|
71
|
72
|
}
|
|
72
|
73
|
|
|
73
|
|
- // Add Value to list[name]
|
|
|
74
|
+ // Add value to list[name]
|
|
74
|
75
|
if len(operator) == 1 { // if single expression
|
|
75
|
76
|
valptr := nameptr.list.getValueNodePos(value)
|
|
76
|
77
|
if valptr == nil {
|
|
|
@@ -80,15 +81,14 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
|
|
80
|
81
|
|
|
81
|
82
|
manager.sub2node[subnumber] = append(manager.sub2node[subnumber], valptr)
|
|
82
|
83
|
valptr.insertSub(operator[0], subnumber, true)
|
|
83
|
|
-
|
|
84
|
84
|
return nil // AddSubscription ok
|
|
85
|
85
|
} else {
|
|
86
|
|
-
|
|
|
86
|
+
|
|
87
|
87
|
// For compound expressions bounded by '&&' and '||'
|
|
88
|
88
|
// (ex) { (234 < x) && (x <= 1293) } , { (234 < x) || ( x < 1293) }
|
|
89
|
89
|
logical_operator := operator[1]
|
|
90
|
90
|
|
|
91
|
|
- // Find ValueNode = (namelist[name].list.val == Value)
|
|
|
91
|
+ // Find ValueNode = (namelist[name].list.val == value)
|
|
92
|
92
|
valptr1 := nameptr.list.getValueNodePos([]int64{value[0]})
|
|
93
|
93
|
valptr2 := nameptr.list.getValueNodePos([]int64{value[1]})
|
|
94
|
94
|
|
|
|
@@ -105,13 +105,13 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
|
|
105
|
105
|
manager.sub2node[subnumber] = append(manager.sub2node[subnumber], valptr2)
|
|
106
|
106
|
|
|
107
|
107
|
if logical_operator == "&&" {
|
|
108
|
|
- // If they are enclosed in '&&' -> Insert Value to range_operator_list
|
|
|
108
|
+ // If they are enclosed in '&&' -> Insert value to range_operator_list
|
|
109
|
109
|
manager.israngesub[subnumber] = true
|
|
110
|
110
|
valptr1.insertSub(operator[0], subnumber, false)
|
|
111
|
111
|
valptr2.insertSub(operator[2], subnumber, false)
|
|
112
|
112
|
|
|
113
|
113
|
} else {
|
|
114
|
|
- // if they are enclosed in '||' -> Insert Value to single_operator_list
|
|
|
114
|
+ // if they are enclosed in '||' -> Insert value to single_operator_list
|
|
115
|
115
|
valptr1.insertSub(operator[0], subnumber, true)
|
|
116
|
116
|
valptr2.insertSub(operator[2], subnumber, true)
|
|
117
|
117
|
}
|
|
|
@@ -214,6 +214,6 @@ func (manager *sub_manager) delete(from string) error {
|
|
214
|
214
|
}
|
|
215
|
215
|
}
|
|
216
|
216
|
}
|
|
217
|
|
- manager.ip2sub[ip] = nil // Delete sub#s mapped to Ip address
|
|
|
217
|
+ manager.ip2sub[ip]=nil // Delete sub#s mapped to Ip address
|
|
218
|
218
|
return nil
|
|
219
|
|
-}
|
|
|
219
|
+}
|