diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/receiver/start.rb | 6 | ||||
-rw-r--r-- | lib/receiver/worker.rb | 22 |
2 files changed, 15 insertions, 13 deletions
diff --git a/lib/receiver/start.rb b/lib/receiver/start.rb deleted file mode 100644 index 476c866..0000000 --- a/lib/receiver/start.rb +++ /dev/null @@ -1,6 +0,0 @@ -Receiver::Worker.spawn!({:working_dir => Rails.root, - :pid_file => File.join(Rails.root, "tmp", "pids", "receiver.pid"), - :log_file => File.join(Rails.root, "log", "receiver.log"), - :sync_log => true, - :singleton => true}) - diff --git a/lib/receiver/worker.rb b/lib/receiver/worker.rb index 7c2c11e..860d890 100644 --- a/lib/receiver/worker.rb +++ b/lib/receiver/worker.rb @@ -112,11 +112,16 @@ class Receiver::Worker < DaemonSpawn::Base arg = line.split(/ /, 2) case arg.first when "CONNECT" - ff = arg.last.split(/&/) - secret_token = ff[0] - worker_number = ff[1].to_i - worker_count = ff[2].to_i - if secret_token == Settings.secret_key + begin + json = ::Yajl::Parser.parse(arg.last, :symbolize_keys => true) + rescue ::Yajl::ParseError + # JSON parse error....?? + p $! + end + secret_key = json[:secret_key] + worker_number = json[:worker_number] + worker_count = json[:worker_count] + if secret_key == Settings.secret_key if $worker_count != worker_count && $connections.size > 0 $logger.error("Error: Worker Count Difference: $worker_count=#{$worker_count}, worker_count=#{worker_count}") send_chunk("ERROR Invalid Worker Count") @@ -125,13 +130,14 @@ class Receiver::Worker < DaemonSpawn::Base $worker_count = worker_count $connections[worker_number] = self @worker_number = worker_number + @authorized = true $logger.info("Connected: #{worker_number}") send_chunk("OK Connected") send_account_all end else $logger.error("Error: Invalid Secret Key") - send_chunk("ERROR Invalid Secret Token") + send_chunk("ERROR Invalid Secret Key") close_connection_after_writing end when "UNAUTHORIZED" @@ -142,7 +148,9 @@ class Receiver::Worker < DaemonSpawn::Base send_chunk("BYE") close_connection_after_writing else - @@wq.push arg + if @authorized + @@wq.push arg + end end end end |