Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
jarthod committed May 20, 2013
1 parent 0f4a580 commit fd07777
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
1.9.3-p392
32 changes: 28 additions & 4 deletions bttrack.rb 100644 → 100755
Expand Up @@ -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,
Expand Down Expand Up @@ -61,4 +70,19 @@ def req

@@ index
bttrack version <%= @version %><br/>
tracking <%= @torrents_count %> torrent(s)
tracking <%= @torrents.size %> torrent(s)
<ul>
<% @torrents.each do |torrent| %>
<% torrent = torrent.split('/').last %>
<li><a href="/info/<%= torrent %>"><%= torrent %></a></li>
<% end %>
</ul>

@@ info
torrent: <%= @info_hash.id %><br/>
peers:
<ul>
<% @peers.each do |peer| %>
<li><%= peer %></a></li>
<% end %>
</ul>
13 changes: 7 additions & 6 deletions lib/bttrack/info_hash.rb
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/unit/info_hash_test.rb
Expand Up @@ -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',
Expand Down

0 comments on commit fd07777

Please sign in to comment.