ArneBab / gnutella_tracker

A simple file-tracker for Gnutella You can put files into the "files" folder which then are made available via magnet links with alternate locations. Also it implements the x-alt protocol to learn about more alternate locations. Use it with "python gnutella_tracker.py"

commit 34: 3a891e412e42
parent 33: 826ac2bb0147
branch: default
Fix in-file documentation
Arne Babenhauserheide
5 months ago

Changed (Δ105 bytes):

raw changeset »

gnutella_tracker.py (10 lines added, 5 lines removed)

Up to file-list gnutella_tracker.py:

3
3
4
4
"""A simple file-tracker for Gnutella
5
5
6
You can upload files which then are made available via magnet links with alternate locations.
6
You can put files into the "files" folder which then are made available via magnet links with alternate locations.
7
7
8
8
Also it implements the x-alt protocol to learn about more alternate locations.
9
9
10
It keeps the 8 most recent accessing IPs and 8 IPs from x-alt. 
10
It keeps the 16 most recent IPs from x-alt. 
11
11
12
12
Usage:
13
13
14
14
    - python gnutella_tracker.py
15
15
      start the server at port 8000 which shares the files inside the files/ folder.
16
      You can now point your browser to http://127.0.0.1:8000 to see the published files. 
16
      You can now point your browser to http://127.0.0.1:8000 to see the published files.
17
18
    - python gnutella_tracker.py --help
19
      print this help output.
17
20
18
21
"""
19
22
@@ -56,6 +59,8 @@ TRACKER_TITLE = "Gnutella Tracker"
56
59
#: The time interval after which the oldest alt-loc gets removed (for health status), in seconds. 
57
60
PRUNING_INTERVAL_SECONDS = 86400 # 24h
58
61
62
## commandline option parsing
63
59
64
## Global objects
60
65
61
66
#: A dict of sha1 hashes with filenames, direct IPs and alt-loc IPs: {sha1: {filename: "filename", x-alt: [IP1, IP2, ...], last-prune-time: 123678123.82}}
@@ -152,8 +157,8 @@ def process_x_alt(sha, x_alt):
152
157
    alts = [a.strip() for a in alts]
153
158
    # add the alts
154
159
    files[sha]["x-alt"].extend(alts)
155
    # and remove all but the last 8 alts. 
156
    files[sha]["x-alt"] = files[sha]["x-alt"][-8:]
160
    # and remove all but the last 16 alts. 
161
    files[sha]["x-alt"] = files[sha]["x-alt"][-16:]
157
162
158
163
def serve_file(sha,start=0,end=None,folder=SHARE):
159
164
    """Return the filedata for the given sha1 hash."""