Class: RubyTorrent::BitTorrent
- Inherits:
-
Object
- Object
- RubyTorrent::BitTorrent
- Includes:
- EventSource
- Defined in:
- lib/rubytorrent.rb
Overview
the top-level class for RubyTorrent.
Constant Summary collapse
- @@server =
nil
Instance Method Summary collapse
- #bytes_completed ⇒ Object
- #complete? ⇒ Boolean
- #dlamt ⇒ Object
- #dlrate ⇒ Object
-
#initialize(metainfo, *rest) ⇒ BitTorrent
constructor
hash arguments: host, port, dlratelim, ulratelim.
- #ip ⇒ Object
- #num_active_peers ⇒ Object
- #num_pieces ⇒ Object
- #num_possible_peers ⇒ Object
- #peer_info ⇒ Object
- #percent_completed ⇒ Object
- #pieces_completed ⇒ Object
- #port ⇒ Object
- #shutdown ⇒ Object
- #shutdown_all ⇒ Object
- #total_bytes ⇒ Object
- #tracker ⇒ Object
- #ulamt ⇒ Object
- #ulrate ⇒ Object
Methods included from EventSource
append_features, #on_event, #relay_event, #send_event, #unregister_events
Constructor Details
#initialize(metainfo, *rest) ⇒ BitTorrent
hash arguments: host, port, dlratelim, ulratelim
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 68 69 70 71 72 |
# File 'lib/rubytorrent.rb', line 37 def initialize(, *rest) args, rest = RubyTorrent::get_args(rest, :host, :port, :dlratelim, :ulratelim, :http_proxy) out = rest.shift raise ArgumentError, "wrong number of arguments (expected 0/1, got #{rest.length})" unless rest.empty? case when MetaInfo @metainfo = when String @metainfo = MetaInfo.from_location() when IO @metainfo = MetaInfo.from_stream() else raise ArgumentError, "'metainfo' should be a String, IO or RubyTorrent::MetaInfo object" end case out when Package @package = out else @package = Package.new(@metainfo, out) end unless @@server @@server = RubyTorrent::Server.new(args[:host], args[:port], args[:http_proxy]) @@server.start end @cont = @@server.add_torrent(@metainfo, @package, args[:dlratelim], args[:ulratelim]) @cont.relay_event self, :trying_peer, :forgetting_peer, :added_peer, :removed_peer, :received_block, :sent_block, :have_piece, :discarded_piece, :tracker_connected, :tracker_lost, :requested_block @package.relay_event self, :complete end |
Instance Method Details
#bytes_completed ⇒ Object
80 |
# File 'lib/rubytorrent.rb', line 80 def bytes_completed; @package.bytes_completed; end |
#complete? ⇒ Boolean
79 |
# File 'lib/rubytorrent.rb', line 79 def complete?; @package.complete?; end |
#dlamt ⇒ Object
85 |
# File 'lib/rubytorrent.rb', line 85 def dlamt; @cont.dlamt; end |
#dlrate ⇒ Object
83 |
# File 'lib/rubytorrent.rb', line 83 def dlrate; @cont.dlrate; end |
#ip ⇒ Object
74 |
# File 'lib/rubytorrent.rb', line 74 def ip; @@server.ip; end |
#num_active_peers ⇒ Object
90 |
# File 'lib/rubytorrent.rb', line 90 def num_active_peers; @cont.num_peers; end |
#num_pieces ⇒ Object
87 |
# File 'lib/rubytorrent.rb', line 87 def num_pieces; @package.num_pieces; end |
#num_possible_peers ⇒ Object
89 |
# File 'lib/rubytorrent.rb', line 89 def num_possible_peers; (@cont.tracker ? @cont.tracker.peers.length : 0); end |
#peer_info ⇒ Object
76 |
# File 'lib/rubytorrent.rb', line 76 def peer_info; @cont.peer_info; end |
#percent_completed ⇒ Object
81 |
# File 'lib/rubytorrent.rb', line 81 def percent_completed; @package.percent_completed; end |
#pieces_completed ⇒ Object
82 |
# File 'lib/rubytorrent.rb', line 82 def pieces_completed; @package.pieces_completed; end |
#port ⇒ Object
75 |
# File 'lib/rubytorrent.rb', line 75 def port; @@server.port; end |
#shutdown ⇒ Object
77 |
# File 'lib/rubytorrent.rb', line 77 def shutdown; @cont.shutdown; end |
#shutdown_all ⇒ Object
78 |
# File 'lib/rubytorrent.rb', line 78 def shutdown_all; @@server.shutdown; end |
#total_bytes ⇒ Object
91 |
# File 'lib/rubytorrent.rb', line 91 def total_bytes; @package.size; end |
#tracker ⇒ Object
88 |
# File 'lib/rubytorrent.rb', line 88 def tracker; (@cont.tracker ? @cont.tracker.url : nil); end |
#ulamt ⇒ Object
86 |
# File 'lib/rubytorrent.rb', line 86 def ulamt; @cont.ulamt; end |
#ulrate ⇒ Object
84 |
# File 'lib/rubytorrent.rb', line 84 def ulrate; @cont.ulrate; end |