Chord Module¶
-
js2p.chord.get_hashes(key)¶ Returns the (adjusted) hashes for a given key. This is in the order of:
- SHA1 (shifted 224 bits left)
- SHA224 (shifted 160 bits left)
- SHA256 (shifted 128 bits left)
- SHA384 (unadjusted)
- SHA512 (unadjusted)
The adjustment is made to allow better load balancing between nodes, which assign responisbility for a value based on their SHA384-assigned ID.
-
class
js2p.chord.chord_connection(sock, server, outgoing)¶ This is the class for chord connection abstractraction. It inherits from
js2p.mesh.mesh_connection()Arguments: - sock – This is the raw socket object
- server (js2p.chord.chord_socket) – This is a link to the
chord_socket()parent - outgoing – This bool describes whether
serverinitiated the connection
-
class
js2p.mesh.mesh_socket(addr, port[, protocol[, out_addr[, debug_level]]])¶ This is the class for mesh network socket abstraction. It inherits from
js2p.base.base_socket()Arguments: - addr (string) – The address you’d like to bind to
- port (number) – The port you’d like to bind to
- protocol (js2p.base.protocol) – The subnet you’re looking to connect to
- out_addr (array) – Your outward-facing address
- debug_level (number) – The verbosity of debug prints
-
js2p.mesh.mesh_socket.routing_table¶ An object which contains
mesh_connection()s keyed by their IDs
-
js2p.mesh.mesh_socket.awaiting_ids¶ An array which contains
mesh_connection()s that are awaiting handshake information
-
js2p.chord.chord_socket.__handle_peers(msg, conn)¶ This callback is used to deal with peer signals. Its primary jobs is to connect to the given peers, if this does not exceed
js2p.chord.max_outgoingArguments: - msg (js2p.base.message) –
- conn (js2p.mesh.mesh_connection) –
Returns: Either
trueorundefined
-
js2p.chord.chord_socket.get(key[, fallback])¶ Retrieves the value at a given key
Arguments: - key – The key you wish to look up (must be transformable into a
Buffer()) - fallback – The value it should return when the key has no data
Returns: The value at the given key, or
fallback.Raises TypeError: If the key could not be transformed into a
Buffer()- key – The key you wish to look up (must be transformable into a
-
js2p.chord.chord_socket.set(key, value)¶ Sets the value at a given key
Arguments: - key – The key you wish to look up (must be transformable into a
Buffer()) - value – The key you wish to store (must be transformable into a
Buffer())
Raises TypeError: If a key or value could not be transformed into a
Buffer()Raises: See
__store()- key – The key you wish to look up (must be transformable into a
-
js2p.sync.sync_socket.update(update_dict)¶ For each key/value pair in the given object, calls
set()Arguments: - update_dict (Object) – An object with keys and values which can be transformed into a
Buffer()
Raises: See
set()- update_dict (Object) – An object with keys and values which can be transformed into a
-
js2p.sync.sync_socket.del(key)¶ Clears the value at a given key
Arguments: - key – The key you wish to look up (must be transformable into a
Buffer())
Raises TypeError: If a key or value could not be transformed into a
Buffer()Raises: See
set()- key – The key you wish to look up (must be transformable into a
-
js2p.chord.chord_socket.keys()¶ Returns a generator for all keys presently in the dictionary
Because this data is changed asynchronously, the key is only garunteed to be present at the time of generation.
Returns: A generator which yields :js:class:`Buffer`s
-
js2p.chord.chord_socket.values()¶ Returns a generator for all values presently in the dictionary
Because this data is changed asynchronously, the value is only garunteed to be accurate at the time of generation.
Returns: A generator which yields :js:class:`Buffer`s
-
js2p.chord.chord_socket.items()¶ Returns a generator for all associations presently in the dictionary
Because this data is changed asynchronously, the association is only garunteed to be present at the time of generation.
Returns: A generator which yields pairs of :js:class:`Buffer`s
-
js2p.chord.chord_socket.pop(key[, fallback])¶ Returns the value at a given key. As a side effect, it it deletes that key.
Returns: A Buffer()