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