Methods

Files

Journeta::PresenceBroadcaster

Spams the local area network with metadata about the local instance. This allows peers to make direct connections back at a later time.

Attributes

thread[RW]

Public Instance Methods

go() click to toggle source
    # File lib/journeta/presence_broadcaster.rb, line 14
14:     def go
15:       address = @engine.presence_address
16:       port = @engine.presence_port
17:       delay = @engine.presence_period
18:       uuid = @engine.uuid
19:       peer_port = @engine.peer_port
20:       groups = @engine.groups
21:       begin
22:         socket = UDPSocket.open
23:         begin
24:           if defined?(PLATFORM) # v1.8 (and prior?) MRI and JRuby on Linux, Windows, OSX and Solaris.
25:             if PLATFORM.match(/linux/)
26:               socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, [1].pack("i_") )
27:             elsif PLATFORM.match(/java/)
28:               # puts 'Running on a JVM!'
29:               socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, [1].pack("i_") )
30:               # socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [1].pack('i'))
31:               # socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, [1].pack("i_") )
32:             else
33:               # socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [1].pack('i')) # Preston's original config for OS X.
34:               socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, [1].pack("i_") ) # Remi's suggested default.
35:             end
36:           elsif defined?(RUBY_PLATFORM) # Ruby 1.9 MRI
37:             if RUBY_PLATFORM.match(/linux/)
38:               socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, [1].pack("i_") )
39:             else
40:               # socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [1].pack('i'))
41:               socket.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEPORT, [1].pack("i_") ) # Remi's suggested default.
42:             end
43:           end
44:         rescue
45:           puts "Native socket library not supported on this platform. Please submit a patch! Exiting since this is fatal :("
46:           exit 1
47:         end    
48:         loop do
49:           putsd "Sending presence event."
50:           note = PresenceMessage.new uuid, peer_port, groups
51:           socket.send(note.to_yaml, 0, address, port)
52:           sleep delay
53:         end
54:       ensure
55:         putsd "Closing event broadcaster socket."
56:         socket.close
57:       end
58:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.