GithubHelp home page GithubHelp logo

elektito / pybtracker Goto Github PK

View Code? Open in Web Editor NEW
53.0 4.0 13.0 25 KB

UDP BitTorrent tracker written in Python 3.5 using co-routines and asyncio.

License: MIT License

Makefile 0.48% Python 99.52%
bittorrent python asyncio tracker bittorrent-tracker

pybtracker's Introduction

pybtracker

pybtracker is a UDP BitTorrent tracker written in Python 3.5 using co-routines and the asyncio module. You can use the tracker in a script like this:

import asyncio
from pybtracker import TrackerServer

loop = asyncio.get_event_loop()
tracker = TrackerServer(local_addr=('127.0.0.1', 8000), loop=loop)
asyncio.ensure_future(tracker.start())
try:
    loop.run_forever()
except KeyboardInterrupt:
    loop.run_until_complete(tracker.stop())

It also includes a UDP tracker client:

import asyncio
from pybtracker import TrackerClient

async def announce():
    client = TrackerClient(announce_uri='udp://127.0.0.1:8000', loop=loop)
    await client.start()
    peers = await client.announce(
        b'01234567890123456789',  # infohash
        10000,                    # downloaded
        40000,                    # left
        5000,                     # uploaded
        0,                        # event (0=none)
        120                       # number of peers wanted
    )
    print(peers)

loop = asyncio.get_event_loop()
loop.run_until_complete(announce())

You can run the server independently by running:

$ python -m pybtracker.server -b 127.0.0.1:8000 -O

The client can also be run independently and it provides you with a shell to interact with the server:

$ python -m pybtracker.client udp://127.0.0.1:8000
BitTorrent tracker client. Type help or ? to list commands.

(btrc) help
Documented commands (type help <topic>):
========================================
EOF  announce  connect  help  quit

(btrc) quit
$

If you have installed pybtracker using pip or setup.py, you can also run pybtracker and pybtracker-client instead of using python -m.

pybtracker's People

Contributors

elektito avatar flyingbird95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pybtracker's Issues

URL format for transmission ?

TRACKERS = [
    "udp://192.168.23.80:9000",
]
tc.change_torrent(trackerAdd=TRACKERS, ids=[t.id])

I've been using rpc to transmission to add the url of the tracker, but it always says

Scrape error: Connection failed - Today 03:09:51 PM

Any idea what the url should look like ?

Problem with timestamp update in server.py announce

Hello

I checking your code and i found problem with validation in server. problem is

example:
connect -> connid setup datetime

in announce

timestamp is only get function from dict.
last_valid is updated but connid datetime no

i dont understand why is no update connid datetime when peer stay connected.

Exception thrown in TrackerServer after announce

I started the server as told in the README,

from pybtracker import TrackerServer
import asyncio


loop = asyncio.get_event_loop()
tracker = TrackerServer(local_addr=('0.0.0.0',6881),loop=loop)
print(":: TrackerServer initiated ::\n\nStarting server ... ")
asyncio.ensure_future(tracker.start())

try:
	loop.run_forever()
except KeyboardInterrupt:
	loop.run_until_complete(tracker.stop())

But an error comes up when I add a torrent file and as soon as Deluge announces the torrent that uses this tracker 'udp://192.168.42.229:6881' [initially tried with 'udp://127.0.0.1:6881']
What am I doing wrong here ๐Ÿค”

Here is the output and the error that follows

:: TrackerServer initiated ::
Starting server ... 
Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 125, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 1016, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/home/madboy/Projects/py3/lib/python3.5/site-packages/pybtracker/server.py", line 124, in datagram_received
    tid, data[16:])
  File "/home/madboy/Projects/py3/lib/python3.5/site-packages/pybtracker/server.py", line 58, in process_announce
    elif len(self.allowed_torrents) > 0 and ih not in self.allowed_torrents:
TypeError: object of type 'NoneType' has no len()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.