Package congress :: Module congress :: Class Congress
[hide private]

Class Congress

source code

node.Node --+
            |
           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.
Instance Methods [hide private]
 
_debug(self, message) source code
 
_hit_peer(self, peer)
Update the node's k-buckets with the peer, using a simplified version of the kademlia specification's routine for updating k-buckets.
source code
 
_node_id_present(self, node_id)
Determine if any of the connected peers have the specified 160-bit node ID.
source code
 
_conn_present(self, conn)
Determine if the given (address, port) tuple is presently connected via any of the peers.
source code
 
_make_buckets(self)
At node, start, create 160 k-buckets and 160 replacement buckets. Currently, replacement buckets are not used but the peer is placed into them if a bucket's peer count is over k.
source code
 
_closest_peers(self, id, how_many, filter_id=None)
Given the specified 160-bit ID, use the k-buckets to return, at most, how_many closest peers to the ID using a XOR metric (id XOR peer.id)
source code
 
rpc_get(self, key, callback)
Since value retrieval is async, provide a callback that will handle the value.
source code
 
rpc_store(self, key, value)
Store hashed key: val with k closest connected peers.
source code
 
rpc_chat(self, node_id, chat_message)
Initiate an RPC_CHAT message.
source code
 
register_chat_callback(self, callback)
Store a callable in our chat callbacks list. Each will be called in order of registration, when we receive an RPC_CHAT with a target_node_id that matches our server's 160-bit ID.
source code
 
peer_cleanup(self, peer)
When error handling or explicit peer removal schedules a peer object for removal, this function is called to remove it from all applicable buckets by the core node.py removal routine.
source code
 
bootstrap_peer(self, conn_address, id=None)
Add a peer. This function does not add it to k-buckets, as this is handled by the final handshake callback.
source code
 
_setup_ctl_socket(self, port=29800)
Setup a socket to listen for simple control connections.
source code
 
__init__(self, host='0.0.0.0', port=16800, initial_peers=[], debug=False, ctl_port=None, pyev_loop=None, debug_file=None) source code
    Inherited from node.Node
 
_gen_id(self) source code
 
_remove_peer(self, peer) source code
 
_sig_cb(self, watcher, events) source code
 
_sock_ev(self, watcher, events) source code
 
_timer_cb(self, watcher, events) source code
 
add_peer(self, conn, connect=False, existing_socket=None) source code
 
debug_peers(self) source code
 
enqueue_message(self, message) source code
 
handle_message(self, message, peer) source code
 
register_handshake(self, func, peer=None)
Any time a new incoming connectin is made, the argument will be executed with the arguments peer and the server itself.
source code
 
register_message_callback(self, message, func) source code
 
register_message_handler(self, atype, func) source code
 
register_message_timeout(self, message, func, peer, timeout=3) source code
 
register_timed(self, interval, func) source code
 
shutdown(self) source code
 
start(self) source code
Method Details [hide private]

_debug(self, message)

source code 
Overrides: node.Node._debug

_hit_peer(self, peer)

source code 
Update the node's k-buckets with the peer, using a simplified version of the kademlia specification's routine for updating k-buckets.
Parameters:
  • peer

_closest_peers(self, id, how_many, filter_id=None)

source code 
Given the specified 160-bit ID, use the k-buckets to return, at most, how_many closest peers to the ID using a XOR metric (id XOR peer.id)
Parameters:
  • id - 160-bit ID
  • how_many - The maximum number of peers to return, usually k.

rpc_get(self, key, callback)

source code 
Since value retrieval is async, provide a callback that will handle the value.
Parameters:
  • key - String key
  • callback - Callable to execute when we get the value.

rpc_store(self, key, value)

source code 
Store hashed key: val with k closest connected peers.
Parameters:
  • key - string key
  • value - Any python value that is json serializable.

rpc_chat(self, node_id, chat_message)

source code 
Initiate an RPC_CHAT message.
Parameters:
  • node_id - The 160-bit ID of the peer you'd like to send a message to. It need not be a connected peer, just a known ID.
  • chat_message - The message to send.

register_chat_callback(self, callback)

source code 

Store a callable in our chat callbacks list. Each will be called in order of registration, when we receive an RPC_CHAT with a target_node_id that matches our server's 160-bit ID.

The signature of the callable should be as follows:
cb(source_node, chat_message, server, peer)

peer_cleanup(self, peer)

source code 
When error handling or explicit peer removal schedules a peer object for removal, this function is called to remove it from all applicable buckets by the core node.py removal routine.
Overrides: node.Node.peer_cleanup

bootstrap_peer(self, conn_address, id=None)

source code 
Add a peer. This function does not add it to k-buckets, as this is handled by the final handshake callback.
Parameters:
  • conn_address - (hostname, port) tuple of the peer
  • id - The ID is supplied if FIND_NODE replies provide the peer.

_setup_ctl_socket(self, port=29800)

source code 
Setup a socket to listen for simple control connections.
Parameters:
  • port - The port that local connections can use.

__init__(self, host='0.0.0.0', port=16800, initial_peers=[], debug=False, ctl_port=None, pyev_loop=None, debug_file=None)
(Constructor)

source code 
Parameters:
  • initial_peers - List of (hostname, port) tuples to connect to.
  • debug - If True, many debug messages will be printed.
  • ctl_port - Local port for the control socket.
  • pyev_loop - If you have your own pyev loop to attach the node to, supply it here.
Overrides: node.Node.__init__