mirror of
https://github.com/mistergibson/gxg-framework.git
synced 2026-08-15 03:46:00 -07:00
Federation tweaks
This commit is contained in:
parent
29d9266ca3
commit
fe0656b79c
2 changed files with 61 additions and 7 deletions
|
|
@ -1,18 +1,53 @@
|
||||||
#
|
#
|
||||||
module GxG
|
module GxG
|
||||||
#
|
#
|
||||||
GXG_FEDERATION = {:title => "Untitled", :uuid => nil, :access_url => nil, :available => {}, :connections => {}}
|
GXG_FEDERATION = {:title => "Untitled", :uuid => nil, :access_url => nil, :servers => {}, :connections => {}}
|
||||||
GXG_FEDERATION_SAFETY = Mutex.new
|
GXG_FEDERATION_SAFETY = Mutex.new
|
||||||
def self.federation_servers()
|
def self.federation_servers()
|
||||||
result = {}
|
result = {}
|
||||||
::GxG::GXG_FEDERATION_SAFETY.synchronize {
|
::GxG::GXG_FEDERATION_SAFETY.synchronize {
|
||||||
::GxG::GXG_FEDERATION[:available].each_pair do |uuid, server|
|
::GxG::GXG_FEDERATION[:servers].each_pair do |uuid, server|
|
||||||
result[(uuid.to_s.to_sym)] = server
|
result[(uuid.to_s.to_sym)] = server
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
def self.add_federation_server(the_server=nil)
|
||||||
|
result = false
|
||||||
|
if the_server.is_a?(::GxG::Networking::GxGRemoteServer)
|
||||||
|
::GxG::GXG_FEDERATION_SAFETY.synchronize {
|
||||||
|
::GxG::GXG_FEDERATION[:servers][(the_server.uuid)] = the_server
|
||||||
|
}
|
||||||
|
result = true
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
|
def self.remove_federation_server(the_reference=nil)
|
||||||
|
result = nil
|
||||||
|
if the_reference.is_any?(::String, ::Symbol)
|
||||||
|
if ::GxG::valid_uuid?(the_reference.to_s.to_sym)
|
||||||
|
the_uuid = the_reference.to_s.to_sym
|
||||||
|
else
|
||||||
|
the_uuid = nil
|
||||||
|
manifest = ::GxG::federation_servers()
|
||||||
|
manifest.each_pair do |uuid,server|
|
||||||
|
if server.title == the_reference.to_s
|
||||||
|
the_uuid = uuid
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if the_uuid
|
||||||
|
::GxG::GXG_FEDERATION_SAFETY.synchronize {
|
||||||
|
result = ::GxG::GXG_FEDERATION[:servers].delete(the_uuid)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
#
|
||||||
module Messages
|
module Messages
|
||||||
class Channel
|
class Channel
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -3915,7 +3915,9 @@ module GxG
|
||||||
@clients[(service)].login(@uri.username, @uri.password)
|
@clients[(service)].login(@uri.username, @uri.password)
|
||||||
#
|
#
|
||||||
end
|
end
|
||||||
@status = :connected
|
unless ::GxG::add_federation_server(self)
|
||||||
|
raise Exception.new("Failure to register remote server #{@hostname.to_s}")
|
||||||
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
|
@ -3992,12 +3994,28 @@ module GxG
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
def login(username=nil, password=nil)
|
def login(username=nil, password=nil)
|
||||||
#
|
result = false
|
||||||
@services.keys.each do |service|
|
unless username
|
||||||
@clients[(service)].login(username, password)
|
username = @uri.username
|
||||||
|
end
|
||||||
|
unless password
|
||||||
|
password = @uri.password
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
true
|
#
|
||||||
|
@services.keys.each do |service|
|
||||||
|
if @clients[(service)].login(username, password)
|
||||||
|
result = true
|
||||||
|
else
|
||||||
|
result = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if result
|
||||||
|
@status = :available
|
||||||
|
end
|
||||||
|
#
|
||||||
|
result
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
def logout
|
def logout
|
||||||
|
|
@ -4005,6 +4023,7 @@ module GxG
|
||||||
@services.keys.each do |service|
|
@services.keys.each do |service|
|
||||||
@clients[(service)].logout
|
@clients[(service)].logout
|
||||||
end
|
end
|
||||||
|
@status = :unavailable
|
||||||
#
|
#
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue