Skip to content

Commit 758b864

Browse files
committed
Fix array extend. #10
1 parent 12a0a18 commit 758b864

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

exporter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func (nfFile *NfFile) addExporterStat(record []byte) {
8181
packets := binary.LittleEndian.Uint64(record[offset+8 : offset+16]) // number of packets sent by this exporter
8282
flows := binary.LittleEndian.Uint64(record[offset+16 : offset+24]) // number of flows sent by this exporter
8383
offset += 24
84+
if int(sysId) >= len(nfFile.ExporterList) {
85+
fmt.Printf("Invalid Exporter id: %d\n", sysId)
86+
return
87+
}
8488
if nfFile.ExporterList[sysId].SysId == uint16(sysId) {
8589
nfFile.ExporterList[sysId].SequenceFailures += sequenceFailures
8690
nfFile.ExporterList[sysId].Packets += packets

nffile.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ func (nfFile *NfFile) ReadDataBlocks() (chan DataBlock, error) {
250250
// fmt.Printf("nfFile read block header: %v", err)
251251
return
252252
}
253+
// fmt.Printf("Datablock type: %d, size: %d records: %d\n", dataBlock.Header.Type, dataBlock.Header.Size, dataBlock.Header.NumRecords)
254+
if dataBlock.Header.Type != 3 {
255+
if _, err := nfFile.file.Seek(int64(dataBlock.Header.Size), os.SEEK_CUR); err != nil {
256+
fmt.Fprintf(os.Stderr, "file seek error: %v\n", err)
257+
}
258+
continue
259+
}
253260
var err error
254261
dataBlock.Data, err = nfFile.uncompressBlock(&dataBlock.Header)
255262
// fmt.Printf("nfFile uncompress block: %v", err)

nffileV1.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,15 @@ func (nfFile *NfFile) openV1() error {
119119
nfFile.Header.Version = nfFileV1Header.Version
120120
nfFile.Header.NfVersion = 0x106
121121
nfFile.Header.Created = 0
122-
nfFile.Header.Compression = 0
122+
compression := 0
123+
if nfFileV1Header.Flags&0x1 == 1 {
124+
compression = 1 // LO0
125+
} else if nfFileV1Header.Flags&0x8 == 0x8 {
126+
compression = 2 // BZIP2
127+
} else if nfFileV1Header.Flags&0x10 == 0x10 {
128+
compression = 3 // LZ4
129+
}
130+
nfFile.Header.Compression = uint8(compression)
123131
nfFile.Header.Encryption = 0
124132
nfFile.Header.AppendixBlocks = 0
125133
nfFile.Header.Unused = 0

orderby.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ func (recordChain *RecordChain) OrderBy(orderBy string, direction int) *RecordCh
152152
var cnt uint32 = 0
153153
for record := range readChan {
154154
if uint32(arrayLen)-cnt == 0 {
155-
// double array, if exhausted
156-
sortArray = append(make([]sortRecord, 2*arrayLen), sortArray...)
157-
recordArray = append(make([]*FlowRecordV3, 2*arrayLen), recordArray...)
155+
// extend array, if exhausted
156+
// sortArray
157+
sortArray = append(sortArray, make([]sortRecord, 2*arrayLen)...)
158+
// recordArray
159+
recordArray = append(recordArray, make([]*FlowRecordV3, 2*arrayLen)...)
158160

159161
// use new len of array. Go may assign more memory than requested
160162
// so use actual len

0 commit comments

Comments
 (0)