Class: Vesta::Helpers
- Inherits:
-
Object
- Object
- Vesta::Helpers
- Defined in:
- lib/vesta/helpers.rb
Class Method Summary collapse
-
.banner ⇒ Object
Print banner.
-
.root ⇒ Object
Root folder.
Instance Method Summary collapse
-
#add_message(messages_object, from, message) ⇒ Object
Add message to [messages_object].
-
#add_peer(peer, host, port, public_key) ⇒ Object
Add peer to peer object [peers_object].
-
#communicate(index, host, port) ⇒ Object
Communicate with peers.
-
#every(seconds) ⇒ Object
Do something in every x seconds.
-
#render_state ⇒ Object
Print out the status.
-
#update_peers(new_peers) ⇒ Object
Update peers.
Class Method Details
.banner ⇒ Object
Print banner
10 11 12 |
# File 'lib/vesta/helpers.rb', line 10 def self. "\t\tRunning Vesta v#{Vesta::VERSION}" end |
.root ⇒ Object
Root folder
25 26 27 |
# File 'lib/vesta/helpers.rb', line 25 def self.root "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}" end |
Instance Method Details
#add_message(messages_object, from, message) ⇒ Object
Add message to [messages_object]
36 37 38 39 |
# File 'lib/vesta/helpers.rb', line 36 def (, from, ) .push({from: from, message: }) end |
#add_peer(peer, host, port, public_key) ⇒ Object
Add peer to peer object [peers_object]
30 31 32 33 |
# File 'lib/vesta/helpers.rb', line 30 def add_peer(peer,host,port,public_key) peer.push({host: host, port: port, public_key: public_key}) peer end |
#communicate(index, host, port) ⇒ Object
Communicate with peers
51 52 53 54 55 56 57 58 |
# File 'lib/vesta/helpers.rb', line 51 def communicate(index,host,port) communicate_response = Client.communicate(host, port, YAML.dump($PEERS)) parsed_response = YAML.load(communicate_response) new_peer = parsed_response['peers'] update_peers(new_peer) rescue Faraday::ConnectionFailed $PEERS.delete_at(index) end |
#every(seconds) ⇒ Object
Do something in every x seconds
15 16 17 18 19 20 21 22 |
# File 'lib/vesta/helpers.rb', line 15 def every(seconds) Thread.new do loop do sleep seconds yield end end end |
#render_state ⇒ Object
Print out the status
42 43 44 45 46 47 48 |
# File 'lib/vesta/helpers.rb', line 42 def render_state puts "Node is running on " + Service::LHOST.to_s.magenta + ':'.colorize(:background => :white, :color => :magenta).bold + Service::LPORT.to_s.magenta.bold print "My Peers: ".upcase $PEERS.each do |peer| print "#{peer[:host]}:#{peer[:port]}".yellow.bold + ', ' end end |
#update_peers(new_peers) ⇒ Object
Update peers
61 62 63 64 65 66 |
# File 'lib/vesta/helpers.rb', line 61 def update_peers(new_peers) # if !new_peers.nil? # if new peers are not nil, then append them to $PEERS $PEERS = $PEERS | new_peers $PEERS.uniq # end end |