pybitmessage.protocol module

Low-level protocol-related functions.

MAX_ADDR_COUNT = 1000[source]

protocol specification says max 1000 addresses in one addr command

ADDRESS_ALIVE = 10800[source]

address is online if online less than this many seconds ago

MAX_MESSAGE_SIZE = 1600100[source]

~1.6 MB which is the maximum possible size of an inv message.

MAX_OBJECT_PAYLOAD_SIZE = 262144[source]

2**18 = 256kB is the maximum size of an object payload

MAX_OBJECT_COUNT = 50000[source]

protocol specification says max 50000 objects in one inv command

MAX_TIME_OFFSET = 3600[source]

maximum time offset

NODE_NETWORK = 1[source]

This is a normal network node

NODE_SSL = 2[source]

This node supports SSL/TLS in the current connect (python < 2.7.9 only supports an SSL client, so in that case it would only have this on when the connection is a client).

NODE_DANDELION = 8[source]

Node supports dandelion

getBitfield(address)[source]

Get a bitfield from an address

checkBitfield(bitfieldBinary, flags)[source]

Check if a bitfield matches the given flags

isBitSetWithinBitfield(fourByteString, n)[source]

Check if a particular bit is set in a bitfeld

encodeHost(host)[source]

Encode a given host to be used in low-level socket operations

networkType(host)[source]

Determine if a host is IPv4, IPv6 or an onion address

network_group(host)[source]

Canonical identifier of network group simplified, borrowed from GetGroup() in src/netaddresses.cpp in bitcoin core

checkIPAddress(host, private=False)[source]

Returns hostStandardFormat if it is a valid IP address, otherwise returns False

checkIPv4Address(host, hostStandardFormat, private=False)[source]

Returns hostStandardFormat if it is an IPv4 address, otherwise returns False

checkIPv6Address(host, hostStandardFormat, private=False)[source]

Returns hostStandardFormat if it is an IPv6 address, otherwise returns False

haveSSL(server=False)[source]

Predicate to check if ECDSA server support is required and available

python < 2.7.9’s ssl library does not support ECDSA server due to missing initialisation of available curves, but client works ok

checkSocksIP(host)[source]

Predicate to check if we’re using a SOCKS proxy

isProofOfWorkSufficient(data, nonceTrialsPerByte=0, payloadLengthExtraBytes=0, recvTime=0)[source]

Validate an object’s Proof of Work using method described here

Parameters:
  • nonceTrialsPerByte (default (int) – from defaults)
  • payloadLengthExtraBytes (default (int) – from defaults)
  • recvTime (float) – received from the network (default: current system time)
Returns:

True if PoW valid and sufficient, False in all other cases

CreatePacket(command, payload='')[source]

Construct and return a packet

assembleAddrMessage(peerList)[source]

Create address command

assembleVersionMessage(remoteHost, remotePort, participatingStreams, server=False, nodeid=None)[source]

Construct the payload of a version message, return the resulting bytes of running CreatePacket on it

assembleErrorMessage(fatal=0, banTime=0, inventoryVector='', errorText='')[source]

Construct the payload of an error message, return the resulting bytes of running CreatePacket on it

decodeObjectParameters(data)[source]

Decode the parameters of a raw object needed to put it in inventory

decryptAndCheckPubkeyPayload(data, address)[source]

Version 4 pubkeys are encrypted. This function is run when we already have the address to which we want to try to send a message. The ‘data’ may come either off of the wire or we might have had it already in our inventory when we tried to send a msg to this particular address.