Skip to content

Commit

Permalink
Update rsdos schema version 2 to include maxmind geo-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
salcock committed May 7, 2021
1 parent 472e826 commit 4ef4967
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/pyavro_stardust/rsdos.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ cpdef enum RsdosAttribute:
ATTR_RSDOS_FIRST_TARGET_PORT = 16
ATTR_RSDOS_LAST_ATTRIBUTE = 17

cpdef enum RsdosAttributeStirng:
ATTR_RSDOS_MAXMIND_CONTINENT = 0
ATTR_RSDOS_MAXMIND_COUNTRY = 1
ATTR_RSDOS_LAST_STRING_ATTRIBUTE = 2

cdef class AvroRsdos(AvroRecord):

cdef unsigned char *packetcontent
Expand Down
19 changes: 16 additions & 3 deletions src/pyavro_stardust/rsdos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ from pyavro_stardust.baseavro cimport AvroRecord, read_long, read_string, \
@cython.final
cdef class AvroRsdos(AvroRecord):
def __init__(self):
super().__init__(ATTR_RSDOS_LAST_ATTRIBUTE, 0, 0)
super().__init__(ATTR_RSDOS_LAST_ATTRIBUTE,
ATTR_RSDOS_LAST_STRING_ATTRIBUTE, 0)
self.pktcontentlen = 0
self.packetcontent = NULL
self.schemaversion = 1

def __str__(self):
return "%u %u.%06u %u.%06u %08x %u %u %u %u %u %u %u %u %u" % \
return "%u %u.%06u %u.%06u %08x %u %u %u %u %u %u %u %u %u %s %s" % \
(self.attributes_l[<int>ATTR_RSDOS_TIMESTAMP], \
self.attributes_l[<int>ATTR_RSDOS_START_TIME_SEC],
self.attributes_l[<int>ATTR_RSDOS_START_TIME_USEC],
Expand All @@ -63,7 +64,9 @@ cdef class AvroRsdos(AvroRecord):
self.attributes_l[<int>ATTR_RSDOS_PACKET_CNT],
self.attributes_l[<int>ATTR_RSDOS_BYTE_CNT],
self.attributes_l[<int>ATTR_RSDOS_MAX_PPM_INTERVAL],
self.getRsdosPacketSize())
self.getRsdosPacketSize(),
self.attributes_s[<int>ATTR_RSDOS_MAXMIND_CONTINENT],
self.attributes_s[<int>ATTR_RSDOS_MAXMIND_COUNTRY])

cpdef dict asDict(self):
cdef dict result
Expand Down Expand Up @@ -95,6 +98,8 @@ cdef class AvroRsdos(AvroRecord):
if self.schemaversion == 2:
result['first_attack_port'] = self.attributes_l[<int>ATTR_RSDOS_FIRST_ATTACK_PORT]
result['first_target_port'] = self.attributes_l[<int>ATTR_RSDOS_FIRST_TARGET_PORT]
result['maxmind_continent'] = self.attributes_s[<int>ATTR_RSDOS_MAXMIND_CONTINENT]
result['maxmind_country'] = self.attributes_s[<int>ATTR_RSDOS_MAXMIND_COUNTRY]

return result

Expand Down Expand Up @@ -195,6 +200,14 @@ cdef class AvroRsdosReader(AvroReader):
return 0
offset += offinc

if self.schemaversion == 2:
for i in range(0, ATTR_RSDOS_LAST_STRING_ATTRIBUTE):
offinc = self.currentrec.parseString(buf[offset:],
maxlen - offset, i)
if offinc <= 0:
return 0
offset += offinc

return self.currentrec.setRsdosPacketString(buf[offset:],
maxlen - offset);

Expand Down

0 comments on commit 4ef4967

Please sign in to comment.