Transfering ip address to trackingd is ok

master
Karchnu 2020-10-02 19:22:36 +02:00
parent 58fec6f966
commit 9f6f711187
1 changed files with 13 additions and 6 deletions

View File

@ -1,5 +1,6 @@
require "option_parser"
require "ipc"
require "ipc/json"
require "socket"
require "./colors"
@ -18,6 +19,15 @@ require "colorize"
# All modifications to standard libraries go there.
require "./lib_modifications.cr"
class Tracking::Request
IPC::JSON.message IpAddress, 1 do
property ipaddress : String?
def initialize(@ipaddress = nil)
end
end
end
class Context
# service instance parameters
# they can be changed via the cli
@ -221,15 +231,12 @@ def websocket_client_connection(client)
sfd = Context.context.switchtable[client.fd]
Baguette::Log.info "trackingd - sending the IP address #{real_ip_address} to fd #{sfd}"
# message = IPC::Message.from_json(JSON).to_packet
# => JSON has to include these attributes: mtype, utype, payload
# message = IPC::Message.new mtype, utype, payload
message = IPC::Message.new sfd, 1, 1.to_u8, "{\"ipaddress\": \"#{real_ip_address}\"}"
message = Tracking::Request::IpAddress.new real_ip_address
if Context.print_messages
Baguette::Log.info "to trackingd: #{message.to_s}"
end
serv = WrappedTCPFileDescriptor.new(fd: sfd, family: Socket::Family::INET)
serv.send message.to_packet
Context.service.send_now sfd, message
end
if Context.print_messages