mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-09-19 06:43:55 +00:00
Improved Worker responses and added support for dns resolution check
This commit is contained in:
@@ -5,7 +5,7 @@ module W3DHubLauncher
|
|||||||
].freeze
|
].freeze
|
||||||
DEFAULT_NETWORK_TIMEOUT = 30
|
DEFAULT_NETWORK_TIMEOUT = 30
|
||||||
|
|
||||||
Response = Data.define(:status, :request_id, :data)
|
Response = Data.define(:status, :request_id, :result)
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
end
|
end
|
||||||
@@ -41,7 +41,7 @@ module W3DHubLauncher
|
|||||||
UNIXServer.open(IPC_PATH) do |server|
|
UNIXServer.open(IPC_PATH) do |server|
|
||||||
while(socket = server.accept)
|
while(socket = server.accept)
|
||||||
task.async do
|
task.async do
|
||||||
while(data =socket.gets)
|
while(data = socket.gets)
|
||||||
json = JSON.parse(data)
|
json = JSON.parse(data)
|
||||||
query = Request::Query.new(type: json["type"].to_sym, request_id: json["request_id"], data: json["data"])
|
query = Request::Query.new(type: json["type"].to_sym, request_id: json["request_id"], data: json["data"])
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ module W3DHubLauncher
|
|||||||
if respond_to?(query.type)
|
if respond_to?(query.type)
|
||||||
response = send(query.type, query)
|
response = send(query.type, query)
|
||||||
pp [:server_to_client, response]
|
pp [:server_to_client, response]
|
||||||
payload = { status: response.status, request_id: response.request_id, data: response.data.data }.to_json
|
payload = { status: response.status, request_id: response.request_id, data: response.result.data, error: response.result.error }.to_json
|
||||||
socket.puts(payload)
|
socket.puts(payload)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -84,16 +84,15 @@ module W3DHubLauncher
|
|||||||
data = @socket.read_nonblock(1_048_576) # 1 MB
|
data = @socket.read_nonblock(1_048_576) # 1 MB
|
||||||
pp [:CLIENT, data]
|
pp [:CLIENT, data]
|
||||||
json = JSON.parse(data)
|
json = JSON.parse(data)
|
||||||
response = Response.new(status: json["status"], request_id: json["request_id"], data: json["data"])
|
request = W3DHubLauncher::Worker::Request.requests.find { |r| r.request_id == json["request_id"] }
|
||||||
request = W3DHubLauncher::Worker::Request.requests.find { |r| r.request_id == response.request_id }
|
|
||||||
|
|
||||||
pp [json, response, request]
|
pp [json, request]
|
||||||
return unless request
|
return unless request
|
||||||
|
|
||||||
CyberarmEngine::Window.instance&.add_to_queue(proc {
|
CyberarmEngine::Window.instance&.add_to_queue(proc {
|
||||||
request.handle_event(
|
request.handle_event(
|
||||||
response.status,
|
json["status"],
|
||||||
CyberarmEngine::Result.new(data: response.data, error: response.status.negative? ? true : nil)
|
CyberarmEngine::Result.new(data: json["data"], error: json["error"])
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -159,6 +158,26 @@ module W3DHubLauncher
|
|||||||
deliver_response(result, query)
|
deliver_response(result, query)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dns_resolution(query)
|
||||||
|
result = CyberarmEngine::Result.new
|
||||||
|
|
||||||
|
domains = [
|
||||||
|
"w3dhub-api.w3d.cyberarm.dev",
|
||||||
|
"s3.w3d.cyberarm.dev",
|
||||||
|
"secure.w3dhub.com"
|
||||||
|
]
|
||||||
|
|
||||||
|
domains.each do |domain|
|
||||||
|
Resolv.getaddress(domain)
|
||||||
|
rescue StandardError => e
|
||||||
|
result.error = "Failed to resolve: #{domain}"
|
||||||
|
end
|
||||||
|
|
||||||
|
result.data = true if result.error.nil?
|
||||||
|
|
||||||
|
deliver_response(result, query)
|
||||||
|
end
|
||||||
|
|
||||||
def w3dhub_api_call(query)
|
def w3dhub_api_call(query)
|
||||||
result = @w3dhub_api.send(query.data["call"], *(query.data["arguments"] || []))
|
result = @w3dhub_api.send(query.data["call"], *(query.data["arguments"] || []))
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ module W3DHubLauncher
|
|||||||
Worker::Request.new(:download_url, { url: url, path: path, method: method, headers: headers, body: body }, &block)
|
Worker::Request.new(:download_url, { url: url, path: path, method: method, headers: headers, body: body }, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.dns_resolution(&block)
|
||||||
|
Worker::Request.new(:dns_resolution, "", &block)
|
||||||
|
end
|
||||||
|
|
||||||
# returns user account data
|
# returns user account data
|
||||||
#
|
#
|
||||||
# automatically handles signing in / refreshing token (DOES NOT remove account data if failed to refresh token due to network timeout)
|
# automatically handles signing in / refreshing token (DOES NOT remove account data if failed to refresh token due to network timeout)
|
||||||
@@ -35,7 +39,8 @@ module W3DHubLauncher
|
|||||||
# returns list of available applications
|
# returns list of available applications
|
||||||
#
|
#
|
||||||
# if updated list is requested, return cached version immediately and then the updated list later.
|
# if updated list is requested, return cached version immediately and then the updated list later.
|
||||||
def self.applications
|
def self.applications(&block)
|
||||||
|
W3DHubLauncher::Worker::Request.new(:w3dhub_api_call, { call: :fetch_applications }, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns current list of servers as reported from GSH / cache
|
# returns current list of servers as reported from GSH / cache
|
||||||
|
|||||||
Reference in New Issue
Block a user