federation fixes

This commit is contained in:
Administrator 2025-09-05 17:42:50 -07:00
parent ecc5c7257e
commit 2052ad7cef
4 changed files with 113 additions and 16 deletions

View file

@ -10,6 +10,10 @@ $object_space = {:registry => {}}
class Object
private
#
def logged_in?()
GxG::DISPLAY_DETAILS[:logged_in]
end
#
def bytes(*args)
GxG::ByteArray::try_convert(args)
end
@ -17,7 +21,7 @@ class Object
def new_message(*args)
unless @uuid
@uuid = ::GxG::uuid_generate.to_s.to_sym
::GxG::CHANNELS.create_channel(@uuid)
::GxG::CHANNELS.create_channel(@uuid,self)
end
::GxG::Events::Message.new({:sender => @uuid, :subject => args[1], :body => args[0]})
end

View file

@ -145,9 +145,6 @@ module GxG
end
# XHR Connector:
module Networking
class Channel
#
end
#
class Connector
#
@ -973,6 +970,10 @@ module GxG
if the_response.is_a?(::Hash)
if the_response[:status] == "credentialed"
GxG::DISPLAY_DETAILS[:logged_in] = true
GXG_FEDERATION[:connections].keys.each do |the_uuid|
socket.send({ :open_channel => the_uuid.to_s }.to_json.encode64, :text)
end
#
end
end
the_handler.call(the_response)
@ -999,6 +1000,9 @@ module GxG
if response.is_a?(::Hash)
# FIXME: possible conflict with proper credential setting.
if response[:status] == "uncredentialed"
GXG_FEDERATION[:connections].keys.each do |the_uuid|
socket.send({ :close_channel => the_uuid.to_s }.to_json.encode64, :text)
end
GxG::DISPLAY_DETAILS[:logged_in] = false
if the_handler.respond_to?(:call)
the_handler.call(response)
@ -1087,7 +1091,6 @@ module GxG
@csrf = nil
@the_connector = self
# Make introduction to host and aquire csrf token
::GxG::CHANNELS.create_channel(@uuid)
the_introduction = new_message({:introduction => @uuid.to_s})
the_introduction[:sender] = @uuid.to_s
the_introduction[:to] = @host_prefix.to_s
@ -1150,6 +1153,10 @@ module GxG
the_message[:sender] = @uuid
the_message[:to] = @remote_uuid
# Review : add fail/succeed code blocks??
# if succeed do this: ::GxG::CHANNELS.create_channel(@uuid)
the_message.on(:success) do |response|
::GxG::CHANNELS.create_channel(@uuid)
end
GxG::CONNECTION.push(the_message)
end
end

View file

@ -3,6 +3,77 @@ module GxG
GXG_FEDERATION = {:title => "Untitled", :uuid => nil, :available => {}, :connections => {}}
# ::GxG::SOCKET_MONITOR
module Messages
class Channel
#
def initialize(the_uuid=nil, the_object=nil)
@uuid = the_uuid
@inbox = []
@outbox = []
@socket = nil
@remote = nil
@channel_secret = nil
@object = the_object
self
end
#
def uuid()
@uuid
end
#
def object()
@object
end
#
def socket()
@socket
end
#
def socket=(the_socket=nil)
@socket = the_socket
end
#
def remote()
@remote
end
#
def remote=(the_remote=nil)
@remote = the_remote
end
#
def secret()
@channel_secret
end
#
def secret=(the_secret=nil)
@channel_secret = the_secret
end
#
def inbox_size()
@inbox.size
end
#
def next_message()
@inbox.unshift
end
#
def outbox_size()
@outbox.size
end
#
def send_message(the_message)
@outbox << the_message
end
#
def read()
@outbox.unshift
end
#
def write(the_message)
@inbox << the_message
end
#
end
#
class ChannelManager
#
def update_channels
@ -33,11 +104,17 @@ module GxG
channel = self.fetch_channel(destination.to_s.to_sym)
if channel
channel.write(the_message)
result = true
else
# Send format: channel.socket.send({ :payload => the_message.export.to_s.encrypt(channel.secret).encode64 }.to_json.encode64, :text)
if GxG::DISPLAY_DETAILS[:logged_in]
socket.send({ :payload => the_message.export.to_s.encrypt(connector.secret).encode64 }.to_json.encode64, :text)
end
result = true
else
log_warn("Message dropped --> login and resend")
result = false
end
end
end
# email address -- TODO
end
@ -48,19 +125,26 @@ module GxG
GXG_FEDERATION[:connections][(the_uuid)]
end
#
def create_channel(the_uuid)
GXG_FEDERATION[:connections][(the_uuid)] = ::GxG::Messages::Channel.new(the_uuid)
def create_channel(the_uuid=nil,the_object=nil)
GXG_FEDERATION[:connections][(the_uuid)] = ::GxG::Messages::Channel.new(the_uuid,the_object)
if GxG::DISPLAY_DETAILS[:logged_in]
socket.send({ :open_channel => the_uuid }.to_json.encode64, :text)
end
end
#
def destroy_channel(the_uuid)
channel = self.fetch_channel(the_uuid)
if channel
channel.outbox_size.times do |indexer|
the_message = channel.read()
if the_message
self.dispatch_message(the_message)
end
end
if GxG::DISPLAY_DETAILS[:logged_in]
socket.send({ :close_channel => the_uuid }.to_json.encode64, :text)
end
end
GXG_FEDERATION[:connections].delete(the_uuid)
end
@ -694,7 +778,7 @@ class Object
def send_message(the_message)
unless @uuid
@uuid = ::GxG::uuid_generate.to_s.to_sym
::GxG::CHANNELS.create_channel(@uuid)
::GxG::CHANNELS.create_channel(@uuid,self)
end
::GxG::CHANNELS.send_message(@uuid, the_message)
true
@ -703,7 +787,7 @@ class Object
def next_message()
unless @uuid
@uuid = ::GxG::uuid_generate.to_s.to_sym
::GxG::CHANNELS.create_channel(@uuid)
::GxG::CHANNELS.create_channel(@uuid,self)
end
::GxG::CHANNELS.next_message(@uuid)
end
@ -711,7 +795,7 @@ class Object
def post(the_message)
unless @uuid
@uuid = ::GxG::uuid_generate.to_s.to_sym
::GxG::CHANNELS.create_channel(@uuid)
::GxG::CHANNELS.create_channel(@uuid,self)
end
channel = ::GxG::CHANNELS.fetch_channel(@uuid)
if channel
@ -719,3 +803,8 @@ class Object
end
true
end
#
def process_message(the_message=nil, options = {})
# override to use
end
end

View file

@ -3,9 +3,6 @@
#
module GxG
module Networking
class Channel
#
end
#
class Connector
#