Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Persistance saves; loading is not fully implemented. If you migrated …

…the last commit (the one that added groups) then you _must_ cd to rails/ and run 'rake db:migrate:redo'. Other than that, enjoy for now.
  • Loading branch information...
commit 235f168055499024ddd0e1ed9a77c748abd093db 1 parent 936085e
@danopia authored
View
28 lib/database.rb
@@ -1,22 +1,38 @@
require 'rubygems'
-require 'active_record'
require 'yaml'
module Sails
-class Database
+module Utils
+
+ def self.connect_db
+ require 'active_record'
+ require 'logger'
- def self.connect
dbconfig = YAML.load(open(File.join(File.dirname(__FILE__), '..', 'database.yml')))
dbconfig = dbconfig['development']
dbconfig['database'] = 'rails/' + dbconfig['database'] if dbconfig['adapter'] == 'sqlite'
ActiveRecord::Base.establish_connection dbconfig
+ ActiveRecord::Base.logger = Logger.new(STDERR)
+
+ load_models
- require 'authlogic'
- require 'models/user'
+ true
end
-end # class
+ def self.load_models
+ return if @models_loaded
+ @models_loaded = true
+
+ require 'authlogic' # for the User model
+
+ #require File.join(File.dirname(__FILE__), '..', 'models', 'server')
+
+ Dir.glob(File.join(File.dirname(__FILE__), '..', 'models', '*.rb')).each do |model|
+ require model
+ end
+ end
+end
end # module
View
59 lib/delta.rb
@@ -4,7 +4,7 @@ module Sails
# Represents a version of a wavelet where the provider has details (as opposed
# to FakeDelta).
class Delta < BaseDelta
- attr_accessor :author, :time, :applied, :signature, :server, :signer_id, :commited
+ attr_accessor :author, :time, :applied, :signature, :server, :signer_id, :commited, :record
# Frozen deltas are considered to be unchanging, so the byte form is cached
# to greatly speed up the creation of packets.
@@ -22,6 +22,11 @@ def initialize wave, author=nil
@frozen = false
self.server = wave.provider.local
+ @record = @wave.record.deltas.build :applied_to => @version,
+ :version => @version,
+ :server => @server.record,
+ :signer_id => Utils.encode64(@signer_id)
+
super wave, @version
end
@@ -32,6 +37,13 @@ def server= server
@server = server
@signer_id = server.certificate_hash if server
+
+ if @record
+ @record.signer_id = Utils.encode64 @signer_id
+ @record.server = (@server.record rescue nil)
+ end
+
+ @signer_id
end
def local?
@@ -42,9 +54,21 @@ def author=(author)
author = "#{author.login}@#{@wave.provider.domain}" if author.is_a? User
author = @wave.provider.find_or_create_user author unless author.is_a? WaveUser
+ if @record
+ @record.author = author.address
+ @record.server = author.server.record
+ @record.user = author.account
+ end
+
@author = author
end
+ def time=(stamp)
+ @record.applied_at = stamp if @record
+
+ @time = stamp
+ end
+
# Parses an incoming delta, taking the wavelet name (from the XML attribute)
# and the bytestring (doesn't handle Base64). It will handle adding the delta
# to a wave, creating the wave if it doesn't exist, and sending out the delta
@@ -68,7 +92,8 @@ def self.parse provider, wavelet, data, applied=false
delta.time = timestamp if timestamp
delta.signature = data[:signature][:signature]
- delta.server = provider.servers.by_signer_id data[:signature][:signer_id]
+ delta.server = provider.servers.by_signer_id(data[:signature][:signer_id])
+ delta.server ||= wave.server if wave.boom
delta.signer_id = data[:signature][:signer_id]
applied_to = delta.wave[delta.version]
@@ -99,7 +124,7 @@ def self.parse provider, wavelet, data, applied=false
if wave.boom
puts "Sending back the delta as applied, even though the wave went boom."
- delta.server << ['message', 'normal', "<request xmlns=\"urn:xmpp:receipts\"/><event xmlns=\"http://jabber.org/protocol/pubsub#event\"><items><item><wavelet-update xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" wavelet-name=\"#{wave.conv_root_path}\"><applied-delta><![CDATA[#{encode64(delta.to_applied)}]]></applied-delta></wavelet-update></item></items></event>"]
+ delta.server << ['message', 'normal', "<request xmlns=\"urn:xmpp:receipts\"/><event xmlns=\"http://jabber.org/protocol/pubsub#event\"><items><item><wavelet-update xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" wavelet-name=\"#{wave.conv_root_path}\"><applied-delta><![CDATA[#{Utils.encode64(delta.to_applied)}]]></applied-delta></wavelet-update></item></items></event>"]
return delta
end
@@ -114,6 +139,9 @@ def self.parse provider, wavelet, data, applied=false
# Add an operation to the delta.
def << operation
@operations << operation
+
+ @record.version = @version + 1 if @record
+
@version += 1
end
@@ -142,9 +170,9 @@ def prev_version
def signature
return @signature if @signature
if @frozen
- return @signature = @wave.provider.sign(delta_raw)
+ @signature = @wave.provider.sign delta_raw
else
- return @wave.provider.sign(delta_raw)
+ @wave.provider.sign delta_raw
end
end
@@ -152,14 +180,6 @@ def signature
# deltas to a wave's master server.
def to_s
return @to_s if @to_s && @frozen
- pp ({
- :delta => delta_data,
- :signature => {
- :signature => signature,
- :signer_id => @signer_id,
- :signer_id_alg => 1 # 1 = RSA
- }
- })
@to_s = Sails::ProtoBuffer.encode(:signed_delta, {
:delta => delta_data,
:signature => {
@@ -190,7 +210,7 @@ def prev_hash
# Hash the delta, using SHA2 and trimming down the length of SHA1.
def hash
return @hash if @hash && @frozen
- @hash = Digest::SHA2.digest("#{prev_hash}#{to_applied}")[0,20]
+ @hash = Utils::sha2("#{prev_hash}#{to_applied}")[0,20]
end
# Freeze the delta for optimal speed once there aren't going to be any more
@@ -203,6 +223,15 @@ def freeze
@hash = nil
@to_s = nil
@to_applied = nil
+
+ if @record
+ @record.version = @version
+ @record.raw = Utils.encode64 self.delta_raw
+ @record.signature = Utils.encode64 self.signature
+ @record.current_hash = Utils.encode64 self.hash
+ @record.applied_at = self.time
+ @record.save
+ end
end
alias commited? commited
@@ -238,7 +267,7 @@ def commit!
unless targets.empty?
- packet = "<request xmlns=\"urn:xmpp:receipts\"/><event xmlns=\"http://jabber.org/protocol/pubsub#event\"><items><item><wavelet-update xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" wavelet-name=\"#{@wave.conv_root_path}\"><applied-delta><![CDATA[#{encode64(to_applied)}]]></applied-delta></wavelet-update></item></items></event>"
+ packet = "<request xmlns=\"urn:xmpp:receipts\"/><event xmlns=\"http://jabber.org/protocol/pubsub#event\"><items><item><wavelet-update xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" wavelet-name=\"#{@wave.conv_root_path}\"><applied-delta><![CDATA[#{Utils.encode64(to_applied)}]]></applied-delta></wavelet-update></item></items></event>"
puts "Sending to #{targets.join(', ')}"
View
14 lib/provider.rb
@@ -3,6 +3,8 @@ 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
@@ -23,7 +25,13 @@ def << server
end
def by_signer_id hash
- values.select{|server| server.certificate_hash == hash}.first
+ 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
@@ -38,10 +46,12 @@ def initialize(domain, subdomain='wave', sock=nil)
@domain = domain
@name = "#{subdomain}#{domain}"
- @servers = ServerList.new self
+ @servers = ServerList.new
@sock = sock
@packet_ids = {}
@ready = false
+
+ @servers.provider = self
@local = Server.new self, @domain, @name, false
@local.state = :local
View
38 lib/server.rb
@@ -4,7 +4,7 @@ module Sails
# Represents a server, remote or local, and tracks certificates, waves, and the
# queue of packets to send to a server once a connection is established.
class Server
- attr_accessor :provider, :certificates, :certificate_hash, :domain, :name, :waves, :queue, :state, :users
+ attr_accessor :provider, :certificates, :certificate_hash, :domain, :name, :waves, :queue, :state, :users, :record
# Create a new server.
def initialize(provider, domain, name=nil, init=true)
@@ -17,6 +17,15 @@ def initialize(provider, domain, name=nil, init=true)
@state = :uninited
@certificates = []
+ @record = ::Server.find_by_domain domain
+ @record ||= ::Server.find_by_jid name || domain
+ @record ||= ::Server.create :domain => domain, :jid => name
+
+ @certificate_hash = Utils.decode64 @record.signer_id if @record.signer_id
+ @name = @record.jid if @record.jid && @name.nil?
+
+ load_waves
+
if init
provider << self
else
@@ -24,6 +33,13 @@ def initialize(provider, domain, name=nil, init=true)
end
end
+ def load_waves
+ return unless @record
+ @record.waves.each do |wave|
+ p wave
+ end
+ end
+
def certificate= cert
self.certificates = [cert]
end
@@ -42,19 +58,27 @@ def certificates= certs
cert
end
sequence = OpenSSL::ASN1::Sequence.new(@certificates.reverse)
- @certificate_hash = sha2 sequence.to_der
+ @certificate_hash = Utils::sha2 sequence.to_der
+
+ @record.signer_id = Utils.encode64 @certificate_hash
+ @record.save if @record.changed?
+
+ @certificate_hash
end
# Returns Base64-encoded certificates, ready for sending in XML packets.
def certificates64
- @certificates.map {|cert| encode64 cert.to_der }
+ @certificates.map {|cert| Utils::encode64 cert.to_der }
end
# Sets the server name.
- def name=(new_name)
+ def name= new_name
@provider.servers.delete @name unless !@name || @name == @domain
@provider.servers[new_name] = self
+ @record.jid = new_name
+ @record.save if @record.changed?
+
@name = new_name
end
@@ -67,7 +91,7 @@ def [](name)
end
# Add a wave to the server's listing -or- queue/send a packet.
- def <<(item)
+ def << item
if item.is_a? Array # packet
if @state == :ready
@provider.send_xml item[0], item[1], @name, item[2], item[3]
@@ -100,8 +124,8 @@ def flush
# Create a unique wave name, accross all waves known to this server
def random_wave_name(length=12)
- name = random_string(length)
- name = random_string(length) while self[name]
+ name = Utils.random_string(length)
+ name = Utils.random_string(length) while self[name]
name
end
end # class
View
46 lib/utils.rb
@@ -25,13 +25,31 @@ def to_hash
module Sails
- class Utils
+ module Utils
# Generate a random alphanumeric string
- def self.random_string(length=12)
+ def self.random_string length=12
@letters ||= ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
([''] * length).map { @letters[rand * @letters.size] }.join('')
end
+
+ # Base64-encode the data with no newlines in the output.
+ def self.encode64 data
+ Base64.encode64(data).gsub("\n", '')
+ end
+ # Base64-decode the data.
+ def self.decode64 data
+ Base64.decode64(data)
+ end
+
+ # SHA1-digest the data. Returns a byte string.
+ def self.sha1 data
+ Digest::SHA1.digest data
+ end
+ # SHA256-digest the data. Returns a byte string.
+ def self.sha2 data
+ Digest::SHA2.digest data
+ end
end
@@ -41,28 +59,4 @@ class Error < RuntimeError; end
# Triggered by the provider code only.
class ProviderError < Error; end
- # Base64-encode the data with no newlines in the output.
- def encode64 data
- Base64.encode64(data).gsub("\n", '')
- end
- # Base64-decode the data.
- def decode64 data
- Base64.decode64(data)
- end
-
- # SHA1-digest the data. Returns a byte string.
- def sha1 data
- Digest::SHA1.digest data
- end
- # SHA256-digest the data. Returns a byte string.
- def sha2 data
- Digest::SHA2.digest data
- end
-
- # Generate a random alphanumeric string
- def random_string(length=12)
- @letters ||= ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
- ([''] * length).map { @letters[rand * @letters.size] }.join('')
- end
-
end
View
7 lib/wave.rb
@@ -3,7 +3,7 @@ module Sails
# Represents a Wave, either local or remote.
class Wave < Playback
- attr_accessor :provider, :server, :name, :deltas, :boom
+ attr_accessor :provider, :server, :name, :deltas, :boom, :record
# Create a new wave. +name+ defaults to a random value and +host+ defaults
# to the local provider's name.
@@ -17,6 +17,9 @@ def initialize(provider, name=nil, server=nil)
end
@server = server || provider.local
+ @record = @server.record.waves.find_by_name @name
+ @record ||= @server.record.waves.create(:name => @name)
+
super self
self << FakeDelta.new(self)
@@ -87,7 +90,7 @@ def request_history first=nil, last=nil
p first
p last
- @server << ['iq', 'get', "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><items node=\"wavelet\"><delta-history xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" start-version=\"#{first[0]}\" start-version-hash=\"#{encode64(first[1])}\" end-version=\"#{last[0]}\" end-version-hash=\"#{encode64(last[1])}\" wavelet-name=\"#{self.conv_root_path}\"/></items></pubsub>", "100-#{@name}"]
+ @server << ['iq', 'get', "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><items node=\"wavelet\"><delta-history xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" start-version=\"#{first[0]}\" start-version-hash=\"#{Utils.encode64(first[1])}\" end-version=\"#{last[0]}\" end-version-hash=\"#{Utils.encode64(last[1])}\" wavelet-name=\"#{self.conv_root_path}\"/></items></pubsub>", "100-#{@name}"]
end
def request_cert delta, signer_id=nil
View
122 rack.ru
@@ -2,7 +2,7 @@ require 'pp'
require 'sails'
puts "Connecting to the database"
-#Sails::Database.connect
+#Sails::Utils.connect_db
module Sails
@@ -12,14 +12,12 @@ class RackAdapter
end
def connect
- return if @remote
- @remote = Remote.connect
- DRb.start_service
+ @remote ||= Remote.connect
end
def call(env)
response = @rails.call env
- return response unless (200..299).include? response[0]
+ return response unless (200..299).include? response[0] || response[2].to_s != 'OK'
response[2].close # release rails, let it work for other requests
connect # to the remote
@@ -34,66 +32,64 @@ class RackAdapter
interval = 0.1
timer = EventMachine::PeriodicTimer.new(interval) do
- elapsed += interval
- if elapsed > 5 || @remote[name].newest_version > version
- timer.cancel
+ next if (elapsed += interval) <= 5 && @remote[name].newest_version <= version
+
+ timer.cancel
- body = []
- if @remote[name].newest_version > version
- @wave = @remote[name]
- #version = @wave.newest_version
- until version == @remote[name].newest_version
- delta = @wave[version + 1]
- version = delta.version
-
- delta.operations.each do |operation|
- if operation.is_a? Operations::Mutate
- unless operation.document_id == 'conversation'
- blip = @wave.blips[operation.document_id]
- parent = blip.parent_blip
- parent = if parent
- "'#{parent.name}'"
- else
- 'undefined'
- end
-
- authors = blip.authors.map {|author| author.to_html }
-
- body << "update_blip('#{blip.name}', #{parent}, '#{authors.join(', ')}', \"#{escape_js blip.to_xml}\");"
- end # unless
- elsif operation.is_a? Operations::RemoveUser
- operation.who.each do |who|
- body << "remove_user('#{who}');"
- end # each
- else#if operation.is_a? Operations::AddUser
- operation.who.each do |who|
- html = who.to_s
- html = who.to_html if who.respond_to? :to_html
- body << "add_user('#{who}', '#{html}');"
- end # each
- end # if
- end # each
- end # until
- end # if
+ body = []
+ if @remote[name].newest_version > version
+ @wave = @remote[name]
+ #version = @wave.newest_version
+ until version == @remote[name].newest_version
+ delta = @wave[version + 1]
+ version = delta.version
+
+ delta.operations.each do |operation|
+ if operation.is_a? Operations::Mutate
+ unless operation.document_id == 'conversation'
+ blip = @wave.blips[operation.document_id]
+ parent = blip.parent_blip
+ parent = if parent
+ "'#{parent.name}'"
+ else
+ 'undefined'
+ end
+
+ authors = blip.authors.map {|author| author.to_html }
+
+ body << "update_blip('#{blip.name}', #{parent}, '#{authors.join(', ')}', \"#{escape_js blip.to_xml}\");"
+ end # unless
+ elsif operation.is_a? Operations::RemoveUser
+ operation.who.each do |who|
+ body << "remove_user('#{who}');"
+ end # each
+ else#if operation.is_a? Operations::AddUser
+ operation.who.each do |who|
+ html = who.to_s
+ html = who.to_html if who.respond_to? :to_html
+ body << "add_user('#{who}', '#{html}');"
+ end # each
+ end # if
+ end # each
+ end # until
+ end # if
- body << "version = #{version};"
-
- env['async.callback'].call [200, {
- 'Cache-Control' => 'no-cache',
- 'Content-Type' => 'text/javascript; charset=utf-8',
- }, body.uniq.join("\n")]
-
- env['rack.errors'].write %{%s - %s [%s] "%s %s%s %s" %d\n} % [
- env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
- env["REMOTE_USER"] || "-",
- Time.now.strftime("%d/%b/%Y %H:%M:%S"),
- env["REQUEST_METHOD"],
- env["PATH_INFO"],
- env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
- env["HTTP_VERSION"],
- 200 ]
-
- end # timer block
+ body << "at_version(#{version});"
+
+ env['async.callback'].call [200, {
+ 'Cache-Control' => 'no-cache',
+ 'Content-Type' => 'text/javascript; charset=utf-8',
+ }, body.uniq.join("\n")]
+
+ env['rack.errors'].write %{%s - %s [%s] "%s %s%s %s" %d\n} % [
+ env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
+ env["REMOTE_USER"] || "-",
+ Time.now.strftime("%d/%b/%Y %H:%M:%S"),
+ env["REQUEST_METHOD"],
+ env["PATH_INFO"],
+ env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
+ env["HTTP_VERSION"],
+ 200 ]
end # on elapsed
View
2  rails/app/controllers/groups_controller.rb
@@ -1,6 +1,6 @@
class GroupsController < ApplicationController
before_filter :require_user, :except => ['index', 'show']
- #before_filter :connect_remote
+ before_filter :connect_remote
# GET /groups
# GET /groups.xml
View
2  rails/app/models/group.rb
@@ -1,7 +1,7 @@
class Group < ActiveRecord::Base
#belongs_to :owner, :source => :user, :class_name => :user
belongs_to :user
- has_many :memberships
+ has_many :memberships, :dependent => :destroy
has_many :users, :through => :memberships
def addresses
View
2  rails/app/models/server.rb
@@ -1,4 +1,4 @@
class Server < ActiveRecord::Base
- has_many :waves
+ has_many :waves, :class_name => 'Wave'
has_many :deltas
end
View
12 rails/app/views/waves/show.html.erb
@@ -16,10 +16,7 @@
</p>
<hr/>
-<p><strong><a name="contents">Contents</a></strong></p>
-<div id="contents">
-<%#= @html %>
-</div>
+<div id="contents"></div>
<%= form_remote_tag :url => wave_update_path(@wave.name), :complete => "submitted();", :html => {'id' => 'add-form'} %>
@@ -28,6 +25,8 @@
<%= submit_tag "Add new blip" %>
</form>
+<p id="version"></p>
+
<script type="text/javascript" src="/javascripts/prototype.js"></script>
<script type="text/javascript">
@@ -125,4 +124,9 @@ function remove_user(address) {
participants.removeChild(node);
}
+function at_version(new_v) {
+ document.getElementById('version').innerHTML = 'At version ' + new_v;
+ version = new_v;
+}
+
</script>
View
10 rails/db/migrate/002_create_lotsa_tables.rb
@@ -18,6 +18,8 @@ def self.up
create_table :groups do |t|
t.references :user
+ t.integer :user_count, :defualt => 0
+
t.string :address, :null => false
t.string :title, :null => false
t.text :description
@@ -47,10 +49,14 @@ def self.up
t.references :server # host, nil=local
t.references :user # author, if local
- t.string :author, :null => false
- t.string :signer_id, :null => false
+ t.integer :applied_at
+ t.integer :applied_to
+ t.integer :version
+ t.string :author
+ t.string :signer_id
t.string :raw
t.string :signature
+ t.string :current_hash
t.timestamps
end
View
11 rails/db/schema.rb
@@ -18,19 +18,24 @@
end
create_table "deltas", :force => true do |t|
- t.integer "wave_id", :null => false
+ t.integer "wave_id", :null => false
t.integer "server_id"
t.integer "user_id"
- t.string "author", :null => false
- t.string "signer_id", :null => false
+ t.integer "applied_at"
+ t.integer "applied_to"
+ t.integer "version"
+ t.string "author"
+ t.string "signer_id"
t.string "raw"
t.string "signature"
+ t.string "current_hash"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "groups", :force => true do |t|
t.integer "user_id"
+ t.integer "user_count"
t.string "address", :null => false
t.string "title", :null => false
t.text "description"
View
27 xmpp_component.rb
@@ -5,12 +5,11 @@
require 'yaml'
require 'sails'
-include Sails
require 'agents/echoey'
puts "Connecting to the database"
-Sails::Database.connect
+Sails::Utils.connect_db
puts "Loading config"
begin
@@ -18,7 +17,7 @@
rescue
raise Sails::ProviderError, 'Could not read the sails.conf file. Make sure it exists and is proper YAML.'
end
-provider = Provider.new config['domain-name'], config['service-name']
+provider = Sails::Provider.new config['domain-name'], config['service-name']
begin
provider.connect_sock config['xmpp-connect-host'], config['xmpp-connect-port'].to_i
@@ -35,7 +34,7 @@
if config['ping']
puts "Sending a ping to #{config['ping']} due to configoration."
- provider << Server.new(provider, config['ping'], config['ping'])
+ provider << Sails::Server.new(provider, config['ping'], config['ping'])
end
provider.send_data '<stream:stream xmlns="jabber:component:accept" xmlns:stream="http://etherx.jabber.org/streams" to="' + provider.name + '">'
@@ -50,7 +49,7 @@
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 ProviderError, message
+ raise Sails::ProviderError, message
end
key = Digest::SHA1.hexdigest(id + config['xmpp-password'])
@@ -113,8 +112,8 @@
until version > node['end-version'].to_i
delta = wave[version]
version = delta.version
- if delta.is_a? Delta
- payload << "<item><applied-delta xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\"><![CDATA[#{encode64 delta.to_applied}]]></applied-delta></item>"
+ 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>"
end
version += 1
end
@@ -132,7 +131,7 @@
node = (packet/'pubsub/items/signer-request').first
hash = decode64 node['signer-id']
- server = provider.servers.by_signer_id hash
+ server = provider.servers.by_signer_id hash
if server
puts "Sending a cert to #{from} on request, for #{server.domain}"
@@ -160,7 +159,7 @@
provider.remote.all_waves.each do |wave|
wave.deltas.each_value do |delta|
- next unless delta.is_a? Delta
+ next unless delta.is_a? Sails::Delta
next unless delta.signer_id == server.certificate_hash
next if delta.server == server
delta.server = server
@@ -174,9 +173,9 @@
puts "Publish request from #{from} for one of my waves"
node = (packet/'publish/item/submit-request/delta').first
p decode64(node.inner_text)
- delta = Delta.parse(provider, node['wavelet-name'], decode64(node.inner_text))
+ delta = Sails::Delta.parse(provider, node['wavelet-name'], Sails::Utils.decode64(node.inner_text))
- provider.send_xml 'iq', id, from, "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><publish><item><submit-response xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" application-timestamp=\"#{delta.time}\" operations-applied=\"#{delta.operations.size}\"><hashed-version history-hash=\"#{encode64 delta.hash}\" version=\"#{delta.version}\"/></submit-response></item></publish></pubsub>"
+ provider.send_xml 'iq', id, from, "<pubsub xmlns=\"http://jabber.org/protocol/pubsub\"><publish><item><submit-response xmlns=\"http://waveprotocol.org/protocol/0.2/waveserver\" application-timestamp=\"#{delta.time}\" operations-applied=\"#{delta.operations.size}\"><hashed-version history-hash=\"#{Sails::Utils.encode64 delta.hash}\" version=\"#{delta.version}\"/></submit-response></item></publish></pubsub>"
end
when [:iq, :result]
@@ -235,7 +234,7 @@
provider.remote.all_waves.each do |wave|
wave.deltas.each_value do |delta|
- next unless delta.is_a? Delta
+ next unless delta.is_a? Sails::Delta
delta.server = server if delta.signer_id == server.certificate_hash
puts "Changed server for #{wave.conv_root_path} ##{delta.version}."
end
@@ -258,7 +257,7 @@
puts "Got history for #{wave.name}"
(packet/'pubsub/items/item/applied-delta').each do |update|
- delta = Delta.parse(provider, wave.conv_root_path, decode64(update.inner_text), true)
+ delta = Sails::Delta.parse(provider, wave.conv_root_path, Sails::Utils.decode64(update.inner_text), true)
puts "Got a delta, version #{delta.version}"
end
@@ -293,7 +292,7 @@
(packet/'event/items/item/wavelet-update').each do |update|
next unless (update/'applied-delta').any?
- delta = Delta.parse(provider, update['wavelet-name'], decode64(update.inner_text), true)
+ delta = Sails::Delta.parse(provider, update['wavelet-name'], Sails::Utils.decode64(update.inner_text), true)
puts "Got delta version #{delta.version rescue -1}"
wave = delta.wave if delta
end
Please sign in to comment.
Something went wrong with that request. Please try again.