mirror of
https://github.com/mistergibson/gxg-server.git
synced 2026-08-15 02:15:59 -07:00
Federation Scaffolding
This commit is contained in:
parent
08fb37ca8c
commit
4067ea945a
5 changed files with 68 additions and 26 deletions
|
|
@ -4,6 +4,7 @@ Requirements:
|
|||
|
||||
JRuby (any recent version)
|
||||
Thus far it has only been tested on Ubuntu Server
|
||||
Database prep: UPDATE mysql.user SET Super_Priv="Y" WHERE user='www-data' AND host='%';
|
||||
|
||||
Installation:
|
||||
|
||||
|
|
|
|||
|
|
@ -364,6 +364,7 @@ module GxG
|
|||
else
|
||||
false
|
||||
end
|
||||
#
|
||||
end
|
||||
#
|
||||
def self.disable_service(moniker=nil)
|
||||
|
|
@ -454,11 +455,13 @@ module GxG
|
|||
::GxG::SERVICES[:www].call_event({:publish_route => {:http_method => the_method, :path => path, :options => options, :code => block}}, ::GxG::DB[:administrator])
|
||||
end
|
||||
end
|
||||
#
|
||||
def publish_api()
|
||||
if ::GxG::Services::service_available?(:www)
|
||||
::GxG::SERVICES[:www].call_event({:publish_api => {:service => self, :path => "/#{@provides.to_s}"}}, ::GxG::DB[:administrator])
|
||||
end
|
||||
end
|
||||
#
|
||||
def unpublish_api()
|
||||
if ::GxG::Services::service_available?(:www)
|
||||
::GxG::SERVICES[:www].call_event({:unpublish_api => {:path => "/#{@provides.to_s}"}}, ::GxG::DB[:administrator])
|
||||
|
|
@ -1797,11 +1800,22 @@ core_service.on(:at_start, {:description => "System Service Layer Startup", :usa
|
|||
::GxG::Engine::determine_event_allocations()
|
||||
::GxG::Engine::determine_loads()
|
||||
end
|
||||
end
|
||||
core_service.on(:at_stop, {:description => "System Service Layer Shutdown", :usage => "{ :at_stop => (service-object) }", :public => false}) do |service|
|
||||
# ### Stop Services
|
||||
::GxG::Services::stop_order().each do |the_service_moniker|
|
||||
unless the_service_moniker == :core
|
||||
log_info("Stopping Service: #{the_service_moniker.inspect} ...")
|
||||
::GxG::Services::stop_service(the_service_moniker)
|
||||
end
|
||||
end
|
||||
#
|
||||
# ### Load Services
|
||||
if service.configuration()[:available]
|
||||
service.configuration()[:available].each do |moniker|
|
||||
unless service.configuration()[:disabled].include?(moniker)
|
||||
service_file_path = ::File.expand_path("#{File.dirname(__FILE__)}/#{moniker}/#{moniker}.rb")
|
||||
puts "Loading : #{service_file_path}"
|
||||
if ::File.exists?(service_file_path)
|
||||
begin
|
||||
require (service_file_path)
|
||||
|
|
@ -1834,18 +1848,7 @@ core_service.on(:at_start, {:description => "System Service Layer Startup", :usa
|
|||
end
|
||||
end
|
||||
end
|
||||
#
|
||||
end
|
||||
#
|
||||
core_service.on(:at_stop, {:description => "System Service Layer Shutdown", :usage => "{ :at_stop => (service-object) }", :public => false}) do |service|
|
||||
# ### Stop Services
|
||||
::GxG::Services::stop_order().each do |the_service_moniker|
|
||||
unless the_service_moniker == :core
|
||||
log_info("Stopping Service: #{the_service_moniker.inspect} ...")
|
||||
::GxG::Services::stop_service(the_service_moniker)
|
||||
end
|
||||
end
|
||||
#
|
||||
end
|
||||
# ### Provide Universal Resouce Access
|
||||
core_service[:resources] = ::GxG::Services::UniversalResourcesAccess.new()
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ end
|
|||
#
|
||||
class WebSocketListener
|
||||
def initialize()
|
||||
# @federation = ::GxG::service_object(:federation)
|
||||
self
|
||||
end
|
||||
#
|
||||
|
|
@ -184,34 +185,56 @@ class WebSocketListener
|
|||
the_socket.instance_variable_set(:@uuid, the_uuid)
|
||||
the_socket.instance_variable_set(:@session, nil)
|
||||
the_socket.instance_variable_set(:@display, nil)
|
||||
the_socket.instance_variable_set(:@inbox, [])
|
||||
#
|
||||
the_channel = ::GxG::CHANNELS.create_channel(the_uuid)
|
||||
if the_channel
|
||||
the_channel.socket = the_socket
|
||||
end
|
||||
#
|
||||
GxGwww::SOCKETS_SAFETY.synchronize {
|
||||
GxGwww::SOCKETS[(the_uuid)] = the_socket
|
||||
}
|
||||
#
|
||||
# Un-encrypted Preamble
|
||||
GxG::SERVICES[:www].dispatcher.post_event(:communications) do
|
||||
sleep 0.5
|
||||
the_socket.send({ :attach_socket => the_uuid.to_s }.to_json.encode64, :text)
|
||||
end
|
||||
# Reference:
|
||||
# ::GxGwww.api_login(session_id=nil, credential=:"00000000-0000-4000-0000-000000000000")
|
||||
# ::GxGwww.api_logout(session_id=nil)
|
||||
#
|
||||
true
|
||||
end
|
||||
#
|
||||
def on_message(the_socket, the_data, the_type)
|
||||
message_queue = the_socket.instance_variable_get(:@inbox)
|
||||
GxGwww::SOCKETS_SAFETY.synchronize {
|
||||
if the_type == :text
|
||||
the_uuid = the_socket.instance_variable_get(:@uuid)
|
||||
the_channel = ::GxG::CHANNELS.fetch_channel(the_uuid)
|
||||
if the_channel
|
||||
the_session = the_channel.socket.instance_variable_get(:@session)
|
||||
if the_session
|
||||
the_secret = the_session["csrf"]
|
||||
if the_secret
|
||||
#
|
||||
begin
|
||||
# Expects: json+base64 of a Hash
|
||||
message_queue << JSON.parse(the_data.to_s.decode64, {:symbolize_names => true})
|
||||
if the_type == :text
|
||||
the_payload = JSON.parse(the_data.to_s.decode64, {:symbolize_names => true})
|
||||
else
|
||||
the_payload = {:body => ::GxG::ByteArray.new(the_data.to_s.decode64)}.gxg_export
|
||||
end
|
||||
the_channel.send_message(::GxG::Events::Message::import(the_payload))
|
||||
rescue Exception => the_error
|
||||
log_error({:error => the_error, :parameters => {:data => the_data}})
|
||||
log_error(:error => the_error, :parameters => {:socket => the_socket, :data => the_data, :type => the_type})
|
||||
end
|
||||
#
|
||||
else
|
||||
log_error(:error => Exception.new("No session secret found"), :parameters => {:socket => the_socket, :data => the_data, :type => the_type})
|
||||
end
|
||||
else
|
||||
# Takes in all other data as binary into inbox
|
||||
message_queue << ::GxG::ByteArray.new(the_data.to_s)
|
||||
log_error(:error => Exception.new("No session found"), :parameters => {:socket => the_socket, :data => the_data, :type => the_type})
|
||||
end
|
||||
else
|
||||
log_error(:error => Exception.new("No channel found"), :parameters => {:socket => the_socket, :data => the_data, :type => the_type})
|
||||
end
|
||||
}
|
||||
true
|
||||
end
|
||||
#
|
||||
|
|
@ -248,6 +271,8 @@ class WebSocketListener
|
|||
end
|
||||
#
|
||||
end
|
||||
# Add socket message pump for ChannelManager
|
||||
|
||||
# Load GxGwww:
|
||||
require (File.expand_path("./www/gxg-www.rb",File.dirname(__FILE__)))
|
||||
www_service[:manifests] = {}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ module GxGwww
|
|||
API = {}
|
||||
API_SESSIONS = {}
|
||||
API_THREAD_SAFETY = ::Mutex.new
|
||||
def self.service_object(moniker=nil)
|
||||
API_THREAD_SAFETY.synchronize { ::GxG::API[(moniker.to_s.to_sym)] }
|
||||
end
|
||||
def self.publish_api(the_service=nil, the_path=nil)
|
||||
if the_service && the_path
|
||||
the_controller = ::GxGwww::APIController.new(the_service, the_path)
|
||||
|
|
@ -939,7 +942,7 @@ module GxGwww
|
|||
else
|
||||
raise Exception, "Manifest Not Found For Session."
|
||||
end
|
||||
puts "Websocket Attached: #{the_uuid.inspect}"
|
||||
log_info "Websocket Attached: #{the_uuid.inspect}"
|
||||
response = [200, {"content-type" => "application/json"}, {:result => true}.to_json()]
|
||||
break
|
||||
end
|
||||
|
|
@ -1165,9 +1168,19 @@ module GxGwww
|
|||
}
|
||||
if the_controller
|
||||
response = the_controller.process(the_method, the_request, the_session)
|
||||
else
|
||||
if request_path.to_s.downcase == "/api/interface"
|
||||
items = []
|
||||
::GxGwww::API_THREAD_SAFETY.synchronize {
|
||||
::GxGwww::API.each_pair do |the_path, the_handler|
|
||||
items << {:provides => File::basename(the_path).to_s.downcase, :path => (GxG::SERVICES[:www].configuration[:relative_url] + the_path)}
|
||||
end
|
||||
}
|
||||
response = [200, {"content-type" => "application/json"}, {:result => items, error => nil}.to_json()]
|
||||
else
|
||||
response = [404, {"content-type" => "application/text"}, "Endpoint Not Found"]
|
||||
end
|
||||
end
|
||||
else
|
||||
if ["", "/", "/index"].include?(request_path) || ::GxG::SERVICES[:core][:resources].exist?("/Public/www/content/pages#{request_path}")
|
||||
# Send bootstrap html page and wait for xhr requests
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue