java.lang.Object
net.i2p.router.transport.GeoIPv6
Generate compressed geoipv6.dat.gz file, and lookup entries in it.
Public only for command line use, not a public API, not for external use.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classUsed to temporarily hold, sort, and merge entries before compressing.Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringComment stored in the data file.private static final StringDefault GeoIP directory name.private static final StringDefault GeoIPv6 data file name.private static final intIncludes magic.private static final StringMagic tag of the compressed data file.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static booleancompressGeoIPv6CSVFiles(List<File> inFiles, File outFile) Read in and parse multiple IPv6 geoip CSV files, merge them, and write out a gzipped binary IPv6 geoip file.static voidMerge and compress CSV files to I2P compressed formatprivate static String[]readGeoIPFile(I2PAppContext context, File geoFile, Long[] search, Map<String, String> codeCache, Log log) Lookup search items in the geoip file.static String[]readGeoIPFile(I2PAppContext context, Long[] search, Map<String, String> codeCache) Lookup search items in the geoip file.private static longreadLong(byte[] src, int offset) LikeDataHelper.readLong(InputStream, int)but allows negative values.private static longtoLong(byte[] ip) Converts an address to a long.private static voidwriteLong(OutputStream rawStream, long value) LikeDataHelper.writeLong(OutputStream, int, long)but allows negative values.
Field Details
GEOIP_DIR_DEFAULT
Default GeoIP directory name.- See Also:
GEOIP_FILE_DEFAULT
Default GeoIPv6 data file name.- See Also:
MAGIC
Magic tag of the compressed data file.- See Also:
COMMENT
HEADER_LEN
Constructor Details
GeoIPv6
private GeoIPv6()Utility class.
Method Details
readGeoIPFile
public static String[] readGeoIPFile(I2PAppContext context, Long[] search, Map<String, String> codeCache) Lookup search items in the geoip file. See below for format.- Parameters:
context- the I2P app contextsearch- a sorted array of IPs to searchcodeCache- the country code cache- Returns:
- an array of country codes, same order as the search param, or a zero-length array on total failure. Individual array elements will be null for lookup failure of that item.
readGeoIPFile
private static String[] readGeoIPFile(I2PAppContext context, File geoFile, Long[] search, Map<String, String> codeCache, Log log) Lookup search items in the geoip file. See below for format.- Parameters:
context- the application context, notified of the data file versiongeoFile- the gzip-compressed IPv6 geoip data file to readsearch- a sorted array of IPs to searchcodeCache- reuses one String per lower-case country codelog- where to log read errors and timing- Returns:
- an array of country codes, same order as the search param, or a zero-length array on total failure. Individual array elements will be null for lookup failure of that item.
compressGeoIPv6CSVFiles
Read in and parse multiple IPv6 geoip CSV files, merge them, and write out a gzipped binary IPv6 geoip file.Acceptable input formats (IPv6 only):
#comment (# must be in column 1) "text IP", "text IP", "bigint IP", "bigint IP", "country code", "country name"
Quotes and spaces optional. Sorting not required. Country code case-insensitive. Fields 1, 2, and 5 are used; fields 3, 4, and 6 are ignored. This is identical to the format of the MaxMind GeoLite IPv6 file.Example:
"2001:200::", "2001:200:ffff:ffff:ffff:ffff:ffff:ffff", "42540528726795050063891204319802818560", "42540528806023212578155541913346768895", "JP", "Japan"
Output format: Bytes 0-9: Magic number "I2PGeoIPv6" Bytes 10-11: version (0x0001) Bytes 12-15 flags (0) Bytes 16-23: Date (long) Bytes 24-xx: Comment (UTF-8) Bytes xx-255: null padding Bytes 256-: 18 byte records: 8 byte from (/64) 8 byte to (/64) 2 byte country code LOWER case (ASCII) Data must be sorted (SIGNED twos complement), no overlapSLOW. For preprocessing only!
- Parameters:
inFiles- the CSV files to merge, each plain or gzip-compressedoutFile- the merged binary database to write, gzip-compressed- Returns:
- true if the merged database was written, false on an I/O error
toLong
private static long toLong(byte[] ip) Converts an address to a long.- Parameters:
ip- the address bytes- Returns:
- the address as a long
writeLong
LikeDataHelper.writeLong(OutputStream, int, long)but allows negative values.- Parameters:
rawStream- where to write the eight big-endian bytesvalue- the value to write, negative allowed- Throws:
IOException- if the stream write fails
readLong
private static long readLong(byte[] src, int offset) LikeDataHelper.readLong(InputStream, int)but allows negative values.- Parameters:
src- the bytes to read eight big-endian bytes fromoffset- index of the first byte to read- Returns:
- the decoded value, negative when the high bit is set
main
Merge and compress CSV files to I2P compressed formatGeoIPv6 infile1.csv[.gz] [infile2.csv[.gz]...] outfile.dat.gz
Used to create the file for distribution, do not comment out.
- Parameters:
args- command line arguments