reverse-tunnel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,13 @@ end
27
27
  require "eventmachine"
28
28
  require "msgpack"
29
29
  require "trollop"
30
- require "syslog/logger"
30
+
31
+ begin
32
+ require "syslog/logger"
33
+ rescue LoadError
34
+ require 'syslog_logger'
35
+ Syslog::Logger = SyslogLogger
36
+ end
31
37
 
32
38
  require "reverse-tunnel/message"
33
39
  require "reverse-tunnel/server"
@@ -16,7 +16,7 @@ module ReverseTunnel
16
16
  end
17
17
 
18
18
  def process_http_request
19
- ReverseTunnel.logger.debug "Process http request #{@http_request_uri}"
19
+ ReverseTunnel.logger.debug { "Process http request #{@http_request_uri}" }
20
20
 
21
21
  response = EM::DelegatedHttpResponse.new(self)
22
22
  response.status = 200
@@ -60,7 +60,7 @@ module ReverseTunnel
60
60
  local_connections.close_all
61
61
  @hearbeat.cancel
62
62
  else
63
- @hearbeat = EventMachine.add_periodic_timer(5) do
63
+ @hearbeat = EventMachine.add_periodic_timer(30) do
64
64
  ping
65
65
  end
66
66
  end
@@ -69,7 +69,7 @@ module ReverseTunnel
69
69
  end
70
70
 
71
71
  def start
72
- ReverseTunnel.logger.debug "Connect to #{host}:#{port}"
72
+ ReverseTunnel.logger.debug { "Connect to #{host}:#{port}" }
73
73
  EventMachine.connect host, port, TunnelConnection, self
74
74
  end
75
75
 
@@ -84,7 +84,7 @@ module ReverseTunnel
84
84
 
85
85
  def ping
86
86
  next_number = self.sequence_number += 1
87
- ReverseTunnel.logger.debug "Send ping #{next_number}"
87
+ ReverseTunnel.logger.debug { "Send ping #{next_number}" }
88
88
  connection.send_data Message::Ping.new(next_number).pack if connection
89
89
  end
90
90
 
@@ -99,7 +99,7 @@ module ReverseTunnel
99
99
 
100
100
  def send_data(session_id, data)
101
101
  if connection
102
- ReverseTunnel.logger.debug "Send data to local connection #{session_id}"
102
+ ReverseTunnel.logger.debug { "Send data to local connection #{session_id}" }
103
103
  connection.send_data Message::Data.new(session_id,data).pack
104
104
  end
105
105
  end
@@ -111,7 +111,7 @@ module ReverseTunnel
111
111
  def receive_data(session_id, data)
112
112
  local_connection = local_connections.find(session_id)
113
113
  if local_connection
114
- ReverseTunnel.logger.debug "Send data to local connection #{session_id}"
114
+ ReverseTunnel.logger.debug { "Send data to local connection #{session_id}" }
115
115
  local_connection.send_data data
116
116
  else
117
117
  local_connections.bufferize session_id, data
@@ -147,7 +147,7 @@ module ReverseTunnel
147
147
  connections << connection
148
148
 
149
149
  session_id = connection.session_id
150
- ReverseTunnel.logger.debug "Clear buffer for #{session_id}"
150
+ ReverseTunnel.logger.debug { "Clear buffer for #{session_id}" }
151
151
 
152
152
  (buffers.delete(session_id) or []).each do |data|
153
153
  connection.send_data data
@@ -160,7 +160,7 @@ module ReverseTunnel
160
160
  end
161
161
 
162
162
  def bufferize(session_id, data)
163
- ReverseTunnel.logger.debug "Push buffer for #{session_id}"
163
+ ReverseTunnel.logger.debug { "Push buffer for #{session_id}" }
164
164
  buffers[session_id] << data
165
165
  end
166
166
 
@@ -188,7 +188,7 @@ module ReverseTunnel
188
188
  end
189
189
 
190
190
  def post_init
191
- ReverseTunnel.logger.debug "New tunnel connection"
191
+ ReverseTunnel.logger.debug { "New tunnel connection" }
192
192
  self.created_at = Time.now
193
193
 
194
194
  tunnel.connection = self
@@ -204,11 +204,11 @@ module ReverseTunnel
204
204
  end
205
205
 
206
206
  def receive_data(data)
207
- ReverseTunnel.logger.debug "Received data '#{data.unpack('H*').join}'"
207
+ ReverseTunnel.logger.debug { "Received data '#{data.unpack('H*').join}'" }
208
208
  message_unpacker.feed data
209
209
 
210
210
  message_unpacker.each do |message|
211
- ReverseTunnel.logger.debug "Received message in tunnel #{message.inspect}"
211
+ ReverseTunnel.logger.debug { "Received message in tunnel #{message.inspect}" }
212
212
 
213
213
  if message.data?
214
214
  tunnel.receive_data message.session_id, message.data
@@ -221,7 +221,7 @@ module ReverseTunnel
221
221
  end
222
222
 
223
223
  def unbind
224
- ReverseTunnel.logger.debug "Close tunnel connection"
224
+ ReverseTunnel.logger.debug { "Close tunnel connection" }
225
225
  tunnel.connection = nil
226
226
  end
227
227
 
@@ -238,24 +238,24 @@ module ReverseTunnel
238
238
  end
239
239
 
240
240
  def post_init
241
- ReverseTunnel.logger.debug "New local connection"
241
+ ReverseTunnel.logger.debug { "New local connection" }
242
242
  @created_at = Time.now
243
243
  tunnel.local_connections << self
244
244
  end
245
245
 
246
246
  def receive_data(data)
247
- ReverseTunnel.logger.debug "Received data in local connection #{session_id}"
247
+ ReverseTunnel.logger.debug { "Received data in local connection #{session_id}" }
248
248
  @received_size += data.size
249
249
  tunnel.send_data session_id, data
250
250
  end
251
251
 
252
252
  def unbind
253
- ReverseTunnel.logger.debug "Close local connection #{session_id}"
253
+ ReverseTunnel.logger.debug { "Close local connection #{session_id}" }
254
254
  tunnel.local_connections.delete self
255
255
  end
256
256
 
257
257
  def send_data(data)
258
- ReverseTunnel.logger.debug "Send data '#{data.unpack('H*').join}'"
258
+ ReverseTunnel.logger.debug { "Send data '#{data.unpack('H*').join}'" }
259
259
  @send_size += data.size
260
260
  super
261
261
  end
@@ -31,7 +31,7 @@ module ReverseTunnel
31
31
  # @http_post_content
32
32
  # @http_headers
33
33
 
34
- ReverseTunnel.logger.debug "Process http request #{@http_request_uri}"
34
+ ReverseTunnel.logger.debug { "Process http request #{@http_request_uri}" }
35
35
 
36
36
  response = EM::DelegatedHttpResponse.new(self)
37
37
  response.status = 200
@@ -138,19 +138,19 @@ module ReverseTunnel
138
138
 
139
139
  def open_session(session_id)
140
140
  if connection
141
- ReverseTunnel.logger.debug "Send open session #{session_id}"
141
+ ReverseTunnel.logger.debug { "Send open session #{session_id}" }
142
142
  connection.send_data Message::OpenSession.new(session_id).pack
143
143
  end
144
144
  end
145
145
 
146
146
  def ping_received(ping)
147
- ReverseTunnel.logger.debug "Receive ping #{token}/#{ping.sequence_number}"
147
+ ReverseTunnel.logger.debug { "Receive ping #{token}/#{ping.sequence_number}" }
148
148
  connection.send_data Message::Ping.new(ping.sequence_number).pack
149
149
  end
150
150
 
151
151
  def send_data(session_id, data)
152
152
  if connection
153
- ReverseTunnel.logger.debug "Send data to local connection #{session_id}"
153
+ ReverseTunnel.logger.debug { "Send data to local connection #{session_id}" }
154
154
  connection.send_data Message::Data.new(session_id,data).pack
155
155
  end
156
156
  end
@@ -162,7 +162,7 @@ module ReverseTunnel
162
162
  def receive_data(session_id, data)
163
163
  local_connection = local_connections.find { |c| c.session_id == session_id }
164
164
  if local_connection
165
- ReverseTunnel.logger.debug "Send data for local connection #{session_id}"
165
+ ReverseTunnel.logger.debug { "Send data for local connection #{session_id}" }
166
166
  local_connection.send_data data
167
167
  end
168
168
  end
@@ -269,13 +269,13 @@ module ReverseTunnel
269
269
  end
270
270
 
271
271
  def post_init
272
- ReverseTunnel.logger.debug "New local connection"
272
+ ReverseTunnel.logger.debug { "New local connection" }
273
273
  tunnel.local_connections << self
274
274
  tunnel.open_session(session_id)
275
275
  end
276
276
 
277
277
  def receive_data(data)
278
- ReverseTunnel.logger.debug "Received data in local #{session_id}"
278
+ ReverseTunnel.logger.debug { "Received data in local #{session_id}" }
279
279
  tunnel.send_data session_id, data
280
280
  end
281
281
 
@@ -284,7 +284,7 @@ module ReverseTunnel
284
284
  end
285
285
 
286
286
  def unbind
287
- ReverseTunnel.logger.debug "Close local connection"
287
+ ReverseTunnel.logger.debug { "Close local connection" }
288
288
  tunnel.local_connections.delete self
289
289
  end
290
290
 
@@ -364,8 +364,6 @@ module ReverseTunnel
364
364
  end
365
365
 
366
366
  def start
367
- tunnels.create "token" => "6B833D3F561369156820B4240C7C2657", "local_port" => 10000
368
-
369
367
  EventMachine.run do
370
368
  start_server
371
369
  start_api
@@ -1,3 +1,3 @@
1
1
  module ReverseTunnel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reverse-tunnel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-27 00:00:00.000000000 Z
13
+ date: 2012-12-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine
@@ -252,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
252
  version: '0'
253
253
  segments:
254
254
  - 0
255
- hash: -1765288854633900914
255
+ hash: 2213340273157857061
256
256
  required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  none: false
258
258
  requirements:
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  version: '0'
262
262
  segments:
263
263
  - 0
264
- hash: -1765288854633900914
264
+ hash: 2213340273157857061
265
265
  requirements: []
266
266
  rubyforge_project:
267
267
  rubygems_version: 1.8.23