Skip to content

Commit

Permalink
Merge pull request #517 from systemcrash/chunks
Browse files Browse the repository at this point in the history
[Cc]huncks -> [Cc]hunks
  • Loading branch information
adubovikov committed Feb 21, 2023
2 parents f1bc2a7 + bbca848 commit 994d7ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
)

// The first 4 bytes are the string "HEP3". The next 2 bytes are the length of the
// whole message (len("HEP3") + length of all the chucks we have. The next bytes
// are all the chuncks created by makeChuncks()
// whole message (len("HEP3") + length of all the chunks we have. The next bytes
// are all the chunks created by makeChunks()
// Bytes: 0 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......
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | "HEP3"|len|chuncks(0x0001|0x0002|0x0003|0x0004|0x0007|0x0008|0x0009|0x000a|0x000b|......)
// | "HEP3"|len|chunks(0x0001|0x0002|0x0003|0x0004|0x0007|0x0008|0x0009|0x000a|0x000b|......)
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

var (
Expand All @@ -42,7 +42,7 @@ var (
strEmpty = []byte(``)
)

// HEP chuncks
// HEP chunks
const (
Version = 1 // Chunk 0x0001 IP protocol family (0x02=IPv4, 0x0a=IPv6)
Protocol = 2 // Chunk 0x0002 IP protocol ID (0x06=TCP, 0x11=UDP)
Expand Down
32 changes: 16 additions & 16 deletions decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var (
hepLen7 = []byte{0x00, 0x07}
hepLen8 = []byte{0x00, 0x08}
hepLen10 = []byte{0x00, 0x0a}
chunck16 = []byte{0x00, 0x00}
chunck32 = []byte{0x00, 0x00, 0x00, 0x00}
chunk16 = []byte{0x00, 0x00}
chunk32 = []byte{0x00, 0x00, 0x00, 0x00}
)

func TestDecodeEncodeHEP(t *testing.T) {
Expand Down Expand Up @@ -60,17 +60,17 @@ func BenchmarkDecodeHEP(b *testing.B) {
}

// EncodeHEP creates the HEP Packet which
// will be send to wire
// will be sent on the wire
func EncodeHEP(h *HEP) []byte {
hepMsg := makeChuncks(h)
hepMsg := makeChunks(h)
binary.BigEndian.PutUint16(hepMsg[4:6], uint16(len(hepMsg)))
return hepMsg
}

var w bytes.Buffer

// makeChuncks will construct the respective HEP chunck
func makeChuncks(h *HEP) []byte {
// makeChunks will construct the respective HEP chunk
func makeChunks(h *HEP) []byte {
w.Reset()
w.Write([]byte{0x48, 0x45, 0x50, 0x33})
// hepMsg length placeholder. Will be written later
Expand Down Expand Up @@ -101,26 +101,26 @@ func makeChuncks(h *HEP) []byte {
// Chunk protocol source port
w.Write([]byte{0x00, 0x00, 0x00, 0x07})
w.Write(hepLen8)
binary.BigEndian.PutUint16(chunck16, uint16(h.SrcPort))
w.Write(chunck16)
binary.BigEndian.PutUint16(chunk16, uint16(h.SrcPort))
w.Write(chunk16)

// Chunk protocol destination port
w.Write([]byte{0x00, 0x00, 0x00, 0x08})
w.Write(hepLen8)
binary.BigEndian.PutUint16(chunck16, uint16(h.DstPort))
w.Write(chunck16)
binary.BigEndian.PutUint16(chunk16, uint16(h.DstPort))
w.Write(chunk16)

// Chunk unix timestamp, seconds
w.Write([]byte{0x00, 0x00, 0x00, 0x09})
w.Write(hepLen10)
binary.BigEndian.PutUint32(chunck32, h.Tsec)
w.Write(chunck32)
binary.BigEndian.PutUint32(chunk32, h.Tsec)
w.Write(chunk32)

// Chunk unix timestamp, microseconds offset
w.Write([]byte{0x00, 0x00, 0x00, 0x0a})
w.Write(hepLen10)
binary.BigEndian.PutUint32(chunck32, h.Tmsec)
w.Write(chunck32)
binary.BigEndian.PutUint32(chunk32, h.Tmsec)
w.Write(chunk32)

// Chunk protocol type (DNS, LOG, RTCP, SIP)
w.Write([]byte{0x00, 0x00, 0x00, 0x0b})
Expand All @@ -130,8 +130,8 @@ func makeChuncks(h *HEP) []byte {
// Chunk capture agent ID
w.Write([]byte{0x00, 0x00, 0x00, 0x0c})
w.Write(hepLen10)
binary.BigEndian.PutUint32(chunck32, h.NodeID)
w.Write(chunck32)
binary.BigEndian.PutUint32(chunk32, h.NodeID)
w.Write(chunk32)

// Chunk keep alive timer
//w.Write([]byte{0x00, 0x00, 0x00, 0x0d})
Expand Down

0 comments on commit 994d7ad

Please sign in to comment.