@@ -2,7 +2,6 @@ package decoder
2
2
3
3
import (
4
4
"bytes"
5
- "errors"
6
5
"hash"
7
6
"os"
8
7
"strconv"
@@ -31,7 +30,7 @@ type Decoder struct {
31
30
unknownCount int
32
31
IPFlow gopacket.Flow
33
32
UDPFlow gopacket.Flow
34
- lru * lru.ARCCache
33
+ lru * lru.Cache
35
34
bigcache * bigcache.BigCache
36
35
hash hash.Hash64
37
36
}
@@ -57,7 +56,7 @@ func NewDecoder() *Decoder {
57
56
host = "sniffer"
58
57
}
59
58
60
- la , err := lru .NewARC ( 8192 )
59
+ la , err := lru .New ( 8000 )
61
60
if err != nil {
62
61
logp .Err ("lru %v" , err )
63
62
}
@@ -68,17 +67,17 @@ func NewDecoder() *Decoder {
68
67
// number of shards (must be a power of 2)
69
68
Shards : 1024 ,
70
69
// time after which entry can be evicted
71
- LifeWindow : 10 * time .Minute ,
70
+ LifeWindow : 180 * time .Minute ,
72
71
// rps * lifeWindow, used only in initial memory allocation
73
72
MaxEntriesInWindow : 1000 * 180 * 60 ,
74
73
// max entry size in bytes, used only in initial memory allocation
75
- MaxEntrySize : 384 ,
74
+ MaxEntrySize : 300 ,
76
75
// prints information about additional memory allocation
77
76
Verbose : true ,
78
77
// cache will not allocate more memory than this limit, value in MB
79
78
// if value is reached then the oldest entries can be overridden for the new ones
80
79
// 0 value means no size limit
81
- HardMaxCacheSize : 1024 ,
80
+ HardMaxCacheSize : 512 ,
82
81
// callback fired when the oldest entry is removed because of its
83
82
// expiration time or no space left for the new entry. Default value is nil which
84
83
// means no callback and it prevents from unwrapping the oldest entry.
@@ -239,7 +238,7 @@ func (d *Decoder) Process(data []byte, ci *gopacket.CaptureInfo) (*Packet, error
239
238
return nil , nil
240
239
}
241
240
242
- func (d * Decoder ) cacheSDPIPPort (payload []byte ) error {
241
+ func (d * Decoder ) cacheSDPIPPort (payload []byte ) {
243
242
var SDPIP , RTCPPort string
244
243
var callID []byte
245
244
@@ -248,38 +247,37 @@ func (d *Decoder) cacheSDPIPPort(payload []byte) error {
248
247
if posRestIP := bytes .Index (restIP , []byte ("\r \n " )); posRestIP >= 0 {
249
248
SDPIP = string (restIP [len ("c=IN IP4 " ):bytes .Index (restIP , []byte ("\r \n " ))])
250
249
} else {
251
- return errors . New ("Couldn't find end of SDP IP" )
250
+ logp . Warn ("Couldn't find end of SDP IP in '%s'" , string ( restIP ) )
252
251
}
253
252
254
253
restPort := payload [posSDPPort :]
255
254
if posRestPort := bytes .Index (restIP , []byte (" RTP" )); posRestPort >= 0 {
256
255
SDPPort , err := strconv .Atoi (string (restPort [len ("m=audio " ):bytes .Index (restPort , []byte (" RTP" ))]))
257
256
if err != nil {
258
- return err
257
+ logp . Warn ( "%v" , err )
259
258
}
260
259
RTCPPort = strconv .Itoa (SDPPort + 1 )
261
260
} else {
262
- return errors . New ("Couldn't find end of SDP Port" )
261
+ logp . Warn ("Couldn't find end of SDP Port in '%s'" , string ( restPort ) )
263
262
}
264
263
265
264
if posCallID := bytes .Index (payload , []byte ("Call-ID: " )); posCallID >= 0 {
266
265
restCallID := payload [posCallID :]
267
266
if posRestCallID := bytes .Index (restIP , []byte ("\r \n " )); posRestCallID >= 0 {
268
267
callID = restCallID [len ("Call-ID: " ):bytes .Index (restCallID , []byte ("\r \n " ))]
269
268
} else {
270
- return errors . New ("Couldn't find end of Call-ID" )
269
+ logp . Warn ("Couldn't find end of Call-ID in '%s'" , string ( restCallID ) )
271
270
}
272
271
} else if posID := bytes .Index (payload , []byte ("i: " )); posID >= 0 {
273
272
restID := payload [posID :]
274
273
if posRestID := bytes .Index (restIP , []byte ("\r \n " )); posRestID >= 0 {
275
274
callID = restID [len ("i: " ):bytes .Index (restID , []byte ("\r \n " ))]
276
275
} else {
277
- return errors . New ("Couldn't find end of Call-ID" )
276
+ logp . Warn ("Couldn't find end of Call-ID in '%s'" , string ( restID ) )
278
277
}
279
278
}
280
279
d .bigcache .Set (SDPIP + RTCPPort , callID )
281
280
}
282
- return nil
283
281
}
284
282
285
283
func (d * Decoder ) correlateRTCP (payload []byte ) ([]byte , []byte , byte ) {
@@ -295,6 +293,6 @@ func (d *Decoder) correlateRTCP(payload []byte) ([]byte, []byte, byte) {
295
293
return nil , nil , 0
296
294
}
297
295
298
- //fmt.Println( string(jsonRTCP))
296
+ logp . Debug ( "decoder" , "RTCP JSON payload: %s" , string (jsonRTCP ))
299
297
return jsonRTCP , corrID , 5
300
298
}
0 commit comments