{"id":21383101,"url":"https://github.com/bashkirtsevich-llc/aiobtdht","last_synced_at":"2025-07-13T13:31:59.220Z","repository":{"id":57408769,"uuid":"198895836","full_name":"bashkirtsevich-llc/aiobtdht","owner":"bashkirtsevich-llc","description":"Asyncio Bittorrent DHT server","archived":false,"fork":false,"pushed_at":"2023-11-01T09:26:19.000Z","size":39,"stargazers_count":26,"open_issues_count":5,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-11T11:12:59.192Z","etag":null,"topics":["asyncio","asyncio-server","bittorrent-dht","bittorrent-dht-protocol","dht","dht-network","dht-server","distributed-hash-table","kademlia","kademlia-dht","krpc","krpc-server","prc-server","udp-server"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/aio-btdht/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bashkirtsevich-llc.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":"2019-07-25T20:17:18.000Z","updated_at":"2024-05-23T04:34:23.000Z","dependencies_parsed_at":"2023-01-23T15:16:43.959Z","dependency_job_id":null,"html_url":"https://github.com/bashkirtsevich-llc/aiobtdht","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/bashkirtsevich-llc%2Faiobtdht","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashkirtsevich-llc%2Faiobtdht/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashkirtsevich-llc%2Faiobtdht/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bashkirtsevich-llc%2Faiobtdht/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bashkirtsevich-llc","download_url":"https://codeload.github.com/bashkirtsevich-llc/aiobtdht/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225886753,"owners_count":17539857,"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":["asyncio","asyncio-server","bittorrent-dht","bittorrent-dht-protocol","dht","dht-network","dht-server","distributed-hash-table","kademlia","kademlia-dht","krpc","krpc-server","prc-server","udp-server"],"created_at":"2024-11-22T11:19:57.774Z","updated_at":"2024-11-22T11:19:58.467Z","avatar_url":"https://github.com/bashkirtsevich-llc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Asyncio Bittorrent DHT Server\n[![Build Status](https://travis-ci.org/bashkirtsevich-llc/aiobtdht.svg?branch=master)](https://travis-ci.org/bashkirtsevich-llc/aiobtdht)\n\nSimply async distributed hash table for Bittorrent network.\n\nBased on [aio-KRPC](https://github.com/bashkirtsevich-llc/aiokrpc) and [aio-UDP](https://github.com/bashkirtsevich-llc/aioudp).\n\nClass hierarchy:\n* UDPServer — low level async [U]ser [D]atagram [P]rotocol socket server;\n  * KRPCServer — async [K]ademlia [R]emote [P]rocedure [C]all protocol provider; \n    * DHT — implementation of Bittorrent [D]istributed [H]ash [T]able;\n\n\n## Methods\n\n### `DHT.__init__`\n\nArguments:\n* `local_id` (int) — local node identifier in range [0..2^160).\n\nOptional arguments:\n* `upload_speed` (int, default `0`) — outgoing traffic throttler;\n* `download_speed` (int, default `0`) — incoming traffic throttler;\n* `recv_max_size` (int, default `256 * 1024`) — socket reading buffer size.\n\n\n### `run`\n\nLaunch servering.\n\nArguments:  \n* `host` (str) — local host address, e.g. `0.0.0.0`;\n* `port` (int) — local port for outgoing and incoming UDP traffic;\n* `loop` (object, default `None`) — asyncio eventloop, will create while `None` and run forever.\n\nResult: `None`.\n\n\n### async `bootstrap`\n\nMethod for initializing routing table.\n\nArguments:\n* `initial_peers` (list, example: `[(ip: str, port: int), ...]`) — list of router for initialize routing table;\n\nResult: `None`.\n\n### async `announce`\n\nAnnounce peer for specified `info_hash`.\n\nArguemtns:\n* `info_hash` (20 bytes) — binary form of `info_hash`;\n* `port` (int, default `None`) — information for announce, value is DHT-server listen port when `None`.\n\nResult: `None`.\n\n\n### async `__getitem__`\n\nGet peers for torrent by `info_hash`.\n\nArguemtns:\n* `info_hash` (20 bytes) — binary form of `info_hash`;\n\nResult: `Set((host: str, port: int), ...)`.\n\n\n## Example\n\n```python\nimport asyncio\nfrom aiobtdht import DHT\nfrom aioudp import UDPServer\n\n\nasync def main(loop):\n    initial_nodes = [\n        (\"67.215.246.10\", 6881),  # router.bittorrent.com\n        (\"87.98.162.88\", 6881),  # dht.transmissionbt.com\n        (\"82.221.103.244\", 6881)  # router.utorrent.com\n    ]\n\n    udp = UDPServer()\n    udp.run(\"0.0.0.0\", 12346, loop=loop)\n\n    dht = DHT(int(\"0x54A10C9B159FC0FBBF6A39029BCEF406904019E0\", 16), server=udp, loop=loop)\n\n    print(\"bootstrap\")\n    await dht.bootstrap(initial_nodes)\n    print(\"bootstrap done\")\n\n    print(\"search peers for Linux Mint torrent (8df9e68813c4232db0506c897ae4c210daa98250)\")\n    peers = await dht[bytes.fromhex(\"8df9e68813c4232db0506c897ae4c210daa98250\")]\n    print(\"peers:\", peers)\n\n    print(\"peer search for ECB3E22E1DC0AA078B48B7323AEBBA827AD9BD80\")\n    peers = await dht[bytes.fromhex(\"ECB3E22E1DC0AA078B48B7323AEBBA827AD9BD80\")]\n    print(\"peers:\", peers)\n\n    print(\"announce with port `2357`\")\n    await dht.announce(bytes.fromhex(\"ECB3E22E1DC0AA078B48B7323AEBBA827AD9BD80\"), 2357)\n    print(\"announce done\")\n\n    print(\"search our own ip\")\n    peers = await dht[bytes.fromhex(\"ECB3E22E1DC0AA078B48B7323AEBBA827AD9BD80\")]\n    print(\"peers:\", peers)\n\n\nif __name__ == '__main__':\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(main(loop))\n    loop.run_forever()\n```\n\nOutput:\n```\nbootstrap\nbootstrap done\nsearch peers for Linux Mint torrent (8df9e68813c4232db0506c897ae4c210daa98250)\npeers: {('146.120.244.10', 1078), ('162.244.138.182', 42000), ('79.226.71.128', 16881), ('24.236.49.9', 41785), ('91.138.144.37', 1487), ('68.44.225.100', 8967), ('80.44.205.104', 6881), ('212.32.229.66', 1160), ('108.204.244.160', 51413), ('66.130.106.74', 49160), ('90.128.48.99', 1348), ('188.232.107.50', 61025), ('173.44.55.179', 8589), ('46.242.8.31', 51413), ('181.97.186.68', 51413), ('68.114.220.251', 49237), ('172.98.67.53', 31545), ('94.212.149.191', 16881), ('188.163.46.182', 31217), ('185.148.3.42', 58489), ('37.24.80.202', 6881), ('86.159.123.195', 51413), ('88.202.177.238', 41280), ('87.79.216.207', 50000), ('73.24.30.122', 35727), ('212.32.229.66', 1842), ('97.103.206.29', 53314), ('58.6.89.141', 1157), ('78.92.112.15', 60745), ('124.176.208.220', 51413), ('68.44.225.100', 5051), ('188.6.231.166', 51413), ('58.6.89.141', 1099), ('99.28.209.57', 29694), ('108.172.92.81', 55555), ('46.107.192.126', 8999), ('212.232.79.196', 27886), ('24.236.49.9', 14100), ('84.28.172.201', 51413), ('188.195.3.8', 51413), ('92.110.18.80', 8999), ('91.153.229.129', 51413), ('5.196.71.175', 51413), ('185.21.217.21', 56031), ('93.77.142.76', 63193), ('145.130.138.96', 51413), ('73.14.170.195', 51413), ('79.121.6.189', 6318), ('78.142.23.65', 57171), ('101.112.156.11', 51413), ('195.242.156.241', 1194), ('92.247.152.29', 54217), ('81.171.9.199', 50781), ('75.108.45.243', 51413), ('172.98.67.53', 1842), ('68.44.225.100', 53849), ('81.171.9.199', 23542), ('37.214.48.240', 51413), ('72.177.3.209', 51413), ('93.203.236.159', 51413), ('95.154.19.186', 6881), ('50.39.164.144', 16881), ('88.223.24.14', 51413), ('213.188.38.130', 8999), ('85.3.104.53', 51413), ('173.69.6.72', 51413), ('46.166.190.136', 46825), ('45.231.194.211', 41481), ('77.50.127.80', 41446), ('5.39.88.54', 49420), ('78.42.236.30', 16881), ('5.227.15.139', 42068), ('31.17.12.154', 51413), ('41.188.115.45', 56763), ('46.246.123.24', 39574), ('144.172.126.68', 65516), ('72.14.181.193', 62904), ('90.128.48.99', 1347), ('90.92.181.147', 16881), ('184.175.133.66', 8999), ('185.45.195.161', 20064), ('188.243.178.111', 51413), ('139.47.117.179', 49967), ('88.138.252.41', 57837), ('91.237.164.182', 57310), ('199.204.160.119', 51413), ('50.39.198.212', 8999), ('183.89.65.240', 44808), ('90.154.5.75', 51413), ('68.44.225.100', 58836), ('89.165.156.40', 32435), ('23.227.192.103', 51413), ('217.10.117.5', 55179), ('83.149.46.57', 51413), ('217.120.102.36', 22449), ('27.255.16.95', 40001), ('68.44.225.100', 11790), ('98.142.213.39', 7401), ('38.141.32.249', 49222), ('71.38.191.134', 51413), ('68.44.225.100', 15234), ('24.236.49.9', 42805), ('74.205.141.130', 8999), ('46.158.232.118', 63782), ('66.78.249.53', 42065), ('78.239.83.41', 50505), ('89.134.45.63', 51413), ('89.202.42.62', 51413), ('198.48.184.203', 51157), ('172.98.67.53', 2623), ('109.104.17.83', 50000), ('80.128.42.85', 51413), ('82.253.238.71', 51413), ('81.171.9.199', 10128), ('68.44.225.100', 47320), ('88.172.132.57', 12464), ('84.57.138.103', 51413), ('68.44.225.100', 7158), ('23.82.10.32', 40779), ('5.189.164.178', 62924), ('86.171.122.135', 51413), ('91.226.253.69', 1039), ('188.32.24.204', 17691), ('79.121.6.189', 1060), ('68.44.225.100', 34255), ('68.44.225.100', 42549), ('91.227.46.177', 51413), ('87.253.244.34', 16881), ('73.64.230.136', 51413), ('203.184.52.1', 8999), ('66.78.249.53', 8999), ('109.197.193.160', 56172), ('109.252.2.116', 8197), ('151.252.157.50', 61213), ('37.53.35.117', 32852), ('74.140.192.66', 18954), ('71.197.139.141', 51413), ('173.179.36.233', 58948), ('75.174.143.174', 55265), ('70.56.193.245', 51413)}\npeer search for ECB3E22E1DC0AA078B48B7323AEBBA827AD9BD80\npeers: {('192.168.10.10', 2357)}\nannounce with port `2357`\nannounce done\nsearch our own ip\npeers: {('192.168.10.10', 2357)}\n```\n\n## Links\n\n* [AIO-KRPC](https://github.com/bashkirtsevich-llc/aiokrpc); \n* [AIO-UDP](https://github.com/bashkirtsevich-llc/aioudp);\n* [BEP 0005](http://www.bittorrent.org/beps/bep_0005.html);\n* [DHT on Wikipedia](https://en.wikipedia.org/wiki/Distributed_hash_table);","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbashkirtsevich-llc%2Faiobtdht","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbashkirtsevich-llc%2Faiobtdht","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbashkirtsevich-llc%2Faiobtdht/lists"}