Package congress :: Module congress
[hide private]

Module congress

source code

Classes [hide private]
  CongressPeer
Peer subclass for Congress. Currently no real logic is here.
  Congress
Main DHT class. The main event loop is a member of this class, and all peers and other pyev callbacks attach to this loop.
Functions [hide private]
 
sha1_hash(key)
Generate a SHA1 hash for a given string.
source code
 
ping_handler(message, server, peer)
Callback for PING messages. Send back a PONG.
source code
 
pong_handler(message, server, peer)
Callback for PONG messages. Refresh the k-bucket information for the given peer.
source code
 
handle_rpc_store(message, server, peer)
Callback for STORE messages. Store the hashed key: value in our store.
source code
 
chat_handler(message, server, peer)
Callback for CHAT messages. Congress makes no attempt to encrypt or secure the message from eavesdropping, and leaves any implementation of chat message security to the developer.
source code
 
handle_rpc_get(message, server, peer)
Callback for GET messages. If we have the value, send it back to the peer. If we don't, build a list of alpha closest peers and send it back to the peer.
source code
 
value_check(message, server)
Check if a given hashed key and value are present in the store.
source code
 
handle_rpc_get_reply(message, server, peer)
Callback for GET replies. If we get the value back in the message, run value_check. If we get a list of peers, bootstrap them and request the same value, but only if we don't have the value.
source code
 
handle_rpc_find_node(message, server, peer)
Callback for FIND_NODE messages. Pass back k closest peers to the ID.
source code
 
handle_rpc_find_node_reply(message, server, peer)
Callback for FIND_NODE replies. Bootstrap any unseen peers.
source code
 
main() source code
Variables [hide private]
  k = 20
  a = 3
  PING = 1
  PONG = 2
  RPC_STORE = 5
  RPC_FIND_NODE = 6
  RPC_GET = 7
  RPC_FIND_NODE_REPLY = 8
  RPC_GET_REPLY = 9
  RPC_CHAT = 10
  __package__ = 'congress'
Function Details [hide private]

sha1_hash(key)

source code 
Generate a SHA1 hash for a given string.
Parameters:
  • key

ping_handler(message, server, peer)

source code 
Callback for PING messages. Send back a PONG.
Parameters:
  • message - PING message
  • server - The Congress server
  • peer - The peer the message was received from

pong_handler(message, server, peer)

source code 
Callback for PONG messages. Refresh the k-bucket information for the given peer.
Parameters:
  • messages - PONG message
  • server - The Congress server
  • peer - The peer the message was received from

handle_rpc_store(message, server, peer)

source code 
Callback for STORE messages. Store the hashed key: value in our store.
Parameters:
  • message - STORE message
  • server - The Congress server
  • peer - The peer the message was received from

chat_handler(message, server, peer)

source code 

Callback for CHAT messages. Congress makes no attempt to encrypt or secure the message from eavesdropping, and leaves any implementation of chat message security to the developer.

To handle chat messages intended for the node itself, register your callback with register_chat_callback.

Parameters:
  • message - CHAT message
  • server - The Congress server
  • peer - The peer hte message was received from

handle_rpc_get(message, server, peer)

source code 
Callback for GET messages. If we have the value, send it back to the peer. If we don't, build a list of alpha closest peers and send it back to the peer.
Parameters:
  • message - GET message
  • server - The Congress server
  • peer - The peer the message was receved from

value_check(message, server)

source code 
Check if a given hashed key and value are present in the store.
Parameters:
  • message - This function is only called from the GET reply, so the message in the callback is passed to this function.
  • server - Same deal as the message, this is the Congress server.

handle_rpc_get_reply(message, server, peer)

source code 
Callback for GET replies. If we get the value back in the message, run value_check. If we get a list of peers, bootstrap them and request the same value, but only if we don't have the value.
Parameters:
  • message - The GET reply itself.
  • server - The Congress server
  • peer - The peer that sent the message

handle_rpc_find_node(message, server, peer)

source code 
Callback for FIND_NODE messages. Pass back k closest peers to the ID.
Parameters:
  • message - The FIND_NODE message itself.
  • server - The Congress server
  • peer - The peer that sent the message.

handle_rpc_find_node_reply(message, server, peer)

source code 
Callback for FIND_NODE replies. Bootstrap any unseen peers.
Parameters:
  • message - The FIND_NODE reply.
  • server - The Congress server
  • peer - The peer that sent the reply.