Class: RubyTorrent::TrackerConnection
- Inherits:
-
Object
- Object
- RubyTorrent::TrackerConnection
- Defined in:
- lib/rubytorrent/tracker.rb
Instance Attribute Summary collapse
-
#downloaded ⇒ Object
Returns the value of attribute downloaded.
-
#in_force_refresh ⇒ Object
readonly
Returns the value of attribute in_force_refresh.
-
#last_conn_time ⇒ Object
readonly
Returns the value of attribute last_conn_time.
-
#left ⇒ Object
Returns the value of attribute left.
-
#numwant ⇒ Object
Returns the value of attribute numwant.
-
#peer_id ⇒ Object
readonly
Returns the value of attribute peer_id.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#uploaded ⇒ Object
Returns the value of attribute uploaded.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #already_completed ⇒ Object
- #completed ⇒ Object
- #force_refresh ⇒ Object
-
#initialize(url, info_hash, length, port, peer_id, ip = nil, numwant = 50, http_proxy = ) ⇒ TrackerConnection
constructor
A new instance of TrackerConnection.
- #refresh ⇒ Object
- #sent_completed? ⇒ Boolean
- #started ⇒ Object
- #stopped ⇒ Object
Constructor Details
#initialize(url, info_hash, length, port, peer_id, ip = nil, numwant = 50, http_proxy = ) ⇒ TrackerConnection
Returns a new instance of TrackerConnection.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rubytorrent/tracker.rb', line 108 def initialize(url, info_hash, length, port, peer_id, ip=nil, numwant=50, http_proxy=ENV["http_proxy"]) @url = url @hash = info_hash @length = length @port = port @uploaded = @downloaded = @left = 0 @ip = ip @numwant = numwant @peer_id = peer_id @http_proxy = http_proxy @state = :stopped @sent_completed = false @last_conn_time = nil @tracker_data = nil @compact = true @in_force_refresh = false end |
Instance Attribute Details
#downloaded ⇒ Object
Returns the value of attribute downloaded.
106 107 108 |
# File 'lib/rubytorrent/tracker.rb', line 106 def downloaded @downloaded end |
#in_force_refresh ⇒ Object (readonly)
Returns the value of attribute in_force_refresh.
105 106 107 |
# File 'lib/rubytorrent/tracker.rb', line 105 def in_force_refresh @in_force_refresh end |
#last_conn_time ⇒ Object (readonly)
Returns the value of attribute last_conn_time.
105 106 107 |
# File 'lib/rubytorrent/tracker.rb', line 105 def last_conn_time @last_conn_time end |
#left ⇒ Object
Returns the value of attribute left.
105 106 107 |
# File 'lib/rubytorrent/tracker.rb', line 105 def left @left end |
#numwant ⇒ Object
Returns the value of attribute numwant.
106 107 108 |
# File 'lib/rubytorrent/tracker.rb', line 106 def numwant @numwant end |
#peer_id ⇒ Object (readonly)
Returns the value of attribute peer_id.
105 106 107 |
# File 'lib/rubytorrent/tracker.rb', line 105 def peer_id @peer_id end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
105 106 107 |
# File 'lib/rubytorrent/tracker.rb', line 105 def port @port end |
#uploaded ⇒ Object
Returns the value of attribute uploaded.
106 107 108 |
# File 'lib/rubytorrent/tracker.rb', line 106 def uploaded @uploaded end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
105 106 107 |
# File 'lib/rubytorrent/tracker.rb', line 105 def url @url end |
Instance Method Details
#already_completed ⇒ Object
126 |
# File 'lib/rubytorrent/tracker.rb', line 126 def already_completed; @sent_completed = true; end |
#completed ⇒ Object
143 144 145 146 147 148 |
# File 'lib/rubytorrent/tracker.rb', line 143 def completed return if @sent_completed @tracker_data = send_tracker "completed" @sent_completed = true self end |
#force_refresh ⇒ Object
155 156 157 158 159 160 |
# File 'lib/rubytorrent/tracker.rb', line 155 def force_refresh return if @in_force_refresh @in_force_refresh = true @tracker_data = send_tracker nil @in_force_refresh = false end |
#refresh ⇒ Object
150 151 152 153 |
# File 'lib/rubytorrent/tracker.rb', line 150 def refresh return unless (Time.now - @last_conn_time) >= (interval || 0) @tracker_data = send_tracker nil end |
#sent_completed? ⇒ Boolean
127 |
# File 'lib/rubytorrent/tracker.rb', line 127 def sent_completed?; @sent_completed; end |
#started ⇒ Object
129 130 131 132 133 134 |
# File 'lib/rubytorrent/tracker.rb', line 129 def started return unless @state == :stopped @state = :started @tracker_data = send_tracker "started" self end |
#stopped ⇒ Object
136 137 138 139 140 141 |
# File 'lib/rubytorrent/tracker.rb', line 136 def stopped return unless @state == :started @state = :stopped @tracker_data = send_tracker "stopped" self end |