diff --git a/.ruby-version b/.ruby-version
new file mode 100644
index 0000000..ae6d5b9
--- /dev/null
+++ b/.ruby-version
@@ -0,0 +1 @@
+1.9.3-p392
diff --git a/bttrack.rb b/bttrack.rb
old mode 100644
new mode 100755
index b0c54f5..ecdc059
--- a/bttrack.rb
+++ b/bttrack.rb
@@ -21,19 +21,28 @@ def req
get '/' do
@version = `cat #{$BTTRACK_ROOT}/VERSION`
- @torrents_count = Dir.glob("#{CONF[:db_dir]}/*/*/*").size
+ @torrents = Dir.glob("#{CONF[:db_dir]}/*/*/*")
erb :index
end
+get '/info/:id' do
+ @info_hash = Bttrack::InfoHash.new id: params[:id]
+ @peers = @info_hash.peers_list(100).map do |p|
+ p['ip'] = [24, 16, 8, 0].collect {|b| (p['ip'] >> b) & 255}.join('.')
+ p
+ end
+ erb :info
+end
+
get '/announce' do
info_hash = req.info_hash
-
+
peers = info_hash.peers(
:compact => req.compact?,
:no_peer_id => req.no_peer_id?,
:numwant => req.numwant
)
-
+
info_hash.event(
:event => req.event,
:downloaded => req.downloaded,
@@ -61,4 +70,19 @@ def req
@@ index
bttrack version <%= @version %>
-tracking <%= @torrents_count %> torrent(s)
+tracking <%= @torrents.size %> torrent(s)
+
+<% @torrents.each do |torrent| %>
+ <% torrent = torrent.split('/').last %>
+ - <%= torrent %>
+<% end %>
+
+
+@@ info
+torrent: <%= @info_hash.id %>
+peers:
+
+<% @peers.each do |peer| %>
+ - <%= peer %>
+<% end %>
+
diff --git a/lib/bttrack/info_hash.rb b/lib/bttrack/info_hash.rb
index 141ae8d..f503df1 100644
--- a/lib/bttrack/info_hash.rb
+++ b/lib/bttrack/info_hash.rb
@@ -13,12 +13,13 @@ def initialize(params)
end
def validate
- raise 'info_hash is missing' if @params[:info_hash].nil?
-
- @id = Array(@params[:info_hash].unpack('H*'))[0].to_s
-
- raise 'invalid info_hash' unless
- @id =~ /[\w\d]{40}/
+ if @params[:id]
+ @id = @params[:id]
+ else
+ raise 'info_hash is missing' if @params[:info_hash].nil?
+ @id = Array(@params[:info_hash].unpack('H*'))[0].to_s
+ end
+ raise 'invalid info_hash' unless @id =~ /[\w\d]{40}/
end
def peers(args)
diff --git a/test/unit/info_hash_test.rb b/test/unit/info_hash_test.rb
index acfc5b5..a4df05b 100644
--- a/test/unit/info_hash_test.rb
+++ b/test/unit/info_hash_test.rb
@@ -25,6 +25,10 @@ def teardown
end
end
+ def test_instanciate_by_id
+ @info_hash = Bttrack::InfoHash.new id: 'db1db6d9510e787dcd72b1ab069c520502a69e32'
+ end
+
def test_event
@info_hash.event(
:event => 'started',