surro-gate 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/lib/surro-gate/proxy.rb +22 -19
- data/lib/surro-gate/version.rb +1 -1
- 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: a27ce2403acd4f16e3d9d0e67209773563b24e9d
|
4
|
+
data.tar.gz: d8eb8edee4f24b9b66c03cea8e0df9cb2f6542da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0801c6d8fa84ea67afab352c434fcbdcb56b0518ffe5886d372e371dc22ae35cc8de4571b23313ea18612d28c0d2f3e4889b4cee447573c1b8e64635a6ab8f0c'
|
7
|
+
data.tar.gz: 9b0324b3ca7638b9869285ea0993994fbabbf297f293eb0bd10b416fb37b4e2c77bc01ca75c7e9b92b7db8f042a906540ca5a94ecdbf237bcd0083ae1d55cd24
|
data/.travis.yml
CHANGED
data/lib/surro-gate/proxy.rb
CHANGED
@@ -13,7 +13,9 @@ module SurroGate
|
|
13
13
|
class Proxy
|
14
14
|
def initialize(logger)
|
15
15
|
@mutex = Mutex.new
|
16
|
-
@
|
16
|
+
@reader = NIO::Selector.new
|
17
|
+
@writer = NIO::Selector.new
|
18
|
+
@selectors = [@reader, @writer]
|
17
19
|
@log = logger || Logger.new(STDOUT)
|
18
20
|
end
|
19
21
|
|
@@ -51,14 +53,13 @@ module SurroGate
|
|
51
53
|
private
|
52
54
|
|
53
55
|
def proxy(left, right, block = nil)
|
54
|
-
#
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# Set up a proc for future transmissions
|
56
|
+
# Register the proxying in both directions
|
57
|
+
[[left, right], [right, left]].each do |rd, wr|
|
58
|
+
# Set up monitors for read/write separately
|
59
|
+
src = @reader.register(rd, :r)
|
60
|
+
dst = @writer.register(wr, :w)
|
61
|
+
|
62
|
+
# Set up handlers for the reader monitor
|
62
63
|
src.value = proc do
|
63
64
|
# Clean up the connection if one of the endpoints gets closed
|
64
65
|
cleanup(src.io, dst.io, &block) if src.io.closed? || dst.io.closed?
|
@@ -67,8 +68,7 @@ module SurroGate
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
|
-
|
71
|
-
thread_start unless @selector.empty?
|
71
|
+
thread_start unless @reader.empty? || @writer.empty?
|
72
72
|
end
|
73
73
|
|
74
74
|
def transmit(src, dst, block)
|
@@ -81,7 +81,7 @@ module SurroGate
|
|
81
81
|
def cleanup(*sockets)
|
82
82
|
# Deregister and close the sockets
|
83
83
|
sockets.each do |socket|
|
84
|
-
@selector.deregister(socket) if
|
84
|
+
@selectors.each { |selector| selector.deregister(socket) if selector.registered?(socket) }
|
85
85
|
socket.close unless socket.closed?
|
86
86
|
end
|
87
87
|
|
@@ -90,7 +90,7 @@ module SurroGate
|
|
90
90
|
yield if block_given?
|
91
91
|
|
92
92
|
# Make sure that the internal thread is stopped if no sockets remain
|
93
|
-
thread_stop if @
|
93
|
+
thread_stop if @reader.empty? && @writer.empty?
|
94
94
|
end
|
95
95
|
|
96
96
|
def thread_start
|
@@ -111,16 +111,19 @@ module SurroGate
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def reactor
|
114
|
-
# Atomically get an array of readable
|
115
|
-
monitors = @mutex.synchronize
|
114
|
+
# Atomically get an array of readable monitors while also polling for writables
|
115
|
+
monitors = @mutex.synchronize do
|
116
|
+
@writer.select(0.1)
|
117
|
+
@reader.select(0.1) || []
|
118
|
+
end
|
116
119
|
# Call each transmission proc and collect the results
|
117
|
-
|
118
|
-
# Sleep for a short time if there was no transmission
|
119
|
-
sleep(0.1) if callers.none? && monitors.any?
|
120
|
+
monitors.map { |m| m.value.call }
|
120
121
|
end
|
121
122
|
|
122
123
|
def includes?(*sockets)
|
123
|
-
sockets.
|
124
|
+
sockets.any? do |socket|
|
125
|
+
@selectors.any? { |selector| selector.registered?(socket) }
|
126
|
+
end
|
124
127
|
end
|
125
128
|
end
|
126
129
|
end
|
data/lib/surro-gate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surro-gate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dávid Halász
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|