ffwd-tunnel 0.1.7 → 0.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 345b23611c880a3c3828a110a2c822b480f90754
4
+ data.tar.gz: 5d3e61598542c9ee58da1f0d6e155acc134a4368
5
+ SHA512:
6
+ metadata.gz: a7a419e95c90f292a3cd98a3648c23a16c159598fac7e7f862d53cdbd5a1e6e826b1e2d27a4dce851e7ad59382bc1638f5eb0e1cddf5e1a4dcdb15b162619c59
7
+ data.tar.gz: ca8ebe5059f72a20499d05b64fb78c2782ed72dbc38fbb3abf0be4f7b4b75a0138fe0182e8eb6e7184cac656d556c534b30a8bc50aed95cc7d90306d4d5f44a1
@@ -17,7 +17,6 @@ require 'eventmachine'
17
17
  require 'base64'
18
18
 
19
19
  require_relative 'tunnel/connection_tcp'
20
- require_relative 'tunnel/binary_protocol'
21
20
 
22
21
  require 'ffwd/logging'
23
22
  require 'ffwd/plugin'
@@ -38,20 +37,17 @@ module FFWD::Plugin::Tunnel
38
37
  :tcp => ConnectionTCP
39
38
  }
40
39
 
41
- def self.setup_input opts, core
42
- opts[:host] ||= DEFAULT_HOST
43
- opts[:port] ||= DEFAULT_PORT
44
- protocol = FFWD.parse_protocol(opts[:protocol] || DEFAULT_PROTOCOL)
45
- protocol_type = opts[:protocol_type] || DEFAULT_PROTOCOL_TYPE
40
+ def self.setup_input config
41
+ config[:host] ||= DEFAULT_HOST
42
+ config[:port] ||= DEFAULT_PORT
43
+ config[:protocol] ||= DEFAULT_PROTOCOL
44
+
45
+ protocol = FFWD.parse_protocol config[:protocol]
46
46
 
47
47
  unless connection = CONNECTIONS[protocol.family]
48
48
  raise "No connection for protocol family: #{protocol.family}"
49
49
  end
50
50
 
51
- if core.tunnel_plugins.empty?
52
- raise "Nothing requires tunneling"
53
- end
54
-
55
- protocol.bind opts, core, log, connection, BinaryProtocol
51
+ protocol.bind config, log, connection
56
52
  end
57
53
  end
@@ -22,108 +22,11 @@ require 'ffwd/plugin_channel'
22
22
  require 'ffwd/tunnel/plugin'
23
23
  require 'ffwd/utils'
24
24
 
25
+ require_relative 'bind_tcp'
26
+ require_relative 'bind_udp'
27
+
25
28
  module FFWD::Plugin::Tunnel
26
29
  class BinaryProtocol < FFWD::Tunnel::Plugin
27
- class BindUDP
28
- class Handle < FFWD::Tunnel::Plugin::Handle
29
- attr_reader :addr
30
-
31
- def initialize bind, addr
32
- @bind = bind
33
- @addr = addr
34
- end
35
-
36
- def send_data data
37
- @bind.send_data @addr, data
38
- end
39
- end
40
-
41
- def initialize port, family, tunnel, block
42
- @port = port
43
- @family = family
44
- @tunnel = tunnel
45
- @block = block
46
- end
47
-
48
- def send_data addr, data
49
- @tunnel.send_data Socket::SOCK_DGRAM, @family, @port, addr, data
50
- end
51
-
52
- def data! addr, data
53
- handle = Handle.new self, addr
54
- @block.call handle, data
55
- end
56
- end
57
-
58
- class BindTCP
59
- class Handle < FFWD::Tunnel::Plugin::Handle
60
- attr_reader :addr
61
-
62
- def initialize bind, addr
63
- @bind = bind
64
- @addr = addr
65
- @close = nil
66
- @data = nil
67
- end
68
-
69
- def send_data data
70
- @bind.send_data @addr, data
71
- end
72
-
73
- def close &block
74
- @close = block
75
- end
76
-
77
- def data &block
78
- @data = block
79
- end
80
-
81
- def recv_close
82
- return if @close.nil?
83
- @close.call
84
- @close = nil
85
- @data = nil
86
- end
87
-
88
- def recv_data data
89
- return if @data.nil?
90
- @data.call data
91
- end
92
- end
93
-
94
- def initialize port, family, tunnel, block
95
- @port = port
96
- @family = family
97
- @tunnel = tunnel
98
- @block = block
99
- @handles = {}
100
- end
101
-
102
- def open addr
103
- raise "Already open: #{addr}" if @handles[addr]
104
- handle = @handles[addr] = Handle.new self, addr
105
- @block.call handle
106
- end
107
-
108
- def close addr
109
- raise "Not open: #{addr}" unless handle = @handles[addr]
110
- handle.recv_close
111
- @handles.delete addr
112
- end
113
-
114
- def data addr, data
115
- unless handle = @handles[addr]
116
- raise "Not available: #{addr}"
117
- end
118
-
119
- handle.recv_data data
120
- end
121
-
122
- def send_data addr, data
123
- @tunnel.send_data Socket::SOCK_STREAM, @family, @port, addr, data
124
- end
125
- end
126
-
127
30
  include FFWD::Logging
128
31
  include FFWD::Lifecycle
129
32
 
@@ -153,62 +56,41 @@ module FFWD::Plugin::Tunnel
153
56
  @c = c
154
57
  @tcp_bind = {}
155
58
  @udp_bind = {}
156
- @input = FFWD::PluginChannel.build 'tunnel_input'
157
59
 
158
- @metadata = nil
159
- @processor = nil
160
- @channel_id = nil
161
- @statistics_id = nil
162
60
  @header = nil
61
+ @parent = core
62
+ end
163
63
 
164
- starting do
165
- raise "no metadata" if @metadata.nil?
166
-
167
- if host = @metadata[:host]
168
- @statistics_id = "tunnel/#{host}"
169
- @channel_id = "tunnel.input/#{host}"
170
- else
171
- @statistics_id = "tunnel/#{@c.get_peer}"
172
- @channel_id = "tunnel.input/#{@c.get_peer}"
173
- end
174
-
175
- # setup a small core
176
- emitter = FFWD::Core::Emitter.build @core.output, @metadata
177
- @processor = FFWD::Core::Processor.build @input, emitter, @core.processors
64
+ def setup metadata
65
+ unless id = metadata[:host]
66
+ id = @c.get_peer
67
+ end
178
68
 
179
- @reporter = FFWD::Core::Reporter.new [@input, @processor]
69
+ input = FFWD::PluginChannel.build "tunnel.input/#{id}"
70
+ core = @parent.reconnect input
180
71
 
181
- if @core.debug
182
- @core.debug.monitor @channel_id, @input, FFWD::Debug::Input
183
- end
72
+ # setup a small core
73
+ emitter = FFWD::Core::Emitter.build core.output, metadata
74
+ processor = FFWD::Core::Processor.build input, emitter, core.processors
184
75
 
185
- if @core.statistics
186
- @core.statistics.register @statistics_id, @reporter
187
- end
76
+ if core.debug
77
+ core.debug.monitor input, FFWD::Debug::Input
188
78
  end
189
79
 
190
- stopping do
191
- if @core.statistics and @statistics_id
192
- @core.statistics.unregister @statistics_id
193
- @statistics_id = nil
194
- end
195
-
196
- @metadata = nil
197
- @processor = nil
198
- @channel_id = nil
199
- @tcp_bind = {}
200
- @udp_bind = {}
80
+ if core.statistics
81
+ reporters = [input, processor]
82
+ reporter = FFWD::Core::Reporter.new reporters
83
+ core.statistics.register self, "tunnel/#{id}", reporter
201
84
  end
202
85
 
203
- @core = core.reconnect @input
204
-
205
- @core.tunnel_plugins.each do |t|
206
- instance = t.setup @core, self
207
- instance.depend_on self
86
+ core.tunnel_plugins.each do |factory|
87
+ factory.call(core, self).depend_on self
208
88
  end
209
89
 
210
- @input.depend_on self
211
- @core.depend_on self
90
+ input.depend_on self
91
+ core.depend_on self
92
+
93
+ start
212
94
  end
213
95
 
214
96
  def tcp port, &block
@@ -224,8 +106,8 @@ module FFWD::Plugin::Tunnel
224
106
  def read_metadata data
225
107
  d = {}
226
108
 
227
- d[:tags] = FFWD.merge_sets @core.tags, data["tags"]
228
- d[:attributes] = FFWD.merge_sets @core.attributes, data["attributes"]
109
+ d[:tags] = FFWD.merge_sets @parent.tags, data["tags"]
110
+ d[:attributes] = FFWD.merge_sets @parent.attributes, data["attributes"]
229
111
 
230
112
  if host = data["host"]
231
113
  d[:host] = host
@@ -257,8 +139,7 @@ module FFWD::Plugin::Tunnel
257
139
  end
258
140
 
259
141
  def receive_metadata data
260
- @metadata = read_metadata data
261
- start
142
+ setup read_metadata(data)
262
143
  send_config
263
144
  end
264
145
 
@@ -353,7 +234,6 @@ module FFWD::Plugin::Tunnel
353
234
 
354
235
  def tunnel_state header, addr, state
355
236
  if header.protocol == Socket::SOCK_DGRAM
356
- # ignored
357
237
  log.error "UDP does not handle: #{state}"
358
238
  return
359
239
  end
@@ -0,0 +1,89 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'ffwd/tunnel/plugin'
17
+
18
+ module FFWD::Plugin::Tunnel
19
+ class BindTCP
20
+ class Handle < FFWD::Tunnel::Plugin::Handle
21
+ attr_reader :addr
22
+
23
+ def initialize bind, addr
24
+ @bind = bind
25
+ @addr = addr
26
+ @close = nil
27
+ @data = nil
28
+ end
29
+
30
+ def send_data data
31
+ @bind.send_data @addr, data
32
+ end
33
+
34
+ def close &block
35
+ @close = block
36
+ end
37
+
38
+ def data &block
39
+ @data = block
40
+ end
41
+
42
+ def recv_close
43
+ return if @close.nil?
44
+ @close.call
45
+ @close = nil
46
+ @data = nil
47
+ end
48
+
49
+ def recv_data data
50
+ return if @data.nil?
51
+ @data.call data
52
+ end
53
+ end
54
+
55
+ def initialize port, family, tunnel, block
56
+ @port = port
57
+ @family = family
58
+ @tunnel = tunnel
59
+ @block = block
60
+ @handles = {}
61
+ end
62
+
63
+ def open addr
64
+ raise "Already open: #{addr}" if @handles[addr]
65
+ handle = @handles[addr] = Handle.new self, addr
66
+ @block.call handle
67
+ end
68
+
69
+ def close addr
70
+ raise "Not open: #{addr}" unless handle = @handles[addr]
71
+ handle.recv_close
72
+ @handles.delete addr
73
+ end
74
+
75
+ def data addr, data
76
+ return if data.empty?
77
+
78
+ unless handle = @handles[addr]
79
+ raise "Not available: #{addr}"
80
+ end
81
+
82
+ handle.recv_data data
83
+ end
84
+
85
+ def send_data addr, data
86
+ @tunnel.send_data Socket::SOCK_STREAM, @family, @port, addr, data
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,49 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'ffwd/tunnel/plugin'
17
+
18
+ module FFWD::Plugin::Tunnel
19
+ class BindUDP
20
+ class Handle < FFWD::Tunnel::Plugin::Handle
21
+ attr_reader :addr
22
+
23
+ def initialize bind, addr
24
+ @bind = bind
25
+ @addr = addr
26
+ end
27
+
28
+ def send_data data
29
+ @bind.send_data @addr, data
30
+ end
31
+ end
32
+
33
+ def initialize port, family, tunnel, block
34
+ @port = port
35
+ @family = family
36
+ @tunnel = tunnel
37
+ @block = block
38
+ end
39
+
40
+ def send_data addr, data
41
+ @tunnel.send_data Socket::SOCK_DGRAM, @family, @port, addr, data
42
+ end
43
+
44
+ def data! addr, data
45
+ handle = Handle.new self, addr
46
+ @block.call handle, data
47
+ end
48
+ end
49
+ end
@@ -15,6 +15,8 @@
15
15
 
16
16
  require 'ffwd/connection'
17
17
 
18
+ require_relative 'binary_protocol'
19
+
18
20
  module FFWD::Plugin::Tunnel
19
21
  class ConnectionTCP < FFWD::Connection
20
22
  include FFWD::Logging
@@ -24,10 +26,10 @@ module FFWD::Plugin::Tunnel
24
26
  "tunnel_in_tcp"
25
27
  end
26
28
 
27
- def initialize bind, core, tunnel_protocol
29
+ def initialize bind, core, config
28
30
  @bind = bind
29
31
  @core = core
30
- @tunnel_protocol = tunnel_protocol
32
+ @tunnel_protocol = BinaryProtocol
31
33
  @protocol_instance = nil
32
34
  end
33
35
 
@@ -43,6 +45,8 @@ module FFWD::Plugin::Tunnel
43
45
  peer = get_peername
44
46
  port, ip = Socket.unpack_sockaddr_in(peer)
45
47
  "#{ip}:#{port}"
48
+ rescue
49
+ nil
46
50
  end
47
51
 
48
52
  def post_init
@@ -16,7 +16,7 @@
16
16
  module FFWD
17
17
  module Plugin
18
18
  module Tunnel
19
- VERSION = "0.1.7"
19
+ VERSION = "0.2.0"
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffwd-tunnel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - John-John Tedro
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ffwd
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '='
20
18
  - !ruby/object:Gem::Version
21
- version: 0.1.7
19
+ version: 0.2.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '='
28
25
  - !ruby/object:Gem::Version
29
- version: 0.1.7
26
+ version: 0.2.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec-mocks
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description:
@@ -68,33 +61,34 @@ extensions: []
68
61
  extra_rdoc_files: []
69
62
  files:
70
63
  - bin/ffwd-tunnel-agent
71
- - lib/ffwd/plugin/tunnel/connection_tcp.rb
64
+ - lib/ffwd/plugin/tunnel.rb
65
+ - lib/ffwd/plugin/tunnel/bind_udp.rb
66
+ - lib/ffwd/plugin/tunnel/bind_tcp.rb
72
67
  - lib/ffwd/plugin/tunnel/binary_protocol.rb
73
68
  - lib/ffwd/plugin/tunnel/version.rb
74
- - lib/ffwd/plugin/tunnel.rb
69
+ - lib/ffwd/plugin/tunnel/connection_tcp.rb
75
70
  homepage: https://github.com/spotify/ffwd
76
71
  licenses:
77
72
  - Apache 2.0
73
+ metadata: {}
78
74
  post_install_message:
79
75
  rdoc_options: []
80
76
  require_paths:
81
77
  - lib
82
78
  required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
79
  requirements:
85
- - - ! '>='
80
+ - - '>='
86
81
  - !ruby/object:Gem::Version
87
82
  version: '0'
88
83
  required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
84
  requirements:
91
- - - ! '>='
85
+ - - '>='
92
86
  - !ruby/object:Gem::Version
93
87
  version: '0'
94
88
  requirements: []
95
89
  rubyforge_project:
96
- rubygems_version: 1.8.23
90
+ rubygems_version: 2.0.3
97
91
  signing_key:
98
- specification_version: 3
92
+ specification_version: 4
99
93
  summary: Simple tunneling support for FFWD.
100
94
  test_files: []