shadowsocks 0.10 → 0.11

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
  SHA1:
3
- metadata.gz: c05c7982253d7dca12efaf7d099f833cb023ecb7
4
- data.tar.gz: 88c4af0e02523a3a84c3c7abdb87eff37b8797c6
3
+ metadata.gz: 13cd39701958e9cbe3c1aa72e2f4037becf509d6
4
+ data.tar.gz: f1d90a849085aec7408ce5f09e0e2f8e8a2cd350
5
5
  SHA512:
6
- metadata.gz: c6863718700fd2284d59bc189b24b83d2c7658f4fe6cb81bc2e69b4b7a4c44f0f6f27a84a148c43b41364db93164379bd9200409d17928349e05637b7276e08d
7
- data.tar.gz: 41ead82ef4f94379f39ac1a362e04d5dca166e684295224ad498a8fae859254fd6864578f8a9c412563098d80f69ea94126f1754e4eddc22e3e848b59bf185ab
6
+ metadata.gz: 688d4af6514d67b927edfcac45958619d844c07ad48473a7174ac84c34bf9625ffbe26ad0151a7a6e6c6625c683d58c4f8050d99cf64713614a6f53209d64122
7
+ data.tar.gz: 54a763dc6a4078a4fdff3b2bb4735139795b03e9f1cb9635e46110d32846125d9c2fb311dec77c2632be518a14595c1fe4eabea7fb2f4023aa80a299208a608a
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  shadowsocks-ruby
2
2
  ================
3
3
 
4
- [![Code Climate](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/badges/9dd6c11b6a17c3a55631/gpa.png)](https://codeclimate.com/repos/524baea6c7f3a37df208dd4c/feed)
5
-
6
- Current version: 0.7
4
+ Current version: 0.11
7
5
 
8
6
  shadowsocks-ruby is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks).
9
7
 
@@ -59,7 +57,7 @@ Command line args
59
57
 
60
58
  You can use args to override settings from `config.json`.
61
59
 
62
- ss-local -s server_name -p server_port -l local_port -k password
60
+ ss-local -s server_name -p server_port -l local_port -k password -m aes-128-cfb -d true
63
61
  ss-server -p server_port -k password
64
62
  ss-server -c /etc/shadowsocks/config.json
65
63
 
data/config.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
- "server":"127.0.0.1",
2
+ "server":"162.243.140.72",
3
3
  "server_port":8388,
4
4
  "local_port":1080,
5
- "password":"barfoo!",
5
+ "password":"marryrocks",
6
6
  "timeout":60,
7
7
  "method":"aes-128-cfb",
8
8
  "chnroutes":true
@@ -1,5 +1,6 @@
1
1
  require 'ipaddr'
2
2
  require 'socket'
3
+ require 'digest/md5'
3
4
 
4
5
  module Shadowsocks
5
6
  class IPDetector
@@ -8,6 +9,7 @@ module Shadowsocks
8
9
  def initialize
9
10
  @internals = {}
10
11
  @nums = []
12
+ @dns_cache = {}
11
13
  lines = File.readlines(GFW_LIST_PATH)
12
14
  lines.each do |line|
13
15
  num = IPAddr.new(line).to_i
@@ -18,13 +20,29 @@ module Shadowsocks
18
20
  end
19
21
 
20
22
  def behind_gfw?(domain)
21
- ip = IPSocket::getaddress(domain)
23
+ key = Digest::MD5.hexdigest domain
22
24
 
23
- ip_num = IPAddr.new(ip).to_i
25
+ if @dns_cache[key]
26
+ @dns_cache[key]
27
+ else
28
+ begin
29
+ ip = IPSocket::getaddress(domain)
24
30
 
25
- i = @nums.bsearch { |x| x > ip_num }
26
- index = @nums.index(i) - 1
27
- IPAddr.new(@internals[@nums[index].to_s]).include? ip
31
+ ip_num = IPAddr.new(ip).to_i
32
+
33
+ i = @nums.bsearch { |x| x > ip_num }
34
+ index = @nums.index(i) - 1
35
+ r = IPAddr.new(@internals[@nums[index].to_s]).include? ip
36
+ if @dns_cache.size > 512
37
+ @dns_cache.delete @dns_cache.first[0]
38
+ end
39
+
40
+ @dns_cache[key] = r
41
+ r
42
+ rescue Exception
43
+ false
44
+ end
45
+ end
28
46
  end
29
47
  end
30
48
  end
@@ -71,19 +71,32 @@ module Shadowsocks
71
71
 
72
72
  @stage = 4
73
73
 
74
- if config.chnroutes
75
- @behind_gfw = @ip_detector.behind_gfw?(@remote_addr[3..-1])
76
- end
74
+ op = proc {
75
+ if config.chnroutes
76
+ @behind_gfw = @ip_detector.behind_gfw?(@remote_addr[3..-1])
77
+ else
78
+ false
79
+ end
80
+ }
81
+
82
+ callback = proc { |result|
83
+ begin
84
+ if !(config.chnroutes and result)
85
+ raise 'will use remote server'
86
+ end
87
+ @connector = EM.connect @remote_addr[3..-1], @remote_port, \
88
+ DirectConnector, self, crypto
89
+ rescue Exception
90
+ @connector = EM.connect config.server, config.server_port, \
91
+ ServerConnector, self, crypto
92
+ end
77
93
 
78
- if config.chnroutes == true and behind_gfw
79
- @connector = EventMachine.connect @remote_addr[3..-1], @remote_port, DirectConnector, self, crypto
80
- else
81
- @connector = EventMachine.connect config.server, config.server_port, ServerConnector, self, crypto
82
- end
94
+ if data.size > header_length
95
+ cached_pieces.push data[header_length, data.size]
96
+ end
97
+ }
83
98
 
84
- if data.size > header_length
85
- cached_pieces.push data[header_length, data.size]
86
- end
99
+ EM.defer op, callback
87
100
  rescue Exception => e
88
101
  warn e
89
102
  connection_cleanup
@@ -1,3 +1,3 @@
1
1
  module Shadowsocks
2
- VERSION = '0.10'
2
+ VERSION = '0.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shadowsocks
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.10'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine