pybitmessage.protocol module

Low-level protocol-related functions.

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


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


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


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


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


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


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

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

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

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

Construct and return a packet

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

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.