torrent_client 0.1.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +16 -0
- data/ext/torrent_client/torrent_client.cc +62 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03d06ee01d006e8d24a119e266b2aaf08f4d7b64
|
4
|
+
data.tar.gz: 71da685aebeea8cfa4b1f29d62d6ea071c4fa6c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5bdbb04d6fb3fe9ecd5429a114b70378443cc6a7f5d3925b6c7fd7d0bcdae5a803a2f0e1e308931667314e271feed68250d5fbeeca72b9fe71c3b99085ebbf0
|
7
|
+
data.tar.gz: 85e7c24edc7c27b66c5822a88e9dc060f03f25df28f53efd71708d14e2267fcc9ef64b10f6424915ab7bf609e87e08f34533b3a12adbaeabbd748edccddb97ec
|
data/CHANGELOG.md
CHANGED
@@ -1 +1,11 @@
|
|
1
1
|
# Changelog
|
2
|
+
|
3
|
+
## [0.2.0] - 2016-04-06
|
4
|
+
|
5
|
+
Adds TorrentClient.verify, moves libtorrent session creation to happen once when
|
6
|
+
the module is loaded, and adds instructions in the README.
|
7
|
+
|
8
|
+
## [0.1.0] - 2016-04-05
|
9
|
+
|
10
|
+
Initial release, supporting TorrentClient.download.
|
11
|
+
|
data/README.md
CHANGED
@@ -2,4 +2,20 @@
|
|
2
2
|
|
3
3
|
A simple Ruby BitTorrent client based on libtorrent-rasterbar
|
4
4
|
|
5
|
+
## Setup
|
6
|
+
|
5
7
|
Requires [Boost](https://boost.org) and [libtorrent](http://libtorrent.org).
|
8
|
+
On Mac OS X these can be setup with Homebrew
|
9
|
+
```
|
10
|
+
brew install boost libtorrent-rasterbar
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```
|
16
|
+
# Returns true if the torrent payload is complete on-disk, false otherwise.
|
17
|
+
TorrentClient.verify '<file>.torrent' '<destination_dir>'
|
18
|
+
|
19
|
+
# Downloads the torrent payload to the destination_dir. Returns when complete.
|
20
|
+
TorrentClient.download '<file>.torrent' '<destination_dir>'
|
21
|
+
```
|
@@ -5,33 +5,40 @@
|
|
5
5
|
#include <libtorrent/torrent_info.hpp>
|
6
6
|
#include <libtorrent/alert_types.hpp>
|
7
7
|
|
8
|
+
namespace lt = libtorrent;
|
9
|
+
|
8
10
|
VALUE TorrentClient = Qnil;
|
11
|
+
std::auto_ptr<lt::session> _session;
|
9
12
|
|
10
13
|
extern "C" {
|
11
14
|
VALUE method_torrentclient_download(VALUE self, VALUE torrent_file, VALUE destination_dir);
|
15
|
+
VALUE method_torrentclient_verify(VALUE self, VALUE torrent_file, VALUE destination_dir);
|
12
16
|
|
13
17
|
void Init_torrent_client()
|
14
18
|
{
|
15
19
|
TorrentClient = rb_define_module("TorrentClient");
|
16
20
|
rb_define_singleton_method(TorrentClient, "download", RUBY_METHOD_FUNC(method_torrentclient_download), 2);
|
17
|
-
|
21
|
+
rb_define_singleton_method(TorrentClient, "verify", RUBY_METHOD_FUNC(method_torrentclient_verify), 2);
|
18
22
|
|
19
|
-
VALUE method_torrentclient_download(VALUE self, VALUE torrent_file, VALUE destination_dir)
|
20
|
-
{
|
21
23
|
try {
|
22
|
-
|
23
|
-
|
24
|
-
lt::session s;
|
25
|
-
s.set_alert_mask(lt::alert::status_notification | lt::alert::error_notification);
|
24
|
+
_session.reset(new lt::session());
|
25
|
+
_session->set_alert_mask(lt::alert::status_notification | lt::alert::error_notification);
|
26
26
|
|
27
27
|
lt::error_code ec;
|
28
|
-
|
28
|
+
_session->listen_on(std::make_pair(6881, 6889), ec);
|
29
29
|
if (ec) {
|
30
30
|
std::string err = "failed to open listen socket: " + ec.message();
|
31
31
|
rb_raise(rb_eRuntimeError, err.c_str());
|
32
|
-
return Qnil;
|
33
32
|
}
|
33
|
+
} catch (std::exception &e) {
|
34
|
+
rb_raise(rb_eRuntimeError, "failed from unknown exception");
|
35
|
+
}
|
36
|
+
}
|
34
37
|
|
38
|
+
VALUE method_torrentclient_download(VALUE self, VALUE torrent_file, VALUE destination_dir)
|
39
|
+
{
|
40
|
+
try {
|
41
|
+
lt::error_code ec;
|
35
42
|
lt::add_torrent_params p;
|
36
43
|
p.save_path = StringValueCStr(destination_dir);
|
37
44
|
p.ti = new lt::torrent_info(StringValueCStr(torrent_file), ec);
|
@@ -40,20 +47,62 @@ extern "C" {
|
|
40
47
|
return Qnil;
|
41
48
|
}
|
42
49
|
|
43
|
-
|
50
|
+
lt::torrent_handle handle = _session->add_torrent(p, ec);
|
44
51
|
if (ec) {
|
45
52
|
rb_raise(rb_eRuntimeError, ec.message().c_str());
|
46
53
|
return Qnil;
|
47
54
|
}
|
48
55
|
|
49
56
|
while (true) {
|
50
|
-
if (
|
51
|
-
std::auto_ptr<lt::alert> a =
|
57
|
+
if (_session->wait_for_alert(lt::seconds(1))) {
|
58
|
+
std::auto_ptr<lt::alert> a = _session->pop_alert();
|
52
59
|
if (a->type() == lt::torrent_finished_alert::alert_type) {
|
53
|
-
|
60
|
+
break;
|
54
61
|
}
|
55
62
|
}
|
56
63
|
}
|
64
|
+
_session->remove_torrent(handle);
|
65
|
+
return Qtrue;
|
66
|
+
} catch (std::exception &e) {
|
67
|
+
rb_raise(rb_eRuntimeError, "failed from unknown exception");
|
68
|
+
}
|
69
|
+
return Qnil;
|
70
|
+
}
|
71
|
+
|
72
|
+
VALUE method_torrentclient_verify(VALUE self, VALUE torrent_file, VALUE destination_dir)
|
73
|
+
{
|
74
|
+
try {
|
75
|
+
lt::error_code ec;
|
76
|
+
lt::add_torrent_params p;
|
77
|
+
p.save_path = StringValueCStr(destination_dir);
|
78
|
+
p.flags = lt::add_torrent_params::flag_paused;
|
79
|
+
p.ti = new lt::torrent_info(StringValueCStr(torrent_file), ec);
|
80
|
+
if (ec) {
|
81
|
+
rb_raise(rb_eRuntimeError, ec.message().c_str());
|
82
|
+
return Qnil;
|
83
|
+
}
|
84
|
+
|
85
|
+
lt::torrent_handle handle = _session->add_torrent(p, ec);
|
86
|
+
if (ec) {
|
87
|
+
rb_raise(rb_eRuntimeError, ec.message().c_str());
|
88
|
+
return Qnil;
|
89
|
+
}
|
90
|
+
|
91
|
+
lt::torrent_status status = handle.status();
|
92
|
+
while (status.state == lt::torrent_status::checking_files ||
|
93
|
+
status.state == lt::torrent_status::checking_resume_data) {
|
94
|
+
_session->wait_for_alert(lt::seconds(1));
|
95
|
+
status = handle.status();
|
96
|
+
}
|
97
|
+
|
98
|
+
_session->remove_torrent(handle);
|
99
|
+
|
100
|
+
if (status.state == lt::torrent_status::seeding ||
|
101
|
+
status.state == lt::torrent_status::queued_for_checking) {
|
102
|
+
return Qtrue;
|
103
|
+
} else {
|
104
|
+
return Qfalse;
|
105
|
+
}
|
57
106
|
} catch (std::exception &e) {
|
58
107
|
rb_raise(rb_eRuntimeError, "failed from unknown exception");
|
59
108
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torrent_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|