meshchat 0.6.3 → 0.6.4
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/README.md +1 -1
- data/lib/meshchat/message/node_list.rb +14 -4
- data/lib/meshchat/message/node_list_hash.rb +2 -0
- data/lib/meshchat/net/client.rb +8 -2
- data/lib/meshchat/net/listener/errors.rb +11 -0
- data/lib/meshchat/net/listener/request.rb +11 -11
- data/lib/meshchat/net/listener/request_processor.rb +1 -3
- data/lib/meshchat/net/listener/server.rb +34 -19
- data/lib/meshchat/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 710116e03c53eb697697204b0fcc82f03dd65f0b
|
4
|
+
data.tar.gz: d296660e62b2dca5dcdfb7338045217c7b14da8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41acfb1c0c96b46fd6f39c5e76d9892c3eb24ee0ecc28b32119f45a2bf950f9f5daea6b1e6b5de2f619b2a5b5130dd7233e81f9c9531f440583f938582d89775
|
7
|
+
data.tar.gz: 5edd7cee532eb5ecc845178a50d5a5a042357c0d9b2e7912d3137f652d12a3f1a21f189bb951616dc79c793da3c35ee7addd8e1eb9759198cdf40a529a46bbc6
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ This is the core functionality for implementing a [mesh-chat](https://github.com
|
|
4
4
|
|
5
5
|
#Usage
|
6
6
|
|
7
|
-
See [Spiced
|
7
|
+
See [Spiced Rumby](https://github.com/NullVoxPopuli/spiced_rumby)
|
8
8
|
|
9
9
|
In order to use meshchat with your own interface, you only need to pass in your own implementations of `Display::Base` and `CLI::Base`
|
10
10
|
|
@@ -25,10 +25,11 @@ module MeshChat
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
if we_only_have.present?
|
29
|
-
location = payload['sender']['location']
|
30
28
|
|
31
|
-
|
29
|
+
location = payload['sender']['location']
|
30
|
+
|
31
|
+
node = Node.find_by_location(location)
|
32
|
+
if we_only_have.present?
|
32
33
|
|
33
34
|
# give the sender our list
|
34
35
|
MeshChat::Net::Client.send(
|
@@ -36,14 +37,23 @@ module MeshChat
|
|
36
37
|
message: NodeListDiff.new(message: we_only_have)
|
37
38
|
)
|
38
39
|
|
39
|
-
# give
|
40
|
+
# give people we know about
|
41
|
+
# (but the sender of the Node List may not know about)
|
42
|
+
# our node list diff
|
40
43
|
Node.online.each do |entry|
|
41
44
|
MeshChat::Net::Client.send(
|
42
45
|
node: entry,
|
43
46
|
message: NodeListDiff.new(message: they_only_have)
|
44
47
|
)
|
45
48
|
end
|
49
|
+
else
|
50
|
+
# lists are in sync, confirm with hash
|
51
|
+
MeshChat::Net::Client.send(
|
52
|
+
node: node,
|
53
|
+
message: NodeListHash.new
|
54
|
+
)
|
46
55
|
end
|
56
|
+
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
@@ -14,8 +14,10 @@ module MeshChat
|
|
14
14
|
|
15
15
|
def respond
|
16
16
|
if message != Node.as_sha512
|
17
|
+
Display.debug 'node list hashes do not match'
|
17
18
|
location = payload['sender']['location']
|
18
19
|
|
20
|
+
Display.debug 'sending a node list to ' + location
|
19
21
|
node = Node.find_by_location(location)
|
20
22
|
|
21
23
|
MeshChat::Net::Client.send(
|
data/lib/meshchat/net/client.rb
CHANGED
@@ -14,8 +14,8 @@ module MeshChat
|
|
14
14
|
node = self.node_for(location: location, uid: uid, node: node)
|
15
15
|
|
16
16
|
Thread.new(node, message) do |node, message|
|
17
|
-
|
18
|
-
|
17
|
+
payload = Client.payload_for(node, message)
|
18
|
+
|
19
19
|
begin
|
20
20
|
Curl::Easy.http_post(node.location, payload.to_json) do |c|
|
21
21
|
c.headers['Accept'] = 'application/json'
|
@@ -37,6 +37,12 @@ module MeshChat
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
# creates a json payload
|
41
|
+
def self.payload_for(node, message)
|
42
|
+
request = MeshChat::Net::Request.new(node, message)
|
43
|
+
{ message: request.payload }
|
44
|
+
end
|
45
|
+
|
40
46
|
# private
|
41
47
|
|
42
48
|
# @return [Node]
|
@@ -7,7 +7,14 @@ module MeshChat
|
|
7
7
|
|
8
8
|
def initialize(input)
|
9
9
|
self._input = try_decrypt(input)
|
10
|
-
|
10
|
+
|
11
|
+
begin
|
12
|
+
self.json = JSON.parse(_input)
|
13
|
+
rescue => e
|
14
|
+
Display.debug e.message
|
15
|
+
Display.debug e.backtrace.join("\n")
|
16
|
+
raise Errors::BadRequest.new
|
17
|
+
end
|
11
18
|
self.message = process_json
|
12
19
|
end
|
13
20
|
|
@@ -15,19 +22,15 @@ module MeshChat
|
|
15
22
|
|
16
23
|
def try_decrypt(input)
|
17
24
|
begin
|
18
|
-
# TODO: do we want to try to decrypting anyway if decoding fails?
|
19
25
|
decoded = Base64.decode64(input)
|
20
26
|
input = Cipher.decrypt(decoded, Settings[:privateKey])
|
21
27
|
rescue => e
|
22
28
|
Display.debug e.message
|
23
29
|
Display.debug e.backtrace.join("\n")
|
24
|
-
Display.
|
25
|
-
|
30
|
+
Display.debug input
|
31
|
+
raise Errors::NotAuthorized.new(e.message)
|
26
32
|
end
|
27
33
|
|
28
|
-
Display.debug 'server received message:'
|
29
|
-
Display.debug input
|
30
|
-
|
31
34
|
input
|
32
35
|
end
|
33
36
|
|
@@ -35,10 +38,7 @@ module MeshChat
|
|
35
38
|
type = json['type']
|
36
39
|
klass = Message::TYPES[type]
|
37
40
|
|
38
|
-
unless klass
|
39
|
-
Display.alert 'message recieved and not recognized...'
|
40
|
-
return
|
41
|
-
end
|
41
|
+
raise Errors::BadRequest.new(type) unless klass
|
42
42
|
|
43
43
|
klass.new(payload: json)
|
44
44
|
end
|
@@ -22,9 +22,7 @@ module MeshChat
|
|
22
22
|
# if the sender isn't currently marked as active,
|
23
23
|
# perform the server list exchange
|
24
24
|
node = Node.find_by_uid(sender['uid'])
|
25
|
-
if node.nil?
|
26
|
-
return Display.alert "#{sender['alias']} is not authorized!"
|
27
|
-
end
|
25
|
+
raise Errors::Forbidden.new if node.nil?
|
28
26
|
|
29
27
|
unless node.online?
|
30
28
|
node.update(online: true)
|
@@ -1,9 +1,15 @@
|
|
1
1
|
require 'sinatra/base'
|
2
|
+
require 'meshchat/net/listener/errors'
|
2
3
|
|
3
4
|
module MeshChat
|
4
5
|
module Net
|
5
6
|
module Listener
|
6
7
|
class Server < Sinatra::Base
|
8
|
+
OK = 200
|
9
|
+
BAD_REQUEST = 400
|
10
|
+
NOT_AUTHORIZED = 401
|
11
|
+
FORBIDDEN = 403
|
12
|
+
|
7
13
|
configure :development do
|
8
14
|
# only shows resulting status
|
9
15
|
disable :logging
|
@@ -32,25 +38,11 @@ module MeshChat
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def process_request
|
35
|
-
Display.debug request.env
|
36
|
-
|
37
41
|
begin
|
38
42
|
# form params should override
|
39
43
|
# raw body
|
40
|
-
raw =
|
41
|
-
|
42
|
-
msg
|
43
|
-
else
|
44
|
-
request_body = request.body.read
|
45
|
-
json_body = JSON.parse(request_body)
|
46
|
-
json_body['message']
|
47
|
-
end
|
48
|
-
|
49
|
-
# decode, etc
|
50
|
-
RequestProcessor.process(raw)
|
51
|
-
|
52
|
-
# hopefully everything went ok
|
53
|
-
ok
|
44
|
+
raw = get_message
|
45
|
+
process(raw)
|
54
46
|
rescue => e
|
55
47
|
Display.error e.message
|
56
48
|
Display.error e.backtrace.join("\n")
|
@@ -59,9 +51,32 @@ module MeshChat
|
|
59
51
|
end
|
60
52
|
end
|
61
53
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
54
|
+
def get_message
|
55
|
+
# if received as form data
|
56
|
+
return params[:message] if params[:message]
|
57
|
+
|
58
|
+
# if received as json
|
59
|
+
request_body = request.body.read
|
60
|
+
json_body = JSON.parse(request_body)
|
61
|
+
json_body['message']
|
62
|
+
end
|
63
|
+
|
64
|
+
def process(raw)
|
65
|
+
# decode, etc
|
66
|
+
begin
|
67
|
+
RequestProcessor.process(raw)
|
68
|
+
rescue Errors::NotAuthorized
|
69
|
+
status_of NOT_AUTHORIZED
|
70
|
+
rescue Errors::Forbidden
|
71
|
+
status_of FORBIDDEN
|
72
|
+
rescue Errors::BadRequest
|
73
|
+
status_of BAD_REQUEST
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def status_of(s)
|
78
|
+
status s
|
79
|
+
body ''
|
65
80
|
end
|
66
81
|
end
|
67
82
|
end
|
data/lib/meshchat/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.4
|
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: 2015-10-
|
11
|
+
date: 2015-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -228,6 +228,7 @@ files:
|
|
228
228
|
- lib/meshchat/message/whisper.rb
|
229
229
|
- lib/meshchat/models/entry.rb
|
230
230
|
- lib/meshchat/net/client.rb
|
231
|
+
- lib/meshchat/net/listener/errors.rb
|
231
232
|
- lib/meshchat/net/listener/request.rb
|
232
233
|
- lib/meshchat/net/listener/request_processor.rb
|
233
234
|
- lib/meshchat/net/listener/server.rb
|
@@ -257,6 +258,6 @@ rubyforge_project:
|
|
257
258
|
rubygems_version: 2.4.7
|
258
259
|
signing_key:
|
259
260
|
specification_version: 4
|
260
|
-
summary: MeshChat-0.6.
|
261
|
+
summary: MeshChat-0.6.4
|
261
262
|
test_files: []
|
262
263
|
has_rdoc:
|