@@ -337,88 +337,90 @@ Public Class Component
337337 If _DBFilePath <> "" Then
338338 CreateMemoryMappedFile()
339339
340- ' below use temp accessor as we only need once to read meta data (use this even when in filestream mode)
341- Using _MetaAccessor As MemoryMappedViewAccessor = _MMF.CreateViewAccessor( 0 , 64 , MemoryMappedFileAccess.Read) ' 64 bytes header
342- _DBType = _MetaAccessor.ReadByte( 0 )
343- _DBColumn = _MetaAccessor.ReadByte( 1 )
344- _DBYear = _MetaAccessor.ReadByte( 2 )
345- _DBMonth = _MetaAccessor.ReadByte( 3 )
346- _DBDay = _MetaAccessor.ReadByte( 4 )
347- _DBCount = _MetaAccessor.ReadInt32( 5 ) '4 bytes
348- _BaseAddr = _MetaAccessor.ReadInt32( 9 ) '4 bytes
349- _DBCountIPv6 = _MetaAccessor.ReadInt32( 13 ) '4 bytes
350- _BaseAddrIPv6 = _MetaAccessor.ReadInt32( 17 ) '4 bytes
351- _IndexBaseAddr = _MetaAccessor.ReadInt32( 21 ) '4 bytes
352- _IndexBaseAddrIPv6 = _MetaAccessor.ReadInt32( 25 ) '4 bytes
353-
354- _IPv4ColumnSize = _DBColumn << 2 ' 4 bytes each column
355- _IPv6ColumnSize = 16 + ((_DBColumn - 1 ) << 2 ) ' 4 bytes each column, except IPFrom column which is 16 bytes
356-
357- ' since both IPv4 and IPv6 use 4 bytes for the below columns, can just do it once here
358- 'COUNTRY_POSITION_OFFSET = If(COUNTRY_POSITION(_DBType) <> 0, (COUNTRY_POSITION(_DBType) - 1) << 2, 0)
359- 'REGION_POSITION_OFFSET = If(REGION_POSITION(_DBType) <> 0, (REGION_POSITION(_DBType) - 1) << 2, 0)
360- 'CITY_POSITION_OFFSET = If(CITY_POSITION(_DBType) <> 0, (CITY_POSITION(_DBType) - 1) << 2, 0)
361- 'ISP_POSITION_OFFSET = If(ISP_POSITION(_DBType) <> 0, (ISP_POSITION(_DBType) - 1) << 2, 0)
362- 'PROXYTYPE_POSITION_OFFSET = If(PROXYTYPE_POSITION(_DBType) <> 0, (PROXYTYPE_POSITION(_DBType) - 1) << 2, 0)
363- 'DOMAIN_POSITION_OFFSET = If(DOMAIN_POSITION(_DBType) <> 0, (DOMAIN_POSITION(_DBType) - 1) << 2, 0)
364- 'USAGETYPE_POSITION_OFFSET = If(USAGETYPE_POSITION(_DBType) <> 0, (USAGETYPE_POSITION(_DBType) - 1) << 2, 0)
365- 'ASN_POSITION_OFFSET = If(ASN_POSITION(_DBType) <> 0, (ASN_POSITION(_DBType) - 1) << 2, 0)
366- 'AS_POSITION_OFFSET = If(AS_POSITION(_DBType) <> 0, (AS_POSITION(_DBType) - 1) << 2, 0)
367- 'LASTSEEN_POSITION_OFFSET = If(LASTSEEN_POSITION(_DBType) <> 0, (LASTSEEN_POSITION(_DBType) - 1) << 2, 0)
368- 'THREAT_POSITION_OFFSET = If(THREAT_POSITION(_DBType) <> 0, (THREAT_POSITION(_DBType) - 1) << 2, 0)
369-
370- ' slightly different offset for reading by row
371- COUNTRY_POSITION_OFFSET = If (COUNTRY_POSITION(_DBType) <> 0 , (COUNTRY_POSITION(_DBType) - 2 ) << 2 , 0 )
372- REGION_POSITION_OFFSET = If (REGION_POSITION(_DBType) <> 0 , (REGION_POSITION(_DBType) - 2 ) << 2 , 0 )
373- CITY_POSITION_OFFSET = If (CITY_POSITION(_DBType) <> 0 , (CITY_POSITION(_DBType) - 2 ) << 2 , 0 )
374- ISP_POSITION_OFFSET = If (ISP_POSITION(_DBType) <> 0 , (ISP_POSITION(_DBType) - 2 ) << 2 , 0 )
375- PROXYTYPE_POSITION_OFFSET = If (PROXYTYPE_POSITION(_DBType) <> 0 , (PROXYTYPE_POSITION(_DBType) - 2 ) << 2 , 0 )
376- DOMAIN_POSITION_OFFSET = If (DOMAIN_POSITION(_DBType) <> 0 , (DOMAIN_POSITION(_DBType) - 2 ) << 2 , 0 )
377- USAGETYPE_POSITION_OFFSET = If (USAGETYPE_POSITION(_DBType) <> 0 , (USAGETYPE_POSITION(_DBType) - 2 ) << 2 , 0 )
378- ASN_POSITION_OFFSET = If (ASN_POSITION(_DBType) <> 0 , (ASN_POSITION(_DBType) - 2 ) << 2 , 0 )
379- AS_POSITION_OFFSET = If (AS_POSITION(_DBType) <> 0 , (AS_POSITION(_DBType) - 2 ) << 2 , 0 )
380- LASTSEEN_POSITION_OFFSET = If (LASTSEEN_POSITION(_DBType) <> 0 , (LASTSEEN_POSITION(_DBType) - 2 ) << 2 , 0 )
381- THREAT_POSITION_OFFSET = If (THREAT_POSITION(_DBType) <> 0 , (THREAT_POSITION(_DBType) - 2 ) << 2 , 0 )
382-
383- COUNTRY_ENABLED = If (COUNTRY_POSITION(_DBType) <> 0 , True , False )
384- REGION_ENABLED = If (REGION_POSITION(_DBType) <> 0 , True , False )
385- CITY_ENABLED = If (CITY_POSITION(_DBType) <> 0 , True , False )
386- ISP_ENABLED = If (ISP_POSITION(_DBType) <> 0 , True , False )
387- PROXYTYPE_ENABLED = If (PROXYTYPE_POSITION(_DBType) <> 0 , True , False )
388- DOMAIN_ENABLED = If (DOMAIN_POSITION(_DBType) <> 0 , True , False )
389- USAGETYPE_ENABLED = If (USAGETYPE_POSITION(_DBType) <> 0 , True , False )
390- ASN_ENABLED = If (ASN_POSITION(_DBType) <> 0 , True , False )
391- AS_ENABLED = If (AS_POSITION(_DBType) <> 0 , True , False )
392- LASTSEEN_ENABLED = If (LASTSEEN_POSITION(_DBType) <> 0 , True , False )
393- THREAT_ENABLED = If (THREAT_POSITION(_DBType) <> 0 , True , False )
394- End Using
395-
396- Using _IndexAccessor As MemoryMappedViewAccessor = _MMF.CreateViewAccessor(_IndexBaseAddr - 1 , _BaseAddr - _IndexBaseAddr, MemoryMappedFileAccess.Read) ' reading indexes
397- Dim Pointer As Integer = 0
398-
399- ' read IPv4 index
400- For x As Integer = _IndexArrayIPv4.GetLowerBound( 0 ) To _IndexArrayIPv4.GetUpperBound( 0 )
401- _IndexArrayIPv4(x, 0 ) = _IndexAccessor.ReadInt32(Pointer) '4 bytes for from row
402- _IndexArrayIPv4(x, 1 ) = _IndexAccessor.ReadInt32(Pointer + 4 ) '4 bytes for to row
403- Pointer += 8
404- Next
405-
406- If _IndexBaseAddrIPv6 > 0 Then
407- ' read IPv6 index
408- For x As Integer = _IndexArrayIPv6.GetLowerBound( 0 ) To _IndexArrayIPv6.GetUpperBound( 0 )
409- _IndexArrayIPv6(x, 0 ) = _IndexAccessor.ReadInt32(Pointer) '4 bytes for from row
410- _IndexArrayIPv6(x, 1 ) = _IndexAccessor.ReadInt32(Pointer + 4 ) '4 bytes for to row
340+ If _MMF IsNot Nothing Then
341+ ' below use temp accessor as we only need once to read meta data (use this even when in filestream mode)
342+ Using _MetaAccessor As MemoryMappedViewAccessor = _MMF.CreateViewAccessor( 0 , 64 , MemoryMappedFileAccess.Read) ' 64 bytes header
343+ _DBType = _MetaAccessor.ReadByte( 0 )
344+ _DBColumn = _MetaAccessor.ReadByte( 1 )
345+ _DBYear = _MetaAccessor.ReadByte( 2 )
346+ _DBMonth = _MetaAccessor.ReadByte( 3 )
347+ _DBDay = _MetaAccessor.ReadByte( 4 )
348+ _DBCount = _MetaAccessor.ReadInt32( 5 ) '4 bytes
349+ _BaseAddr = _MetaAccessor.ReadInt32( 9 ) '4 bytes
350+ _DBCountIPv6 = _MetaAccessor.ReadInt32( 13 ) '4 bytes
351+ _BaseAddrIPv6 = _MetaAccessor.ReadInt32( 17 ) '4 bytes
352+ _IndexBaseAddr = _MetaAccessor.ReadInt32( 21 ) '4 bytes
353+ _IndexBaseAddrIPv6 = _MetaAccessor.ReadInt32( 25 ) '4 bytes
354+
355+ _IPv4ColumnSize = _DBColumn << 2 ' 4 bytes each column
356+ _IPv6ColumnSize = 16 + ((_DBColumn - 1 ) << 2 ) ' 4 bytes each column, except IPFrom column which is 16 bytes
357+
358+ ' since both IPv4 and IPv6 use 4 bytes for the below columns, can just do it once here
359+ 'COUNTRY_POSITION_OFFSET = If(COUNTRY_POSITION(_DBType) <> 0, (COUNTRY_POSITION(_DBType) - 1) << 2, 0)
360+ 'REGION_POSITION_OFFSET = If(REGION_POSITION(_DBType) <> 0, (REGION_POSITION(_DBType) - 1) << 2, 0)
361+ 'CITY_POSITION_OFFSET = If(CITY_POSITION(_DBType) <> 0, (CITY_POSITION(_DBType) - 1) << 2, 0)
362+ 'ISP_POSITION_OFFSET = If(ISP_POSITION(_DBType) <> 0, (ISP_POSITION(_DBType) - 1) << 2, 0)
363+ 'PROXYTYPE_POSITION_OFFSET = If(PROXYTYPE_POSITION(_DBType) <> 0, (PROXYTYPE_POSITION(_DBType) - 1) << 2, 0)
364+ 'DOMAIN_POSITION_OFFSET = If(DOMAIN_POSITION(_DBType) <> 0, (DOMAIN_POSITION(_DBType) - 1) << 2, 0)
365+ 'USAGETYPE_POSITION_OFFSET = If(USAGETYPE_POSITION(_DBType) <> 0, (USAGETYPE_POSITION(_DBType) - 1) << 2, 0)
366+ 'ASN_POSITION_OFFSET = If(ASN_POSITION(_DBType) <> 0, (ASN_POSITION(_DBType) - 1) << 2, 0)
367+ 'AS_POSITION_OFFSET = If(AS_POSITION(_DBType) <> 0, (AS_POSITION(_DBType) - 1) << 2, 0)
368+ 'LASTSEEN_POSITION_OFFSET = If(LASTSEEN_POSITION(_DBType) <> 0, (LASTSEEN_POSITION(_DBType) - 1) << 2, 0)
369+ 'THREAT_POSITION_OFFSET = If(THREAT_POSITION(_DBType) <> 0, (THREAT_POSITION(_DBType) - 1) << 2, 0)
370+
371+ ' slightly different offset for reading by row
372+ COUNTRY_POSITION_OFFSET = If (COUNTRY_POSITION(_DBType) <> 0 , (COUNTRY_POSITION(_DBType) - 2 ) << 2 , 0 )
373+ REGION_POSITION_OFFSET = If (REGION_POSITION(_DBType) <> 0 , (REGION_POSITION(_DBType) - 2 ) << 2 , 0 )
374+ CITY_POSITION_OFFSET = If (CITY_POSITION(_DBType) <> 0 , (CITY_POSITION(_DBType) - 2 ) << 2 , 0 )
375+ ISP_POSITION_OFFSET = If (ISP_POSITION(_DBType) <> 0 , (ISP_POSITION(_DBType) - 2 ) << 2 , 0 )
376+ PROXYTYPE_POSITION_OFFSET = If (PROXYTYPE_POSITION(_DBType) <> 0 , (PROXYTYPE_POSITION(_DBType) - 2 ) << 2 , 0 )
377+ DOMAIN_POSITION_OFFSET = If (DOMAIN_POSITION(_DBType) <> 0 , (DOMAIN_POSITION(_DBType) - 2 ) << 2 , 0 )
378+ USAGETYPE_POSITION_OFFSET = If (USAGETYPE_POSITION(_DBType) <> 0 , (USAGETYPE_POSITION(_DBType) - 2 ) << 2 , 0 )
379+ ASN_POSITION_OFFSET = If (ASN_POSITION(_DBType) <> 0 , (ASN_POSITION(_DBType) - 2 ) << 2 , 0 )
380+ AS_POSITION_OFFSET = If (AS_POSITION(_DBType) <> 0 , (AS_POSITION(_DBType) - 2 ) << 2 , 0 )
381+ LASTSEEN_POSITION_OFFSET = If (LASTSEEN_POSITION(_DBType) <> 0 , (LASTSEEN_POSITION(_DBType) - 2 ) << 2 , 0 )
382+ THREAT_POSITION_OFFSET = If (THREAT_POSITION(_DBType) <> 0 , (THREAT_POSITION(_DBType) - 2 ) << 2 , 0 )
383+
384+ COUNTRY_ENABLED = If (COUNTRY_POSITION(_DBType) <> 0 , True , False )
385+ REGION_ENABLED = If (REGION_POSITION(_DBType) <> 0 , True , False )
386+ CITY_ENABLED = If (CITY_POSITION(_DBType) <> 0 , True , False )
387+ ISP_ENABLED = If (ISP_POSITION(_DBType) <> 0 , True , False )
388+ PROXYTYPE_ENABLED = If (PROXYTYPE_POSITION(_DBType) <> 0 , True , False )
389+ DOMAIN_ENABLED = If (DOMAIN_POSITION(_DBType) <> 0 , True , False )
390+ USAGETYPE_ENABLED = If (USAGETYPE_POSITION(_DBType) <> 0 , True , False )
391+ ASN_ENABLED = If (ASN_POSITION(_DBType) <> 0 , True , False )
392+ AS_ENABLED = If (AS_POSITION(_DBType) <> 0 , True , False )
393+ LASTSEEN_ENABLED = If (LASTSEEN_POSITION(_DBType) <> 0 , True , False )
394+ THREAT_ENABLED = If (THREAT_POSITION(_DBType) <> 0 , True , False )
395+ End Using
396+
397+ Using _IndexAccessor As MemoryMappedViewAccessor = _MMF.CreateViewAccessor(_IndexBaseAddr - 1 , _BaseAddr - _IndexBaseAddr, MemoryMappedFileAccess.Read) ' reading indexes
398+ Dim Pointer As Integer = 0
399+
400+ ' read IPv4 index
401+ For x As Integer = _IndexArrayIPv4.GetLowerBound( 0 ) To _IndexArrayIPv4.GetUpperBound( 0 )
402+ _IndexArrayIPv4(x, 0 ) = _IndexAccessor.ReadInt32(Pointer) '4 bytes for from row
403+ _IndexArrayIPv4(x, 1 ) = _IndexAccessor.ReadInt32(Pointer + 4 ) '4 bytes for to row
411404 Pointer += 8
412405 Next
413- End If
414- End Using
415406
416- If _UseMemoryMappedFile Then
417- CreateAccessors()
418- Else
419- DestroyMemoryMappedFile()
407+ If _IndexBaseAddrIPv6 > 0 Then
408+ ' read IPv6 index
409+ For x As Integer = _IndexArrayIPv6.GetLowerBound( 0 ) To _IndexArrayIPv6.GetUpperBound( 0 )
410+ _IndexArrayIPv6(x, 0 ) = _IndexAccessor.ReadInt32(Pointer) '4 bytes for from row
411+ _IndexArrayIPv6(x, 1 ) = _IndexAccessor.ReadInt32(Pointer + 4 ) '4 bytes for to row
412+ Pointer += 8
413+ Next
414+ End If
415+ End Using
416+
417+ If _UseMemoryMappedFile Then
418+ CreateAccessors()
419+ Else
420+ DestroyMemoryMappedFile()
421+ End If
422+ LoadOK = True
420423 End If
421- LoadOK = True
422424 End If
423425 Catch Ex As Exception
424426 ErrLog(Ex.Message)
0 commit comments