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
@@ -1,17 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Help < Command::Base
|
4
|
-
def self.description
|
5
|
-
'displays this help message'
|
6
|
-
end
|
7
|
-
|
8
|
-
def handle
|
9
|
-
MeshChat::CLI::COMMAND_MAP.each do |key, klass|
|
10
|
-
if klass.respond_to?(:description)
|
11
|
-
Display.info "/#{key}\t\t" + klass.description
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Import < Command::Base
|
4
|
-
def self.description
|
5
|
-
'imports an identity file (formatted as json)'
|
6
|
-
end
|
7
|
-
|
8
|
-
def handle
|
9
|
-
if command_valid?
|
10
|
-
node = Models::Entry.import_from_file(filename)
|
11
|
-
if node.valid? && node.persisted?
|
12
|
-
Display.success "#{node.alias_name} successfully imported"
|
13
|
-
|
14
|
-
# send the server list to this new node
|
15
|
-
Net::Client.send(
|
16
|
-
node: node,
|
17
|
-
message: Message::NodeList.new
|
18
|
-
)
|
19
|
-
else
|
20
|
-
Display.alert "#{node.alias_name} is invalid"
|
21
|
-
Display.alert node.errors.full_messages.join("\n")
|
22
|
-
end
|
23
|
-
else
|
24
|
-
Display.alert usage
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def usage
|
29
|
-
'Usage: /import {filename}'
|
30
|
-
end
|
31
|
-
|
32
|
-
def command_valid?
|
33
|
-
filename.present?
|
34
|
-
end
|
35
|
-
|
36
|
-
def filename
|
37
|
-
sub_command
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Init < Command::Base
|
4
|
-
def handle
|
5
|
-
if Settings.uid_exists?
|
6
|
-
if confirm? 'uid exists, are you sure you want a new identity?'
|
7
|
-
Settings.generate_uid
|
8
|
-
else
|
9
|
-
Display.alert 'uid generation aborted'
|
10
|
-
end
|
11
|
-
else
|
12
|
-
Settings.generate_uid
|
13
|
-
end
|
14
|
-
|
15
|
-
if Settings.keys_exist?
|
16
|
-
if confirm? 'keys exist, overwrite?'
|
17
|
-
Settings.generate_keys
|
18
|
-
else
|
19
|
-
Display.alert 'key generation aborted'
|
20
|
-
end
|
21
|
-
else
|
22
|
-
Settings.generate_keys
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def confirm?(msg)
|
27
|
-
Display.warning(msg + ' (Y/N)')
|
28
|
-
response = MeshChat::CLI.get_input
|
29
|
-
response = response.chomp
|
30
|
-
['yes', 'y'].include?(response.downcase)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/meshchat/command/irb.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
|
4
|
-
# TODO: only include this and awesome_print when booted with
|
5
|
-
# debug=true in the config
|
6
|
-
class IRB < Command::Base
|
7
|
-
def self.description
|
8
|
-
'runs ruby commands (useful for debugging)'
|
9
|
-
end
|
10
|
-
|
11
|
-
def handle
|
12
|
-
begin
|
13
|
-
code = command_args[1..command_args.length].join(' ')
|
14
|
-
ap eval(code)
|
15
|
-
''
|
16
|
-
rescue => e
|
17
|
-
ap e.message
|
18
|
-
ap e.backtrace
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Offline < Command::Base
|
4
|
-
def self.description
|
5
|
-
'shows offline users'
|
6
|
-
end
|
7
|
-
|
8
|
-
def handle
|
9
|
-
list = Node.offline.map(&:as_info)
|
10
|
-
msg = if list.present?
|
11
|
-
list.join(", ")
|
12
|
-
else
|
13
|
-
'no one is offline'
|
14
|
-
end
|
15
|
-
|
16
|
-
Display.info msg
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Online < Command::Base
|
4
|
-
def self.description
|
5
|
-
'shows online users'
|
6
|
-
end
|
7
|
-
|
8
|
-
def handle
|
9
|
-
msg = Node.online.map(&:as_info).join(", ").presence || 'no one is online'
|
10
|
-
|
11
|
-
Display.info msg
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Ping < Command::Base
|
4
|
-
def self.description
|
5
|
-
'pings a particular user'
|
6
|
-
end
|
7
|
-
|
8
|
-
def handle
|
9
|
-
if command_valid?
|
10
|
-
msg = Message::Ping.new
|
11
|
-
|
12
|
-
field, value = parse_ping_command
|
13
|
-
|
14
|
-
node =
|
15
|
-
if field == 'location'
|
16
|
-
Node.find_by_location(lookup_value)
|
17
|
-
else
|
18
|
-
Node.find_by_alias_name(lookup_value)
|
19
|
-
end
|
20
|
-
|
21
|
-
location = node.try(:location)
|
22
|
-
|
23
|
-
unless location
|
24
|
-
return Display.alert "#{lookup_value} could not be found"
|
25
|
-
end
|
26
|
-
|
27
|
-
Net::Client.send(
|
28
|
-
node: node,
|
29
|
-
message: msg
|
30
|
-
)
|
31
|
-
else
|
32
|
-
Display.alert usage
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def usage
|
37
|
-
'Usage: /ping {field} {value} e.g.: /ping alias neurotek or /ping location 10.10.10.10:8080'
|
38
|
-
end
|
39
|
-
|
40
|
-
def lookup_field
|
41
|
-
sub_command
|
42
|
-
end
|
43
|
-
|
44
|
-
def lookup_value
|
45
|
-
value = command_args.last
|
46
|
-
value if value != sub_command
|
47
|
-
end
|
48
|
-
|
49
|
-
def command_valid?
|
50
|
-
parse_ping_command.compact.length == 2
|
51
|
-
end
|
52
|
-
|
53
|
-
def parse_ping_command
|
54
|
-
@parsed_args ||=
|
55
|
-
if lookup_field == 'location' || lookup_field == 'alias'
|
56
|
-
[lookup_field, lookup_value]
|
57
|
-
elsif lookup_field =~ /(?:[0-9]{1,3}\.){3}[0-9]{1,3}/
|
58
|
-
['location', lookup_field]
|
59
|
-
else
|
60
|
-
['alias', lookup_field]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class SendDisconnect < Command::Base
|
4
|
-
def self.description
|
5
|
-
'sends a disconnect message to all users'
|
6
|
-
end
|
7
|
-
|
8
|
-
def handle
|
9
|
-
Node.all.each do |n|
|
10
|
-
Net::Client.send(node: n, message: Message::Disconnect.new)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Server < Command::Base
|
4
|
-
ONLINE = 'online'
|
5
|
-
def self.description
|
6
|
-
'known server statuses'
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
def handle
|
11
|
-
case sub_command
|
12
|
-
when ONLINE
|
13
|
-
Display.info Node.online.map(&:as_info).join(', ') || 'no one is online'
|
14
|
-
else
|
15
|
-
Display.info Node.all.map(&:as_info).join(', ') || 'there are no nodes'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
class Command
|
3
|
-
class Whisper < Command::Base
|
4
|
-
def self.description
|
5
|
-
'sends a private message to a spepcific person'
|
6
|
-
end
|
7
|
-
|
8
|
-
def target
|
9
|
-
# get first arg
|
10
|
-
command
|
11
|
-
end
|
12
|
-
|
13
|
-
def message
|
14
|
-
command_args[1..command_args.length].try(:join, ' ')
|
15
|
-
end
|
16
|
-
|
17
|
-
def handle
|
18
|
-
node = Node.find_by_alias_name(target)
|
19
|
-
|
20
|
-
if node
|
21
|
-
m = Message::Whisper.new(
|
22
|
-
message: message,
|
23
|
-
to: target
|
24
|
-
)
|
25
|
-
|
26
|
-
Display.whisper m.display
|
27
|
-
|
28
|
-
Net::Client.send(
|
29
|
-
node: node,
|
30
|
-
message: m
|
31
|
-
)
|
32
|
-
else
|
33
|
-
Display.alert "node for #{target} not found or is not online"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/meshchat/database.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
module Database
|
3
|
-
module_function
|
4
|
-
|
5
|
-
# Upon initial startup, instantiated the database
|
6
|
-
# this is used for storing the information of every node
|
7
|
-
# on the network
|
8
|
-
def setup_storage
|
9
|
-
ActiveRecord::Base.establish_connection(
|
10
|
-
adapter: "sqlite3",
|
11
|
-
database: "meshchat.sqlite3",
|
12
|
-
pool: 128
|
13
|
-
)
|
14
|
-
|
15
|
-
ActiveRecord::Migration.suppress_messages do
|
16
|
-
ActiveRecord::Schema.define do
|
17
|
-
unless table_exists? :entries
|
18
|
-
create_table :entries do |table|
|
19
|
-
table.column :alias_name, :string
|
20
|
-
table.column :location, :string
|
21
|
-
table.column :uid, :string
|
22
|
-
table.column :public_key, :string
|
23
|
-
table.column :online, :boolean, default: true, null: false
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/meshchat/display.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module MeshChat
|
2
|
-
module Display
|
3
|
-
|
4
|
-
module_function
|
5
|
-
|
6
|
-
# delegate :start, :add_line,
|
7
|
-
# :info, :warning, :alert, :success, :chat, :whisper,
|
8
|
-
# :present_message, to: :current
|
9
|
-
|
10
|
-
# TODO: Delegate doesn't work on modules?
|
11
|
-
def start(*args); current.start(*args); end
|
12
|
-
def add_line(*args); current.add_line(*args); end
|
13
|
-
def info(*args); current.info(*args); end
|
14
|
-
def emote(*args); current.emote(*args); end
|
15
|
-
def warning(*args); current.warning(*args); end
|
16
|
-
def alert(*args); current.alert(*args); end
|
17
|
-
def success(*args); current.success(*args); end
|
18
|
-
def chat(*args); current.chat(*args); end
|
19
|
-
def whisper(*args); current.whisper(*args); end
|
20
|
-
def present_message(*args); current.present_message(*args); end
|
21
|
-
|
22
|
-
# TODO: break these out in to their own Logger class, and not
|
23
|
-
# on the display object
|
24
|
-
def fatal(*args); current.fatal(*args); end
|
25
|
-
def debug(*args); current.debug(*args); end
|
26
|
-
def error(*args); current.error(*args); end
|
27
|
-
|
28
|
-
def current
|
29
|
-
MeshChat::Instance.display
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|