tem_multi_proxy 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1 +1,3 @@
1
+ v0.2. The multi_proxy can respond to remote queries on connected TEMs.
2
+
1
3
  v0.1. Initial release. Standalone manager works.
data/Manifest CHANGED
@@ -1,8 +1,11 @@
1
1
  bin/tem_multi_proxy
2
+ bin/tem_multi_proxy_query
2
3
  CHANGELOG
4
+ lib/tem_multi_proxy/client.rb
3
5
  lib/tem_multi_proxy/manager.rb
6
+ lib/tem_multi_proxy/server.rb
4
7
  lib/tem_multi_proxy.rb
5
8
  LICENSE
9
+ Manifest
6
10
  Rakefile
7
11
  README
8
- Manifest
data/bin/tem_multi_proxy CHANGED
@@ -3,5 +3,5 @@
3
3
  require 'rubygems'
4
4
  require 'tem_multi_proxy'
5
5
 
6
- manager = Tem::MultiProxy::Manager.new
7
- manager.management_loop
6
+ server = Tem::MultiProxy::Server.new(ARGV[0] && ARGV[0].to_i)
7
+ server.serving_loop
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'tem_multi_proxy'
5
+
6
+ server_addr = ARGV[0] || 'localhost'
7
+ print "Querying #{server_addr}...\n"
8
+ tem_transports = Tem::MultiProxy::Client.query_tems server_addr
9
+ print tem_transports.inspect, "\n"
@@ -0,0 +1,30 @@
1
+ # :nodoc: namespace
2
+ module Tem::MultiProxy
3
+
4
+ class Client
5
+ Protocol = Zerg::Support::Protocols::ObjectProtocol
6
+ Adapter = Zerg::Support::Sockets::ProtocolAdapter.adapter_module Protocol
7
+ SocketFactory = Zerg::Support::SocketFactory
8
+ JcopRemoteTransport = Tem::Transport::JcopRemoteTransport
9
+
10
+ # Queries a multi_proxy for its TEMs, and returns them as transport
11
+ # configurations suitable for Tem::Tem#new.
12
+ def self.query_tems(server_addr = 'localhost')
13
+ @client_socket = SocketFactory.socket :out_addr => server_addr,
14
+ :out_port => Server::DEFAULT_PORT,
15
+ :no_delay => true
16
+ @client_socket.extend Adapter
17
+ @client_socket.send_object :query => 'tem_ports'
18
+ tem_ports = @client_socket.recv_object
19
+ @client_socket.close
20
+
21
+ return nil unless tem_ports
22
+ server_host = SocketFactory.host_from_address server_addr
23
+ tem_ports.map do |port|
24
+ { :class => JcopRemoteTransport,
25
+ :opts => { :host => server_host, :port => port } }
26
+ end
27
+ end
28
+ end
29
+
30
+ end # namespace Tem::MultiProxy
@@ -15,6 +15,11 @@ class Manager
15
15
  (9001...9050).each { |port| @free_ports[port] = true }
16
16
  @logger = Logger.new STDERR
17
17
  end
18
+
19
+ # Returns an array of ports that TEMs can listen to.
20
+ def tem_ports
21
+ @proxy_ports.values.sort
22
+ end
18
23
 
19
24
  # Polls each smartcard reader to see if there's a card present.
20
25
  def poll_readers
@@ -0,0 +1,55 @@
1
+ require 'logger'
2
+ require 'rbtree'
3
+ require 'set'
4
+
5
+
6
+ # :nodoc: namespace
7
+ module Tem::MultiProxy
8
+
9
+ class Server
10
+ DEFAULT_PORT = 9051
11
+
12
+ Protocol = Zerg::Support::Protocols::ObjectProtocol
13
+ Adapter = Zerg::Support::Sockets::ProtocolAdapter.adapter_module Protocol
14
+ SocketFactory = Zerg::Support::SocketFactory
15
+
16
+ def initialize(server_port = nil)
17
+ @manager = Manager.new
18
+ @socket = SocketFactory.socket :in_port => (server_port || DEFAULT_PORT),
19
+ :no_delay => true
20
+ end
21
+
22
+ # The main server loop.
23
+ def serving_loop
24
+ Thread.new { socket_loop }
25
+ @manager.management_loop
26
+ end
27
+
28
+ # Socket-serving loop that takes in clients and spins off a thread for each
29
+ # client.
30
+ def socket_loop
31
+ @socket.listen
32
+ loop do
33
+ client_socket, client_addr = @socket.accept
34
+ Thread.new(client_socket) { |client_socket| serve_client client_socket }
35
+ end
36
+ @manager.tem_ports
37
+ end
38
+
39
+ # Handle a single client.
40
+ def serve_client(client)
41
+ client.extend Adapter
42
+ request = client.recv_object
43
+ if request
44
+ case request[:query]
45
+ when 'tem_ports'
46
+ client.send_object @manager.tem_ports
47
+ else
48
+ client.send_object 'Unknown request'
49
+ end
50
+ end
51
+ client.close rescue nil
52
+ end
53
+ end
54
+
55
+ end # namespace Tem::MultiProxy
@@ -1,5 +1,6 @@
1
1
  # Gem requirements.
2
2
  require 'rubygems'
3
+ require 'eventmachine'
3
4
  require 'smartcard'
4
5
  require 'tem_ruby'
5
6
  require 'zerg_support'
@@ -9,4 +10,6 @@ module Tem::MultiProxy
9
10
  end
10
11
 
11
12
  # The files making up the gem.
13
+ require 'tem_multi_proxy/client.rb'
12
14
  require 'tem_multi_proxy/manager.rb'
15
+ require 'tem_multi_proxy/server.rb'
@@ -2,17 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tem_multi_proxy}
5
- s.version = "0.1"
5
+ s.version = "0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Victor Costan"]
9
- s.date = %q{2009-06-01}
10
- s.default_executable = %q{tem_multi_proxy}
9
+ s.date = %q{2009-06-02}
11
10
  s.description = %q{Maintains TEM proxies for all the physically attached TEMs.}
12
11
  s.email = %q{victor@costan.us}
13
- s.executables = ["tem_multi_proxy"]
14
- s.extra_rdoc_files = ["bin/tem_multi_proxy", "CHANGELOG", "lib/tem_multi_proxy/manager.rb", "lib/tem_multi_proxy.rb", "LICENSE", "README"]
15
- s.files = ["bin/tem_multi_proxy", "CHANGELOG", "lib/tem_multi_proxy/manager.rb", "lib/tem_multi_proxy.rb", "LICENSE", "Rakefile", "README", "Manifest", "tem_multi_proxy.gemspec"]
12
+ s.executables = ["tem_multi_proxy", "tem_multi_proxy_query"]
13
+ s.extra_rdoc_files = ["bin/tem_multi_proxy", "bin/tem_multi_proxy_query", "CHANGELOG", "lib/tem_multi_proxy/client.rb", "lib/tem_multi_proxy/manager.rb", "lib/tem_multi_proxy/server.rb", "lib/tem_multi_proxy.rb", "LICENSE", "README"]
14
+ s.files = ["bin/tem_multi_proxy", "bin/tem_multi_proxy_query", "CHANGELOG", "lib/tem_multi_proxy/client.rb", "lib/tem_multi_proxy/manager.rb", "lib/tem_multi_proxy/server.rb", "lib/tem_multi_proxy.rb", "LICENSE", "Manifest", "Rakefile", "README", "tem_multi_proxy.gemspec"]
16
15
  s.homepage = %q{http://tem.rubyforge.org}
17
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tem_multi_proxy", "--main", "README"]
18
17
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tem_multi_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: "0.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-01 00:00:00 -04:00
12
+ date: 2009-06-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -56,24 +56,31 @@ description: Maintains TEM proxies for all the physically attached TEMs.
56
56
  email: victor@costan.us
57
57
  executables:
58
58
  - tem_multi_proxy
59
+ - tem_multi_proxy_query
59
60
  extensions: []
60
61
 
61
62
  extra_rdoc_files:
62
63
  - bin/tem_multi_proxy
64
+ - bin/tem_multi_proxy_query
63
65
  - CHANGELOG
66
+ - lib/tem_multi_proxy/client.rb
64
67
  - lib/tem_multi_proxy/manager.rb
68
+ - lib/tem_multi_proxy/server.rb
65
69
  - lib/tem_multi_proxy.rb
66
70
  - LICENSE
67
71
  - README
68
72
  files:
69
73
  - bin/tem_multi_proxy
74
+ - bin/tem_multi_proxy_query
70
75
  - CHANGELOG
76
+ - lib/tem_multi_proxy/client.rb
71
77
  - lib/tem_multi_proxy/manager.rb
78
+ - lib/tem_multi_proxy/server.rb
72
79
  - lib/tem_multi_proxy.rb
73
80
  - LICENSE
81
+ - Manifest
74
82
  - Rakefile
75
83
  - README
76
- - Manifest
77
84
  - tem_multi_proxy.gemspec
78
85
  has_rdoc: true
79
86
  homepage: http://tem.rubyforge.org