Class: QuartzTorrent::HttpTrackerDriver
- Inherits:
-
TrackerDriver
- Object
- TrackerDriver
- QuartzTorrent::HttpTrackerDriver
- Defined in:
- lib/quartz_torrent/httptrackerdriver.rb
Overview
A tracker driver that uses the HTTP protocol. This is the classic BitTorrent tracker protocol.
Instance Method Summary collapse
-
#initialize(announceUrl, infoHash) ⇒ HttpTrackerDriver
constructor
A new instance of HttpTrackerDriver.
-
#request(event = nil) ⇒ Object
Request a list of peers from the tracker and return it as a TrackerResponse.
Constructor Details
#initialize(announceUrl, infoHash) ⇒ HttpTrackerDriver
Returns a new instance of HttpTrackerDriver.
9 10 11 12 13 14 15 |
# File 'lib/quartz_torrent/httptrackerdriver.rb', line 9 def initialize(announceUrl, infoHash) super() @startSent = false @logger = LogManager.getLogger("http_tracker_client") @announceUrl = announceUrl @infoHash = infoHash end |
Instance Method Details
#request(event = nil) ⇒ Object
Request a list of peers from the tracker and return it as a TrackerResponse.
Event, if specified, may be set to :started, :stopped, or :completed. This is used to notify the tracker that this is the first request, that we are shutting down, or that we have the full torrent respectively. Not specifying the event just means this is a regular poll. def getPeers(event = nil)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/quartz_torrent/httptrackerdriver.rb', line 23 def request(event = nil) uri = URI(@announceUrl) dynamicParams = @dynamicRequestParamsBuilder.call params = {} params['info_hash'] = CGI.escape(@infoHash) params['peer_id'] = dynamicParams.peerId params['port'] = dynamicParams.port params['uploaded'] = dynamicParams.uploaded.to_s params['downloaded'] = dynamicParams.downloaded.to_s params['left'] = dynamicParams.left.to_s params['compact'] = "1" params['no_peer_id'] = "1" if ! @startSent event = :started @startSent = true end params['event'] = event.to_s if event @logger.debug "Request parameters: " params.each do |k,v| @logger.debug " #{k}: #{v}" end query = "" params.each do |k,v| query << "&" if query.length > 0 query << "#{k}=#{v}" end uri.query = query begin res = Net::HTTP.get_response(uri) rescue Timeout::Error return TrackerResponse.new(false, "Tracker request timed out", []) end @logger.debug "Tracker response code: #{res.code}" @logger.debug "Tracker response body: #{res.body}" result = buildTrackerResponse(res) @logger.debug "TrackerResponse: #{result.inspect}" result end |