@@ -30,9 +30,9 @@ type Decoder struct {
30
30
unknownCount int
31
31
IPFlow gopacket.Flow
32
32
UDPFlow gopacket.Flow
33
- lru * lru. Cache
34
- bigcache * bigcache. BigCache
35
- hash hash. Hash64
33
+ SIPHash hash. Hash64
34
+ SIPCache * lru. Cache
35
+ RTCPCache * bigcache. BigCache
36
36
}
37
37
38
38
type Packet struct {
@@ -56,14 +56,14 @@ func NewDecoder() *Decoder {
56
56
host = "sniffer"
57
57
}
58
58
59
- la , err := lru .New (8000 )
59
+ sh := xxhash .New ()
60
+
61
+ sc , err := lru .New (8000 )
60
62
if err != nil {
61
63
logp .Err ("lru %v" , err )
62
64
}
63
65
64
- xh := xxhash .New ()
65
-
66
- bConf := bigcache.Config {
66
+ rcConf := bigcache.Config {
67
67
// number of shards (must be a power of 2)
68
68
Shards : 1024 ,
69
69
// time after which entry can be evicted
@@ -73,7 +73,7 @@ func NewDecoder() *Decoder {
73
73
// max entry size in bytes, used only in initial memory allocation
74
74
MaxEntrySize : 300 ,
75
75
// prints information about additional memory allocation
76
- Verbose : true ,
76
+ Verbose : false ,
77
77
// cache will not allocate more memory than this limit, value in MB
78
78
// if value is reached then the oldest entries can be overridden for the new ones
79
79
// 0 value means no size limit
@@ -84,7 +84,7 @@ func NewDecoder() *Decoder {
84
84
OnRemove : nil ,
85
85
}
86
86
87
- bc , err := bigcache .NewBigCache (bConf )
87
+ rc , err := bigcache .NewBigCache (rcConf )
88
88
if err != nil {
89
89
logp .Err ("bigcache %v" , err )
90
90
}
@@ -99,9 +99,9 @@ func NewDecoder() *Decoder {
99
99
tcpCount : 0 ,
100
100
dnsCount : 0 ,
101
101
unknownCount : 0 ,
102
- lru : la ,
103
- hash : xh ,
104
- bigcache : bc ,
102
+ SIPHash : sh ,
103
+ SIPCache : sc ,
104
+ RTCPCache : rc ,
105
105
}
106
106
go d .flushFrag ()
107
107
go d .printStats ()
@@ -126,12 +126,12 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
126
126
}
127
127
128
128
if config .Cfg .Dedup {
129
- d .hash .Write (ip4 .Payload )
129
+ d .SIPHash .Write (ip4 .Payload )
130
130
//key := fastHash(ip4.Payload)
131
- key := d .hash .Sum64 ()
132
- d .hash .Reset ()
133
- _ , dup := d .lru .Get (key )
134
- d .lru .Add (key , nil )
131
+ key := d .SIPHash .Sum64 ()
132
+ d .SIPHash .Reset ()
133
+ _ , dup := d .SIPCache .Get (key )
134
+ d .SIPCache .Add (key , nil )
135
135
if dup == true {
136
136
d .dupCount ++
137
137
return nil , nil
@@ -251,7 +251,7 @@ func (d *Decoder) cacheSDPIPPort(payload []byte) {
251
251
}
252
252
253
253
restPort := payload [posSDPPort :]
254
- if posRestPort := bytes .Index (restIP , []byte (" RTP" )); posRestPort >= 0 {
254
+ if posRestPort := bytes .Index (restPort , []byte (" RTP" )); posRestPort >= 0 {
255
255
SDPPort , err := strconv .Atoi (string (restPort [len ("m=audio " ):bytes .Index (restPort , []byte (" RTP" ))]))
256
256
if err != nil {
257
257
logp .Warn ("%v" , err )
@@ -263,20 +263,20 @@ func (d *Decoder) cacheSDPIPPort(payload []byte) {
263
263
264
264
if posCallID := bytes .Index (payload , []byte ("Call-ID: " )); posCallID >= 0 {
265
265
restCallID := payload [posCallID :]
266
- if posRestCallID := bytes .Index (restIP , []byte ("\r \n " )); posRestCallID >= 0 {
266
+ if posRestCallID := bytes .Index (restCallID , []byte ("\r \n " )); posRestCallID >= 0 {
267
267
callID = restCallID [len ("Call-ID: " ):bytes .Index (restCallID , []byte ("\r \n " ))]
268
268
} else {
269
269
logp .Warn ("Couldn't find end of Call-ID in '%s'" , string (restCallID ))
270
270
}
271
271
} else if posID := bytes .Index (payload , []byte ("i: " )); posID >= 0 {
272
272
restID := payload [posID :]
273
- if posRestID := bytes .Index (restIP , []byte ("\r \n " )); posRestID >= 0 {
273
+ if posRestID := bytes .Index (restID , []byte ("\r \n " )); posRestID >= 0 {
274
274
callID = restID [len ("i: " ):bytes .Index (restID , []byte ("\r \n " ))]
275
275
} else {
276
276
logp .Warn ("Couldn't find end of Call-ID in '%s'" , string (restID ))
277
277
}
278
278
}
279
- d .bigcache .Set (SDPIP + RTCPPort , callID )
279
+ d .RTCPCache .Set (SDPIP + RTCPPort , callID )
280
280
}
281
281
}
282
282
@@ -287,7 +287,7 @@ func (d *Decoder) correlateRTCP(payload []byte) ([]byte, []byte, byte) {
287
287
return nil , nil , 0
288
288
}
289
289
290
- corrID , err := d .bigcache .Get (d .IPFlow .Src ().String () + d .UDPFlow .Src ().String ())
290
+ corrID , err := d .RTCPCache .Get (d .IPFlow .Src ().String () + d .UDPFlow .Src ().String ())
291
291
if err != nil {
292
292
logp .Warn ("%v" , err )
293
293
return nil , nil , 0
0 commit comments