throttle 0.0.1 → 0.0.2
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/.rbenv-version +1 -0
- data/README.md +9 -2
- data/Rakefile +9 -0
- data/bin/throttle +0 -0
- data/lib/throttle/bandwidth.rb +21 -3
- data/lib/throttle/version.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/throttle/bandwidth_spec.rb +26 -0
- data/spec/throttle/client_spec.rb +39 -0
- data/spec/throttle/ipfw_spec.rb +17 -0
- data/spec/throttle/pipe_spec.rb +43 -0
- data/spec/throttle_spec.rb +11 -0
- data/throttle.gemspec +3 -2
- metadata +96 -22
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.8.7-p352
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ At the moment the code is REAAAAAAL ugly and needs much improvement. There are a
|
|
12
12
|
### Prerequisites
|
13
13
|
|
14
14
|
* Mac OSX 10.5, 10.6, 10.7
|
15
|
-
* ruby 1.8.7
|
15
|
+
* ruby >= 1.8.7
|
16
16
|
* rubygems
|
17
17
|
|
18
18
|
### Installation
|
@@ -27,8 +27,9 @@ From the command line:
|
|
27
27
|
#### Start throttling
|
28
28
|
|
29
29
|
Limit traffic to 100 Kilobits per second
|
30
|
+
|
30
31
|
```
|
31
|
-
throttle limit
|
32
|
+
throttle limit 100Kbps
|
32
33
|
```
|
33
34
|
|
34
35
|
#### Current Status
|
@@ -39,6 +40,12 @@ List all current limits in place.
|
|
39
40
|
throttle status
|
40
41
|
```
|
41
42
|
|
43
|
+
#### Remove all limits
|
44
|
+
|
45
|
+
```
|
46
|
+
throttle reset
|
47
|
+
```
|
48
|
+
|
42
49
|
|
43
50
|
#### Bandwidth
|
44
51
|
|
data/Rakefile
CHANGED
data/bin/throttle
CHANGED
File without changes
|
data/lib/throttle/bandwidth.rb
CHANGED
@@ -4,7 +4,7 @@ module Throttle
|
|
4
4
|
amount = nil
|
5
5
|
units = "KBp/s"
|
6
6
|
|
7
|
-
if /(\d*)/.match(str)
|
7
|
+
if !(/(\d*)/.match(str).to_s.empty?)
|
8
8
|
amount = Regexp.last_match(0).to_i
|
9
9
|
|
10
10
|
if /((K|M|k|m)(b|B)(p|P))/.match(str)
|
@@ -14,14 +14,32 @@ module Throttle
|
|
14
14
|
units += '/s'
|
15
15
|
end
|
16
16
|
|
17
|
-
# Maximum allowed
|
18
|
-
|
17
|
+
# Maximum allowed by ipfw
|
18
|
+
if over_limit?(amount, units)
|
19
|
+
amount = 268
|
20
|
+
units = "MBp/s"
|
21
|
+
end
|
19
22
|
|
20
23
|
"#{amount}#{units}"
|
21
24
|
else
|
22
25
|
nil
|
23
26
|
end
|
24
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def over_limit?(amount, units)
|
32
|
+
case units
|
33
|
+
when "MBp/s"
|
34
|
+
true if amount > 268
|
35
|
+
when "Mbp/s"
|
36
|
+
true if amount > 2144
|
37
|
+
when "KBp/s"
|
38
|
+
true if amount > 268000
|
39
|
+
when "Kbp/s"
|
40
|
+
true if amount > 2144000
|
41
|
+
end
|
42
|
+
end
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
data/lib/throttle/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Throttle::Bandwidth do
|
4
|
+
before do
|
5
|
+
class Bandwidth
|
6
|
+
extend Throttle::Bandwidth
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return nil on invalid string" do
|
11
|
+
Bandwidth.parse_bandwidth('notabandwidthstring').must_be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return correct bandwidth on properly formed string" do
|
15
|
+
Bandwidth.parse_bandwidth('400 Kbps').must_equal('400Kbp/s')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should cap at 268MBp/s" do
|
19
|
+
Bandwidth.parse_bandwidth('10000 MBps').must_equal('268MBp/s')
|
20
|
+
Bandwidth.parse_bandwidth('9999999 KBps').must_equal('268MBp/s')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should properly format a messy string" do
|
24
|
+
Bandwidth.parse_bandwidth('5 Kbp').must_equal('5Kbp/s')
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Throttle::Client do
|
4
|
+
before do
|
5
|
+
@client = Throttle::Client.new
|
6
|
+
@pipe = Throttle::Pipe.new( {:id => 1, :bandwidth => '100Kbp/s'} )
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return current pipe limit" do
|
10
|
+
Throttle::Pipe.stubs(:all).returns( [ @pipe ] )
|
11
|
+
|
12
|
+
@client.status.must_equal('100Kbp/s')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return no limits if there are no pipes" do
|
16
|
+
Throttle::Pipe.stubs(:all).returns([])
|
17
|
+
|
18
|
+
@client.status.must_equal('No Limits.')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return status after reset" do
|
22
|
+
Throttle::Pipe.stubs(:reset).returns(nil)
|
23
|
+
Throttle::Pipe.stubs(:all).returns([])
|
24
|
+
|
25
|
+
@client.status.must_equal('No Limits.')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return status after limit" do
|
29
|
+
bandwidth = '100Kbps'
|
30
|
+
@pipe.bandwidth = bandwidth
|
31
|
+
|
32
|
+
Throttle::Pipe.stubs(:reset).returns(nil)
|
33
|
+
Throttle::Pipe.any_instance.stubs(:set).returns(nil)
|
34
|
+
|
35
|
+
Throttle::Pipe.stubs(:all).returns( [ @pipe ] )
|
36
|
+
|
37
|
+
@client.limit(bandwidth).must_equal(bandwidth)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Throttle::Ipfw do
|
4
|
+
before do
|
5
|
+
class Ipfw
|
6
|
+
extend Throttle::Ipfw
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return pipe id" do
|
11
|
+
Ipfw.parse_pipe_id('00200 pipe 1 ip from any to any').must_equal(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return nil when there is no pipe id" do
|
15
|
+
Ipfw.parse_pipe_id("00200 pipe ip from any to any").must_be_nil
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Throttle::Pipe do
|
4
|
+
before do
|
5
|
+
@list_output = <<EOF
|
6
|
+
00100 fwd 127.0.0.1,20559 tcp from any to me dst-port 80 in
|
7
|
+
00200 pipe 1 ip from any to any
|
8
|
+
65535 allow ip from any to any
|
9
|
+
EOF
|
10
|
+
|
11
|
+
@show_output = <<EOF
|
12
|
+
show_output = <<EOF
|
13
|
+
00001: 12.000 Mbit/s 0 ms 50 sl. 1 queues (1 buckets) droptail
|
14
|
+
mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
|
15
|
+
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
|
16
|
+
0 tcp 199.47.217.146/80 10.0.1.2/59964 7938 4287713 0 0 66
|
17
|
+
EOF
|
18
|
+
|
19
|
+
@pipe = Throttle::Pipe.new({:id => 100, :bandwidth => '12Mbp/s'})
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return pipe" do
|
23
|
+
Throttle::Pipe.expects(:ipfw).with('list').returns(@list_output)
|
24
|
+
Throttle::Pipe.expects(:ipfw).with('pipe 1 show').returns(@show_output)
|
25
|
+
|
26
|
+
pipe = Throttle::Pipe.all[0]
|
27
|
+
|
28
|
+
pipe.id.must_equal(1)
|
29
|
+
pipe.bandwidth.must_equal("12.000 Mbit/s")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return correct bandwidth" do
|
33
|
+
Throttle::Pipe.expects(:ipfw).with('pipe 1 show').returns(@show_output)
|
34
|
+
|
35
|
+
Throttle::Pipe.bandwidth(1).must_equal("12.000 Mbit/s")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return nil for unknown pipe" do
|
39
|
+
Throttle::Pipe.expects(:ipfw).with('pipe 2 show').returns("ipfw: getsockopt(IP_DUMMYNET_GET): No buffer space available")
|
40
|
+
|
41
|
+
Throttle::Pipe.bandwidth(2).must_be_nil
|
42
|
+
end
|
43
|
+
end
|
data/throttle.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
|
-
|
23
|
-
|
22
|
+
s.add_development_dependency "minitest"
|
23
|
+
s.add_development_dependency "cucumber"
|
24
|
+
s.add_development_dependency "mocha"
|
24
25
|
end
|
metadata
CHANGED
@@ -1,25 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: throttle
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- brookemckim
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
date: 2011-11-22 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: minitest
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: cucumber
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: mocha
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
14
63
|
description: Throttle your local bandwidth with IPFW on OSX
|
15
|
-
email:
|
64
|
+
email:
|
16
65
|
- brooke.mckim@gmail.com
|
17
|
-
executables:
|
66
|
+
executables:
|
18
67
|
- throttle
|
19
68
|
extensions: []
|
69
|
+
|
20
70
|
extra_rdoc_files: []
|
21
|
-
|
71
|
+
|
72
|
+
files:
|
22
73
|
- .gitignore
|
74
|
+
- .rbenv-version
|
23
75
|
- Gemfile
|
24
76
|
- README.md
|
25
77
|
- Rakefile
|
@@ -30,29 +82,51 @@ files:
|
|
30
82
|
- lib/throttle/ipfw.rb
|
31
83
|
- lib/throttle/pipe.rb
|
32
84
|
- lib/throttle/version.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
- spec/throttle/bandwidth_spec.rb
|
87
|
+
- spec/throttle/client_spec.rb
|
88
|
+
- spec/throttle/ipfw_spec.rb
|
89
|
+
- spec/throttle/pipe_spec.rb
|
90
|
+
- spec/throttle_spec.rb
|
33
91
|
- throttle.gemspec
|
92
|
+
has_rdoc: true
|
34
93
|
homepage: https://github.com/brookemckim/throttle
|
35
94
|
licenses: []
|
95
|
+
|
36
96
|
post_install_message:
|
37
97
|
rdoc_options: []
|
38
|
-
|
98
|
+
|
99
|
+
require_paths:
|
39
100
|
- lib
|
40
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
102
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
111
|
none: false
|
48
|
-
requirements:
|
49
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
52
119
|
requirements: []
|
120
|
+
|
53
121
|
rubyforge_project: throttle
|
54
|
-
rubygems_version: 1.
|
122
|
+
rubygems_version: 1.6.2
|
55
123
|
signing_key:
|
56
124
|
specification_version: 3
|
57
125
|
summary: Throttle bandwidth on OS X
|
58
|
-
test_files:
|
126
|
+
test_files:
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
- spec/throttle/bandwidth_spec.rb
|
129
|
+
- spec/throttle/client_spec.rb
|
130
|
+
- spec/throttle/ipfw_spec.rb
|
131
|
+
- spec/throttle/pipe_spec.rb
|
132
|
+
- spec/throttle_spec.rb
|