torckapi 0.0.22 → 0.0.23
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/lib/torckapi/tracker/udp.rb +18 -12
- data/lib/torckapi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0e78cdf84987163d2164e0eab58654e6c0825c6
|
4
|
+
data.tar.gz: 7516aecf37f02107ce58f5c193dfd1a9285f7289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c560a87c520bf0f0220fb8608e72cc0072455aeb7be1ed884d8bbb1bb285eb3e9e3f01a3d500e49ee31c99cdaeab6ed241acb6e8e035fbf9dcfe6cea265a0a6
|
7
|
+
data.tar.gz: 76931f6d709de866750b102a8097d7fbf2b30dbc098c419d4208cf83a10fd54dc411545cf080b8fcd371446a3653e783abd93ce333671eb180b025337a554e38
|
data/lib/torckapi/tracker/udp.rb
CHANGED
@@ -28,7 +28,7 @@ module Torckapi
|
|
28
28
|
connect
|
29
29
|
response = communicate action, data
|
30
30
|
|
31
|
-
RESPONSE_CLASSES[response[
|
31
|
+
RESPONSE_CLASSES[response[:type]].from_udp(*args, response[:data])
|
32
32
|
end
|
33
33
|
|
34
34
|
def announce_request_data info_hash, peer_id
|
@@ -42,39 +42,45 @@ module Torckapi
|
|
42
42
|
def connect
|
43
43
|
return if @connection_id && @communicated_at.to_i >= Time.now.to_i - CONNECTION_TIMEOUT
|
44
44
|
|
45
|
-
@connection_id = [
|
45
|
+
@connection_id = [0x041727101980].pack('Q>')
|
46
46
|
response = communicate Connect
|
47
|
-
@connection_id = response[
|
47
|
+
@connection_id = response[:data]
|
48
48
|
end
|
49
49
|
|
50
50
|
def communicate action, data=nil
|
51
51
|
@socket ||= UDPSocket.new
|
52
52
|
|
53
53
|
transaction_id = SecureRandom.random_bytes(4)
|
54
|
-
packet = [@connection_id, [action].pack('L>'), transaction_id, data].join
|
55
|
-
|
56
54
|
tries = 0
|
57
55
|
response = nil
|
58
56
|
|
59
57
|
begin
|
58
|
+
packet = [@connection_id, [action].pack('L>'), transaction_id, data].join
|
59
|
+
|
60
60
|
Timeout::timeout(@options[:timeout], CommunicationTimeoutError) do
|
61
61
|
@socket.send(packet, 0, @url.host, @url.port)
|
62
|
-
response = @socket.recvfrom(65536)
|
63
|
-
raise TransactionIdMismatchError if transaction_id != response[0][4..7]
|
64
|
-
|
65
|
-
response_type = response[0][0..3].unpack('L>')[0]
|
66
|
-
raise(MalformedResponseError, response) if !(0...RESPONSE_CLASSES.length).include?(response_type) ||
|
67
|
-
RESPONSE_MIN_LENGTHS[response_type] > response[0].length
|
62
|
+
response = parse_response @socket.recvfrom(65536), transaction_id
|
68
63
|
@communicated_at = Time.now
|
69
64
|
end
|
70
65
|
rescue CommunicationTimeoutError
|
71
66
|
retry if (tries += 1) <= @options[:tries]
|
72
67
|
end
|
73
68
|
|
74
|
-
raise CommunicationFailedError
|
69
|
+
raise CommunicationFailedError unless response
|
75
70
|
|
76
71
|
response
|
77
72
|
end
|
73
|
+
|
74
|
+
def parse_response data, transaction_id
|
75
|
+
response, sender_addrinfo = data
|
76
|
+
|
77
|
+
response_type = response[0..3].unpack('L>')[0]
|
78
|
+
|
79
|
+
raise TransactionIdMismatchError, response.inspect if transaction_id != response[4..7]
|
80
|
+
raise MalformedResponseError, response.inspect if RESPONSE_MIN_LENGTHS[response_type] > response.length
|
81
|
+
|
82
|
+
{type: response_type, data: response[8..-1]}
|
83
|
+
end
|
78
84
|
end
|
79
85
|
end
|
80
86
|
end
|
data/lib/torckapi/version.rb
CHANGED