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)
|
JRuby (any recent version)
|
||||||
Thus far it has only been tested on Ubuntu Server
|
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:
|
Installation:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -364,6 +364,7 @@ module GxG
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
#
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
def self.disable_service(moniker=nil)
|
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])
|
::GxG::SERVICES[:www].call_event({:publish_route => {:http_method => the_method, :path => path, :options => options, :code => block}}, ::GxG::DB[:administrator])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
#
|
||||||
def publish_api()
|
def publish_api()
|
||||||
if ::GxG::Services::service_available?(:www)
|
if ::GxG::Services::service_available?(:www)
|
||||||
::GxG::SERVICES[:www].call_event({:publish_api => {:service => self, :path => "/#{@provides.to_s}"}}, ::GxG::DB[:administrator])
|
::GxG::SERVICES[:www].call_event({:publish_api => {:service => self, :path => "/#{@provides.to_s}"}}, ::GxG::DB[:administrator])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
#
|
||||||
def unpublish_api()
|
def unpublish_api()
|
||||||
if ::GxG::Services::service_available?(:www)
|
if ::GxG::Services::service_available?(:www)
|
||||||
::GxG::SERVICES[:www].call_event({:unpublish_api => {:path => "/#{@provides.to_s}"}}, ::GxG::DB[:administrator])
|
::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_event_allocations()
|
||||||
::GxG::Engine::determine_loads()
|
::GxG::Engine::determine_loads()
|
||||||
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
|
||||||
|
#
|
||||||
# ### Load Services
|
# ### Load Services
|
||||||
if service.configuration()[:available]
|
if service.configuration()[:available]
|
||||||
service.configuration()[:available].each do |moniker|
|
service.configuration()[:available].each do |moniker|
|
||||||
unless service.configuration()[:disabled].include?(moniker)
|
unless service.configuration()[:disabled].include?(moniker)
|
||||||
service_file_path = ::File.expand_path("#{File.dirname(__FILE__)}/#{moniker}/#{moniker}.rb")
|
service_file_path = ::File.expand_path("#{File.dirname(__FILE__)}/#{moniker}/#{moniker}.rb")
|
||||||
|
puts "Loading : #{service_file_path}"
|
||||||
if ::File.exists?(service_file_path)
|
if ::File.exists?(service_file_path)
|
||||||
begin
|
begin
|
||||||
require (service_file_path)
|
require (service_file_path)
|
||||||
|
|
@ -1836,17 +1850,6 @@ 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
|
# ### Provide Universal Resouce Access
|
||||||
core_service[:resources] = ::GxG::Services::UniversalResourcesAccess.new()
|
core_service[:resources] = ::GxG::Services::UniversalResourcesAccess.new()
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,7 @@ end
|
||||||
#
|
#
|
||||||
class WebSocketListener
|
class WebSocketListener
|
||||||
def initialize()
|
def initialize()
|
||||||
|
# @federation = ::GxG::service_object(:federation)
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
|
@ -184,34 +185,56 @@ class WebSocketListener
|
||||||
the_socket.instance_variable_set(:@uuid, the_uuid)
|
the_socket.instance_variable_set(:@uuid, the_uuid)
|
||||||
the_socket.instance_variable_set(:@session, nil)
|
the_socket.instance_variable_set(:@session, nil)
|
||||||
the_socket.instance_variable_set(:@display, 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_SAFETY.synchronize {
|
||||||
GxGwww::SOCKETS[(the_uuid)] = the_socket
|
GxGwww::SOCKETS[(the_uuid)] = the_socket
|
||||||
}
|
}
|
||||||
#
|
# Un-encrypted Preamble
|
||||||
GxG::SERVICES[:www].dispatcher.post_event(:communications) do
|
GxG::SERVICES[:www].dispatcher.post_event(:communications) do
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
the_socket.send({ :attach_socket => the_uuid.to_s }.to_json.encode64, :text)
|
the_socket.send({ :attach_socket => the_uuid.to_s }.to_json.encode64, :text)
|
||||||
end
|
end
|
||||||
|
# Reference:
|
||||||
|
# ::GxGwww.api_login(session_id=nil, credential=:"00000000-0000-4000-0000-000000000000")
|
||||||
|
# ::GxGwww.api_logout(session_id=nil)
|
||||||
#
|
#
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
def on_message(the_socket, the_data, the_type)
|
def on_message(the_socket, the_data, the_type)
|
||||||
message_queue = the_socket.instance_variable_get(:@inbox)
|
the_uuid = the_socket.instance_variable_get(:@uuid)
|
||||||
GxGwww::SOCKETS_SAFETY.synchronize {
|
the_channel = ::GxG::CHANNELS.fetch_channel(the_uuid)
|
||||||
if the_type == :text
|
if the_channel
|
||||||
|
the_session = the_channel.socket.instance_variable_get(:@session)
|
||||||
|
if the_session
|
||||||
|
the_secret = the_session["csrf"]
|
||||||
|
if the_secret
|
||||||
|
#
|
||||||
begin
|
begin
|
||||||
# Expects: json+base64 of a Hash
|
if the_type == :text
|
||||||
message_queue << JSON.parse(the_data.to_s.decode64, {:symbolize_names => true})
|
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
|
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
|
end
|
||||||
else
|
else
|
||||||
# Takes in all other data as binary into inbox
|
log_error(:error => Exception.new("No session found"), :parameters => {:socket => the_socket, :data => the_data, :type => the_type})
|
||||||
message_queue << ::GxG::ByteArray.new(the_data.to_s)
|
end
|
||||||
|
else
|
||||||
|
log_error(:error => Exception.new("No channel found"), :parameters => {:socket => the_socket, :data => the_data, :type => the_type})
|
||||||
end
|
end
|
||||||
}
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
|
|
@ -248,6 +271,8 @@ class WebSocketListener
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
end
|
end
|
||||||
|
# Add socket message pump for ChannelManager
|
||||||
|
|
||||||
# Load GxGwww:
|
# Load GxGwww:
|
||||||
require (File.expand_path("./www/gxg-www.rb",File.dirname(__FILE__)))
|
require (File.expand_path("./www/gxg-www.rb",File.dirname(__FILE__)))
|
||||||
www_service[:manifests] = {}
|
www_service[:manifests] = {}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ module GxGwww
|
||||||
API = {}
|
API = {}
|
||||||
API_SESSIONS = {}
|
API_SESSIONS = {}
|
||||||
API_THREAD_SAFETY = ::Mutex.new
|
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)
|
def self.publish_api(the_service=nil, the_path=nil)
|
||||||
if the_service && the_path
|
if the_service && the_path
|
||||||
the_controller = ::GxGwww::APIController.new(the_service, the_path)
|
the_controller = ::GxGwww::APIController.new(the_service, the_path)
|
||||||
|
|
@ -939,7 +942,7 @@ module GxGwww
|
||||||
else
|
else
|
||||||
raise Exception, "Manifest Not Found For Session."
|
raise Exception, "Manifest Not Found For Session."
|
||||||
end
|
end
|
||||||
puts "Websocket Attached: #{the_uuid.inspect}"
|
log_info "Websocket Attached: #{the_uuid.inspect}"
|
||||||
response = [200, {"content-type" => "application/json"}, {:result => true}.to_json()]
|
response = [200, {"content-type" => "application/json"}, {:result => true}.to_json()]
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
@ -1165,9 +1168,19 @@ module GxGwww
|
||||||
}
|
}
|
||||||
if the_controller
|
if the_controller
|
||||||
response = the_controller.process(the_method, the_request, the_session)
|
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
|
else
|
||||||
response = [404, {"content-type" => "application/text"}, "Endpoint Not Found"]
|
response = [404, {"content-type" => "application/text"}, "Endpoint Not Found"]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if ["", "/", "/index"].include?(request_path) || ::GxG::SERVICES[:core][:resources].exist?("/Public/www/content/pages#{request_path}")
|
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
|
# Send bootstrap html page and wait for xhr requests
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue