Blockfile Specification

On-disk blockfile storage format used by I2P for hostname resolution

On This Page

Overview

This document specifies the I2P blockfile file format and the tables in the hostsdb.blockfile used by the Blockfile Naming Service.
For background, see I2P Naming and Address Book.

The blockfile enables fast destination lookups in a compact binary format.
Compared to the legacy hosts.txt system:

  • Destinations are stored in binary, not Base64.
  • Arbitrary metadata (e.g., added date, source, comments) can be attached.
  • Lookup times are roughly 10× faster.
  • Disk use increases modestly.

A blockfile is an on-disk collection of sorted maps (key-value pairs) implemented as skiplists.
It was derived from the Metanotion Blockfile Database.
This specification first defines the file structure, then describes how it is used by the BlockfileNamingService.

The Blockfile Naming Service replaced the old hosts.txt implementation in I2P 0.8.8.
On initialization, it imports entries from privatehosts.txt, userhosts.txt, and hosts.txt.


Blockfile Format

The format is composed of 1024-byte pages, each prefixed with a magic number for integrity.
Pages are numbered starting at 1:

PageDescription
1Superblock (starts at byte 0)
2Metaindex skiplist (starts at byte 1024)

All integers use network byte order (big-endian).
2-byte values are unsigned; 4-byte values (page numbers) are signed and must be positive.

Threading: The database is designed for single-threaded access; BlockfileNamingService provides synchronization.


Superblock Format

ByteContents
0-5Magic number 0x3141de493250 ("1A" 0xde "I2P")
6Major version 0x01
7Minor version 0x02
8-15File length (in bytes)
16-19First free list page
20-21Mounted flag (0x01 = yes)
22-23Span size (max key/value pairs per span, 16 for hostsdb)
24-27Page size (as of v1.2; 1024 before that)
28-1023Unused

Skip List Block Page Format

ByteContents
0-7Magic 0x536b69704c697374 ("SkipList")
8-11First span page
12-15First level page
16-19Size (total keys, valid at startup)
20-23Spans (total spans, valid at startup)
24-27Levels (total levels, valid at startup)
28-29Span size (as of v1.2; used for new spans)
30-1023Unused

Skip Level Block Page Format

Every level has a span, but not all spans have levels.

ByteContents
0-7Magic 0x42534c6576656c73 ("BSLevels")
8-9Max height
10-11Current height
12-15Span page
16-…Next level pages (current height × 4 bytes, lowest first)
Remaining bytes unused

Skip Span Block Page Format

Key/value pairs are sorted by key across spans.
Non-first spans must not be empty.

ByteContents
0-3Magic 0x5370616e ("Span")
4-7First continuation page or 0
8-11Previous span page or 0
12-15Next span page or 0
16-17Max keys (16 for hostsdb)
18-19Size (current keys)
20-1023Key/value structures

Span Continuation Block Page Format

ByteContents
0-3Magic 0x434f4e54 ("CONT")
4-7Next continuation page or 0
8-1023Key/value structures

Key/Value Structure Format

Key and value length fields cannot span pages (all 4 bytes must fit).
If insufficient space remains, pad up to 3 bytes and continue at offset 8 of the next page.

ByteContents
0-1Key length (bytes)
2-3Value length (bytes)
4-…Key data → Value data
Max length = 65535 bytes each

Free List Block Page Format

ByteContents
0-7Magic 0x2366724c69737423 ("#frList#")
8-11Next free list block or 0
12-15Number of valid free pages (0 – 252)
16-1023Free page numbers (4 bytes each)

Free Page Block Format

ByteContents
0-7Magic 0x7e2146524545217e ("~!FREE!~")
8-1023Unused

Metaindex

Located at page 2.
Maps US-ASCII strings4-byte integers.
The key is the skiplist name; the value is the page index.


Blockfile Naming Service Tables

The service defines several skiplists.
Each span supports up to 16 entries.


Properties Skiplist

%%__INFO__%% contains one entry:

KeyValue
infoA Properties object (UTF-8 String / String map) serialized as a Mapping

Typical fields:

PropertyDescription
version"4"
createdJava long (ms since epoch)
upgradedJava long (ms since epoch, since DB v2)
listsComma-separated host DBs (e.g. privatehosts.txt,userhosts.txt,hosts.txt)
listversion_*Version of each DB (used to detect partial upgrades, since v4)

Reverse Lookup Skiplist

%%__REVERSE__%% contains Integer → Properties entries (since DB v2).

  • Key: First 4 bytes of the SHA-256 hash of the Destination.
  • Value: Properties object (serialized Mapping).
  • Multiple entries handle collisions and multi-hostname Destinations.
  • Each property key = hostname; value = empty string.

Host Database Skiplists

Each of hosts.txt, userhosts.txt, and privatehosts.txt maps hostnames → Destinations.

Version 4 supports multiple Destinations per hostname (introduced in I2P 0.9.26).
Version 3 databases are migrated automatically.

Key

UTF-8 string (hostname, lowercase, ending in .i2p)

Value

  • Version 4:
    • 1 byte count of Property/Destination pairs
    • For each pair: Properties → Destination (binary)
  • Version 3:
    • Properties → Destination (binary)

DestEntry Properties

KeyMeaning
aTime added (Java long ms)
mLast modified (Java long ms)
notesUser comments
sSource (file or subscription URL)
vSignature verified (true/false)

Implementation Notes

The BlockfileNamingService Java class implements this specification.

  • Outside router context, the database opens read-only unless i2p.naming.blockfile.writeInAppContext=true.
  • Not intended for multi-instance or multi-JVM access.
  • Maintains three primary maps (privatehosts, userhosts, hosts) and a reverse map for fast lookups.

References

Was this page helpful?