Module: Pokan::ServerMessages

Included in:
Server
Defined in:
lib/pokan/server_messages.rb

Instance Method Summary collapse

Instance Method Details

#digest_messageObject

Gets a digest containing all peers’ key/timestamp of all peers It returns a json with all the pairs for each peer in a Digest Structure



19
20
21
22
23
24
25
# File 'lib/pokan/server_messages.rb', line 19

def digest_message
  data= Hash.new
  peers = Query.new(Peer).where(role:['peer','seed'], status:'alive')
  peers.each { |peer| data[peer.id] = peer.digest }

  { action: 'digest', data: data, origin:"#{address}:#{port}" }.to_json
end

#goodbye_messageObject

Gets the message that the peer needs to send when is going to stop participating of the group



12
13
14
# File 'lib/pokan/server_messages.rb', line 12

def goodbye_message
  { action: 'goodbye', origin:"#{address}:#{port}" }.to_json
end

#hello_messageObject

Gets a message for the introduction of the new peer to the seed



6
7
8
# File 'lib/pokan/server_messages.rb', line 6

def hello_message
  { action: 'hello', origin:"#{address}:#{port}" }.to_json
end