fizx-proxymachine 1.6.1 → 1.7.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/fizx-proxymachine.gemspec +4 -4
- data/lib/proxymachine.rb +15 -0
- data/lib/proxymachine/callback_server_connection.rb +5 -5
- data/lib/proxymachine/client_connection.rb +11 -1
- data/test/configs/simple.rb +8 -3
- data/test/proxymachine_test.rb +33 -33
- metadata +36 -74
data/fizx-proxymachine.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'fizx-proxymachine'
|
16
|
-
s.version = '1.
|
16
|
+
s.version = '1.7.0'
|
17
17
|
s.date = '2011-05-07'
|
18
18
|
s.rubyforge_project = 'fizx-proxymachine'
|
19
19
|
|
@@ -48,10 +48,10 @@ Gem::Specification.new do |s|
|
|
48
48
|
|
49
49
|
## List your development dependencies here. Development dependencies are
|
50
50
|
## those that are only needed during development
|
51
|
-
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
51
|
+
# s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
52
52
|
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
53
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
54
|
-
s.add_development_dependency("ruby-debug")
|
53
|
+
# s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
54
|
+
# s.add_development_dependency("ruby-debug")
|
55
55
|
|
56
56
|
## Leave this section as-is. It will be automatically generated from the
|
57
57
|
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
data/lib/proxymachine.rb
CHANGED
@@ -6,6 +6,7 @@ require 'socket'
|
|
6
6
|
|
7
7
|
require 'proxymachine/client_connection'
|
8
8
|
require 'proxymachine/server_connection'
|
9
|
+
require 'proxymachine/warning_server_connection'
|
9
10
|
require 'proxymachine/callback_server_connection'
|
10
11
|
|
11
12
|
$logger = Logger.new(STDOUT)
|
@@ -85,10 +86,18 @@ class ProxyMachine
|
|
85
86
|
def self.set_inactivity_error_callback(&block)
|
86
87
|
@@inactivity_error_callback = block
|
87
88
|
end
|
89
|
+
|
90
|
+
def self.set_inactivity_warning_callback(&block)
|
91
|
+
@@inactivity_warning_callback = block
|
92
|
+
end
|
88
93
|
|
89
94
|
def self.inactivity_error_callback
|
90
95
|
@@inactivity_error_callback
|
91
96
|
end
|
97
|
+
|
98
|
+
def self.inactivity_warning_callback
|
99
|
+
@@inactivity_warning_callback
|
100
|
+
end
|
92
101
|
|
93
102
|
def self.run(name, host, port)
|
94
103
|
@@totalcounter = 0
|
@@ -98,6 +107,7 @@ class ProxyMachine
|
|
98
107
|
@@listen = "#{host}:#{port}"
|
99
108
|
@@connect_error_callback ||= proc { |remote| }
|
100
109
|
@@inactivity_error_callback ||= proc { |remote| }
|
110
|
+
@@inactivity_warning_callback ||= proc { |remote| }
|
101
111
|
self.update_procline
|
102
112
|
EM.epoll
|
103
113
|
|
@@ -128,4 +138,9 @@ module Kernel
|
|
128
138
|
def proxy_inactivity_error(&block)
|
129
139
|
ProxyMachine.set_inactivity_error_callback(&block)
|
130
140
|
end
|
141
|
+
|
142
|
+
def proxy_inactivity_warning(&block)
|
143
|
+
ProxyMachine.set_inactivity_warning_callback(&block)
|
144
|
+
end
|
145
|
+
|
131
146
|
end
|
@@ -45,6 +45,8 @@ class ProxyMachine
|
|
45
45
|
try_connect
|
46
46
|
end
|
47
47
|
|
48
|
+
attr_reader :inactivity_warning_timeout, :inactivity_warning_callback
|
49
|
+
|
48
50
|
def try_connect
|
49
51
|
@commands = @routes.shift
|
50
52
|
$logger.info "#{peer} #{@commands.inspect}"
|
@@ -60,8 +62,10 @@ class ProxyMachine
|
|
60
62
|
end
|
61
63
|
@connect_timeout = @commands[:connect_timeout]
|
62
64
|
@inactivity_timeout = @commands[:inactivity_timeout]
|
65
|
+
@inactivity_warning_timeout = @commands[:inactivity_warning_timeout]
|
63
66
|
@connect_error_callback = @commands[:connect_error_callback]
|
64
67
|
@inactivity_error_callback = @commands[:inactivity_error_callback]
|
68
|
+
@inactivity_warning_callback = @commands[:inactivity_warning_callback]
|
65
69
|
connect_to_server
|
66
70
|
elsif close = @commands[:close]
|
67
71
|
if close == true
|
@@ -83,7 +87,7 @@ class ProxyMachine
|
|
83
87
|
host, port = @remote
|
84
88
|
$logger.info "Establishing new connection with #{host}:#{port}"
|
85
89
|
cb = @commands[:callback]
|
86
|
-
klass = cb ? CallbackServerConnection :
|
90
|
+
klass = cb ? CallbackServerConnection : WarningServerConnection
|
87
91
|
@server_side = klass.request(host, port, self)
|
88
92
|
@server_side.callback = cb if cb
|
89
93
|
@server_side.pending_connect_timeout = @connect_timeout
|
@@ -100,6 +104,12 @@ class ProxyMachine
|
|
100
104
|
@buffer = []
|
101
105
|
proxy_incoming_to(@server_side, 10240)
|
102
106
|
end
|
107
|
+
|
108
|
+
def inactivity_warning_triggered
|
109
|
+
proc {
|
110
|
+
(@inactivity_warning_callback || ProxyMachine.inactivity_warning_callback).call(@remote.join(':'))
|
111
|
+
}
|
112
|
+
end
|
103
113
|
|
104
114
|
# Called by the server side when a connection could not be established,
|
105
115
|
# either due to a hard connection failure or to a connection timeout.
|
data/test/configs/simple.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$logger = Logger.new(File.new('/
|
1
|
+
$logger = Logger.new(File.new('/tmp/proxymachine-server-test', 'w'))
|
2
2
|
|
3
3
|
callback = proc do |data|
|
4
4
|
data + ":callback"
|
@@ -24,18 +24,23 @@ proxy do |data|
|
|
24
24
|
elsif data == 'connect reject'
|
25
25
|
{ :remote => "localhost:9989" }
|
26
26
|
elsif data == 'inactivity'
|
27
|
-
{ :remote => "localhost:9980", :data => 'sleep 3', :inactivity_timeout => 1 }
|
27
|
+
{ :remote => "localhost:9980", :data => 'sleep 3', :inactivity_timeout => 1, :inactivity_warning_timeout => 0.5 }
|
28
28
|
else
|
29
29
|
{ :close => true }
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
ERROR_FILE =
|
33
|
+
ERROR_FILE = '/tmp/proxy_error'
|
34
|
+
WARN_FILE = '/tmp/proxy_warn'
|
34
35
|
|
35
36
|
proxy_connect_error do |remote|
|
36
37
|
File.open(ERROR_FILE, 'wb') { |fd| fd.write("connect error: #{remote}") }
|
37
38
|
end
|
38
39
|
|
40
|
+
proxy_inactivity_warning do |remote|
|
41
|
+
File.open(WARN_FILE, 'wb') { |fd| fd.write("activity warning: #{remote}") }
|
42
|
+
end
|
43
|
+
|
39
44
|
proxy_inactivity_error do |remote|
|
40
45
|
File.open(ERROR_FILE, 'wb') { |fd| fd.write("activity error: #{remote}") }
|
41
46
|
end
|
data/test/proxymachine_test.rb
CHANGED
@@ -9,10 +9,8 @@ end
|
|
9
9
|
|
10
10
|
class ProxymachineTest < Test::Unit::TestCase
|
11
11
|
def setup
|
12
|
-
@proxy_error_file =
|
13
|
-
|
14
|
-
# require "ruby-debug"
|
15
|
-
# debugger
|
12
|
+
@proxy_error_file = '/tmp/proxy_error'
|
13
|
+
@proxy_warn_file = '/tmp/proxy_warn'
|
16
14
|
end
|
17
15
|
|
18
16
|
def teardown
|
@@ -20,13 +18,11 @@ class ProxymachineTest < Test::Unit::TestCase
|
|
20
18
|
end
|
21
19
|
|
22
20
|
should "handle simple routing" do
|
23
|
-
puts "h"
|
24
21
|
assert_proxy('localhost', 9990, 'a', '9980:a')
|
25
22
|
assert_proxy('localhost', 9990, 'b', '9981:b')
|
26
23
|
end
|
27
24
|
|
28
25
|
should "handle connection closing" do
|
29
|
-
puts "hi1"
|
30
26
|
sock = TCPSocket.new('localhost', 9990)
|
31
27
|
sock.write('xxx')
|
32
28
|
assert_equal nil, sock.read(1)
|
@@ -34,22 +30,18 @@ class ProxymachineTest < Test::Unit::TestCase
|
|
34
30
|
end
|
35
31
|
|
36
32
|
should "handle rewrite routing" do
|
37
|
-
puts "hi2"
|
38
33
|
assert_proxy('localhost', 9990, 'c', '9980:ccc')
|
39
34
|
end
|
40
35
|
|
41
36
|
should "handle rewrite closing" do
|
42
|
-
|
43
|
-
assert_proxy('localhost', 9990, 'd', 'ddd')
|
37
|
+
assert_proxy('localhost', 9990, 'd', 'ddd')
|
44
38
|
end
|
45
39
|
|
46
40
|
should "handle data plus reply" do
|
47
|
-
puts "hi4"
|
48
41
|
assert_proxy('localhost', 9990, 'g', 'g3-9980:g2')
|
49
42
|
end
|
50
43
|
|
51
44
|
should "handle noop" do
|
52
|
-
puts "hi5"
|
53
45
|
sock = TCPSocket.new('localhost', 9990)
|
54
46
|
sock.write('e' * 2048)
|
55
47
|
sock.flush
|
@@ -59,34 +51,42 @@ class ProxymachineTest < Test::Unit::TestCase
|
|
59
51
|
end
|
60
52
|
|
61
53
|
should "execute a callback" do
|
62
|
-
puts "hi6"
|
63
54
|
assert_proxy('localhost', 9990, 'h', '9980:h:callback')
|
64
55
|
end
|
65
56
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# end
|
57
|
+
should "call proxy_connect_error when a connection is rejected" do
|
58
|
+
sock = TCPSocket.new('localhost', 9990)
|
59
|
+
sock.write('connect reject')
|
60
|
+
sock.flush
|
61
|
+
assert_equal "", sock.read
|
62
|
+
sock.close
|
63
|
+
assert_equal "connect error: localhost:9989", File.read(@proxy_error_file)
|
64
|
+
end
|
75
65
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
66
|
+
should "call proxy_inactivity_error when initial read times out" do
|
67
|
+
sock = TCPSocket.new('localhost', 9990)
|
68
|
+
sent = Time.now
|
69
|
+
sock.write('inactivity')
|
70
|
+
sock.flush
|
71
|
+
assert_equal "", sock.read
|
72
|
+
assert_operator Time.now - sent, :>=, 1.0
|
73
|
+
assert_equal "activity error: localhost:9980", File.read(@proxy_error_file)
|
74
|
+
sock.close
|
75
|
+
end
|
76
|
+
|
77
|
+
should "call proxy_inactivity_error when initial read times out" do
|
78
|
+
sock = TCPSocket.new('localhost', 9990)
|
79
|
+
sent = Time.now
|
80
|
+
sock.write('inactivity')
|
81
|
+
sock.flush
|
82
|
+
assert_equal "", sock.read
|
83
|
+
assert_operator Time.now - sent, :>=, 1.0
|
84
|
+
assert_equal "activity error: localhost:9980", File.read(@proxy_error_file)
|
85
|
+
assert_equal "activity warning: localhost:9980", File.read(@proxy_warn_file)
|
86
|
+
sock.close
|
87
|
+
end
|
87
88
|
|
88
89
|
should "not consider client disconnect a server error" do
|
89
|
-
puts "hi9"
|
90
90
|
sock = TCPSocket.new('localhost', 9990)
|
91
91
|
sock.write('inactivity')
|
92
92
|
sock.close
|
metadata
CHANGED
@@ -1,84 +1,49 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fizx-proxymachine
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.7.0
|
4
5
|
prerelease:
|
5
|
-
version: 1.6.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Tom Preston-Werner
|
9
9
|
- Kyle Maxwell
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
dependencies:
|
17
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2011-05-07 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
18
16
|
name: eventmachine
|
19
|
-
|
20
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &70266777049060 !ruby/object:Gem::Requirement
|
21
18
|
none: false
|
22
|
-
requirements:
|
23
|
-
- -
|
24
|
-
- !ruby/object:Gem::Version
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
25
22
|
version: 0.12.10
|
26
23
|
type: :runtime
|
27
|
-
version_requirements: *id001
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: rake
|
30
24
|
prerelease: false
|
31
|
-
|
32
|
-
|
33
|
-
requirements:
|
34
|
-
- - ~>
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.8.7
|
37
|
-
type: :development
|
38
|
-
version_requirements: *id002
|
39
|
-
- !ruby/object:Gem::Dependency
|
25
|
+
version_requirements: *70266777049060
|
26
|
+
- !ruby/object:Gem::Dependency
|
40
27
|
name: shoulda
|
41
|
-
|
42
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
28
|
+
requirement: &70266777047880 !ruby/object:Gem::Requirement
|
43
29
|
none: false
|
44
|
-
requirements:
|
30
|
+
requirements:
|
45
31
|
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
32
|
+
- !ruby/object:Gem::Version
|
47
33
|
version: 2.11.3
|
48
34
|
type: :development
|
49
|
-
version_requirements: *id003
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: jeweler
|
52
35
|
prerelease: false
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: 1.5.2
|
59
|
-
type: :development
|
60
|
-
version_requirements: *id004
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: ruby-debug
|
63
|
-
prerelease: false
|
64
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: "0"
|
70
|
-
type: :development
|
71
|
-
version_requirements: *id005
|
72
|
-
description: ProxyMachine is a simple content aware (layer 7) TCP routing proxy written in Ruby with EventMachine.
|
36
|
+
version_requirements: *70266777047880
|
37
|
+
description: ProxyMachine is a simple content aware (layer 7) TCP routing proxy written
|
38
|
+
in Ruby with EventMachine.
|
73
39
|
email: tom@mojombo.com
|
74
|
-
executables:
|
40
|
+
executables:
|
75
41
|
- proxymachine
|
76
42
|
extensions: []
|
77
|
-
|
78
|
-
extra_rdoc_files:
|
43
|
+
extra_rdoc_files:
|
79
44
|
- README.md
|
80
45
|
- LICENSE
|
81
|
-
files:
|
46
|
+
files:
|
82
47
|
- Gemfile
|
83
48
|
- History.txt
|
84
49
|
- LICENSE
|
@@ -97,33 +62,30 @@ files:
|
|
97
62
|
- test/configs/simple.rb
|
98
63
|
- test/proxymachine_test.rb
|
99
64
|
- test/test_helper.rb
|
100
|
-
has_rdoc: true
|
101
65
|
homepage: http://github.com/fizx/proxymachine
|
102
66
|
licenses: []
|
103
|
-
|
104
67
|
post_install_message:
|
105
|
-
rdoc_options:
|
68
|
+
rdoc_options:
|
106
69
|
- --charset=UTF-8
|
107
|
-
require_paths:
|
70
|
+
require_paths:
|
108
71
|
- lib
|
109
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
73
|
none: false
|
111
|
-
requirements:
|
112
|
-
- -
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
version:
|
115
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
79
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version:
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
121
84
|
requirements: []
|
122
|
-
|
123
85
|
rubyforge_project: fizx-proxymachine
|
124
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.8.10
|
125
87
|
signing_key:
|
126
88
|
specification_version: 2
|
127
89
|
summary: ProxyMachine is a simple content aware (layer 7) TCP routing proxy.
|
128
|
-
test_files:
|
90
|
+
test_files:
|
129
91
|
- test/proxymachine_test.rb
|