wsd now sends {"ip-address": "10.0.0.3"} to `tracker` at client connection.

master
Karchnu 2020-06-04 17:18:48 +02:00
parent 2ddcdfb27b
commit 119ccbca3c
1 changed files with 14 additions and 1 deletions

View File

@ -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"