Permalink
Browse files

Large commit; run. Needs a client/server protocol badly.

  • Loading branch information...
1 parent c8e0452 commit dc209c0505def7a195bc7ca2b45661e8163ee47a @danopia committed Dec 1, 2009
Showing with 357 additions and 195 deletions.
  1. +0 −53 lib/provider.rb
  2. +31 −7 lib/server.rb
  3. +38 −0 lib/server_list.rb
  4. +6 −0 lib/utils.rb
  5. +116 −73 lib/xmpp/component.rb
  6. +11 −2 lib/xmpp/packet.rb
  7. +144 −49 lib/xmpp/waveserver.rb
  8. +1 −1 sails.rb
  9. +10 −10 xmpp_component.rb
View
53 lib/provider.rb
@@ -1,40 +1,6 @@
module Sails
-# Variation of Hash with a degree of case-insensitive keys.
-class ServerList < Hash
- attr_accessor :provider
-
- def [](server)
- return nil unless server
- super server.downcase
- end
- def []=(name, server)
- return nil unless name
- super name.downcase, server
- end
-
- def delete server
- return nil unless server
- super server.downcase
- end
-
- def << server
- self[server.domain] = server
- self[server.jid] = server
- end
-
- def by_signer_id hash
- server = values.find{|server| server.certificate_hash == hash}
- return server if server
-
- record = ::Server.find_by_signer_id Utils.encode64(hash)
- server = Server.new @provider, record.domain if record
-
- server
- end
-end
-
# Most popular class. Represents the local server and the waves on it, and
# keeps a list of external servers.
class Provider
@@ -159,25 +125,6 @@ def <<(item)
end
end
- # Init a Server connection by pinging it and sending a cert. Called for you
- # if/when you << the Server to the Provider.
- def init_server server
- return unless self.ready? && server.state == :uninited
- return if server == @local
-
- target = server.name || server.domain
- if target == 'wavesandbox.com'
- send_xml 'iq', 'get', "wave.#{target}",
- '<query xmlns="http://jabber.org/protocol/disco#info"/>'
- server.state = :listing
- server.name = "wave.#{server.domain}"
- else
- send_xml 'iq', 'get', target,
- '<query xmlns="http://jabber.org/protocol/disco#items"/>'
- server.state = :sent_item_request
- end
- end
-
# Flush all the remote servers.
def flush
return unless ready?
View
38 lib/server.rb
@@ -11,6 +11,7 @@ def initialize(provider, domain, jid=nil, init=true)
@provider = provider
@domain = domain
@jid = jid
+ @jids = []
@waves = {}
@users = {}
@queue = []
@@ -24,11 +25,8 @@ def initialize(provider, domain, jid=nil, init=true)
@certificate_hash = Utils.decode64 @record.signer_id if @record.signer_id
@jid = @record.jid if @record.jid && @jid.nil?
- if init
- provider << self
- else
- provider.servers << self
- end
+ provider.servers << self
+ disco 'items' if init
load_waves
end
@@ -74,6 +72,12 @@ def certificates64
@certificates.map {|cert| Utils::encode64 cert.to_der }
end
+ def certificate_xml
+ certificates64.map do |cert|
+ "<certificate><![CDATA[#{cert}]]></certificate>"
+ end.join ''
+ end
+
# Sets the server name.
def jid= jid
@provider.servers.delete @jid unless !@jid || @jid == @domain
@@ -83,6 +87,11 @@ def jid= jid
@record.save if @record.changed?
@jid = jid
+
+ return unless @state == :listing
+ @state = :details
+ ping
+ @jid
end
# Look up a wave.
@@ -97,7 +106,7 @@ def [](name)
def << item
if item.is_a? Array # packet
if @state == :ready
- @provider.send_xml item[0], item[1], @name, item[2], item[3]
+ @provider.send item[0], item[1], @jid, item[2], item[3]
else
@queue << item
end
@@ -119,7 +128,7 @@ def flush
return nil unless @queue && @queue.any?
@queue.each do |packet|
- @provider.send_xml packet[0], packet[1], @name, packet[2], packet[3]
+ @provider.send packet[0], packet[1], @jid, packet[2], packet[3]
end
@queue = nil
@@ -131,6 +140,21 @@ def random_wave_name(length=12)
name = Utils.random_string(length) while self[name]
name
end
+
+ def disco dance, jid=nil
+ target = jid || (dance == 'items' ? @domain : @jid)
+ @provider.disco target, dance
+ end
+
+ def ping
+ @provider.queue 'message', 'normal', @jid || @domain, '<ping xmlns="http://waveprotocol.org/protocol/0.2/waveserver"/><request xmlns="urn:xmpp:receipts"/>'
+ end
+
+ def disco_jids
+ p @state
+ @state = :listing
+ @jids.each {|jid| disco 'info', jid }
+ end
end # class
end # module
View
38 lib/server_list.rb
@@ -0,0 +1,38 @@
+
+module Sails
+
+# Variation of Hash with a degree of case-insensitive keys.
+class ServerList < Hash
+ attr_accessor :provider
+
+ def [](server)
+ return nil unless server
+ super server.downcase
+ end
+ def []=(name, server)
+ return nil unless name
+ super name.downcase, server
+ end
+
+ def delete server
+ return nil unless server
+ super server.downcase
+ end
+
+ def << server
+ self[server.domain] = server
+ self[server.jid] = server
+ end
+
+ def by_signer_id hash
+ server = values.find{|server| server.certificate_hash == hash}
+ return server if server
+
+ record = ::Server.find_by_signer_id Utils.encode64(hash)
+ server = Server.new @provider, record.domain if record
+
+ server
+ end
+end # class
+
+end # module
View
6 lib/utils.rb
@@ -50,6 +50,12 @@ def self.sha1 data
def self.sha2 data
Digest::SHA2.digest data
end
+
+ # Parse a wave://server/w+wave/wavelet address into 3 parts.
+ def self.parse_wavelet_address address
+ raise StandardError, 'invalid format' unless address =~ /^wave:\/\/(.+)\/w\+(.+)\/(.+)$/
+ [$1, $2, $3]
+ end
end
View
189 lib/xmpp/component.rb
@@ -1,100 +1,143 @@
module Sails
module XMPP
- class Component < Connection
- attr_accessor :server_host, :server_port, :subdomain, :jid, :domain, :secret, :config
-
- def self.handle name, type, &blck
- @@handlers ||= {}
- @@handlers[name] ||= {}
- @@handlers[name][type] = blck
+class Component < Connection
+ attr_accessor :server_host, :server_port, :subdomain, :jid, :domain, :secret, :config, :ready
+
+ def self.handle name, type, &blck
+ @@handlers ||= {}
+ @@handlers[name] ||= {}
+ @@handlers[name][type] = blck
+ end
+
+ def self.load_and_connect filename
+ begin
+ config = YAML.load open('sails.conf')
+ rescue
+ raise Sails::ProviderError, "Could not read the #{path} file. Make sure it exists and is proper YAML."
end
-
- def self.load_and_connect filename
- begin
- config = YAML.load open('sails.conf')
- rescue
- raise Sails::ProviderError, "Could not read the #{path} file. Make sure it exists and is proper YAML."
- end
- server_host = config['xmpp-connect-host']
- server_port = config['xmpp-connect-port'].to_i
+ server_host = config['xmpp-connect-host']
+ server_port = config['xmpp-connect-port'].to_i
- connect server_host, server_port, config
- end
-
- def me
- @jid
- end
-
- def disco target
- send 'iq', 'get', target, '<query xmlns="http://jabber.org/protocol/disco#items"/>'
- end
+ connect server_host, server_port, config
+ end
+
+ def me
+ @jid
+ end
+
+ def disco target, dance='items'
+ queue 'iq', 'get', target, "<query xmlns=\"http://jabber.org/protocol/disco##{dance}\"/>"
+ end
+
+ def receive_object packet, node
+ case packet.name
- def receive_object packet, node
- case packet.name
+ when 'stream:error'
+ error = node.children.first.name rescue nil
+ message = case error
+ when 'conflict': 'The XMPP server denied this component because it conflicts with one that is already connected.'
+ when nil: 'Unable to connect to XMPP. The server denied the component for an unknown reason.'
+ else; "Unable to connect to XMPP: #{error}"
+ end
+ raise Sails::ProviderError, message
- when 'stream:error'
- error = node.children.first.name rescue nil
+ when 'stream:stream'
+ id = packet.id
+ unless id
+ error = (node/'stream:error').first.children.first.name rescue nil
message = case error
when 'conflict': 'The XMPP server denied this component because it conflicts with one that is already connected.'
when nil: 'Unable to connect to XMPP. The server denied the component for an unknown reason.'
else; "Unable to connect to XMPP: #{error}"
end
raise Sails::ProviderError, message
+ end
- when 'stream:stream'
- id = packet.id
-
- puts "Stream opened, sending challenge response"
+ puts "Stream opened, sending challenge response"
- key = Digest::SHA1.hexdigest id + @secret
- send_raw "<handshake>#{key}</handshake>"
-
- when 'handshake'
- puts "Server accepted component; we are now live"
- disco 'acmewave.com'
- #TODO: flush queues
-
- else
- if @@handlers[packet.name] && @@handlers[packet.name][packet.type]
- @@handlers[packet.name][packet.type].call self, packet, node
- end
- end
+ key = Digest::SHA1.hexdigest id + @secret
+ send_raw "<handshake>#{key}</handshake>"
+
+ when 'handshake'
+ puts "Server accepted component; we are now live"
+ ready!
+
+ else
+ if @@handlers[packet.name] && @@handlers[packet.name][packet.type]
+ @@handlers[packet.name][packet.type].call self, packet, node
+ end
end
+ end
+
+ def start_auth
+ send_raw "<stream:stream xmlns=\"jabber:component:accept\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"#{@jid}\">"
+ end
+
+ def initialize config
+ super()
- def start_auth
- send_raw "<stream:stream xmlns=\"jabber:component:accept\" xmlns:stream=\"http://etherx.jabber.org/streams\" to=\"#{@jid}\">"
- end
+ @ready = false
+ @queue = []
- def initialize config
- super()
- load_config config
- start_auth
- end
+ load_config config
+ start_auth
+ end
+
+ def load_config config
+ @config = config
- def load_config config
- @config = config
-
- @server_host = @config['xmpp-connect-host']
- @server_port = @config['xmpp-connect-port'].to_i
+ @server_host = @config['xmpp-connect-host']
+ @server_port = @config['xmpp-connect-port'].to_i
+
+ @subdomain = @config['service-name']
+ @domain = @config['domain-name']
+ @jid = "#{@subdomain}.#{@domain}"
- @subdomain = @config['service-name']
- @domain = @config['domain-name']
- @jid = "#{@subdomain}.#{@domain}"
-
- @secret = @config['xmpp-password']
+ @secret = @config['xmpp-password']
+ end
+
+ alias ready? ready
+
+ # Marks the provider as ready and flushes all queued packets. Also starts a
+ # remote if not already started.
+ def ready!
+ return if ready?
+ @ready = true
+ flush
+ end
+
+ # Add a wave to the correct server -or- Add a server to the main list
+ def << item
+ if item.is_a? Array
+ if ready?
+ send *item
+ else
+ @queue << item
+ end
- load_certs config['certificate-chain']
- load_key config['private-key-path']
- end
-
- def load_certs paths
+ else
+ raise ArgumentError, 'expected a Server or Wave or Array' # TODO: change message
end
+ end
+
+ # Easier way to use << to queue packets
+ def queue *args
+ self << args
+ end
+
+ # Flush the packet buffer
+ def flush
+ return unless ready?
- def load_key path
+ @queue.each do |packet|
+ self << packet # send
end
+ @queue.clear
end
-end
-end
+
+end # component class
+end # xmpp module
+end # sails module
View
13 lib/xmpp/packet.rb
@@ -2,7 +2,7 @@
module Sails
module XMPP
class Packet
- attr_accessor :connection, :name, :type, :to, :from, :id, :node
+ attr_accessor :connection, :name, :type, :to, :from, :id, :node, :server
def initialize connection, xml
@connection = connection
@@ -13,10 +13,19 @@ def initialize connection, xml
@to = xml['to']
@from = xml['from']
@id = xml['id']
+
+ if @from == @connection.jid || @from.nil?
+ @server = @connection.local
+ elsif @connection.servers.keys.include? @from.downcase
+ @server = @connection.servers[@from]
+ else
+ @server = @connection.servers.values.find {|server| server.jids.include? @from}
+ @server ||= Server.new @connection, @from
+ end
end
def respond data
- @connection.send @name, 'result', @from, data, @id
+ @connection << [@name, 'result', @from, data, @id]
end
end
end
View
193 lib/xmpp/waveserver.rb
@@ -1,18 +1,126 @@
module Sails
module XMPP
class WaveServer < Component
- attr_accessor :provider
+ attr_accessor :servers, :local
def initialize config
super
+
+ @servers = ServerList.new
+
+ @servers.provider = self
+
+ @local = Server.new self, @domain, @subdomain, false
+ @local.state = :local
- @provider = Provider.new @domain, @subdomain, self
+ load_certs_and_key
#rescue => e
#puts e.class, e.message, e.backtrace
end
+ def load_certs_and_key
+ load_certs @config['certificate-chain']
+ load_key @config['private-key-path']
+ rescue Errno::ENOENT => e
+ puts "Error while loading certificate chain and private key (did you make them?):"
+ puts e.message
+ EventMachine.stop_event_loop # hehe
+ end
+
+ # Load the provider's certificate from a file.
+ def load_certs(paths)
+ @local.certificates = paths.map {|path| open(path).read }
+ end
+
+ # Load the provider's private key from a file.
+ def load_key(path)
+ @key = OpenSSL::PKey::RSA.new(open(path).read)
+ end
+
+ # Signs a chunk of data using the private key.
+ def sign data
+ @key.sign OpenSSL::Digest::SHA1.new, data
+ end
+
+ # Look up a wave.
+ #
+ # Can be passed in domain/w+name format for a certain wave, or name format
+ # to search all known waves.
+ def [](name)
+ if name =~ /^(.+)\/w\+(.+)$/
+ server = @servers[$1]
+ return nil unless server
+ server[$2]
+ else
+ # allow fallback to not specifing a domain
+
+ @servers.values.each do |server|
+ return server[name] if server[name]
+ end
+
+ nil
+ end
+ end
+
+ # Add a wave to the correct server -or- Add a server to the main list
+ def << item
+ if item.is_a? Server
+ @servers[item.domain] = item
+ init_server item
+
+ elsif item.is_a? Wave
+ (item.server || @local) << item
+
+ else
+ super # for packets
+ end
+ end
+
+ # Flush all the remote servers.
+ def flush
+ return unless ready?
+
+ super # flush self
+
+ @servers.each_value do |server|
+ if server.state != :uninited
+ server.flush
+ end
+ end
+ end
+
+ def find_or_create_wave path
+ domain, name, wavelet = Utils.parse_wavelet_address path
+
+ server = find_or_create_server domain
+ return server[name] if server[name]
+
+ wave = Wave.new self, name, server
+ self << wave
+ wave
+ end
+
+ def find_or_create_server name
+ if @servers.keys.include? name.downcase
+ @servers[name]
+ else
+ Server.new self, name
+ end
+ end
+
+ def find_or_create_user address
+ return address if address.is_a? WaveUser
+
+ username, domain = address.downcase.split '@', 2
+
+ server = find_or_create_server domain
+
+ return server.users[username] if server.users[username]
+ WaveUser.new self, address
+ end
+
+
handle 'iq', 'get' do |conn, packet, xml|
- server = conn.provider.find_or_create_server packet.from
if (xml/'query').any?
if (xml/'query').first['xmlns'].include? 'items'
packet.respond "<query xmlns=\"http://jabber.org/protocol/disco#items\"><item jid=\"#{conn.jid}\" name=\"#{conn.config['identity']}\"/></query>"
@@ -23,7 +131,7 @@ def initialize config
puts "#{packet.from} requested some deltas"
node = (xml/'pubsub/items/delta-history').first
- wave = conn.provider.find_or_create_wave node['wavelet-name']
+ wave = conn.find_or_create_wave node['wavelet-name']
wave.boom = true if wave.deltas.size == 1 && wave.local?
payload = ''
@@ -32,8 +140,8 @@ def initialize config
until version > node['end-version'].to_i
delta = wave[version]
version = delta.version
- if delta.is_a? Sails::Delta
- payload << "<item><applied-delta xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\"><![CDATA[#{Sails::Utils.encode64 delta.to_applied}]]></applied-delta></item>"
+ if delta.is_a? Delta
+ payload << "<item><applied-delta xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\"><![CDATA[#{Utils.encode64 delta.to_applied}]]></applied-delta></item>"
end
version += 1
end
@@ -50,17 +158,13 @@ def initialize config
puts "#{packet.from} requested a certificate"
node = (xml/'pubsub/items/signer-request').first
- hash = decode64 node['signer-id']
- server = conn.provider.servers.by_signer_id hash
+ hash = Utils.decode64 node['signer-id']
+ server = conn.servers.by_signer_id hash
if server
puts "Sending a cert to #{packet.from} on request, for #{server.domain}"
- payload = server.certificates64.map do |cert|
- "<certificate><![CDATA[#{cert}]]></certificate>"
- end.join ''
-
- packet.respond "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><items><signature xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" domain=\"#{server.certificates.first.subject['CN']}\" algorithm=\"SHA256\">#{payload}</signature></items></pubsub>"
+ packet.respond "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><items><signature xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" domain=\"#{server.certificates.first.subject['CN']}\" algorithm=\"SHA256\">#{server.certificate_xml}</signature></items></pubsub>"
else
puts 'Couldn\'t find the signer ID.' # TODO: Send error packet
end
@@ -69,20 +173,18 @@ def initialize config
end
handle 'iq', 'result' do |conn, packet, xml|
- server = conn.provider.find_or_create_server packet.from
if (xml/'query').any?
- if (xml/'query').first['xmlns'].include? 'items'
- puts "Got service listing from #{packet.from}:"
- (xml/'item').each do |node|
- conn.send 'iq', 'get', node['jid'], "<query xmlns=\"http://jabber.org/protocol/disco#info\" />"
- end
+ if (xml/'query[@xmlns=http://jabber.org/protocol/disco#items]').any?
+ puts "Got service listing from #{packet.from}, inviting the services to a disco party"
+ # at danopia's house, of course (i have a disco ball)
+ packet.server.jids = (xml/'item').map {|node| node['jid']}
+ packet.server.disco_jids
else
node = (xml/'query/identity').first
if (xml/'feature[@var=http://waveprotocol.org/protocol/0.2/waveserver]').any?
- server.state = :details
puts "#{packet.from} is Google Wave service (#{node['name']}), sending ping (state = :details)"
- conn.send 'message', 'normal', packet.from, '<ping xmlns="http://waveprotocol.org/protocol/0.2/waveserver"/><request xmlns="urn:xmpp:receipts"/>'
+ packet.server.jid = packet.from
else
puts "#{packet.from} does not have the Google Wave feature."
end
@@ -92,14 +194,14 @@ def initialize config
node = (xml/'signature').first
puts "Got a cert from #{packet.from} for #{node['domain']}"
- server = conn.provider.find_or_create_server node['domain']
+ server = conn.find_or_create_server node['domain']
server.domain = node['domain']
server.certificates = (node/'certificate').map do |cert|
cert.inner_text
end
- conn.provider.remote.all_waves.each do |wave|
+ conn.remote.all_waves.each do |wave|
wave.deltas.each_value do |delta|
next unless delta.is_a? Sails::Delta
delta.server = server if delta.signer_id == server.certificate_hash
@@ -108,10 +210,10 @@ def initialize config
end
elsif (xml/'pubsub/publish/item/signature-response').any?
- if server.state == :ponged
- server.state = :ready
+ if packet.server.state == :ponged
+ packet.server.state = :ready
puts "#{packet.from} ACK'ed my cert, now to flush the queue (state = :ready)"
- server.flush
+ packet.server.flush
else
puts "#{packet.from} ACK'ed my cert."
@@ -124,7 +226,7 @@ def initialize config
puts "Got history for #{wave.name}"
(packet/'pubsub/items/item/applied-delta').each do |update|
- delta = Sails::Delta.parse(conn.provider, wave.conv_root_path, Sails::Utils.decode64(update.inner_text), true)
+ delta = Sails::Delta.parse(conn, wave.conv_root_path, Sails::Utils.decode64(update.inner_text), true)
puts "Got a delta, version #{delta.version}"
end
@@ -136,22 +238,21 @@ def initialize config
end
handle 'iq', 'set' do |conn, packet, xml|
- server = conn.provider.find_or_create_server packet.from
if (xml/'certificate').any?
node = (xml/'signature').first
puts "Got a cert from #{node['domain']}"
- server.domain = node['domain']
- server.certificates = (node/'certificate').map do |cert|
+ packet.server.domain = node['domain']
+ packet.server.certificates = (node/'certificate').map do |cert|
cert.inner_text
end
- conn.provider.remote.all_waves.each do |wave|
+ conn.remote.all_waves.each do |wave|
wave.deltas.each_value do |delta|
next unless delta.is_a? Sails::Delta
- next unless delta.signer_id == server.certificate_hash
- next if delta.server == server
- delta.server = server
+ next unless delta.signer_id == packet.server.certificate_hash
+ next if delta.server == packet.server
+ delta.server = packet.server
puts "Changed server for #{wave.conv_root_path} ##{delta.version}."
end
end
@@ -169,19 +270,14 @@ def initialize config
end
handle 'message', 'normal' do |conn, packet, xml|
- server = conn.provider.find_or_create_server packet.from
xml.children.each do |message|
subtype = message.name
if subtype == 'received'
- if server.state == :details
- server.state = :ponged
+ if packet.server.state == :details
+ packet.server.state = :ponged
puts "#{packet.from} ponged, attempting to send my cert (state = :ponged)"
- payload = conn.provider.local.certificates64.map do |cert|
- "<certificate><![CDATA[#{cert}]]></certificate>"
- end.join ''
-
- conn.send 'iq', 'set', packet.from, "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><publish node=\"signer\"><item><signature xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" domain=\"#{conn.provider.domain}\" algorithm=\"SHA256\">#{payload}</signature></item></publish></pubsub>"
+ conn.send 'iq', 'set', packet.from, "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><publish node=\"signer\"><item><signature xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" domain=\"#{conn.domain}\" algorithm=\"SHA256\">#{conn.local.certificate_xml}</signature></item></publish></pubsub>"
else
puts "#{packet.from} ACK'ed our previous packet."
@@ -194,7 +290,7 @@ def initialize config
(xml/'event/items/item/wavelet-update').each do |update|
next unless (update/'applied-delta').any?
- delta = Sails::Delta.parse(conn.provider, update['wavelet-name'], Sails::Utils.decode64(update.inner_text), true)
+ delta = Delta.parse(conn, update['wavelet-name'], Utils.decode64(update.inner_text), true)
puts "Got delta version #{delta.version rescue -1}"
wave = delta.wave if delta
end
@@ -212,17 +308,16 @@ def initialize config
end
handle 'iq', 'error' do |conn, packet, xml|
- server = conn.provider.find_or_create_server packet.from
if (xml/'remote-server-not-found').any?
- if "wave.#{server.domain}" == server.name
+ if "wave.#{packet.server.domain}" == packet.server.name
puts "Already tried the wave. trick on #{packet.from}. (state = :error)"
- server.state = :error
+ packet.server.state = :error
else
puts "Trying the wave. trick on #{packet.from}. (state = :listing)"
- server.name = "wave.#{server.domain}"
- server.state = :listing
- packet.conn.send 'iq', 'get', server.name, '<query xmlns="http://jabber.org/protocol/disco#info"/>'
+ packet.server.name = "wave.#{packet.server.domain}"
+ packet.server.state = :listing
+ packet.server.disco 'info'
end
else
View
2 sails.rb
@@ -1,7 +1,7 @@
# Includes the lib/ files: wave_proto utils delta_builder operations playback provider
# server remote wave blip annotation thread base_delta fake_delta delta database wave_user
-%w{wave_proto utils delta_builder operations playback provider server remote wave blip annotation thread base_delta fake_delta delta database wave_user}.each do |file|
+%w{wave_proto utils delta_builder operations playback server wave blip annotation thread base_delta fake_delta delta database wave_user server_list}.each do |file|
require File.join(File.dirname(__FILE__), 'lib', file)
end
View
20 xmpp_component.rb
@@ -6,21 +6,16 @@
require 'sails'
-require 'agents/echoey'
+#require 'agents/echoey'
Sails::Utils.connect_db
-#if config['ping']
- #puts "Sending a ping to #{config['ping']} due to configoration."
- #provider << Sails::Server.new(provider, config['ping'], config['ping'])
+#trap("INT") do
+# provider.remote.stop_service
+# puts 'OBAI'
+# exit
#end
-trap("INT") do
- provider.remote.stop_service
- puts 'OBAI'
- exit
-end
-
#Thread.new do
#provider.send_data ' ' while sleep 60
#end
@@ -34,4 +29,9 @@
EventMachine.run {
provider = Sails::XMPP::WaveServer.load_and_connect 'sails.conf'
+
+ if provider.config['ping']
+ puts "Sending a ping to #{provider.config['ping']} due to configuration."
+ Sails::Server.new(provider, provider.config['ping'], provider.config['ping'])
+ end
}

0 comments on commit dc209c0

Please sign in to comment.