{"id":16798460,"url":"https://github.com/flosch/libdht","last_synced_at":"2025-04-11T00:14:02.959Z","repository":{"id":66790178,"uuid":"11284571","full_name":"flosch/libdht","owner":"flosch","description":"Pure python library for implementing a simple DHT based on the Kademlia protocol.","archived":false,"fork":false,"pushed_at":"2013-07-14T18:31:54.000Z","size":132,"stargazers_count":12,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T00:13:54.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.florian-schlachter.de/post/libdht/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flosch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-09T14:26:21.000Z","updated_at":"2020-04-09T11:44:18.000Z","dependencies_parsed_at":"2023-02-20T11:45:30.386Z","dependency_job_id":null,"html_url":"https://github.com/flosch/libdht","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Flibdht","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Flibdht/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Flibdht/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Flibdht/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flosch","download_url":"https://codeload.github.com/flosch/libdht/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317730,"owners_count":21083530,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T09:25:43.341Z","updated_at":"2025-04-11T00:14:02.933Z","avatar_url":"https://github.com/flosch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Important note**: The library is still **work in progress**, there are a lot of TODOs in it. So please be careful when using libdht. I strongly advise against using it in a production environment yet.\n\nlibdht supports bootstrapping (currently only searching for nodes in the local network using broadcast).\n\nSimple example of how to use the DHT library:\n\n\n```bash\n(There are already 2 other nodes started.)\n\n$ python example.py\nMy ID = 315266357664053077240863549245018455720435477024\n\nSaving: True\nLoading: Hallo!\nHow many nodes have this key? 3\nRemoving: True\nHow many nodes have this key now? 0\nEnter to exit.\n```\n\n```python\n# -*- coding: utf-8 -*-\n\nimport random, time, sys, dht, bootstrap\nrandom.seed(time.time())\n\nclass MyNetwork(dht.DHT):\n    def __init__(self, *args, **kwargs):\n        self._my_db = {}\n        super(MyNetwork, self).__init__(*args, **kwargs)\n\n    def handle_save(self, key, value):\n        self._my_db[key] = value\n        return True\n\n    def handle_load(self, key):\n        return self._my_db.get(key)\n\n    def handle_delete(self, key):\n        del self._my_db[key]\n        return True\n\n    def handle_has_key(self, key):\n        return key in self._my_db\n\ndef main():\n    # Uses port as first argument for communication (TCP+UDP)\n    my_id = random.randint(0, dht.MAX_ID)\n    port = random.randint(5000, 10000)\n    n = MyNetwork(node_id=my_id, port=port)\n    \n    bootstrapper = bootstrap.Bootstrapper(network_id=\"test\", node_id=my_id,\n                                          dht_port=port)\n    bootstrapper.start_network(n)\n    try:\n        print \"My ID = %d\" % my_id\n        print\n     \n        # Hash your data (160-bit integer), for this example we'll get a random int\n        data_id = random.randint(0, dht.MAX_ID)\n    \n        # Returns True on success, gets automatically replicated\n        print \"Saving:\", n.save(data_id, \"Hallo!\", replicas=20)\n    \n        # Returns \"Hallo!\" (received from one of the nodes available in the network having this key)\n        print \"Loading:\", n.load(data_id)\n    \n        # Is the key available in the network? Returns the number of replicas.\n        print \"How many nodes have this key?\", n.has_key(data_id)\n    \n        # Removes the key+data from all nodes in the network\n        print \"Removing:\", n.delete(data_id)\n        \n        print \"How many nodes have this key now?\", n.has_key(data_id)\n    \n        raw_input(\"Enter to exit.\")\n    finally:\n        # Make sure network is always shutting down\n        bootstrapper.stop_network(n)\n\nif __name__ == \"__main__\":\n    main()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosch%2Flibdht","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflosch%2Flibdht","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosch%2Flibdht/lists"}