torrent_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16bce221ec57ce23550242b63a6c4b4ca29514f0
4
+ data.tar.gz: ff62f2894030b4243cecc603c31963d2b464623d
5
+ SHA512:
6
+ metadata.gz: 94ce50a5192dfd6eb1f8bad579aca25689547de5c1b234d0f1303f5d6e575529d287101c6619a83c30d65b204939ff92e6f886af399aa9d5950bb57a60ce604d
7
+ data.tar.gz: 2b5e697f5c6fb2f7ca41d60b8b79ece0dc51ce9f96e0fc57af9562106840791fd988d2106ac908cab86dfe20fe87f7318f200cb222ac8789b354eb97d01bd407
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Changelog
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # torrent_client
2
+
3
+ A simple Ruby BitTorrent client based on libtorrent-rasterbar
4
+
5
+ Requires [Boost](https://boost.org) and [libtorrent](http://libtorrent.org).
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+ extension_name = 'torrent_client'
3
+ dir_config(extension_name)
4
+
5
+ $libs = append_library($libs, 'torrent-rasterbar')
6
+
7
+ create_makefile(extension_name)
@@ -0,0 +1,62 @@
1
+ #include <ruby.h>
2
+ #include <libtorrent/entry.hpp>
3
+ #include <libtorrent/bencode.hpp>
4
+ #include <libtorrent/session.hpp>
5
+ #include <libtorrent/torrent_info.hpp>
6
+ #include <libtorrent/alert_types.hpp>
7
+
8
+ VALUE TorrentClient = Qnil;
9
+
10
+ extern "C" {
11
+ VALUE method_torrentclient_download(VALUE self, VALUE torrent_file, VALUE destination_dir);
12
+
13
+ void Init_torrent_client()
14
+ {
15
+ TorrentClient = rb_define_module("TorrentClient");
16
+ rb_define_singleton_method(TorrentClient, "download", RUBY_METHOD_FUNC(method_torrentclient_download), 2);
17
+ }
18
+
19
+ VALUE method_torrentclient_download(VALUE self, VALUE torrent_file, VALUE destination_dir)
20
+ {
21
+ try {
22
+ namespace lt = libtorrent;
23
+
24
+ lt::session s;
25
+ s.set_alert_mask(lt::alert::status_notification | lt::alert::error_notification);
26
+
27
+ lt::error_code ec;
28
+ s.listen_on(std::make_pair(6881, 6889), ec);
29
+ if (ec) {
30
+ std::string err = "failed to open listen socket: " + ec.message();
31
+ rb_raise(rb_eRuntimeError, err.c_str());
32
+ return Qnil;
33
+ }
34
+
35
+ lt::add_torrent_params p;
36
+ p.save_path = StringValueCStr(destination_dir);
37
+ p.ti = new lt::torrent_info(StringValueCStr(torrent_file), ec);
38
+ if (ec) {
39
+ rb_raise(rb_eRuntimeError, ec.message().c_str());
40
+ return Qnil;
41
+ }
42
+
43
+ s.add_torrent(p, ec);
44
+ if (ec) {
45
+ rb_raise(rb_eRuntimeError, ec.message().c_str());
46
+ return Qnil;
47
+ }
48
+
49
+ while (true) {
50
+ if (s.wait_for_alert(lt::milliseconds(100))) {
51
+ std::auto_ptr<lt::alert> a = s.pop_alert();
52
+ if (a->type() == lt::torrent_finished_alert::alert_type) {
53
+ return Qtrue;
54
+ }
55
+ }
56
+ }
57
+ } catch (std::exception &e) {
58
+ rb_raise(rb_eRuntimeError, "failed from unknown exception");
59
+ }
60
+ return Qnil;
61
+ }
62
+ }
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: torrent_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.7
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.7
27
+ description:
28
+ email: mikael.t.smith@gmail.com
29
+ executables: []
30
+ extensions:
31
+ - ext/torrent_client/extconf.rb
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - README.md
36
+ - ext/torrent_client/extconf.rb
37
+ - ext/torrent_client/torrent_client.cc
38
+ homepage: https://github.com/MikaelSmith/torrent_client
39
+ licenses:
40
+ - Apache 2.0
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.5.1
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: A simple Ruby torrent downloader
62
+ test_files: []