@@ -11,55 +11,111 @@ import Auburn
1111
1212class ConnectionInspector
1313{
14- func analyzeConnections( enableSequenceAnalysis: Bool , enableTLSAnalysis: Bool )
14+ func analyzeConnections( enableSequenceAnalysis: Bool , enableTLSAnalysis: Bool , removePackets : Bool )
1515 {
1616 analysisQueue. async
1717 {
1818 // Allowed Connections
19- let allowedConnectionList : RList < String > = RList ( key: allowedConnectionsKey)
20- while allowedConnectionList. count != 0
21- {
22- print ( " Analyzing an allowed connection async. Allowed connections left: \( allowedConnectionList. count) " )
23- // Get the first connection ID from the list
24- guard let allowedConnectionID = allowedConnectionList. removeFirst ( )
25- else
19+ if removePackets {
20+ NSLog ( " Analyzed packets and removing " )
21+ let allowedConnectionList : RList < String > = RList ( key: allowedConnectionsKey)
22+ while allowedConnectionList. count != 0
2623 {
27- continue
24+ print ( " Analyzing an allowed connection async. Allowed connections left: \( allowedConnectionList. count) " )
25+ // Get the first connection ID from the list
26+ guard let allowedConnectionID = allowedConnectionList. removeFirst ( )
27+ else
28+ {
29+ continue
30+ }
31+
32+ print ( " \n Popped Allowed Connection: \( allowedConnectionID) " )
33+
34+ if " \( type ( of: allowedConnectionID) ) " == " NSNull "
35+ {
36+ continue
37+ }
38+
39+ let allowedConnection = ObservedConnection ( connectionType: . allowed, connectionID: allowedConnectionID)
40+
41+ self . analyze ( connection: allowedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
2842 }
2943
30- print ( " \n Popped Allowed Connection: \( allowedConnectionID ) " )
31-
32- if " \( type ( of : allowedConnectionID ) ) " == " NSNull "
44+ // Blocked Connections
45+ let blockedConnectionList : RList < String > = RList ( key : blockedConnectionsKey )
46+ while blockedConnectionList . count != 0
3347 {
34- continue
48+ print ( " Analyzing a blocked connection async. Blocked connections left: \( blockedConnectionList. count) " )
49+ // Get the first connection ID from the list
50+ guard let blockedConnectionID = blockedConnectionList. removeFirst ( )
51+ else
52+ {
53+ continue
54+ }
55+ print ( " \n Popped Blocked Connection: \( blockedConnectionID) " )
56+
57+ if " \( type ( of: blockedConnectionID) ) " == " NSNull "
58+ {
59+ continue
60+ }
61+
62+ let blockedConnection = ObservedConnection ( connectionType: . blocked, connectionID: blockedConnectionID)
63+
64+ self . analyze ( connection: blockedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
3565 }
36-
37- let allowedConnection = ObservedConnection ( connectionType: . allowed, connectionID: allowedConnectionID)
38-
39- self . analyze ( connection: allowedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
40- }
41-
42- // Blocked Connections
43- let blockedConnectionList : RList < String > = RList ( key: blockedConnectionsKey)
44- while blockedConnectionList. count != 0
45- {
46- print ( " Analyzing a blocked connection async. Blocked connections left: \( blockedConnectionList. count) " )
47- // Get the first connection ID from the list
48- guard let blockedConnectionID = blockedConnectionList. removeFirst ( )
49- else
66+ } else {
67+ NSLog ( " Analyzed packets and retaining " )
68+ let packetsAnalyzedDictionary : RMap < String , Int > = RMap ( key: packetStatsKey)
69+ packetsAnalyzedDictionary [ allowedPacketsAnalyzedKey] = 0
70+ packetsAnalyzedDictionary [ blockedPacketsAnalyzedKey] = 0
71+ NotificationCenter . default. post ( name: . updateStats, object: nil )
72+
73+ let allowedConnectionList : RList < String > = RList ( key: allowedConnectionsKey)
74+ print ( " Analyzing allowed connections \( allowedConnectionList. count) " )
75+ for index in 0 ..< allowedConnectionList. count
5076 {
51- continue
77+ print ( " Analyzing an allowed connection async. \( index) / \( allowedConnectionList. count) " )
78+ // Get the first connection ID from the list
79+ guard let allowedConnectionID = allowedConnectionList [ index]
80+ else
81+ {
82+ continue
83+ }
84+
85+ print ( " \n Indexed Allowed Connection: \( allowedConnectionID) " )
86+
87+ if " \( type ( of: allowedConnectionID) ) " == " NSNull "
88+ {
89+ continue
90+ }
91+
92+ let allowedConnection = ObservedConnection ( connectionType: . allowed, connectionID: allowedConnectionID)
93+
94+ self . analyze ( connection: allowedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
5295 }
53- print ( " \n Popped Blocked Connection: \( blockedConnectionID) " )
5496
55- if " \( type ( of: blockedConnectionID) ) " == " NSNull "
97+ // Blocked Connections
98+ let blockedConnectionList : RList < String > = RList ( key: blockedConnectionsKey)
99+ print ( " Analyzing blocked connections \( blockedConnectionList. count) " )
100+ for index in 0 ..< blockedConnectionList. count
56101 {
57- continue
102+ print ( " Analyzing a blocked connection async. \( index) / \( allowedConnectionList. count) " )
103+ // Get the first connection ID from the list
104+ guard let blockedConnectionID = blockedConnectionList [ index]
105+ else
106+ {
107+ continue
108+ }
109+
110+ if " \( type ( of: blockedConnectionID) ) " == " NSNull "
111+ {
112+ continue
113+ }
114+
115+ let blockedConnection = ObservedConnection ( connectionType: . blocked, connectionID: blockedConnectionID)
116+
117+ self . analyze ( connection: blockedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
58118 }
59-
60- let blockedConnection = ObservedConnection ( connectionType: . blocked, connectionID: blockedConnectionID)
61-
62- self . analyze ( connection: blockedConnection, enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
63119 }
64120
65121 self . scoreConnections ( enableSequenceAnalysis: enableSequenceAnalysis, enableTLSAnalysis: enableTLSAnalysis)
0 commit comments