dcase 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d798b7687187ae48822a7697be6f6481ec5147d
4
- data.tar.gz: a216c5043444fa4cd375af0f16a1724d76eade1e
3
+ metadata.gz: 1fec588b807e7fbd5220c48f3f742dcbe9bddaa5
4
+ data.tar.gz: 4d34376f2ff60eb1e2340b11e9f3d7b1790d0e41
5
5
  SHA512:
6
- metadata.gz: 75fb759cf33a02d4bf5a13b11a003d75b0462b4b212f4bab0bd757e3222002519dd9e5c3ded0a72f889f77577bac5d1b17c98dde02ee1ea0bc95cfc0d916cb16
7
- data.tar.gz: e5950388fe64ac83e88a81d00168a42e64cc251b9541d6c5e6c07a416c3e1a777812e9bee040489fef37cd1fa92598144cfab2076abcd2044d1ce4ba15f369e6
6
+ metadata.gz: 20eabd04c3ef770cb5f15668a60812efdaf55f3f2bbb311ad4ecfe577497f024eb7ff0c9dcae805ef0731f654d0d726623c8ff79c4f9d3cc449f172795021a86
7
+ data.tar.gz: 7e1cd1a5eb774599e69be9c588b4577d63e3fc1616d8bb528fef8a13226c61c2ee0de344b58280b07a30f1bd5eda579e6a0694af602442f12774ceb2a375c709
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  DCase
2
2
  =====
3
3
 
4
- Current version: 0.2
4
+ Current version: 0.3
5
5
 
6
6
  DCase is a lightweight dns proxy which can help you get through firewalls.
7
7
 
@@ -22,8 +22,10 @@ Create a file named `config.yml`, with the following content.
22
22
  side: 'local or server'
23
23
  password: 'your password'
24
24
  port: '8440'
25
- # you don't need this line when it's on server side
26
25
  server: 'remote server address'
26
+ dns_list:
27
+ - '8.8.8.8'
28
+ - '8.8.4.4'
27
29
 
28
30
  Explanation of the fields:
29
31
 
@@ -31,7 +33,8 @@ Explanation of the fields:
31
33
  server Remote server address
32
34
  port Remote server port
33
35
  password Password, should be same in client and server sides
34
-
36
+ dns_list A dns server will pick on server side
37
+
35
38
  `cd` into the directory of `config.yml`. Run `dcase` on your server. To run it in the background, run
36
39
  `nohup dcase -c ./config.yml > log &`.
37
40
 
@@ -43,7 +46,7 @@ Command line args
43
46
  You can use args to override settings from `config.json`.
44
47
 
45
48
  sudo dcase -s local -r remote_server_ip_address -p remote_server_port -k your_password
46
- sudo dcase -s server -p remote_server_port -k your_password
49
+ sudo dcase -s server -p remote_server_port -k your_password -l 8.8.8.8,8.8.4.4
47
50
 
48
51
  License
49
52
  -------
data/Rakefile CHANGED
@@ -5,8 +5,9 @@ require 'rake/testtask'
5
5
  # Load custom tasks
6
6
  Dir['tasks/*.rake'].sort.each { |f| load f }
7
7
 
8
- Rake::TestTask.new do |task|
9
- task.libs << 'test'
8
+ Rake::TestTask.new do |t|
9
+ t.libs << 'test'
10
+ t.pattern = "test/**/*_test.rb"
10
11
  end
11
12
 
12
13
  task :default => :test
data/config.yml CHANGED
@@ -1,3 +1,6 @@
1
1
  password: 'your password'
2
2
  port: '8440'
3
3
  server: '127.0.0.1'
4
+ dns_list:
5
+ - '8.8.8.8'
6
+ - '8.8.4.4'
@@ -12,8 +12,8 @@ module DCase
12
12
  puts "*** Local side is up, remote server port:#{@config.port}"
13
13
  DCase::Local.supervise('0.0.0.0', 53, @crypto, @config)
14
14
  when 'server'
15
- puts "*** Server side is up, port:#{@config.port}"
16
- DCase::Server.supervise('0.0.0.0', @config.port, @crypto)
15
+ puts "*** Server side is up, port:#{@config.port}, with dns list: #{@config.dns_list.join(', ')}"
16
+ DCase::Server.supervise('0.0.0.0', @crypto, @config)
17
17
  end
18
18
 
19
19
  puts "*** Hit Ctrl+c to stop"
@@ -5,10 +5,10 @@ require File.expand_path('../version', __FILE__)
5
5
 
6
6
  module DCase
7
7
  class Config
8
- attr_accessor :args, :side, :server, :port, :password, :config_path
8
+ attr_accessor :args, :side, :server, :port, :password, :dns_list, :config_path
9
9
 
10
- def initialize(args)
11
- @args = args || []
10
+ def initialize(args = [])
11
+ @args = args
12
12
 
13
13
  parse_args
14
14
  read_config
@@ -44,6 +44,7 @@ module DCase
44
44
  @server = config["server"] if @server.nil?
45
45
  @port = config["port"].to_i if @port.nil?
46
46
  @password = config["password"] if @password.nil?
47
+ @dns_list = config["dns_list"] if @dns_list.nil?
47
48
  end
48
49
 
49
50
  def parse_args
@@ -73,6 +74,10 @@ module DCase
73
74
  @password = c
74
75
  end
75
76
 
77
+ opts.on("-l", "--dns-list LIST", "Password, should be same in client and server sides") do |c|
78
+ @dns_list = c.split(',').map(&:strip)
79
+ end
80
+
76
81
  opts.on_tail("-v", "--version", "Show shadowsocks gem version") do
77
82
  puts DCase::VERSION
78
83
  exit
@@ -8,6 +8,7 @@ module DCase
8
8
 
9
9
  def initialize(addr, port, crypto, config)
10
10
  @socket = UDPSocket.new
11
+ @socket.to_io.setsockopt(:SOCKET, :REUSEADDR, 1)
11
12
  @socket.bind(addr, port)
12
13
  @crypto = crypto
13
14
  @config = config
@@ -5,9 +5,12 @@ module DCase
5
5
 
6
6
  attr_accessor :crypto
7
7
 
8
- def initialize(host, port, crypto)
8
+ def initialize(host, crypto, config)
9
+ @config = config
10
+
9
11
  @server = UDPSocket.new
10
- @server.bind(host, port)
12
+ @server.to_io.setsockopt(:SOCKET, :REUSEADDR, 1)
13
+ @server.bind(host, @config.port)
11
14
 
12
15
  @crypto = crypto
13
16
 
@@ -27,7 +30,7 @@ module DCase
27
30
 
28
31
  def handle_data(data, port, addr)
29
32
  request = UDPSocket.new
30
- request.send crypto.decrypt(data), 0, '8.8.8.8', 53
33
+ request.send crypto.decrypt(data), 0, @config.dns_list.sample, 53
31
34
 
32
35
  async.start_connect(request, port, addr)
33
36
  end
@@ -1,3 +1,3 @@
1
1
  module DCase
2
- VERSION = '0.2'
2
+ VERSION = '0.3'
3
3
  end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+ require_relative '../../lib/dcase/cli.rb'
3
+
4
+ class TestCli < TestCase
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+ require_relative '../../lib/dcase/config.rb'
3
+
4
+ class TestConfig < TestCase
5
+ def test_local_params
6
+ config = DCase::Config.new ['-s', 'local']
7
+
8
+ assert_equal config.password, 'your password'
9
+ assert_equal config.server, '127.0.0.1'
10
+ assert_equal config.port, 8440
11
+ assert_equal config.dns_list, ['8.8.8.8', '8.8.4.4']
12
+ end
13
+
14
+ def test_server_params
15
+ config = DCase::Config.new ['-s', 'server']
16
+
17
+ assert_equal config.password, 'your password'
18
+ assert_equal config.server, '127.0.0.1'
19
+ assert_equal config.port, 8440
20
+ assert_equal config.dns_list, ['8.8.8.8', '8.8.4.4']
21
+ end
22
+
23
+ def test_local_with_command
24
+ config = DCase::Config.new ['-s', 'local', '-k', 'your password', '-r', '127.0.0.1', '-p', '8440']
25
+ assert_equal config.password, 'your password'
26
+ assert_equal config.server, '127.0.0.1'
27
+ assert_equal config.port, 8440
28
+ end
29
+
30
+ def test_server_with_command
31
+ config = DCase::Config.new ['-s', 'server', '-k', 'your password', '-r', '127.0.0.1', '-p', '8440', '-l', '8.8.8.8,8.8.4.4']
32
+ assert_equal config.password, 'your password'
33
+ assert_equal config.server, '127.0.0.1'
34
+ assert_equal config.port, 8440
35
+ assert_equal config.dns_list, ['8.8.8.8', '8.8.4.4']
36
+ end
37
+
38
+ def test_blank_side
39
+ e = assert_raises(RuntimeError) { DCase::Config.new }
40
+ assert_equal 'You need to define side of dcase in', e.message
41
+ end
42
+ end
@@ -1,3 +1,8 @@
1
1
  require "bundler/setup"
2
2
  require "minitest/autorun"
3
3
  require "mocha/setup"
4
+
5
+ Dir[File.expand_path('../support/**/*', __FILE__)].each &method(:require)
6
+
7
+ class TestCase < Minitest::Test
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcase
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
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-31 00:00:00.000000000 Z
11
+ date: 2014-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-io
@@ -108,6 +108,8 @@ files:
108
108
  - lib/dcase/version.rb
109
109
  - tasks/compile.rake
110
110
  - tasks/dev.rake
111
+ - test/dcase/cli_test.rb
112
+ - test/dcase/config_test.rb
111
113
  - test/test_helper.rb
112
114
  homepage: https://github.com/Sen/DCase
113
115
  licenses: