-
Notifications
You must be signed in to change notification settings - Fork 8
/
dpt.info.lua
278 lines (240 loc) · 7.18 KB
/
dpt.info.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
-- Info package
-- This package provides information tables that are built up and maintained over the course of the dissection.
-- Package header
local master = diffusion or {}
if master.info ~= nil then
return master.info
end
local int_to_string = master.utilities.int_to_string
-- -----------------------------------
-- The Alias Table
local AliasTable = {}
function AliasTable:new()
local result = {}
setmetatable( result, self )
self.__index = self
return result
end
function AliasTable:setAlias( tcpStream, alias, topicName )
-- Get the table for the tcpStream, or create a new one
local conversation = self[tcpStream] or {}
conversation[alias] = topicName
self[tcpStream] = conversation
end
function AliasTable:getAlias( tcpStream, alias )
local conversation = self[tcpStream]
if conversation == nil then
return nil
end
return conversation[alias]
end
local aliasTable = AliasTable:new()
-- ------------------------------------
-- The EndpointTable Table
local EndpointTable = {}
function EndpointTable:new()
local result = {}
setmetatable( result, self )
self.__index = self
return result
end
function EndpointTable:add( host, port, server )
local machine = self[host] or {}
machine[port] = server
self[host] = machine
end
function EndpointTable:get( host, port )
return self[host][port]
end
local clientTable = EndpointTable:new()
local serverTable = EndpointTable:new()
-- -----------------------------------
-- Create and register a listener for TCP connections
local tcpConnections = {}
function tcpConnections:len()
local result = 0
local i,v
for i,v in pairs( self ) do result = result +1 end
return result
end
-- -----------------------------------
-- Stores information about specific service requests
local ServiceMessageTable = {}
function ServiceMessageTable:new()
local result = {}
setmetatable( result, self )
self.__index = self
return result
end
-- Add information about a service request
function ServiceMessageTable:addRequest( tcpStream, requestSrc, conversation, time )
local serviceConversationStream = self[tcpStream] or {}
local serviceConversation = serviceConversationStream[requestSrc] or {}
serviceConversation[conversation] = {}
serviceConversation[conversation].time = time
serviceConversationStream[requestSrc] = serviceConversation
self[tcpStream] = serviceConversationStream
end
-- Get the time of a service request
function ServiceMessageTable:getRequestTime( tcpStream, requestSrc, conversation )
local res = self[tcpStream][requestSrc][conversation]
return res.time
end
local serviceMessageTable = ServiceMessageTable:new()
local DescriptionsTable = {
count = 0
}
function DescriptionsTable:new()
local result = {}
setmetatable( result, DescriptionsTable )
DescriptionsTable.__index = DescriptionsTable
return result
end
function DescriptionsTable:addDescription( description )
local pos = self.count
self[pos] = description
self.count = pos + 1
end
function DescriptionsTable:summarise()
if self.count == 1 then
return self[0]
end
local desc = string.format( "%d messages", self.count )
for i = 0, self.count - 1 do
desc = desc .. " [" .. self[i] .. "]"
if i < self.count - 1 then
desc = desc .. ","
end
end
return desc
end
-- -----------------------------------
-- The Topic Info Table
local TopicInfoTable = {}
function TopicInfoTable:new()
local result = {}
setmetatable( result, self )
self.__index = self
return result
end
function TopicInfoTable:setInfo( tcpStream, id, topicPath, topicDetails )
-- Get the table for the tcpStream, or create a new one
local stream = self[tcpStream] or {}
local info = stream[id] or {}
info.topicPath = topicPath
info.alias = string.format ( "!%s", int_to_string( id, 36 ) )
info.topicDetails = topicDetails
stream[id] = info
stream[info.alias] = info
self[tcpStream] = stream
end
function TopicInfoTable:getTopicPath( tcpStream, id )
if self[tcpStream] == nil then
return nil
end
if self[tcpStream][id] == nil then
return nil
end
return self[tcpStream][id].topicPath
end
function TopicInfoTable:getTopicDetails( tcpStream, id )
if self[tcpStream] == nil then
return nil
end
if self[tcpStream][id] == nil then
return nil
end
return self[tcpStream][id].topicDetails
end
local topicInfoTable = TopicInfoTable:new()
local UpdateStreamInfo = {}
function UpdateStreamInfo:new()
local result = {}
setmetatable( result, self )
self.__index = self
return result
end
function UpdateStreamInfo:recordCreateRequest( tcpStream, conversation, path )
local updateStream = {
path = path
}
if self[tcpStream] ~= nil then
self[tcpStream].conversations[conversation] = updateStream
else
local conversations = {}
conversations[conversation] = updateStream
self[tcpStream] = {
conversations = conversations,
}
end
end
function UpdateStreamInfo:recordCreateResponse( tcpStream, conversation, updateStreamId )
if self.streams == nil then
self.streams = {}
end
local conn = self[tcpStream]
if conn ~= nil then
local updateStream = conn.conversations[conversation]
if updateStream ~= nil then
-- Found the update stream creation request
-- Find the stream information for the partition
local partition = self.streams[updateStreamId.partition.int]
if partition == nil then
partition = {}
self.streams[updateStreamId.partition.int] = partition
end
-- Find the stream information for the generation
local generation = partition[updateStreamId.generation.int]
if generation == nil then
generation = {}
partition[updateStreamId.generation.int] = generation
end
-- Find the stream information for the topic Id
local topicInfo = generation[updateStreamId.topicId.int]
if topicInfo == nil then
topicInfo = {}
generation[updateStreamId.topicId.int] = topicInfo
end
-- Update the stream information for the instance
topicInfo[updateStreamId.instance.int] = updateStream
-- Return stream information
return updateStream
end
end
end
function UpdateStreamInfo:getUpdateStream( updateStreamId )
if self.streams == nil then
return nil
end
-- Find the stream information for the partition
local partition = self.streams[updateStreamId.partition.int]
if partition == nil then
return nil
end
-- Find the stream information for the generation
local generation = partition[updateStreamId.generation.int]
if generation == nil then
return nil
end
-- Find the stream information for the topic Id
local topicInfo = generation[updateStreamId.topicId.int]
if topicInfo == nil then
return nil
end
-- Return stream information
return topicInfo[updateStreamId.instance.int]
end
local updateStreamTable = UpdateStreamInfo:new()
-- Package footer
master.info = {
aliasTable = aliasTable,
tcpConnections = tcpConnections,
topicInfoTable = topicInfoTable,
clientTable = clientTable,
serverTable = serverTable,
serviceMessageTable = serviceMessageTable,
DescriptionsTable = DescriptionsTable,
updateStreamTable = updateStreamTable
}
diffusion = master
return master.info