lib/envoy/server/trunk.rb in envoy-proxy-0.0.12 vs lib/envoy/server/trunk.rb in envoy-proxy-0.0.14
- old
+ new
@@ -3,10 +3,15 @@
module Envoy
module Server
module Trunk
include Protocol
+ def initialize key
+ super
+ @key = key
+ end
+
def self.trunks
@trunks ||= Hash.new{|h,k|h[k] = []}
end
def hosts
@@ -37,17 +42,22 @@
def key
@options[:key]
end
- def halt
+ def halt message = nil
+ send_object :message, message if message
send_object :halt
close_connection(true)
end
def receive_options options
@options = options
+ if @key and @key != @options[:key]
+ halt "Key is invalid"
+ return
+ end
hosts = @options[:hosts] || []
hosts.any? do |label|
if label == "s"
send_object :message, "#{label}: label is reserved"
true
@@ -65,12 +75,14 @@
m = ["#{options[:local_host]}:#{options[:local_port]} now available at:"]
@hosts = hosts.each do |host|
Trunk.trunks[host] << self
m << "http://#{host}.#{$zone}/"
end
- @options[:key] ||= SecureRandom.hex(8)
send_object :message, m.join(" ")
- send_object :message, "Your key is #{@options[:key]}"
+ unless @options[:key]
+ @options[:key] ||= SecureRandom.hex(8)
+ send_object :message, "Your key is #{@options[:key]}"
+ end
end
def unbind
hosts.each do |host|
Trunk.trunks[host].delete self