meshchat 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -11
- data/lib/meshchat.rb +48 -42
- data/lib/meshchat/configuration.rb +14 -0
- data/lib/meshchat/configuration/app_config.rb +63 -0
- data/lib/meshchat/configuration/database.rb +41 -0
- data/lib/meshchat/{config → configuration}/hash_file.rb +7 -6
- data/lib/meshchat/configuration/identity.rb +79 -0
- data/lib/meshchat/{config → configuration}/settings.rb +22 -26
- data/lib/meshchat/debug.rb +69 -0
- data/lib/meshchat/encryption.rb +7 -2
- data/lib/meshchat/encryption/aes_rsa.rb +2 -1
- data/lib/meshchat/encryption/passthrough.rb +5 -3
- data/lib/meshchat/locale/en.yml +14 -0
- data/lib/meshchat/models/node.rb +140 -0
- data/lib/meshchat/network.rb +19 -0
- data/lib/meshchat/network/dispatcher.rb +83 -0
- data/lib/meshchat/network/errors.rb +11 -0
- data/lib/meshchat/network/incoming.rb +13 -0
- data/lib/meshchat/network/incoming/message_decryptor.rb +51 -0
- data/lib/meshchat/network/incoming/message_processor.rb +75 -0
- data/lib/meshchat/network/incoming/request_processor.rb +30 -0
- data/lib/meshchat/network/local.rb +12 -0
- data/lib/meshchat/network/local/connection.rb +58 -0
- data/lib/meshchat/network/local/server.rb +69 -0
- data/lib/meshchat/network/message.rb +34 -0
- data/lib/meshchat/network/message/base.rb +139 -0
- data/lib/meshchat/network/message/chat.rb +9 -0
- data/lib/meshchat/network/message/disconnect.rb +21 -0
- data/lib/meshchat/network/message/emote.rb +9 -0
- data/lib/meshchat/network/message/factory.rb +80 -0
- data/lib/meshchat/network/message/node_list.rb +75 -0
- data/lib/meshchat/network/message/node_list_diff.rb +18 -0
- data/lib/meshchat/network/message/node_list_hash.rb +32 -0
- data/lib/meshchat/network/message/ping.rb +31 -0
- data/lib/meshchat/network/message/ping_reply.rb +12 -0
- data/lib/meshchat/network/message/whisper.rb +28 -0
- data/lib/meshchat/network/remote.rb +13 -0
- data/lib/meshchat/network/remote/connection.rb +28 -0
- data/lib/meshchat/network/remote/relay.rb +109 -0
- data/lib/meshchat/network/remote/relay_pool.rb +52 -0
- data/lib/meshchat/ui.rb +13 -0
- data/lib/meshchat/ui/cli.rb +48 -0
- data/lib/meshchat/ui/cli/base.rb +39 -0
- data/lib/meshchat/ui/cli/input_factory.rb +50 -0
- data/lib/meshchat/ui/cli/keyboard_line_input.rb +14 -0
- data/lib/meshchat/ui/command.rb +51 -0
- data/lib/meshchat/ui/command/base.rb +77 -0
- data/lib/meshchat/ui/command/bind.rb +47 -0
- data/lib/meshchat/ui/command/chat.rb +31 -0
- data/lib/meshchat/ui/command/config.rb +37 -0
- data/lib/meshchat/ui/command/emote.rb +23 -0
- data/lib/meshchat/ui/command/exit.rb +16 -0
- data/lib/meshchat/ui/command/help.rb +20 -0
- data/lib/meshchat/ui/command/identity.rb +16 -0
- data/lib/meshchat/ui/command/import.rb +42 -0
- data/lib/meshchat/ui/command/irb.rb +22 -0
- data/lib/meshchat/ui/command/offline.rb +23 -0
- data/lib/meshchat/ui/command/online.rb +18 -0
- data/lib/meshchat/ui/command/ping.rb +65 -0
- data/lib/meshchat/ui/command/ping_all.rb +19 -0
- data/lib/meshchat/ui/command/send_disconnect.rb +20 -0
- data/lib/meshchat/ui/command/server.rb +22 -0
- data/lib/meshchat/ui/command/share.rb +16 -0
- data/lib/meshchat/ui/command/whisper.rb +40 -0
- data/lib/meshchat/ui/display.rb +78 -0
- data/lib/meshchat/ui/display/base.rb +58 -0
- data/lib/meshchat/ui/display/manager.rb +59 -0
- data/lib/meshchat/ui/notifier.rb +9 -0
- data/lib/meshchat/ui/notifier/base.rb +33 -0
- data/lib/meshchat/version.rb +3 -2
- metadata +150 -80
- data/lib/meshchat/cli.rb +0 -188
- data/lib/meshchat/cli/base.rb +0 -13
- data/lib/meshchat/cli/input.rb +0 -37
- data/lib/meshchat/command/base.rb +0 -80
- data/lib/meshchat/command/bind.rb +0 -44
- data/lib/meshchat/command/chat.rb +0 -30
- data/lib/meshchat/command/config.rb +0 -34
- data/lib/meshchat/command/emote.rb +0 -20
- data/lib/meshchat/command/exit.rb +0 -13
- data/lib/meshchat/command/help.rb +0 -17
- data/lib/meshchat/command/identity.rb +0 -13
- data/lib/meshchat/command/import.rb +0 -41
- data/lib/meshchat/command/init.rb +0 -34
- data/lib/meshchat/command/irb.rb +0 -23
- data/lib/meshchat/command/listen.rb +0 -13
- data/lib/meshchat/command/offline.rb +0 -20
- data/lib/meshchat/command/online.rb +0 -15
- data/lib/meshchat/command/ping.rb +0 -65
- data/lib/meshchat/command/ping_all.rb +0 -15
- data/lib/meshchat/command/send_disconnect.rb +0 -15
- data/lib/meshchat/command/server.rb +0 -20
- data/lib/meshchat/command/share.rb +0 -13
- data/lib/meshchat/command/stop_listening.rb +0 -13
- data/lib/meshchat/command/whisper.rb +0 -38
- data/lib/meshchat/database.rb +0 -30
- data/lib/meshchat/display.rb +0 -33
- data/lib/meshchat/display/base.rb +0 -60
- data/lib/meshchat/display/manager.rb +0 -55
- data/lib/meshchat/instance.rb +0 -40
- data/lib/meshchat/message.rb +0 -41
- data/lib/meshchat/message/base.rb +0 -97
- data/lib/meshchat/message/chat.rb +0 -19
- data/lib/meshchat/message/disconnect.rb +0 -13
- data/lib/meshchat/message/emote.rb +0 -9
- data/lib/meshchat/message/node_list.rb +0 -63
- data/lib/meshchat/message/node_list_diff.rb +0 -15
- data/lib/meshchat/message/node_list_hash.rb +0 -33
- data/lib/meshchat/message/ping.rb +0 -32
- data/lib/meshchat/message/ping_reply.rb +0 -9
- data/lib/meshchat/message/relay.rb +0 -43
- data/lib/meshchat/message/whisper.rb +0 -36
- data/lib/meshchat/models/entry.rb +0 -104
- data/lib/meshchat/net/client.rb +0 -83
- data/lib/meshchat/net/listener/errors.rb +0 -11
- data/lib/meshchat/net/listener/request.rb +0 -48
- data/lib/meshchat/net/listener/request_processor.rb +0 -50
- data/lib/meshchat/net/listener/server.rb +0 -114
- data/lib/meshchat/net/request.rb +0 -29
- data/lib/meshchat/notifier/base.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b78573438d48db0c4e67092319332d045ca76b2
|
4
|
+
data.tar.gz: 07de08af6980a361b232fc659b38863b32c49608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2273a362c088cc1eb3898f97d7c8c175d2ab62892093d0030f53fe0ec91f5927e51acf018396344ece8caa05c0c0d49143a5fa95cbf74e28dae65fad11d92c9c
|
7
|
+
data.tar.gz: 3336359fe0a01a70974f0d17b4ffc444303ec88f6d71a3ccd5b1b2f09420805ba16bd8c00244b67f5fde7f647797f521a9a471d29b5cc99b3d1f9f6cb6817bdb
|
data/README.md
CHANGED
@@ -1,22 +1,50 @@
|
|
1
|
-
#
|
1
|
+
#Meshchat Core [![Build Status](https://travis-ci.org/NullVoxPopuli/meshchat.svg)](https://travis-ci.org/NullVoxPopuli/meshchat) [![Code Climate](https://codeclimate.com/github/NullVoxPopuli/meshchat/badges/gpa.svg)](https://codeclimate.com/github/NullVoxPopuli/meshchat) [![Test Coverage](https://codeclimate.com/github/NullVoxPopuli/meshchat/badges/coverage.svg)](https://codeclimate.com/github/NullVoxPopuli/meshchat/coverage)
|
2
2
|
|
3
|
-
This is the core functionality for implementing a [mesh-chat](https://github.com/neuravion/mesh-chat) compatible client in ruby
|
3
|
+
This is the core functionality for implementing a [mesh-chat](https://github.com/neuravion/mesh-chat-protocol) compatible client in ruby
|
4
|
+
|
5
|
+
[Documentation](http://nullvoxpopuli.github.io/meshchat/)
|
4
6
|
|
5
7
|
#Usage
|
6
8
|
|
7
|
-
See [Spiced Rumby](https://github.com/NullVoxPopuli/spiced_rumby)
|
9
|
+
See [Spiced Rumby](https://github.com/NullVoxPopuli/spiced_rumby) (GUI wrapper around this gem)
|
8
10
|
|
9
|
-
In order to use meshchat with your own interface, you only need to pass in your own
|
11
|
+
In order to use meshchat with your own interface, you only need to pass in your own implementation of `Display::Base`
|
10
12
|
|
11
13
|
Optionally, you may pass in a notifier to have the mesh-chat trigger notifications for your system
|
12
14
|
|
13
15
|
```ruby
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
Meshchat.start(
|
17
|
+
# name of your client
|
18
|
+
client_name: Meshchat.name,
|
19
|
+
# version of your client
|
20
|
+
client_version: Meshchat::VERSION,
|
21
|
+
# your class implementing `Meshchat::Ui::Display::Base`
|
22
|
+
display: Meshchat::Ui::Display::Base,
|
23
|
+
# your class implementing `Meshchat::Ui::CLI::Base`
|
24
|
+
input: Meshchat::Ui::CLI::KeyboardLineInput,
|
25
|
+
# (optional) your class implementing `Notifier::Base`
|
26
|
+
# typically, this hooks in to libnotify on *nix
|
27
|
+
notifier: Meshchat::Ui::Notifier::Base,
|
21
28
|
)
|
22
29
|
```
|
30
|
+
For a lightweight, runnable sample for how to invoke this, see the included `run` script.
|
31
|
+
|
32
|
+
# Development
|
33
|
+
|
34
|
+
### Running
|
35
|
+
|
36
|
+
```bash
|
37
|
+
./run
|
38
|
+
```
|
39
|
+
|
40
|
+
### Tests
|
41
|
+
|
42
|
+
```bash
|
43
|
+
rspec
|
44
|
+
```
|
45
|
+
|
46
|
+
### Line Count
|
47
|
+
|
48
|
+
```bash
|
49
|
+
loco
|
50
|
+
```
|
data/lib/meshchat.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# required standard libs
|
2
3
|
require 'openssl'
|
3
4
|
require 'socket'
|
@@ -5,45 +6,38 @@ require 'json'
|
|
5
6
|
require 'date'
|
6
7
|
require 'colorize'
|
7
8
|
require 'io/console'
|
8
|
-
require
|
9
|
+
require 'readline'
|
9
10
|
require 'logger'
|
10
11
|
|
11
12
|
# required gems
|
12
13
|
require 'awesome_print'
|
13
14
|
require 'sqlite3'
|
14
15
|
require 'active_record'
|
15
|
-
require '
|
16
|
-
require '
|
16
|
+
require 'eventmachine'
|
17
|
+
require 'i18n'
|
17
18
|
|
18
19
|
# active support extensions
|
19
20
|
require 'active_support/core_ext/module/delegation'
|
20
21
|
require 'active_support/core_ext/object/blank'
|
21
22
|
require 'active_support/core_ext/object/try'
|
22
23
|
|
23
|
-
# local files for meshchat
|
24
24
|
require 'meshchat/version'
|
25
|
-
require 'meshchat/database'
|
26
|
-
require 'meshchat/instance'
|
27
|
-
require 'meshchat/encryption'
|
28
|
-
require 'meshchat/display'
|
29
|
-
require 'meshchat/display/manager'
|
30
|
-
require 'meshchat/notifier/base'
|
31
|
-
require 'meshchat/models/entry'
|
32
|
-
require 'meshchat/config/hash_file'
|
33
|
-
require 'meshchat/config/settings'
|
34
|
-
require 'meshchat/net/request'
|
35
|
-
require 'meshchat/net/client'
|
36
|
-
require 'meshchat/net/listener/request'
|
37
|
-
require 'meshchat/net/listener/request_processor'
|
38
|
-
require 'meshchat/net/listener/server'
|
39
|
-
require 'meshchat/cli'
|
40
|
-
require 'meshchat/message'
|
41
25
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
26
|
+
# debug logging....
|
27
|
+
# ^ at least util 'all' scenarios are captured via tests
|
28
|
+
# TODO: look in to how Active Support does logging
|
29
|
+
require 'meshchat/debug'
|
30
|
+
|
31
|
+
module Meshchat
|
32
|
+
extend ActiveSupport::Autoload
|
33
|
+
|
34
|
+
eager_autoload do
|
35
|
+
autoload :Encryption
|
36
|
+
autoload :Ui
|
37
|
+
autoload :Node, 'meshchat/models/node'
|
38
|
+
autoload :Network
|
39
|
+
autoload :Configuration
|
40
|
+
end
|
47
41
|
|
48
42
|
module_function
|
49
43
|
|
@@ -51,25 +45,37 @@ module MeshChat
|
|
51
45
|
# @option overrides [Proc] on_display_start what to do upon start of the display manager
|
52
46
|
# @option overrides [class] display the display ui to use inherited from Display::Base
|
53
47
|
def start(overrides = {})
|
54
|
-
|
55
|
-
|
56
|
-
client_name: NAME,
|
57
|
-
client_version: VERSION,
|
58
|
-
input: CLI::Base,
|
59
|
-
notifier: Notifier::Base
|
60
|
-
}
|
61
|
-
options = defaults.merge(overrides)
|
48
|
+
app_config = Configuration::AppConfig.new(overrides)
|
49
|
+
app_config.validate
|
62
50
|
|
63
|
-
#
|
64
|
-
|
51
|
+
# if everything is configured correctly, boot the app
|
52
|
+
# this handles all of the asyncronous stuff
|
53
|
+
EventMachine.run do
|
54
|
+
bootstrap_runloop(app_config)
|
55
|
+
end
|
56
|
+
end
|
65
57
|
|
66
|
-
|
67
|
-
|
58
|
+
def bootstrap_runloop(app_config)
|
59
|
+
# 1. hook up the display / output 'device'
|
60
|
+
# - responsible for notifications
|
61
|
+
# - created in Configuration
|
62
|
+
display = Display
|
68
63
|
|
69
|
-
#
|
70
|
-
|
71
|
-
|
64
|
+
# 2. create the message dispatcher
|
65
|
+
# - boots the local and relay network connections
|
66
|
+
# - sends the messages out to the network
|
67
|
+
# - tries p2p first, than uses the relays
|
68
|
+
message_dispatcher = Network::Dispatcher.new
|
69
|
+
|
70
|
+
# 3. hook up the keyboard / input 'device'
|
71
|
+
# - tesponsible for parsing input
|
72
|
+
input_receiver = Ui::CLI.new(
|
73
|
+
message_dispatcher,
|
74
|
+
message_dispatcher._message_factory,
|
75
|
+
display)
|
72
76
|
|
73
|
-
|
74
|
-
|
77
|
+
# by default the app_config[:input] is
|
78
|
+
# Meshchat::Cli::KeyboardLineInput
|
79
|
+
EM.open_keyboard(app_config[:input], input_receiver)
|
80
|
+
end
|
75
81
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Meshchat
|
3
|
+
module Configuration
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
|
6
|
+
eager_autoload do
|
7
|
+
autoload :Database
|
8
|
+
autoload :HashFile
|
9
|
+
autoload :Settings
|
10
|
+
autoload :Identity
|
11
|
+
autoload :AppConfig
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Meshchat
|
3
|
+
module Configuration
|
4
|
+
class AppConfig
|
5
|
+
DEFAULTS = {
|
6
|
+
display: Ui::Display::Base,
|
7
|
+
client_name: Meshchat.name,
|
8
|
+
client_version: Meshchat::VERSION,
|
9
|
+
input: Ui::CLI::KeyboardLineInput,
|
10
|
+
notifier: Ui::Notifier::Base
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
attr_reader :_options
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
@_options = DEFAULTS.merge(options)
|
17
|
+
@_options[:user] = Configuration::Settings.new
|
18
|
+
|
19
|
+
locale_path = 'lib/meshchat/locale/'
|
20
|
+
# I18n.load_path = Dir[locale_path + '*.yml']
|
21
|
+
I18n.backend.store_translations(:en,
|
22
|
+
YAML.load(File.read(locale_path + 'en.yml')))
|
23
|
+
|
24
|
+
Meshchat.const_set(:Notify, options[:notifier])
|
25
|
+
|
26
|
+
# The display has to be created right away so that
|
27
|
+
# we can start outputting to it
|
28
|
+
manager = Ui::Display::Manager.new(options[:display])
|
29
|
+
Meshchat.const_set(:Display, manager)
|
30
|
+
Meshchat.const_set(:APP_CONFIG, self)
|
31
|
+
|
32
|
+
Meshchat::Display.start
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate
|
36
|
+
# Check user config, go through initial setup if we haven't done so already.
|
37
|
+
# This should only need to be done once per user.
|
38
|
+
#
|
39
|
+
# This will also generate a whatever-alias-you-choose.json that the user
|
40
|
+
# can pass around to someone gain access to the network.
|
41
|
+
#
|
42
|
+
# Personal settings are stored in settings.json. This should never be
|
43
|
+
# shared with anyone.
|
44
|
+
Identity.check_or_create
|
45
|
+
|
46
|
+
# setup the storage - for keeping track of nodes on the network
|
47
|
+
Database.setup_storage
|
48
|
+
end
|
49
|
+
|
50
|
+
def [](key)
|
51
|
+
_options[key]
|
52
|
+
end
|
53
|
+
|
54
|
+
def []=(key, value)
|
55
|
+
_options[key] = value
|
56
|
+
end
|
57
|
+
|
58
|
+
def user
|
59
|
+
_options[:user]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Meshchat
|
3
|
+
module Configuration
|
4
|
+
module Database
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Upon initial startup, instantiated the database
|
8
|
+
# this is used for storing the information of every node
|
9
|
+
# on the network
|
10
|
+
def setup_storage
|
11
|
+
ActiveRecord::Base.establish_connection(
|
12
|
+
adapter: 'sqlite3',
|
13
|
+
database: 'meshchat.sqlite3',
|
14
|
+
pool: 128
|
15
|
+
)
|
16
|
+
|
17
|
+
create_database
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_database
|
21
|
+
ActiveRecord::Migration.suppress_messages do
|
22
|
+
ActiveRecord::Schema.define do
|
23
|
+
unless data_source_exists? :nodes
|
24
|
+
create_table :nodes do |table|
|
25
|
+
table.column :alias_name, :string
|
26
|
+
table.column :uid, :string
|
27
|
+
table.column :public_key, :string
|
28
|
+
|
29
|
+
table.column :location_on_network, :string
|
30
|
+
table.column :location_of_relay, :string
|
31
|
+
|
32
|
+
table.column :on_local_network, :boolean, default: true, null: false
|
33
|
+
table.column :on_relay, :boolean, default: false, null: false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Meshchat
|
3
|
+
module Configuration
|
3
4
|
class HashFile
|
4
5
|
attr_accessor :_hash
|
5
6
|
|
6
|
-
DEFAULT_SETTINGS = {}
|
7
|
+
DEFAULT_SETTINGS = {}.freeze
|
7
8
|
|
8
9
|
def initialize
|
9
|
-
self._hash = default_settings
|
10
|
+
self._hash = default_settings.dup
|
10
11
|
exists? ? load : save
|
11
12
|
end
|
12
13
|
|
@@ -22,7 +23,7 @@ module MeshChat
|
|
22
23
|
f = read_file
|
23
24
|
begin
|
24
25
|
self._hash = JSON.parse(f)
|
25
|
-
rescue
|
26
|
+
rescue => e
|
26
27
|
Display.alert e.message
|
27
28
|
self._hash = default_settings
|
28
29
|
Display.warning 'writing defaults...'
|
@@ -64,7 +65,7 @@ module MeshChat
|
|
64
65
|
|
65
66
|
def filename
|
66
67
|
return @filename if @filename
|
67
|
-
|
68
|
+
raise 'filename must be set'
|
68
69
|
end
|
69
70
|
|
70
71
|
def default_settings
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Meshchat
|
3
|
+
module Configuration
|
4
|
+
module Identity
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def check_or_create(overwrite = false, auto_confirm = false)
|
8
|
+
# if setup is complete, we don't need to do anything.
|
9
|
+
# it's likely the user already went through the setup process
|
10
|
+
return if setup_is_completed? && !overwrite
|
11
|
+
|
12
|
+
generate! if auto_confirm || confirm?(I18n.t('identity.settings_not_detected'))
|
13
|
+
# if everything is good, the app can boot
|
14
|
+
return APP_CONFIG.user.save if setup_is_completed?
|
15
|
+
|
16
|
+
# if something has gone wrong, we'll ask if they want to try again
|
17
|
+
return check_or_create(true, true) if confirm? I18n.t('identity.unknown_error_try_again')
|
18
|
+
|
19
|
+
# we failed, and don't want to continue
|
20
|
+
alert_and_exit
|
21
|
+
end
|
22
|
+
|
23
|
+
def alert_and_exit
|
24
|
+
Display.alert I18n.t('identity.settings_are_invalid')
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup_is_completed?
|
29
|
+
APP_CONFIG.user.is_complete?
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate!
|
33
|
+
confirm_uid
|
34
|
+
confirm_alias
|
35
|
+
confirm_keys
|
36
|
+
# TODO: port and ip?
|
37
|
+
end
|
38
|
+
|
39
|
+
def confirm_uid
|
40
|
+
if APP_CONFIG.user.uid_exists?
|
41
|
+
APP_CONFIG.user.generate_uid if confirm? I18n.t('identity.confirm_uid_replace')
|
42
|
+
else
|
43
|
+
APP_CONFIG.user.generate_uid
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def confirm_alias
|
48
|
+
if APP_CONFIG.user['alias'].present?
|
49
|
+
Display.add_line I18.t('idenity.current_alias', name: APP_CONFIG.user['alias'])
|
50
|
+
ask_for_alias if confirm? I18n.t('identity.confirm_alias_replace')
|
51
|
+
else
|
52
|
+
ask_for_alias
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def confirm_keys
|
57
|
+
if APP_CONFIG.user.keys_exist?
|
58
|
+
APP_CONFIG.user.generate_keys if confirm? I18n.t('identity.confirm_key_replace')
|
59
|
+
else
|
60
|
+
APP_CONFIG.user.generate_keys
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def ask_for_alias
|
65
|
+
Display.add_line I18n.t('identity.ask_for_alias')
|
66
|
+
response = gets
|
67
|
+
response = response.chomp
|
68
|
+
APP_CONFIG.user['alias'] = response
|
69
|
+
end
|
70
|
+
|
71
|
+
def confirm?(msg)
|
72
|
+
Display.warning msg + I18n.t(:confirm_options)
|
73
|
+
response = gets
|
74
|
+
response = response.chomp
|
75
|
+
[I18n.t(:confirm_yes), I18n.t(:confirm_y)].include?(response.downcase)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -1,31 +1,23 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Meshchat
|
3
|
+
module Configuration
|
3
4
|
class Settings < HashFile
|
4
5
|
FILENAME = 'settings.json'
|
5
6
|
|
6
7
|
DEFAULT_SETTINGS = {
|
7
|
-
'alias' => '
|
8
|
-
'port' => '
|
8
|
+
'alias' => '',
|
9
|
+
'port' => '8009',
|
9
10
|
'ip' => 'localhost',
|
10
|
-
'uid' => '
|
11
|
-
'publickey' => '
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:location, :identity, :keys_exist?, :public_key,
|
18
|
-
:private_key, :generate_keys, :share, :key_pair,
|
19
|
-
:uid_exists?, :generate_uid, :debug?, :identity_as_json,
|
20
|
-
to: :instance
|
21
|
-
|
22
|
-
def instance
|
23
|
-
@instance ||= new
|
24
|
-
end
|
25
|
-
end
|
11
|
+
'uid' => '',
|
12
|
+
'publickey' => '',
|
13
|
+
'relays' => [
|
14
|
+
'wss://mesh-relay-in-us-1.herokuapp.com',
|
15
|
+
'wss://mesh-relay-us-2.herokuapp.com'
|
16
|
+
]
|
17
|
+
}.freeze
|
26
18
|
|
27
19
|
def debug?
|
28
|
-
|
20
|
+
%w(true 1 yes y t).include?(self['debug'].try(:downcase))
|
29
21
|
end
|
30
22
|
|
31
23
|
def identity_as_json
|
@@ -41,7 +33,7 @@ module MeshChat
|
|
41
33
|
data = identity_as_json.to_json
|
42
34
|
|
43
35
|
filename = "#{identity_as_json['alias']}.json"
|
44
|
-
File.open(filename, 'w'){ |f| f.syswrite(data) }
|
36
|
+
File.open(filename, 'w') { |f| f.syswrite(data) }
|
45
37
|
Display.info "#{filename} written..."
|
46
38
|
end
|
47
39
|
|
@@ -101,12 +93,16 @@ module MeshChat
|
|
101
93
|
|
102
94
|
def errors
|
103
95
|
messages = []
|
104
|
-
messages << 'must have an alias'
|
105
|
-
messages << 'must have ip set'
|
106
|
-
messages << 'must have port set'
|
107
|
-
messages << 'must have uid set'
|
96
|
+
messages << 'must have an alias' unless self['alias'].present?
|
97
|
+
messages << 'must have ip set' unless self['ip'].present?
|
98
|
+
messages << 'must have port set' unless self['port'].present?
|
99
|
+
messages << 'must have uid set' unless self['uid'].present?
|
108
100
|
messages
|
109
101
|
end
|
102
|
+
|
103
|
+
def is_complete?
|
104
|
+
valid? && self['privatekey'] && self['publickey']
|
105
|
+
end
|
110
106
|
end
|
111
107
|
end
|
112
108
|
end
|