vesta-chat 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/vesta +2 -2
- data/lib/vesta/client.rb +33 -33
- data/lib/vesta/helpers.rb +67 -67
- data/lib/vesta/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22a70c10a58b0e5fb1f59ddfa25a74b1435e4d46
|
4
|
+
data.tar.gz: 4a553b517c3a5313e3bc9df165775f678b47013d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae1c90d5adca62d0a8bdc770d76b1f43c2149098a117bd559342083ac0938b88e97f674a6a7cd361322dfa5b2b6a7d3ff7b0f14778be3d0acf473349a7ba55b5
|
7
|
+
data.tar.gz: 28df144b721830dc0f91ee3bc14e3db93a71bbc305c4089d3949fbe53d721114ee736b504f6100d2fe2099d662a3ba3be062d38e605f521fdc8c2661109f5ed8
|
data/bin/vesta
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "vesta"
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "vesta"
|
3
3
|
Vesta::Service
|
data/lib/vesta/client.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
#
|
2
|
-
# Client class
|
3
|
-
#
|
4
|
-
|
5
|
-
require 'faraday'
|
6
|
-
|
7
|
-
# module Vesta
|
8
|
-
class Client
|
9
|
-
|
10
|
-
# Communicating
|
11
|
-
def self.communicate(host, port, peers)
|
12
|
-
begin
|
13
|
-
Faraday.post("#{host}:#{port}/communicate", peers: peers).body
|
14
|
-
rescue Faraday::ConnectionFailed => e
|
15
|
-
raise
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Getting public key from connected peer
|
20
|
-
def self.get_public_key(host,port)
|
21
|
-
Faraday.post("#{host}:#{port}/get_pubkey").body
|
22
|
-
end
|
23
|
-
|
24
|
-
# Sending messages to peers
|
25
|
-
def self.send_message(host,port,from,message)
|
26
|
-
begin
|
27
|
-
Faraday.post("#{host}:#{port}/get_message", from: from, message: message).body
|
28
|
-
rescue Faraday::ConnectionFailed => e
|
29
|
-
raise
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
1
|
+
#
|
2
|
+
# Client class
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'faraday'
|
6
|
+
|
7
|
+
# module Vesta
|
8
|
+
class Client
|
9
|
+
|
10
|
+
# Communicating
|
11
|
+
def self.communicate(host, port, peers)
|
12
|
+
begin
|
13
|
+
Faraday.post("#{host}:#{port}/communicate", peers: peers).body
|
14
|
+
rescue Faraday::ConnectionFailed => e
|
15
|
+
raise
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Getting public key from connected peer
|
20
|
+
def self.get_public_key(host,port)
|
21
|
+
Faraday.post("#{host}:#{port}/get_pubkey").body
|
22
|
+
end
|
23
|
+
|
24
|
+
# Sending messages to peers
|
25
|
+
def self.send_message(host,port,from,message)
|
26
|
+
begin
|
27
|
+
Faraday.post("#{host}:#{port}/get_message", from: from, message: message).body
|
28
|
+
rescue Faraday::ConnectionFailed => e
|
29
|
+
raise
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
34
|
# end
|
data/lib/vesta/helpers.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
#
|
2
|
-
# Helpers
|
3
|
-
#
|
4
|
-
module Vesta
|
5
|
-
class Helpers
|
6
|
-
|
7
|
-
Thread.abort_on_exception = true
|
8
|
-
|
9
|
-
# Print banner
|
10
|
-
def self.banner
|
11
|
-
"\t\tRunning Vesta v#{Vesta::VERSION}"
|
12
|
-
end
|
13
|
-
|
14
|
-
# Do something in every x seconds
|
15
|
-
def every(seconds)
|
16
|
-
Thread.new do
|
17
|
-
loop do
|
18
|
-
sleep seconds
|
19
|
-
yield
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Root folder
|
25
|
-
def self.root
|
26
|
-
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
|
27
|
-
end
|
28
|
-
|
29
|
-
# Add peer to peer object [peers_object]
|
30
|
-
def add_peer(peer,host,port,public_key)
|
31
|
-
peer.push({host: host, port: port, public_key: public_key})
|
32
|
-
peer
|
33
|
-
end
|
34
|
-
|
35
|
-
# Add message to [messages_object]
|
36
|
-
def add_message(messages_object, from, message)
|
37
|
-
messages_object.push({from: from, message: message})
|
38
|
-
messages_object
|
39
|
-
end
|
40
|
-
|
41
|
-
# Print out the status
|
42
|
-
def render_state
|
43
|
-
puts "Node is running on " + Service::LHOST.to_s.magenta + ':'.colorize(:background => :white, :color => :magenta).bold + Service::LPORT.to_s.magenta.bold
|
44
|
-
print "My Peers: ".upcase
|
45
|
-
$PEERS.each do |peer|
|
46
|
-
print "#{peer[:host]}:#{peer[:port]}".yellow.bold + ', '
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Communicate with peers
|
51
|
-
def communicate(index,host,port)
|
52
|
-
communicate_response = Client.communicate(host, port, YAML.dump($PEERS))
|
53
|
-
parsed_response = YAML.load(communicate_response)
|
54
|
-
new_peer = parsed_response['peers']
|
55
|
-
update_peers(new_peer)
|
56
|
-
rescue Faraday::ConnectionFailed
|
57
|
-
$PEERS.delete_at(index)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Update peers
|
61
|
-
def update_peers(new_peers)
|
62
|
-
# if !new_peers.nil? # if new peers are not nil, then append them to $PEERS
|
63
|
-
$PEERS = $PEERS | new_peers
|
64
|
-
$PEERS.uniq
|
65
|
-
# end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
#
|
2
|
+
# Helpers
|
3
|
+
#
|
4
|
+
module Vesta
|
5
|
+
class Helpers
|
6
|
+
|
7
|
+
Thread.abort_on_exception = true
|
8
|
+
|
9
|
+
# Print banner
|
10
|
+
def self.banner
|
11
|
+
"\t\tRunning Vesta v#{Vesta::VERSION}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Do something in every x seconds
|
15
|
+
def every(seconds)
|
16
|
+
Thread.new do
|
17
|
+
loop do
|
18
|
+
sleep seconds
|
19
|
+
yield
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Root folder
|
25
|
+
def self.root
|
26
|
+
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Add peer to peer object [peers_object]
|
30
|
+
def add_peer(peer,host,port,public_key)
|
31
|
+
peer.push({host: host, port: port, public_key: public_key})
|
32
|
+
peer
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add message to [messages_object]
|
36
|
+
def add_message(messages_object, from, message)
|
37
|
+
messages_object.push({from: from, message: message})
|
38
|
+
messages_object
|
39
|
+
end
|
40
|
+
|
41
|
+
# Print out the status
|
42
|
+
def render_state
|
43
|
+
puts "Node is running on " + Service::LHOST.to_s.magenta + ':'.colorize(:background => :white, :color => :magenta).bold + Service::LPORT.to_s.magenta.bold
|
44
|
+
print "My Peers: ".upcase
|
45
|
+
$PEERS.each do |peer|
|
46
|
+
print "#{peer[:host]}:#{peer[:port]}".yellow.bold + ', '
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Communicate with peers
|
51
|
+
def communicate(index,host,port)
|
52
|
+
communicate_response = Client.communicate(host, port, YAML.dump($PEERS))
|
53
|
+
parsed_response = YAML.load(communicate_response)
|
54
|
+
new_peer = parsed_response['peers']
|
55
|
+
update_peers(new_peer)
|
56
|
+
rescue Faraday::ConnectionFailed
|
57
|
+
$PEERS.delete_at(index)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Update peers
|
61
|
+
def update_peers(new_peers)
|
62
|
+
# if !new_peers.nil? # if new peers are not nil, then append them to $PEERS
|
63
|
+
$PEERS = $PEERS | new_peers
|
64
|
+
$PEERS.uniq
|
65
|
+
# end
|
66
|
+
end
|
67
|
+
end
|
68
68
|
end
|
data/lib/vesta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vesta-chat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- eVanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
requirements: []
|
160
160
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.5.2.1
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: Secure decentralized chat groups via ruby!
|