Chord Module ============ .. js:function:: 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. .. js:class:: js2p.chord.ChordConnection(sock, server, outgoing) This is the class for chord connection abstractraction. It inherits from :js:class:`js2p.mesh.MeshConnection` :param sock: This is the raw socket object :param js2p.chord.ChordSocket server: This is a link to the :js:class:`~js2p.chord.ChordSocket` parent :param outgoing: This bool describes whether ``server`` initiated the connection .. js:class:: js2p.chord.ChordSocket(addr, port [, protocol [, out_addr [, debug_level]]]) This is the class for chord network socket abstraction. It inherits from :js:class:`js2p.mesh.MeshSocket` :param string addr: The address you'd like to bind to :param number port: The port you'd like to bind to :param js2p.base.Protocol protocol: The subnet you're looking to connect to :param array out_addr: Your outward-facing address :param number debug_level: The verbosity of debug prints .. js:function:: js2p.chord.ChordSocket Event 'add'(conn, key) This event is triggered when a key is added to the distributed dictionary. Because value information is not transmitted in this message, you must specifically request it. :param js2p.chord.ChordSocket conn: A reference to this abstract socket :param Buffer key: The key which has a new value .. js:function:: js2p.chord.ChordSocket Event 'delete'(conn, key) This event is triggered when a key is deleted from your distributed dictionary. :param js2p.chord.ChordSocket conn: A reference to this abstract socket :param Buffer key: The key which has a new value .. js:attribute:: js2p.chord.ChordSocket.id_10 This socket's ID as a :js:class:`big-integer` .. js:function:: js2p.chord.ChordSocket.__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 :js:data:`js2p.chord.max_outgoing` :param js2p.base.Message msg: :param js2p.mesh.MeshConnection conn: :returns: Either ``true`` or ``undefined`` .. js:function:: js2p.chord.ChordSocket.get(key [, fallback [, timeout]]) Retrieves the value at a given key :param key: The key you wish to look up (must be transformable into a :js:class:`Buffer` ) :param fallback: The value it should return when the key has no data :param timeout: The maximum time (in seconds) to wait before returning ``fallback`` :returns: A :js:class:`Promise` for the value at the given key, or ``fallback``. :raises TypeError: If the key could not be transformed into a :js:class:`Buffer` .. js:function:: js2p.chord.ChordSocket.set(key, value) Sets the value at a given key :param key: The key you wish to look up (must be transformable into a :js:class:`Buffer` ) :param value: The value you wish to store :raises TypeError: If a key could not be transformed into a :js:class:`Buffer` :raises: See :js:func:`~js2p.chord.ChordSocket.__store` .. js:function:: js2p.chord.ChordSocket.update(update_dict) For each key/value pair in the given object, calls :js:func:`~js2p.chord.ChordSocket.set` :param Object update_dict: An object with keys and values which can be transformed into a :js:class:`Buffer` :raises: See :js:func:`~js2p.chord.ChordSocket.set` .. js:function:: js2p.chord.ChordSocket.del(key) Clears the value at a given key :param key: The key you wish to look up (must be transformable into a :js:class:`Buffer` ) :raises TypeError: If a key or value could not be transformed into a :js:class:`Buffer` :raises: See :js:func:`~js2p.chord.ChordSocket.set` .. js:function:: js2p.chord.ChordSocket.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 .. js:function:: js2p.chord.ChordSocket.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:`Promise` s. These :js:class:`Promise` s will yield a :js:class:`Buffer` , on success. .. js:function:: js2p.chord.ChordSocket.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 and :js:class:`Promise` s. The :js:class:`Promise` s will yield a :js:class:`Buffer` , on success. .. js:function:: js2p.chord.ChordSocket.pop(key [, fallback]) Returns the value at a given key. As a side effect, it it deletes that association. :returns: A :js:class:`Promise` , similar to the :js:func:`js2p.chord.ChordSocket.get` method. .. js:function:: js2p.chord.ChordSocket.popitem() Returns the association at a key. As a side effect, it it deletes that association. :returns: A pair of :js:class:`Buffer` and :js:class:`Promise` , similar to an item in :js:func:`js2p.chord.ChordSocket.items` .. js:function:: js2p.chord.ChordSocket.copy() Returns the :js:class:`Promise` of an :js:class:`Object` , with the same associations as this DHT. .. note:: This is potentially a very slow operation. It is probably significantly faster, and likely to be more accurate, if you iterate over :js:func:`js2p.chord.ChordSocket.items` :returns: The :js:class:`Promise` of an :js:class:`Object` , with the same associations as this DHT.