Hi Guillaume,
Yes, correct. I think I figured it out. On the server, when a client connects and a tunnel is initialised, I can find out the client's ip and port through EventMachine, and then use this information to see if a client is already connected from the same IP address and, if this is the case, I call close_connection on the tunnel so the other instance on the client knows it has to shut down.
So this seems to be working well, plus it gave me another idea: since I can get the IP address of the client easily, I can also use then drb's acl to implement some sort of app-firewall :)
For now I am just monkey patching to see how this works but I will add to some other changes I mentioned earlier and send a pull request:
class BrB::Tunnel::Handler
attr_reader :ip_address, :port
alias_method :post_init_without_client_ip_and_port, :post_init
def post_init
@port, @ip_address = Socket.unpack_sockaddr_in(get_peername)
post_init_without_client_ip_and_port
end
end
then to access and use this information:
BrB::Service.start_service(@settings) do |event, client|
if event == :register
if allowed_client? client
if already_connected? client
client.close_connection
else
logger.info "Client connected on #{client.ip_address}:#{client.port}"
end
else
logger.warn "Blocked connection from unauthorised client on #{client.ip_address}:#{client.port}"
end
else
# do something else
end
end
Cheers
Vito