From 119ccbca3cbaf1b1b940e09220f24fc1c24a26fc Mon Sep 17 00:00:00 2001 From: Karchnu Date: Thu, 4 Jun 2020 17:18:48 +0200 Subject: [PATCH] wsd now sends {"ip-address": "10.0.0.3"} to `tracker` at client connection. --- src/websocketd.cr | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/websocketd.cr b/src/websocketd.cr index d76e209..97b202d 100644 --- a/src/websocketd.cr +++ b/src/websocketd.cr @@ -166,9 +166,22 @@ def websocket_client_connection(client, context : InstanceStorage) context.is_json[client.fd] = false end - websocket_connection_procedure req_service, client.fd, context + # TODO: if trackerd, send the IP address of the client + if req_service == "tracker" + puts "tracker - sending the IP address" + puts "connection from #{client.remote_address}" + sfd = context.switchtable[client.fd] + # message = IPC::Message.from_json(JSON).to_packet + # => JSON has to include these attributes: mtype, utype, payload + # message = IPC::Message.new mtype, utype, payload + remote_address = client.remote_address.address + message = IPC::Message.new 1, 1.to_u8, "{\"ip-address\": \"#{remote_address}\"}" + serv = WrappedTCPFileDescriptor.new(fd: sfd, family: Socket::Family::INET) + serv.send message.to_packet + end + # puts "#{headers_header}\n#{headers.to_s}\r\n" client.send "#{headers_header}\n#{headers.to_s}\r\n"