Going to next libipc bindings version.
parent
80a995cc08
commit
8fe249218f
|
@ -35,7 +35,7 @@
|
|||
# if filestoraged.users_status[userid]?
|
||||
# puts "We already knew this user"
|
||||
#
|
||||
# filestoraged.connected_users[event.connection.fd] = userid
|
||||
# filestoraged.connected_users[event.fd] = userid
|
||||
# # TODO
|
||||
# pp! filestoraged.connected_users
|
||||
# pp! filestoraged.users_status[userid]
|
||||
|
@ -47,7 +47,7 @@
|
|||
# # AuthenticationMessage includes requests.
|
||||
# new_user = User.new token, @uploads, @downloads
|
||||
#
|
||||
# filestoraged.connected_users[event.connection.fd] = userid
|
||||
# filestoraged.connected_users[event.fd] = userid
|
||||
#
|
||||
# # record the new user in users_status
|
||||
# filestoraged.users_status[userid] = new_user
|
||||
|
|
|
@ -15,7 +15,7 @@ class FileStorage::Request
|
|||
return Errors::Authorization.new @mid if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.connection.fd
|
||||
fd = event.fd
|
||||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
|
|
|
@ -19,10 +19,9 @@ class FileStorage::Request
|
|||
user, _ = filestoraged.decode_token token
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.connection.fd
|
||||
fd = event.fd
|
||||
|
||||
filestoraged.logged_users[fd] = user
|
||||
filestoraged.logged_connections[fd] = event.connection
|
||||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class FileStorage::Request
|
|||
return Errors::Authorization.new @mid if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.connection.fd
|
||||
fd = event.fd
|
||||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
|
@ -51,7 +51,7 @@ class FileStorage::Request
|
|||
return Errors::Authorization.new @mid if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.connection.fd
|
||||
fd = event.fd
|
||||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class FileStorage::Request
|
|||
return Errors::Authorization.new @mid if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.connection.fd
|
||||
fd = event.fd
|
||||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require "option_parser"
|
||||
require "ipc"
|
||||
require "json"
|
||||
require "ipc/json"
|
||||
require "authd"
|
||||
|
||||
require "colorize"
|
||||
|
@ -29,9 +28,8 @@ require "./storage.cr"
|
|||
require "./network.cr"
|
||||
|
||||
require "dodb"
|
||||
require "json"
|
||||
|
||||
class FileStorage::Service < IPC::Service
|
||||
class FileStorage::Service < IPC::Server
|
||||
# List of connected users (fd => uid).
|
||||
property connected_users = Hash(Int32, Int32).new
|
||||
|
||||
|
@ -43,7 +41,6 @@ class FileStorage::Service < IPC::Service
|
|||
getter storage : FileStorage::Storage
|
||||
|
||||
getter logged_users : Hash(Int32, AuthD::User::Public)
|
||||
getter logged_connections : Hash(Int32, IPC::Connection)
|
||||
getter all_connections : Array(Int32)
|
||||
|
||||
@auth : AuthD::Client
|
||||
|
@ -54,7 +51,6 @@ class FileStorage::Service < IPC::Service
|
|||
@storage = FileStorage::Storage.new storage_directory
|
||||
|
||||
@logged_users = Hash(Int32, AuthD::User::Public).new
|
||||
@logged_connections = Hash(Int32, IPC::Connection).new
|
||||
@all_connections = Array(Int32).new
|
||||
|
||||
@auth = AuthD::Client.new
|
||||
|
@ -64,7 +60,7 @@ class FileStorage::Service < IPC::Service
|
|||
end
|
||||
|
||||
def get_logged_user(event : IPC::Event::Events)
|
||||
fd = event.connection.fd
|
||||
fd = event.fd
|
||||
|
||||
@logged_users[fd]?
|
||||
end
|
||||
|
@ -115,19 +111,18 @@ class FileStorage::Service < IPC::Service
|
|||
puts "#{CORANGE}IPC::Event::Timer#{CRESET}"
|
||||
|
||||
when IPC::Event::Connection
|
||||
puts "#{CBLUE}IPC::Event::Connection: #{event.connection.fd}#{CRESET}"
|
||||
@all_connections << event.connection.fd
|
||||
puts "#{CBLUE}IPC::Event::Connection: #{event.fd}#{CRESET}"
|
||||
@all_connections << event.fd
|
||||
|
||||
when IPC::Event::Disconnection
|
||||
puts "#{CBLUE}IPC::Event::Disconnection: #{event.connection.fd}#{CRESET}"
|
||||
fd = event.connection.fd
|
||||
puts "#{CBLUE}IPC::Event::Disconnection: #{event.fd}#{CRESET}"
|
||||
fd = event.fd
|
||||
|
||||
@logged_connections.delete fd
|
||||
@logged_users.delete fd
|
||||
@all_connections.select! &.!=(fd)
|
||||
|
||||
@connected_users.select! do |fd, uid|
|
||||
fd != event.connection.fd
|
||||
fd != event.fd
|
||||
end
|
||||
|
||||
when IPC::Event::ExtraSocket
|
||||
|
@ -138,8 +133,8 @@ class FileStorage::Service < IPC::Service
|
|||
|
||||
# IPC::Event::Message has to be the last entry
|
||||
# because ExtraSocket and Switch inherit from Message class
|
||||
when IPC::Event::Message
|
||||
puts "#{CBLUE}IPC::Event::Message#{CRESET}: #{event.connection.fd}"
|
||||
when IPC::Event::MessageReceived
|
||||
puts "#{CBLUE}IPC::Event::Message#{CRESET}: #{event.fd}"
|
||||
|
||||
request_start = Time.utc
|
||||
|
||||
|
@ -173,7 +168,7 @@ class FileStorage::Service < IPC::Service
|
|||
# mtype = FileStorage::MessageType.new event.message.utype.to_i32
|
||||
#
|
||||
# # First, the user has to be authenticated unless we are receiving its first message.
|
||||
# userid = Context.connected_users[event.connection.fd]?
|
||||
# userid = Context.connected_users[event.fd]?
|
||||
#
|
||||
# # If the user is not yet connected but does not try to perform authentication.
|
||||
# if ! userid && mtype != FileStorage::MessageType::Authentication
|
||||
|
@ -234,10 +229,12 @@ class FileStorage::Service < IPC::Service
|
|||
# in the responses. Allows identifying responses easily.
|
||||
response.id = request.id
|
||||
|
||||
event.connection.send response
|
||||
send event.fd, response
|
||||
|
||||
duration = Time.utc - request_start
|
||||
puts "request took: #{duration}"
|
||||
when IPC::Event::MessageSent
|
||||
puts "#{CBLUE}IPC::Event::MessageSent#{CRESET}: #{event.fd}"
|
||||
else
|
||||
warning "unhandled IPC event: #{event.class}"
|
||||
end
|
||||
|
|
|
@ -57,4 +57,12 @@ def parse_message(requests : Array(JSONIPC.class), message : IPC::Message) : JSO
|
|||
request_type.from_json payload
|
||||
end
|
||||
|
||||
require "../common/requests/*"
|
||||
|
||||
require "../common/requests/client.cr"
|
||||
require "../common/requests/login.cr"
|
||||
require "../common/requests/transfer.cr"
|
||||
require "../common/requests/upload.cr"
|
||||
require "../common/requests/errors.cr"
|
||||
require "../common/requests/download.cr"
|
||||
|
||||
# require "../common/requests/*"
|
||||
|
|
Loading…
Reference in New Issue