File: fix_fetching_ascii_codes_from_chars.patch

package info (click to toggle)
ruby-rubytorrent 0.3-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 380 kB
  • ctags: 491
  • sloc: ruby: 2,751; makefile: 2
file content (96 lines) | stat: -rw-r--r-- 3,152 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Description: Extract ASCII code of characters in way understandable for Ruby1.9
 Using chr and ord method to pass from integers to the corresponding characters and vice versa
Author: Cédric Boutillier <cedric.boutillier@gmail.com>
Forwarded: http://rubyforge.org/pipermail/rubytorrent-devel/2012-May/000051.html
Origin: vendor
Last-Update: 2012-05-23
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/lib/rubytorrent/tracker.rb
+++ b/lib/rubytorrent/tracker.rb
@@ -90,8 +90,8 @@
       x.map { |e| TrackerResponsePeer.new e }.extend(ArrayUniq2).uniq2
     when String
       x.unpack("a6" * (x.length / 6)).map do |y|
-        TrackerResponsePeer.new({"ip" => (0..3).map { |i| y[i] }.join('.'),
-                                 "port" => (y[4] << 8) + y[5] })
+        TrackerResponsePeer.new({"ip" => (0..3).map { |i| y[i].ord }.join('.'),
+                                 "port" => (y[4].ord << 8) + y[5].ord })
       end.extend(ArrayUniq2).uniq2
     else
       raise "don't know how to make peers array from #{x.class}"
--- a/lib/rubytorrent/server.rb
+++ b/lib/rubytorrent/server.rb
@@ -133,7 +133,7 @@
 
     len = sock.recv(1)[0]
 #    rt_debug "length #{len.inspect}"
-    raise ProtocolError, "invalid handshake length byte #{len.inspect}" unless len == 19
+    raise ProtocolError, "invalid handshake length byte #{len.inspect}" unless (not len.nil? and len.ord == 19)
 
     name = sock.recv(19)
 #    rt_debug "name #{name.inspect}"
--- a/lib/rubytorrent/message.rb
+++ b/lib/rubytorrent/message.rb
@@ -17,7 +17,7 @@
 class String
   def from_fbbe # four-byte big-endian integer
     raise "fbbe must be four-byte string (got #{self.inspect})" unless length == 4
-    (self[0] << 24) + (self[1] << 16) + (self[2] << 8) + self[3]
+    (self[0].ord << 24) + (self[1].ord << 16) + (self[2].ord << 8) + self[3].ord
   end
 end
 
@@ -25,11 +25,16 @@
   def to_fbbe # four-byte big-endian integer
     raise "fbbe must be < 2^32" unless self <= 2**32
     raise "fbbe must be >= 0" unless self >= 0
-    s = "    "
-    s[0] = (self >> 24) % 256
-    s[1] = (self >> 16) % 256
-    s[2] = (self >>  8) % 256
-    s[3] = (self      ) % 256
+#    s = "    "
+#    s[0] = (self >> 24) % 256
+#    s[1] = (self >> 16) % 256
+#    s[2] = (self >>  8) % 256
+#    s[3] = (self      ) % 256
+    s = ""
+    s << (self >> 24) % 256
+    s << (self >> 16) % 256
+    s << (self >>  8) % 256
+    s << (self      ) % 256
     s
   end
 end
--- a/lib/rubytorrent/peer.rb
+++ b/lib/rubytorrent/peer.rb
@@ -26,7 +26,7 @@
         ret += "\0"
         bit = 7
       end
-      ret[ret.length - 1] |= (1 << bit) if b
+      ret[-1] = (ret[-1].ord || (1 << bit)).chr if b
       bit -= 1
     end
     ret
@@ -367,7 +367,7 @@
 #      rt_debug "* hey, a keepalive!"
     end
 
-    id = recv_bytes(1)[0]
+    id = recv_bytes(1)[0].ord
 
     if Message::WIRE_IDS[id] == :piece # add a block
       len -= 9
--- a/rtpeer-ncurses.rb
+++ b/rtpeer-ncurses.rb
@@ -237,7 +237,7 @@
 
 def handle_any_input(display)
   case(Ncurses.getch())
-  when ?q, ?Q
+  when "q".ord, "Q".ord
     Ncurses.curs_set(1)
     Ncurses.endwin()
     exit