vesta-chat 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f1743834f184e5d41e3ddc9a6a3fa2e7694bfdb
4
+ data.tar.gz: a10ba1991ad4c8b29e9b4eb517e47c0d108303df
5
+ SHA512:
6
+ metadata.gz: 65a1797329901e846ec72eaba5acefc26d6affda0f1b1057d4f88d5c09784300aada110f1af9d7025d3a6c7b8de7751a6b328ab5fa6af3135b7aa8cb9cf564d4
7
+ data.tar.gz: c4169c0edc1515cbf32bbea84eebbf71c1028465aab6644699358f1076a132788f15c28f65ef2086c1b8489262e6ee89ba4746bbd39a55cfddf84dffca496c76
data/bin/vesta ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "vesta"
3
+ Vesta::Service
@@ -0,0 +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
34
+ # end
@@ -0,0 +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
68
+ end
@@ -0,0 +1,3 @@
1
+ module Vesta
2
+ VERSION = "0.1.0"
3
+ end
data/lib/vesta.rb ADDED
@@ -0,0 +1,124 @@
1
+ require "vesta/client"
2
+ require "vesta/helpers"
3
+ require "vesta/version"
4
+
5
+ require 'sinatra/base'
6
+ require 'encryption'
7
+ require 'colorize'
8
+ require 'yaml'
9
+ require 'active_support/time'
10
+ require 'json'
11
+ require 'pp'
12
+
13
+ module Vesta
14
+ class Service < Sinatra::Base
15
+ # client = Client.new # initialzing client class
16
+ helpers = Helpers.new # # initialzing helpers class
17
+
18
+ LHOST, LPORT, PEER_HOST, PEER_PORT = ARGV.first(4)
19
+
20
+ # Total peers
21
+ $PEERS = []
22
+ $MESSAGES = []
23
+ # Generate a 1024 bit private-key & public-key
24
+ $my_public_key, $my_private_key = Encryption::Keypair.generate( 1024 )
25
+
26
+ # Adding local network to peers
27
+ helpers.add_peer($PEERS, LHOST, LPORT, $my_public_key.to_s)
28
+ # Checking options(a simple option parser)
29
+ if PEER_PORT.nil? || PEER_HOST.nil? # => if peer port and peer host were nil.. that means you're a node
30
+ puts "Running node..".green.bold
31
+ else
32
+ # Adding peer to $PEERS
33
+ $their_public_key = Client.get_public_key(PEER_HOST,PEER_PORT)
34
+ helpers.add_peer($PEERS, PEER_HOST, PEER_PORT, $their_public_key)
35
+ end
36
+
37
+ # Sinatra configuration
38
+ set :server, 'thin'
39
+ set :connections, []
40
+ set :port, LPORT
41
+ set :public_folder, "#{Helpers.root}/lib/vesta/public"
42
+ set :views, "#{Helpers.root}/lib/vesta/views"
43
+ set :environment, :production
44
+
45
+ # Communicate yield
46
+ helpers.every(10.seconds) do
47
+ # Communicate with peers in every x seconds
48
+ $PEERS.each_with_index do |peer,index|
49
+ host = peer[:host]
50
+ port = peer[:port]
51
+ # next if that peer is you
52
+ next if LHOST == host && LPORT == port
53
+ puts "communicating about peers #{host.to_s.green.bold}:#{port.to_s.green}"
54
+ helpers.communicate(index, host, port)
55
+ end
56
+ system 'clear'
57
+ helpers.render_state
58
+ end
59
+
60
+ # Communication route
61
+ post '/communicate' do
62
+ their_peers = YAML.load(params['peers'])
63
+ helpers.update_peers(their_peers)
64
+ YAML.dump('peers' => $PEERS)
65
+ end
66
+
67
+ # Send message route
68
+ post '/send_message' do
69
+ $PEERS.each do |peer|
70
+ next if peer[:host] == LHOST && peer[:port] == LPORT
71
+ pub_key = Encryption::PublicKey.new(peer[:public_key])
72
+ message = pub_key.encrypt(params['message'])
73
+ puts "-- ENCRYPTED MESSAGE --".cyan.bold
74
+ puts message.to_s[0..50] + " ..."
75
+ puts "-- ENCRYPTED MESSAGE --".cyan.bold
76
+ from = "#{LHOST}:#{LPORT}"
77
+ Client.send_message(peer[:host],peer[:port], from, message)
78
+ end
79
+ end
80
+
81
+ # Add my messages to $MESSAGES
82
+ post '/my_messages' do
83
+ encrypted_message = $my_public_key.encrypt(params['message']).to_s
84
+ $MESSAGES = helpers.add_message($MESSAGES, "#{LHOST}:#{LPORT}", encrypted_message)
85
+ end
86
+
87
+ # Add messages to $MESSAGES
88
+ post '/get_message' do
89
+ puts "-- GOT A MESSAGE".cyan.bold
90
+ $MESSAGES = helpers.add_message($MESSAGES, params['from'], params['message'])
91
+ end
92
+
93
+ # Return $MESSAGES to json output
94
+ post '/get_messages' do
95
+ messages = []
96
+ $MESSAGES.each do |msg|
97
+ messages << {from: msg[:from], message: $my_private_key.decrypt(msg[:message]).to_s.force_encoding('ASCII-8BIT').force_encoding('UTF-8')}
98
+ end
99
+ messages.to_json
100
+ end
101
+
102
+ # Share pub key
103
+ post '/get_pubkey' do
104
+ $my_public_key.to_s
105
+ end
106
+
107
+ # Return $PEERS length
108
+ post '/total_peers' do
109
+ $PEERS.size.to_s
110
+ end
111
+
112
+ # Index route
113
+ get '/' do
114
+ erb :index
115
+ end
116
+
117
+ # 404 not found route
118
+ not_found do
119
+ status 404
120
+ erb :oops
121
+ end
122
+ run!
123
+ end
124
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vesta-chat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - eVanilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 5.1.4
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '5.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 5.1.4
47
+ - !ruby/object:Gem::Dependency
48
+ name: colorize
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.8.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: thin
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.7'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.7.2
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.7'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.7.2
81
+ - !ruby/object:Gem::Dependency
82
+ name: json
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '2.1'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '2.1'
95
+ - !ruby/object:Gem::Dependency
96
+ name: sinatra
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: encryption
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.1'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 1.1.8
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.1'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 1.1.8
129
+ description: A decentralized p2p & E2EE chat group
130
+ email:
131
+ - evoke.lektrique@gmail.com
132
+ executables:
133
+ - vesta
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - bin/vesta
138
+ - lib/vesta.rb
139
+ - lib/vesta/client.rb
140
+ - lib/vesta/helpers.rb
141
+ - lib/vesta/version.rb
142
+ homepage: http://github.com/eVanilla/vesta
143
+ licenses: []
144
+ metadata: {}
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 2.6.4
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Secure decentralized chat groups via ruby!
165
+ test_files: []