meshchat 0.6.11 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6704e3fae4b8087d79dba4722e38249a252adb43
4
- data.tar.gz: b617601966357d43e37cec0bdb84f6c3c22ecfde
3
+ metadata.gz: a669862d8119b09c7bfbf437c476aba8974bb349
4
+ data.tar.gz: 13d7944d37b968bc43c6fc57332b1e0296a62e36
5
5
  SHA512:
6
- metadata.gz: 965d1330b0860323aefb6739e0834493a7878dd298c1ca46bf5a5df173a7834216d03507d916b7d6e855bdaac81b984ed729d6b168d605fd74ca8f880fb40401
7
- data.tar.gz: fbb391de6550c6eb3a7bdf736739137b03398f1cb4767354ad79ed76803c4ad699a5e6735d8eaf53960ba51bd29271d05acaf61f0abd8486706429544f354254
6
+ metadata.gz: eb9df8e25b985e6d92b7e9fd70f053e770960ec29994dd104de7ba02fd84d0b97e93c4ad0c16d37510d8d5f09aa4fe5c7cb810f81c057dd367b8e11255e85619
7
+ data.tar.gz: 914be292200fe5b1309702fb36d5cca2e9eb3990b7895d5d498524ad565ae7ddbae1ab12ce1f4a072bbeeadbdd6d61223e55599c028d89c87e4ff13c98a4c8e7
@@ -11,6 +11,7 @@ require 'meshchat/command/whisper'
11
11
  require 'meshchat/command/exit'
12
12
  require 'meshchat/command/listen'
13
13
  require 'meshchat/command/stop_listening'
14
+ require 'meshchat/command/send_disconnect'
14
15
  require 'meshchat/command/help'
15
16
  require 'meshchat/command/bind'
16
17
  require 'meshchat/command/online'
@@ -43,7 +44,8 @@ module MeshChat
43
44
  MeshChat::Command::Base::ONLINE => MeshChat::Command::Online,
44
45
  MeshChat::Command::Base::OFFLINE => MeshChat::Command::Offline,
45
46
  MeshChat::Command::Base::HELP => MeshChat::Command::Help,
46
- MeshChat::Command::Base::BIND => MeshChat::Command::Bind
47
+ MeshChat::Command::Base::BIND => MeshChat::Command::Bind,
48
+ MeshChat::Command::Base::SEND_DISCONNECT => MeshChat::Command::SendDisconnect
47
49
  }
48
50
 
49
51
 
@@ -168,8 +170,14 @@ module MeshChat
168
170
  # close_server
169
171
  Display.info 'saving config...'
170
172
  Settings.save
173
+ Display.info 'notifying of disconnection...'
174
+ send_disconnect
171
175
  Display.alert "\n\nGoodbye. \n\nThank you for using #{MeshChat.name}"
172
176
  exit
173
177
  end
178
+
179
+ def send_disconnect
180
+ MeshChat::Command::SendDisconnect.new('/senddisconnect')
181
+ end
174
182
  end
175
183
  end
@@ -31,6 +31,7 @@ module MeshChat
31
31
  OFFLINE = 'offline'
32
32
  HELP = 'help'
33
33
  BIND = 'bind'
34
+ SEND_DISCONNECT = 'senddisconnect'
34
35
 
35
36
  def handle
36
37
  klass = CLI::COMMAND_MAP[command]
@@ -25,15 +25,18 @@ module MeshChat
25
25
  Display.alert 'Invalid selection'
26
26
  handle # repeat
27
27
  end
28
-
29
-
30
28
  end
31
29
 
32
30
  def ip_addresses
33
31
  local = Socket.getifaddrs.map { |i| i.addr.ip_address if i.addr.ipv4? }.compact
34
32
  # get public
35
- remote_ip = open('http://whatismyip.akamai.com').read
36
- local << remote_ip
33
+ begin
34
+ remote_ip = open('http://whatismyip.akamai.com').read
35
+ local << remote_ip
36
+ rescue => e
37
+ Display.fatal e.message
38
+ Display.alert 'public ip lookup failed'
39
+ end
37
40
  local
38
41
  end
39
42
  end
@@ -0,0 +1,15 @@
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
@@ -8,7 +8,7 @@ module MeshChat
8
8
  'port' => '2008',
9
9
  'ip' => 'localhost',
10
10
  'uid' => '1',
11
- 'publicKey' => 'replace this'
11
+ 'publickey' => 'replace this'
12
12
  }
13
13
 
14
14
  class << self
@@ -33,7 +33,7 @@ module MeshChat
33
33
  'alias' => self['alias'],
34
34
  'location' => location,
35
35
  'uid' => self['uid'],
36
- 'publicKey' => public_key
36
+ 'publickey' => public_key
37
37
  }
38
38
  end
39
39
 
@@ -54,11 +54,11 @@ module MeshChat
54
54
  end
55
55
 
56
56
  def public_key
57
- self['publicKey']
57
+ self['publickey']
58
58
  end
59
59
 
60
60
  def private_key
61
- self['privatKey']
61
+ self['privatkey']
62
62
  end
63
63
 
64
64
  # generates 32 bytes
@@ -69,14 +69,14 @@ module MeshChat
69
69
 
70
70
  def generate_keys
71
71
  @key_pair = OpenSSL::PKey::RSA.new(2048)
72
- self['publicKey'] = @key_pair.public_key.to_pem
73
- self['privateKey'] = @key_pair.to_pem
72
+ self['publickey'] = @key_pair.public_key.to_pem
73
+ self['privatekey'] = @key_pair.to_pem
74
74
  Display.success 'new keys generated'
75
75
  end
76
76
 
77
77
  def key_pair
78
78
  if !@key_pair && keys_exist?
79
- @key_pair = OpenSSL::PKey::RSA.new(self['privateKey'] + self['publicKey'])
79
+ @key_pair = OpenSSL::PKey::RSA.new(self['privatekey'] + self['publickey'])
80
80
  end
81
81
  @key_pair
82
82
  end
@@ -2,7 +2,7 @@ require 'meshchat/message/base'
2
2
  require 'meshchat/message/chat'
3
3
  require 'meshchat/message/ping'
4
4
  require 'meshchat/message/ping_reply'
5
- require 'meshchat/message/disconnection'
5
+ require 'meshchat/message/disconnect'
6
6
  require 'meshchat/message/whisper'
7
7
  require 'meshchat/message/relay'
8
8
  require 'meshchat/message/node_list'
@@ -16,7 +16,7 @@ module MeshChat
16
16
  PING_REPLY = 'pingreply'
17
17
  WHISPER = 'whisper'
18
18
  RELAY = 'relay'
19
- DISCONNECTION = 'disconnection'
19
+ DISCONNECT = 'disconnect'
20
20
 
21
21
  NODE_LIST = 'nodelist'
22
22
  NODE_LIST_HASH = 'nodelisthash'
@@ -25,7 +25,7 @@ module MeshChat
25
25
  TYPES = {
26
26
  CHAT => Chat,
27
27
  WHISPER => Whisper,
28
- DISCONNECTION => Disconnection,
28
+ DISCONNECT => Disconnect,
29
29
  PING => Ping,
30
30
  PING_REPLY => PingReply,
31
31
  NODE_LIST => NodeList,
@@ -62,6 +62,10 @@ module MeshChat
62
62
  MeshChat.version
63
63
  end
64
64
 
65
+ def sender
66
+ payload['sender']
67
+ end
68
+
65
69
  # shows the message
66
70
  # should be used locally, before *sending* a message
67
71
  def display
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
2
  module Message
3
- class Disconnection < Base
3
+ class Disconnect < Base
4
4
  def display
5
5
  location = payload['sender']['location']
6
6
  name = payload['sender']['alias']
@@ -16,12 +16,12 @@ module MeshChat
16
16
  received_list = message
17
17
  we_only_have, they_only_have = Node.diff(received_list)
18
18
 
19
+ Display.debug('node_list#respond: me: ' + we_only_have.to_s)
20
+ Display.debug('node_list#respond: they: ' + they_only_have.to_s)
21
+
19
22
  if they_only_have.present?
20
23
  they_only_have.each do |n|
21
- # be sure that we don't add ourselves
22
- unless n['uid'] == Settings['uid']
23
- Node.from_json(n).save!
24
- end
24
+ Node.from_json(n).save!
25
25
  end
26
26
  end
27
27
 
@@ -30,6 +30,7 @@ module MeshChat
30
30
 
31
31
  node = Node.find_by_location(location)
32
32
  if we_only_have.present?
33
+ Display.debug 'we have nodes that they do not'
33
34
 
34
35
  # give the sender our list
35
36
  MeshChat::Net::Client.send(
@@ -47,6 +48,8 @@ module MeshChat
47
48
  )
48
49
  end
49
50
  else
51
+ Display.debug 'node lists are in sync'
52
+
50
53
  # lists are in sync, confirm with hash
51
54
  MeshChat::Net::Client.send(
52
55
  node: node,
@@ -46,7 +46,7 @@ module MeshChat
46
46
  alias_name: json['alias'],
47
47
  location: json['location'],
48
48
  uid: json['uid'],
49
- public_key: json['publicKey']
49
+ public_key: json['publickey']
50
50
  )
51
51
  end
52
52
 
@@ -92,7 +92,7 @@ module MeshChat
92
92
  'alias' => alias_name,
93
93
  'location' => location,
94
94
  'uid' => uid,
95
- 'publicKey' => public_key
95
+ 'publickey' => public_key
96
96
  }
97
97
  end
98
98
 
@@ -13,10 +13,19 @@ module MeshChat
13
13
  # verify node is valid
14
14
  node = self.node_for(location: location, uid: uid, node: node)
15
15
 
16
+ if Settings['uid'] == node.uid
17
+ Display.debug 'avoiding sending to self'
18
+ return
19
+ end
20
+
16
21
  Thread.new(node, message) do |node, message|
17
22
  begin
18
23
  payload = Client.payload_for(node, message)
19
24
 
25
+ Display.debug('SENDING: ' + message.type)
26
+ Display.debug('SENDING: ' + message.sender.to_s)
27
+ Display.debug('SENDING: ' + message.message.to_s)
28
+
20
29
  # TODO: this is horrible, come up with something better / abstract it
21
30
  begin
22
31
  Curl::Easy.http_post(node.location, payload.to_json) do |c|
@@ -23,7 +23,7 @@ module MeshChat
23
23
  def try_decrypt(input)
24
24
  begin
25
25
  decoded = Base64.decode64(input)
26
- input = Cipher.decrypt(decoded, Settings[:privateKey])
26
+ input = Cipher.decrypt(decoded, Settings[:privatekey])
27
27
  rescue => e
28
28
  Display.debug e.message
29
29
  Display.debug e.backtrace.join("\n")
@@ -9,6 +9,11 @@ module MeshChat
9
9
  request = Request.new(raw)
10
10
  message = request.message
11
11
 
12
+ # TODO: wrap in debug if check
13
+ Display.debug('RECEIVING: ' + message.type)
14
+ Display.debug('RECEIVING: ' + message.sender.to_s)
15
+ Display.debug('RECEIVING: ' + message.message.to_s)
16
+
12
17
  # handle the message
13
18
  Display.present_message message
14
19
 
@@ -77,6 +77,7 @@ module MeshChat
77
77
 
78
78
  def status_of(s)
79
79
  status s
80
+ Display.debug('SERVER: ' + s)
80
81
  body ''
81
82
  end
82
83
 
@@ -1,3 +1,3 @@
1
1
  module MeshChat
2
- VERSION = '0.6.11'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meshchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.11
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-08 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -204,6 +204,7 @@ files:
204
204
  - lib/meshchat/command/online.rb
205
205
  - lib/meshchat/command/ping.rb
206
206
  - lib/meshchat/command/ping_all.rb
207
+ - lib/meshchat/command/send_disconnect.rb
207
208
  - lib/meshchat/command/server.rb
208
209
  - lib/meshchat/command/share.rb
209
210
  - lib/meshchat/command/stop_listening.rb
@@ -221,7 +222,7 @@ files:
221
222
  - lib/meshchat/message.rb
222
223
  - lib/meshchat/message/base.rb
223
224
  - lib/meshchat/message/chat.rb
224
- - lib/meshchat/message/disconnection.rb
225
+ - lib/meshchat/message/disconnect.rb
225
226
  - lib/meshchat/message/node_list.rb
226
227
  - lib/meshchat/message/node_list_diff.rb
227
228
  - lib/meshchat/message/node_list_hash.rb
@@ -261,5 +262,5 @@ rubyforge_project:
261
262
  rubygems_version: 2.4.8
262
263
  signing_key:
263
264
  specification_version: 4
264
- summary: MeshChat-0.6.11
265
+ summary: MeshChat-0.7.0
265
266
  test_files: []