Class: RubyTorrent::TrackerConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/rubytorrent/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#downloadedObject

Returns the value of attribute downloaded.



106
107
108
# File 'lib/rubytorrent/tracker.rb', line 106

def downloaded
  @downloaded
end

#in_force_refreshObject (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_timeObject (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

#leftObject

Returns the value of attribute left.



105
106
107
# File 'lib/rubytorrent/tracker.rb', line 105

def left
  @left
end

#numwantObject

Returns the value of attribute numwant.



106
107
108
# File 'lib/rubytorrent/tracker.rb', line 106

def numwant
  @numwant
end

#peer_idObject (readonly)

Returns the value of attribute peer_id.



105
106
107
# File 'lib/rubytorrent/tracker.rb', line 105

def peer_id
  @peer_id
end

#portObject (readonly)

Returns the value of attribute port.



105
106
107
# File 'lib/rubytorrent/tracker.rb', line 105

def port
  @port
end

#uploadedObject

Returns the value of attribute uploaded.



106
107
108
# File 'lib/rubytorrent/tracker.rb', line 106

def uploaded
  @uploaded
end

#urlObject (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_completedObject



126
# File 'lib/rubytorrent/tracker.rb', line 126

def already_completed; @sent_completed = true; end

#completedObject



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_refreshObject



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

#refreshObject



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

Returns:

  • (Boolean)


127
# File 'lib/rubytorrent/tracker.rb', line 127

def sent_completed?; @sent_completed; end

#startedObject



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

#stoppedObject



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