r_proxy 0.2.3 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f0065ab65442af3554629362b7ba10f12e247a4b81c53ededc545c381b4d5e8
4
- data.tar.gz: 3882a0ec3c594581970a7db9cca5a79056563bc2d64dfa7bed91495724c903eb
3
+ metadata.gz: 50837a373486d272c73b9ed6db87ad8b493ddb8e1f8414cbeefc57fb48fe70fd
4
+ data.tar.gz: 871267b24a049f223e3685445744472cd0f4b1d34d907f080a0e0d7ae00abc1f
5
5
  SHA512:
6
- metadata.gz: 0a53bd67b6d97a735a0cfc4d1a3b836f54ec6aa41301b5d450905f09612b0374dd52ea29e173873048fa1242439fa7025c1a60c89e25eab6d7231d7e6ad1846a
7
- data.tar.gz: 867cd29058afb86b28aa7d45d9e30c1f6d2b5f5c16c806464de9e3388f30048bc6008943331f7c0cd87ac4b89d855a7f5a0b9014e7e56497cd34e360943e0d5d
6
+ metadata.gz: 3988856e3fd0aebf0cab190d8a56130db797d41f06b280fa880be8b083546223ace4d729c5e53bc1b125bf0bc614253bed106e55ef0f92a4c05a3d6d882a8e50
7
+ data.tar.gz: b6b1170d829f7167fafd6fceb72e125cb032aaf667a7e7cea3bd3cf03dbd0ab79b984b8d982c58b606c65eec21681d9b353ec985561749babfd8a4cb11641a96
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- r_proxy (0.2.3)
4
+ r_proxy (0.2.4)
5
5
  eventmachine (~> 1.2, >= 1.2.7)
6
6
  redis (~> 4.1, >= 4.1.4)
7
7
 
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- ##### Currently only support `BSD` and `MacOS`
24
+ ##### Currently only support `BSD`, `Linux` and `MacOS`
25
25
 
26
26
  Http and Https proxy server
27
27
 
@@ -14,21 +14,24 @@ module RProxy
14
14
  @logger = logger
15
15
  end
16
16
 
17
- def connection_completed
17
+ def post_init
18
18
  start_tls if @need_tls
19
19
  set_comm_inactivity_timeout(20)
20
+ end
21
+
22
+ def ssl_handshake_completed
20
23
  send_data(@http_request)
21
24
  end
22
25
 
26
+ def connection_completed
27
+ send_data(@http_request) if !@need_tls
28
+ end
29
+
23
30
  def receive_data(data)
24
31
  @response = data.split("\r\n")[0]
25
32
  close_connection
26
33
  end
27
34
 
28
- def ssl_handshake_completed
29
- send_data(@http_request)
30
- end
31
-
32
35
  def unbind
33
36
  @logger.info("#{@uri.host}#{@path} response status: #{@response}") if @logger
34
37
  end
@@ -4,7 +4,6 @@ module RProxy
4
4
  return if url.nil? || url.empty?
5
5
  uri = URI(url)
6
6
  tls = uri.scheme == 'https'
7
-
8
7
  EventMachine.connect(
9
8
  uri.host,
10
9
  uri.port,
@@ -14,7 +14,6 @@ module RProxy
14
14
  @cache_pool = cache_pool
15
15
  @usage_manager = RProxy::UsageManager.new(config, @cache_pool, @redis)
16
16
  @http_parser = HttpProxyParser.new(@usage_manager)
17
- @snapshot_service = RProxy::CheckSnapshotService.new(@redis, @config)
18
17
  @enable_force_quit = config.enable_force_quit
19
18
  end
20
19
 
@@ -59,9 +58,6 @@ module RProxy
59
58
  @username = @http_parser.username
60
59
  @password = @http_parser.password
61
60
  @target_connection.assign_user_and_password(@username, @password)
62
-
63
- # check snapshot
64
- @snapshot_service.call(@username, @password, remain)
65
61
  end
66
62
  rescue RProxy::HTTPAuthFailed
67
63
  send_data(RProxy::Constants::HTTP_FAILED_AUTH)
@@ -39,7 +39,7 @@ module RProxy
39
39
  next unless pid
40
40
  Process.kill("TERM", pid)
41
41
  end
42
- @watchers.each { |t| t.join }
42
+ sleep(1)
43
43
  @logger.info('all process exited....') if @logger
44
44
  end
45
45
 
@@ -5,12 +5,11 @@ module RProxy
5
5
  @cache_pool = cache_pool
6
6
  @redis = redis
7
7
  @no_cache_below = config.no_cache_below
8
+ @check_snapshot_service = RProxy::CheckSnapshotService.new(@redis, config)
8
9
  end
9
10
 
10
11
  def auth_user(user, pass)
11
- key = proxy_key(user, pass)
12
-
13
- value = fetch_usage(key)
12
+ value = fetch_usage(user, pass)
14
13
 
15
14
  return value if !value.nil? && value.to_i > 0
16
15
  nil
@@ -32,15 +31,23 @@ module RProxy
32
31
 
33
32
  private
34
33
 
35
- def fetch_usage(key)
36
- return @redis.get(key) if !@enable_cache || !@cache_pool.writable?
34
+ def fetch_usage(user, pass)
35
+ key = proxy_key(user, pass)
36
+ if !@enable_cache || !@cache_pool.writable?
37
+ value = @redis.get(key)
38
+ @check_snapshot_service.call(user, pass, value)
39
+ end
37
40
 
38
41
  cache = @cache_pool[key]
39
42
 
40
43
  if cache.nil?
44
+
41
45
  value = @redis.get(key)
42
46
 
43
- return value if !value.nil? && value.to_i <= @no_cache_below
47
+ if !value.nil?
48
+ @check_snapshot_service.call(user, pass, value)
49
+ return value if value.to_i <= @no_cache_below
50
+ end
44
51
 
45
52
  @cache_pool[key] = {
46
53
  usage: value,
@@ -1,3 +1,3 @@
1
1
  module RProxy
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick An
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-09 00:00:00.000000000 Z
11
+ date: 2020-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine