diff --git a/lib/rpush/daemon/agent.rb b/lib/rpush/daemon/agent.rb new file mode 100644 index 000000000..0cc826245 --- /dev/null +++ b/lib/rpush/daemon/agent.rb @@ -0,0 +1,6 @@ +module Rpush + module Agent + @id = SecureRandom.uuid + attr_reader :id + end +end diff --git a/lib/rpush/daemon/agent/heartbeat.rb b/lib/rpush/daemon/agent/heartbeat.rb new file mode 100644 index 000000000..65acece4c --- /dev/null +++ b/lib/rpush/daemon/agent/heartbeat.rb @@ -0,0 +1,13 @@ +module Rpush + module Agent + class Heartbeat + def payload + { + id: Rpush::Agent.id, + timestamp: Time.now.iso8601, + version: Rpush::VERSION + } + end + end + end +end diff --git a/lib/rpush/daemon/agent/server.rb b/lib/rpush/daemon/agent/server.rb new file mode 100644 index 000000000..b4289aa4b --- /dev/null +++ b/lib/rpush/daemon/agent/server.rb @@ -0,0 +1,44 @@ +module Rpush + module Agent + class Server + HOST = '0.0.0.0' + PORT = 42426 + RECV_BYTES = 1024 + + def self.start + @instance ||= new + @instance.start + end + + def self.stop + @instance.stop if @instance + end + + def initialize + BasicSocket.do_not_reverse_lookup = true + end + + def start + @socket = UDPSocket.new + @socket.bind(HOST, PORT) + + Thread.new do + until @stop do + begin + data, addr = @socket.recvfrom_nonblock(RECV_BYTES) + rescue IO::WaitReadable + IO.select([@socket]) + retry + end + end + end + end + + def stop + @stop = true + @thread.join if @thread + @socket.close if @socket + end + end + end +end pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy