Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added exceptional, made modular the app and many bugfixes & improvements

  • Loading branch information...
commit d113df1c7dfb405855533c372fbc1b8cd77e7a8c 1 parent edb47f0
@razielgn authored
View
2  LICENCE
@@ -1,4 +1,4 @@
-Copyright (c) 2010 Federico Ravasio
+Copyright (c) 2011 Federico Ravasio
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
16 README
@@ -0,0 +1,16 @@
+# BitTorrent Tracker with Ruby flavor!
+I'm trying to keep it as simple as possible!
+
+**PERFORMANCE**
+I measured 2-4ms responses on Heroku.
+
+**CONFIG**
+To change config see config/tracker.yaml
+
+* tracker_id: String. It is also reported to the clients.
+* announce_interval: In seconds.
+* timeout_interval: In seconds. After the timeout the zombie peers will be purged.
+* min_announce_interval: In seconds.
+* allow_unregistered_torrents: Bool. A la opentracker or not, your choice!
+* allow_noncompact: Bool. Compact responses save bandwidth.
+* full_scrape: Bool. Decide if a full tracker scrape is permitted. It is useful to indexing websites.
View
4 config.ru
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + "/server.rb"
-if ENV["HEROKU"]
+if ENV["HEROKU"] # dunno why this doesn't work on my mac
run STracker::SinatraTracker
-else
+else # and this doesn't work on Heroku!
STracker::SinatraTracker.run!
end
View
2  config/tracker.yaml
@@ -5,7 +5,7 @@ defaults: &defaults
min_announce_interval: 900
allow_unregistered_torrents: true
allow_noncompact: true
- full_scrape: true
+ full_scrape: false
development:
<<: *defaults
View
20 lib/tracker.rb
@@ -29,7 +29,7 @@ def initialize
def announce(req)
begin
request = Request.new(req)
- @logger.info "Request from #{request.ip} with torrent #{request.info_hash}."
+ #@logger.info "Request from #{request.ip} with torrent #{request.info_hash}."
torrent = Torrent.find(:one, :conditions => {:_id => request.info_hash}).first
if torrent.nil?
@@ -48,10 +48,10 @@ def announce(req)
torrent.update_torrent(request)
zombies = torrent.clear_zombies(Time.now - @timeout_interval)
- @logger.info "Torrent had #{zombies} in it, removed them."
+ @logger.info "Torrent had #{zombies} in it, removed them." if zombies > 0
peers = torrent.get_peers(request.numwant, request.compact)
- @logger.info "Sent #{peers.count} to #{request.ip} for torrent #{request.info_hash}."
+ @logger.info "Sent #{peers.count} peers to #{request.ip} for torrent #{request.info_hash}."
{"complete" => torrent.seeders,
"incomplete" => torrent.leechers,
@@ -63,8 +63,7 @@ def announce(req)
rescue TrackerException => ex
@logger.info "Request from #{req["ip"]} failed. Reason: #{ex.message}"
- send_error(ex.message)
- return
+ return send_error(ex.message)
end
end
@@ -72,10 +71,9 @@ def scrape(params)
if params.keys.include? "info_hash"
torrents = [Torrent.find(STracker::Tracker.bin2hex(params["info_hash"]))]
elsif @full_scrape
- torrents = Torrent.all
+ torrents = Torrent.only(:seeders, :leechers, :completed)
else
- send_error("Full scrape is not permitted!")
- return
+ return send_error("Full scrape is not permitted!")
end
out = {}
@@ -89,7 +87,11 @@ def scrape(params)
})
end
- {"files" => out}.bencode
+ if not out.empty?
+ {"files" => out}.bencode
+ else
+ send_error("The tracker is empty!")
+ end
end
def status
View
1  server.rb
@@ -10,6 +10,7 @@ class SinatraTracker < Sinatra::Base
set :root, File.dirname(__FILE__)
set :show_exceptions, true if development?
+ enable :logging, :raise_errors
configure do
$rootdir = options.root
Please sign in to comment.
Something went wrong with that request. Please try again.