transmission 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.
- data/CHANGELOG +0 -0
- data/LICENSE +23 -0
- data/README +50 -0
- data/Rakefile +41 -0
- data/ext/bencode.c +335 -0
- data/ext/bencode.h +64 -0
- data/ext/choking.c +335 -0
- data/ext/choking.h +30 -0
- data/ext/clients.c +90 -0
- data/ext/clients.h +25 -0
- data/ext/completion.c +266 -0
- data/ext/completion.h +67 -0
- data/ext/extconf.rb +3 -0
- data/ext/fastresume.h +375 -0
- data/ext/fdlimit.c +297 -0
- data/ext/fdlimit.h +36 -0
- data/ext/inout.c +620 -0
- data/ext/inout.h +38 -0
- data/ext/internal.h +202 -0
- data/ext/metainfo.c +339 -0
- data/ext/metainfo.h +44 -0
- data/ext/net.c +405 -0
- data/ext/net.h +54 -0
- data/ext/peer.c +584 -0
- data/ext/peer.h +55 -0
- data/ext/peermessages.h +326 -0
- data/ext/peerparse.h +564 -0
- data/ext/peerutils.h +394 -0
- data/ext/platform.c +196 -0
- data/ext/platform.h +63 -0
- data/ext/r_transmission.c +1135 -0
- data/ext/ratecontrol.c +170 -0
- data/ext/ratecontrol.h +33 -0
- data/ext/sha1.c +235 -0
- data/ext/sha1.h +68 -0
- data/ext/tracker.c +767 -0
- data/ext/tracker.h +53 -0
- data/ext/transmission.c +776 -0
- data/ext/transmission.h +317 -0
- data/ext/utils.c +142 -0
- data/ext/utils.h +164 -0
- data/lib/transmission.rb +75 -0
- metadata +98 -0
data/ext/utils.h
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
/******************************************************************************
|
2
|
+
* $Id: utils.h 310 2006-06-09 19:53:35Z joshe $
|
3
|
+
*
|
4
|
+
* Copyright (c) 2005-2006 Transmission authors and contributors
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
7
|
+
* copy of this software and associated documentation files (the "Software"),
|
8
|
+
* to deal in the Software without restriction, including without limitation
|
9
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
10
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
11
|
+
* Software is furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
22
|
+
* DEALINGS IN THE SOFTWARE.
|
23
|
+
*****************************************************************************/
|
24
|
+
|
25
|
+
#ifndef TR_UTILS_H
|
26
|
+
#define TR_UTILS_H 1
|
27
|
+
|
28
|
+
#define TR_MSG_ERR 1
|
29
|
+
#define TR_MSG_INF 2
|
30
|
+
#define TR_MSG_DBG 4
|
31
|
+
#define tr_err( a... ) tr_msg( TR_MSG_ERR, ## a )
|
32
|
+
#define tr_inf( a... ) tr_msg( TR_MSG_INF, ## a )
|
33
|
+
#define tr_dbg( a... ) tr_msg( TR_MSG_DBG, ## a )
|
34
|
+
void tr_msg ( int level, char * msg, ... );
|
35
|
+
|
36
|
+
int tr_rand ( int );
|
37
|
+
|
38
|
+
void * tr_memmem( const void *, size_t, const void *, size_t );
|
39
|
+
|
40
|
+
/***********************************************************************
|
41
|
+
* tr_mkdir
|
42
|
+
***********************************************************************
|
43
|
+
* Create a directory and any needed parent directories.
|
44
|
+
* Note that the string passed in must be writable!
|
45
|
+
**********************************************************************/
|
46
|
+
int tr_mkdir( char * path );
|
47
|
+
|
48
|
+
/***********************************************************************
|
49
|
+
* tr_date
|
50
|
+
***********************************************************************
|
51
|
+
* Returns the current date in milliseconds
|
52
|
+
**********************************************************************/
|
53
|
+
static inline uint64_t tr_date()
|
54
|
+
{
|
55
|
+
struct timeval tv;
|
56
|
+
gettimeofday( &tv, NULL );
|
57
|
+
return (uint64_t) tv.tv_sec * 1000 + ( tv.tv_usec / 1000 );
|
58
|
+
}
|
59
|
+
|
60
|
+
/***********************************************************************
|
61
|
+
* tr_wait
|
62
|
+
***********************************************************************
|
63
|
+
* Wait 'delay' milliseconds
|
64
|
+
**********************************************************************/
|
65
|
+
static inline void tr_wait( uint64_t delay )
|
66
|
+
{
|
67
|
+
#ifdef SYS_BEOS
|
68
|
+
snooze( 1000 * delay );
|
69
|
+
#else
|
70
|
+
usleep( 1000 * delay );
|
71
|
+
#endif
|
72
|
+
}
|
73
|
+
|
74
|
+
/***********************************************************************
|
75
|
+
* tr_bitfieldHas
|
76
|
+
**********************************************************************/
|
77
|
+
static inline int tr_bitfieldHas( uint8_t * bitfield, int piece )
|
78
|
+
{
|
79
|
+
return ( bitfield[ piece / 8 ] & ( 1 << ( 7 - ( piece % 8 ) ) ) );
|
80
|
+
}
|
81
|
+
|
82
|
+
/***********************************************************************
|
83
|
+
* tr_bitfieldAdd
|
84
|
+
**********************************************************************/
|
85
|
+
static inline void tr_bitfieldAdd( uint8_t * bitfield, int piece )
|
86
|
+
{
|
87
|
+
bitfield[ piece / 8 ] |= ( 1 << ( 7 - ( piece % 8 ) ) );
|
88
|
+
}
|
89
|
+
|
90
|
+
static inline void tr_bitfieldRem( uint8_t * bitfield, int piece )
|
91
|
+
{
|
92
|
+
bitfield[ piece / 8 ] &= ~( 1 << ( 7 - ( piece % 8 ) ) );
|
93
|
+
}
|
94
|
+
|
95
|
+
#define tr_blockPiece(a) _tr_blockPiece(tor,a)
|
96
|
+
static inline int _tr_blockPiece( tr_torrent_t * tor, int block )
|
97
|
+
{
|
98
|
+
tr_info_t * inf = &tor->info;
|
99
|
+
return block / ( inf->pieceSize / tor->blockSize );
|
100
|
+
}
|
101
|
+
|
102
|
+
#define tr_blockSize(a) _tr_blockSize(tor,a)
|
103
|
+
static inline int _tr_blockSize( tr_torrent_t * tor, int block )
|
104
|
+
{
|
105
|
+
tr_info_t * inf = &tor->info;
|
106
|
+
int dummy;
|
107
|
+
|
108
|
+
if( block != tor->blockCount - 1 ||
|
109
|
+
!( dummy = inf->totalSize % tor->blockSize ) )
|
110
|
+
{
|
111
|
+
return tor->blockSize;
|
112
|
+
}
|
113
|
+
|
114
|
+
return dummy;
|
115
|
+
}
|
116
|
+
|
117
|
+
#define tr_blockPosInPiece(a) _tr_blockPosInPiece(tor,a)
|
118
|
+
static inline int _tr_blockPosInPiece( tr_torrent_t * tor, int block )
|
119
|
+
{
|
120
|
+
tr_info_t * inf = &tor->info;
|
121
|
+
return tor->blockSize *
|
122
|
+
( block % ( inf->pieceSize / tor->blockSize ) );
|
123
|
+
}
|
124
|
+
|
125
|
+
#define tr_pieceCountBlocks(a) _tr_pieceCountBlocks(tor,a)
|
126
|
+
static inline int _tr_pieceCountBlocks( tr_torrent_t * tor, int piece )
|
127
|
+
{
|
128
|
+
tr_info_t * inf = &tor->info;
|
129
|
+
if( piece < inf->pieceCount - 1 ||
|
130
|
+
!( tor->blockCount % ( inf->pieceSize / tor->blockSize ) ) )
|
131
|
+
{
|
132
|
+
return inf->pieceSize / tor->blockSize;
|
133
|
+
}
|
134
|
+
return tor->blockCount % ( inf->pieceSize / tor->blockSize );
|
135
|
+
}
|
136
|
+
|
137
|
+
#define tr_pieceStartBlock(a) _tr_pieceStartBlock(tor,a)
|
138
|
+
static inline int _tr_pieceStartBlock( tr_torrent_t * tor, int piece )
|
139
|
+
{
|
140
|
+
tr_info_t * inf = &tor->info;
|
141
|
+
return piece * ( inf->pieceSize / tor->blockSize );
|
142
|
+
}
|
143
|
+
|
144
|
+
#define tr_pieceSize(a) _tr_pieceSize(tor,a)
|
145
|
+
static inline int _tr_pieceSize( tr_torrent_t * tor, int piece )
|
146
|
+
{
|
147
|
+
tr_info_t * inf = &tor->info;
|
148
|
+
if( piece < inf->pieceCount - 1 ||
|
149
|
+
!( inf->totalSize % inf->pieceSize ) )
|
150
|
+
{
|
151
|
+
return inf->pieceSize;
|
152
|
+
}
|
153
|
+
return inf->totalSize % inf->pieceSize;
|
154
|
+
}
|
155
|
+
|
156
|
+
#define tr_block(a,b) _tr_block(tor,a,b)
|
157
|
+
static inline int _tr_block( tr_torrent_t * tor, int index, int begin )
|
158
|
+
{
|
159
|
+
tr_info_t * inf = &tor->info;
|
160
|
+
return index * ( inf->pieceSize / tor->blockSize ) +
|
161
|
+
begin / tor->blockSize;
|
162
|
+
}
|
163
|
+
|
164
|
+
#endif
|
data/lib/transmission.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "transmission.so"
|
2
|
+
|
3
|
+
class Transmission
|
4
|
+
#
|
5
|
+
# Opens a torrent file at 'path' just as in Transmission#open, but creates
|
6
|
+
# an internal copy of it. Later you can open this torrent with Transmission#open_saved
|
7
|
+
# by passing it Torrent#hash_string value.
|
8
|
+
#
|
9
|
+
def copy(path)
|
10
|
+
open(path, true)
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# Opens a previously saved torrent by its hash string.
|
15
|
+
#
|
16
|
+
def open_saved(hash)
|
17
|
+
open(hash, false, true)
|
18
|
+
end
|
19
|
+
|
20
|
+
class Torrent
|
21
|
+
def to_s
|
22
|
+
format = "Torrent: %s\nHash: %s\nStatus: %s"
|
23
|
+
format % [name, hash_string, stat.status_name, ]
|
24
|
+
end
|
25
|
+
|
26
|
+
class Stat
|
27
|
+
def status_name
|
28
|
+
case status
|
29
|
+
when STATUS_CHECK
|
30
|
+
"Checking"
|
31
|
+
when STATUS_DOWNLOAD
|
32
|
+
"Downloading"
|
33
|
+
when STATUS_SEED
|
34
|
+
"Seeding"
|
35
|
+
when STATUS_STOPPING
|
36
|
+
"Stopping"
|
37
|
+
when STATUS_STOPPED
|
38
|
+
"Stopped"
|
39
|
+
when STATUS_PAUSE
|
40
|
+
"Paused"
|
41
|
+
else
|
42
|
+
"Unknown"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def error_name
|
47
|
+
case error
|
48
|
+
when ERR_TRACKER
|
49
|
+
"Tracker: #{tracker_error}"
|
50
|
+
when ERR_INOUT
|
51
|
+
"Input/Output"
|
52
|
+
else
|
53
|
+
"Unknown"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
format =<<-EOS
|
59
|
+
Status: %s, Error: %d
|
60
|
+
Progress: %.1f, Rate: Down/Up %.1fKb/%.1fKb, ETA: %d
|
61
|
+
Peers Total: %d, Downloading: %d, Uploading: %d
|
62
|
+
Seeders: %d, Leechers: %d\nDownloaded: %d, Uploaded: %d
|
63
|
+
EOS
|
64
|
+
format % [status_name, error, progress, rates, eta, peers_total,
|
65
|
+
peers, seeders, leechers, downloaded, uploaded].flatten
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class FileInfo
|
70
|
+
def to_s
|
71
|
+
"FileInfo{name: %s, size: %d}" % [name, size]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transmission
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Nuxoll
|
8
|
+
- Kent Sibilev
|
9
|
+
autorequire: transmission
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-06 00:00:00 -06:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Ruby bindings for libtransmission
|
18
|
+
email: stefan@nuxoll.eu.org
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions:
|
22
|
+
- ext/extconf.rb
|
23
|
+
extra_rdoc_files:
|
24
|
+
- LICENSE
|
25
|
+
- README
|
26
|
+
files:
|
27
|
+
- CHANGELOG
|
28
|
+
- LICENSE
|
29
|
+
- README
|
30
|
+
- Rakefile
|
31
|
+
- ext/bencode.c
|
32
|
+
- ext/bencode.h
|
33
|
+
- ext/choking.c
|
34
|
+
- ext/choking.h
|
35
|
+
- ext/clients.c
|
36
|
+
- ext/clients.h
|
37
|
+
- ext/completion.c
|
38
|
+
- ext/completion.h
|
39
|
+
- ext/extconf.rb
|
40
|
+
- ext/fastresume.h
|
41
|
+
- ext/fdlimit.c
|
42
|
+
- ext/fdlimit.h
|
43
|
+
- ext/inout.c
|
44
|
+
- ext/inout.h
|
45
|
+
- ext/internal.h
|
46
|
+
- ext/metainfo.c
|
47
|
+
- ext/metainfo.h
|
48
|
+
- ext/net.c
|
49
|
+
- ext/net.h
|
50
|
+
- ext/peer.c
|
51
|
+
- ext/peer.h
|
52
|
+
- ext/peermessages.h
|
53
|
+
- ext/peerparse.h
|
54
|
+
- ext/peerutils.h
|
55
|
+
- ext/platform.c
|
56
|
+
- ext/platform.h
|
57
|
+
- ext/r_transmission.c
|
58
|
+
- ext/ratecontrol.c
|
59
|
+
- ext/ratecontrol.h
|
60
|
+
- ext/sha1.c
|
61
|
+
- ext/sha1.h
|
62
|
+
- ext/tracker.c
|
63
|
+
- ext/tracker.h
|
64
|
+
- ext/transmission.c
|
65
|
+
- ext/transmission.h
|
66
|
+
- ext/utils.c
|
67
|
+
- ext/utils.h
|
68
|
+
- lib/transmission.rb
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://github.com/snuxoll/ruby-transmission
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --charset=UTF-8
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Ruby bindings for libtransmission
|
97
|
+
test_files: []
|
98
|
+
|