rtunnel 0.3.1 → 0.3.5

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.
Files changed (4) hide show
  1. data/lib/client.rb +24 -22
  2. data/lib/core.rb +1 -1
  3. data/lib/server.rb +7 -52
  4. metadata +20 -2
data/lib/client.rb CHANGED
@@ -4,7 +4,7 @@ require 'timeout'
4
4
  require 'resolv'
5
5
 
6
6
  require 'facets'
7
- require 'synchash'
7
+ require 'facets/synchash'
8
8
 
9
9
  require 'core'
10
10
  require 'cmds'
@@ -59,7 +59,6 @@ module RTunnel
59
59
  while true
60
60
  last_objects = objects.dup
61
61
  ObjectSpace.each_object do |o|
62
- next if ! o.respond_to? :class
63
62
  objects[o.class] += 1
64
63
  end
65
64
 
@@ -106,27 +105,31 @@ module RTunnel
106
105
  when PingCommand
107
106
  @last_ping = Time.now
108
107
  when CreateConnectionCommand
109
- # TODO: this currently blocks, but if we put it in thread, a SendDataCommand may try to get run for this connection before the connection exists
110
- CONNECTIONS[command.conn_id] = TCPSocket.new(*@tunnel_to_address.split(/:/))
111
- Thread.safe do
112
- cmd = command
113
- conn = CONNECTIONS[cmd.conn_id]
114
-
115
- begin
116
- D "reading local data"
117
- while localdata = conn.readpartial(16834)
118
- D "sending data back to server: #{localdata.size}"
119
- write_to_control_sock SendDataCommand.new(cmd.conn_id, localdata)
108
+ begin
109
+ # TODO: this currently blocks, but if we put it in thread, a SendDataCommand may try to get run for this connection before the connection exists
110
+ CONNECTIONS[command.conn_id] = TCPSocket.new(*@tunnel_to_address.split(/:/))
111
+
112
+ Thread.safe do
113
+ cmd = command
114
+ conn = CONNECTIONS[cmd.conn_id]
115
+
116
+ begin
117
+ while localdata = conn.readpartial(16834)
118
+ write_to_control_sock SendDataCommand.new(cmd.conn_id, localdata)
119
+ end
120
+ rescue EOFError
121
+ D "to tunnel closed, closing from tunnel"
122
+ conn.close
123
+ CONNECTIONS.delete cmd.conn_id
124
+ write_to_control_sock CloseConnectionCommand.new(cmd.conn_id)
120
125
  end
121
- rescue EOFError
122
- D "to tunnel closed, closing from tunnel"
123
- conn.close
124
- CONNECTIONS.delete cmd.conn_id
125
- write_to_control_sock CloseConnectionCommand.new(cmd.conn_id)
126
- end
126
+ end
127
+ rescue Exception
128
+ D "error connecting to local port"
129
+ write_to_control_sock CloseConnectionCommand.new(command.conn_id)
127
130
  end
128
131
  when CloseConnectionCommand
129
- D "close " + command.conn_id
132
+ D "closing connection #{command.conn_id}"
130
133
  if connection = CONNECTIONS[command.conn_id]
131
134
  # TODO: how the hell do u catch a .close error?
132
135
  connection.close_read
@@ -134,7 +137,6 @@ module RTunnel
134
137
  CONNECTIONS.delete(command.conn_id)
135
138
  end
136
139
  when SendDataCommand
137
- D "send to local " + command.conn_id + " " + command.inspect
138
140
  if connection = CONNECTIONS[command.conn_id]
139
141
  connection.write(command.data)
140
142
  else
@@ -175,4 +177,4 @@ module RTunnel
175
177
  @check_ping = false
176
178
  end
177
179
  end
178
- end
180
+ end
data/lib/core.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RTunnel
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.5'
3
3
 
4
4
  DEFAULT_CONTROL_PORT = 19050
5
5
  PING_TIMEOUT = 10
data/lib/server.rb CHANGED
@@ -3,7 +3,7 @@ require 'optparse'
3
3
  require 'uuidtools'
4
4
 
5
5
  require 'facets'
6
- require 'synchash'
6
+ require 'facets/synchash'
7
7
 
8
8
  require 'core'
9
9
  require 'cmds'
@@ -45,52 +45,6 @@ module RTunnel
45
45
  puts $!.backtrace.join("\n")
46
46
  end
47
47
  end
48
- #
49
- # class TunnelListenServer < GServer
50
- # @@tunneled_connections = []
51
- #
52
- # def initialize(port, host = DEFAULT_HOST)
53
- # super(port, host, 10)
54
- # end
55
- #
56
- # def serve(sock)
57
- # D "new tunneled connection"
58
- # cv, incoming_connection = RemoteListenServer.next_incoming_connection
59
- # if ! incoming_connection
60
- # D "no incoming connections for this tunneled connection, closing"
61
- # return
62
- # end
63
- #
64
- # while ready = (IO.select([incoming_connection, sock], nil, nil, 0.5).first rescue [])
65
- # if ready.include? incoming_connection
66
- # begin
67
- # sock.write(incoming_connection.readpartial(1024))
68
- # rescue EOFError
69
- # D "incoming socket closed, closing tunneled socket"
70
- # sock.close
71
- # cv.signal
72
- #
73
- # return
74
- # end
75
- # end
76
- #
77
- # if ready.include? sock
78
- # begin
79
- # incoming_connection.write(sock.readpartial(1024))
80
- # rescue EOFError
81
- # D "tunneled socket closed, closing incoming connection socket"
82
- # incoming_connection.close
83
- # cv.signal
84
- #
85
- # return
86
- # end
87
- # end
88
- # end
89
- # rescue Exception
90
- # p $!
91
- # puts $!.backtrace.join("\n")
92
- # end
93
- # end
94
48
 
95
49
  class ControlServer < GServer
96
50
  @@control_connection = nil
@@ -107,7 +61,6 @@ module RTunnel
107
61
  end
108
62
 
109
63
  def self.send_data(conn_id, data)
110
- D "send to client: #{conn_id}"
111
64
  @@m.synchronize { @@control_connection.write SendDataCommand.new(conn_id, data) }
112
65
  end
113
66
 
@@ -130,11 +83,12 @@ module RTunnel
130
83
  cmd = Command.parse(cmd_queue)
131
84
  case cmd
132
85
  when RemoteListenCommand
133
- @@remote_listen_server.stop if @@remote_listen_server
134
- (@@remote_listen_server = RemoteListenServer.new(*cmd.address.split(/:/).reverse)).start
86
+ @@m.synchronize do
87
+ @@remote_listen_server.stop if @@remote_listen_server
88
+ (@@remote_listen_server = RemoteListenServer.new(*cmd.address.split(/:/).reverse)).start
89
+ end
135
90
  D "listening for remote connections on #{cmd.address}"
136
91
  when SendDataCommand
137
- D "send data to remote conn #{cmd.conn_id}"
138
92
  RemoteListenServer::CONNECTIONS[cmd.conn_id].write cmd.data
139
93
  when CloseConnectionCommand
140
94
  if connection = RemoteListenServer::CONNECTIONS[cmd.conn_id]
@@ -146,11 +100,12 @@ module RTunnel
146
100
  end
147
101
  end
148
102
  end
149
- D "ping"
103
+
150
104
  @@m.synchronize { @@control_connection.write PingCommand.new }
151
105
  end
152
106
  rescue
153
107
  D $!.inspect
108
+ D $!.backtrace.join("\n")
154
109
  raise
155
110
  end
156
111
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rtunnel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.1
7
- date: 2007-11-27 00:00:00 +07:00
6
+ version: 0.3.5
7
+ date: 2007-12-03 00:00:00 +07:00
8
8
  summary: The author was too lazy to write a summary
9
9
  require_paths:
10
10
  - lib
@@ -59,6 +59,24 @@ extensions: []
59
59
  requirements: []
60
60
 
61
61
  dependencies:
62
+ - !ruby/object:Gem::Dependency
63
+ name: uuidtools
64
+ version_requirement:
65
+ version_requirements: !ruby/object:Gem::Version::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.2
70
+ version:
71
+ - !ruby/object:Gem::Dependency
72
+ name: facets
73
+ version_requirement:
74
+ version_requirements: !ruby/object:Gem::Version::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.1.2
79
+ version:
62
80
  - !ruby/object:Gem::Dependency
63
81
  name: hoe
64
82
  version_requirement: