zerolib.protocol
- Full list of packets¶
Unlike BitTorrent, not all ZeroNet packets are symmetrical. This page lists all documented ZeroNet packets in two categories.
Symmetrical Packets¶
Every symmetrical packet contains enough information which the program can interpret without referring to the previous request packets.
-
class
Handshake
(Packet)¶ Unpacked
handshake
packet sent when the connection was initialized.Variables: - crypto_set (set of str) – the set of supported cryptographic algorithms.
- peer_id (bytes or None) – the peer ID as a binary string. (not available in Tor mode)
- port (int) – the port number the sender is actively listening on.
- open (bool) – whether the sender believes his port is open.
- onion (AddrPort or None) – the Tor Onion Service destination of the peer. (only used in Tor mode)
- onion_address (OnionAddress or None) – the Tor Onion Service address of the peer, excluding the port. (only used in Tor mode)
- protocol (str) – a unicode string representing the protocol version.
- version (str) – the version string of the sender’s software.
- rev (int) – the rev number of the sender’s software.
-
class
ACK
(Handshake)¶ Response packet of
Handshake
. Marks the end of a handshake.Variables: preferred_crypto (str) – the cryptographic algorithm that the sender would like to use. … as well as the attributes inherited from
Handshake
.
-
class
Ping
(Packet)¶
-
class
Pong
(Packet)¶
Asymmetrical Packets¶
An asymmetrical response packet itself does not contain enough information. To fully interpret an asymmetrical response, the program has to refer to its previous requests.
-
class
PEX
(Packet)¶ Unpacked
pex
packet that exchanges peers with the client. Peers are parsed at construct-time.Variables:
-
class
RespPEX
(Packet)¶ Response packet of
PEX
.Variables: The following variables will be injected when the packet is handled by the state machine.
Variables: site (str) – the site address, a human-readable Bitcoin address.
-
class
GetFile
(Packet)¶ Unpacked
getFile
packet that requests for a file.Variables: - site (str) – the site address, a human-readable Bitcoin address.
- inner_path (str) – the relative path to the requested file.
- offset (int) – request file from this offset.
- total_size (int or None) – the total size of the requested file. (optional)
-
class
RespFile
(Packet)¶ Response packet of
GetFile
.Variables: - body (bytes) – a chunk of file content.
- last_byte (int) – the absolute offset of the last byte of
body
. - total_size (int) – the total size of the whole file.
- offset (int) – property. The absolute offset of the first byte of
body
. - next_offset (int) – property. The start offset of the next
getFile
request.
The following variables will be injected when the packet is handled by the state machine.
Variables: - site (str) – the site address, a human-readable Bitcoin address.
- inner_path (str) – the relative path to the requested file.
-
class
ListMod
(Packet)¶ Unpacked
listModified
packet that requests for the paths ofcontent.json
files modified since the given time. This packet is used to heuristically list a site’s new user content.Variables: - site (str) – the site address, a human-readable Bitcoin address.
- since (int) – list modified
content.json
files since this timestamp. The timestamp is in seconds.
Warning
This timestamp is defined vaguely in the spec. Is it an int or a float? Link to the spec.
-
class
RespMod
(Packet)¶ Response packet of
ListMod
.Variables: timestamps (dict of str and int) – the {inner_path : mtime}
dictionary.-
__iter__
(self)¶
-
__contains__
(self, key)¶
-
items
(self)¶ Helper methods for iterating through the
timestamps
.for (inner_path, mtime) in packet.items(): print('New file %r, last modified %d' % (inner_path, mtime))
The following variables will be injected when the packet is handled by the state machine.
Variables: site (str) – the site address, a human-readable Bitcoin address. -
-
class
GetHash
(Packet)¶ Unpacked
getHashfield
packet that requests for the client’s list of downloaded optional file IDs.Variables: site (str) – the site address, a human-readable Bitcoin address.
-
class
RespHashSet
(Packet, PrefixIter)¶ Response packet of
GetHash
.Variables: prefixes (set of bytes) – hash ID prefixes in a set. The following variables will be injected when the packet is handled by the state machine.
Variables: site (str) – the site address, a human-readable Bitcoin address.
-
class
FindHash
(Packet)¶ Unpacked
findHashIds
packet that asks if the client knows any peer that has the said optional file IDs.Variables: - site (str) – the site address, a human-readable Bitcoin address.
- prefixes (set of bytes) – the set of optional file IDs. An optional file ID is the first 2 bytes of the file’s hash.
-
class
SetHash
(Packet)¶ Unpacked
setHashfield
packet that announces the sender’s list of optional file IDs.Variables: - site (str) – the site address, a human-readable Bitcoin address.
- prefixes (set of bytes) – the set of optional file IDs. An optional file ID is the first 2 bytes of the file’s hash.
-
class
Predicate
(Packet)¶ Status predicate. Either an
ok
packet or anerror
packet. Response packet ofUpdate
andSetHash
.Variables: ok (bool) – Okay?
-
class
Update
(Packet)¶ Unpacked
update
packet that pushes a new site file.Its response packet is a
Predicate
.
-
class
CheckPort
(Packet)¶ Unpacked
actionCheckport
packet that asks the client to check the sender’s port status.Variables: port (int) – the port number which the sender would like you to check.
-
class
RespPort
(Packet)¶ Response packet of
CheckPort
.Variables: - status (str) – port status as a human-readable string.
- open (bool) – whether the port is open.
The following variables will be injected when the packet is handled by the state machine.
Variables: port (int) – the port number which the sender would like you to check.