jstp 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -47
- data/jstp.gemspec +0 -1
- data/lib/jstp.rb +0 -1
- data/lib/jstp/version.rb +1 -1
- data/lib/reader/jstp/dispatch.rb +1 -1
- data/lib/writer/jstp/dispatch.rb +4 -4
- metadata +3 -19
data/README.md
CHANGED
@@ -1,53 +1,9 @@
|
|
1
1
|
# JSTP Ruby Gem
|
2
2
|
|
3
|
-
Server & Client reference implementation of the sketch protocol JSTP (JavaScript Serialization Transfer Protocol).
|
3
|
+
Server & Client reference implementation of the sketch protocol JSTP (JavaScript Serialization Transfer Protocol).
|
4
4
|
|
5
|
-
|
6
|
-
----
|
5
|
+
The protocol specification can be found in the [RFC](https://github.com/Fetcher/jstp-rfc)
|
7
6
|
|
8
|
-
JSTP is a communication protocol based on JSON serialization that works over websockets in the default TCP port `33333`. It's inspired and aimed to maintain compatibility with HTTP as used in REST architectures but using JSON as the protocol language.
|
9
|
-
|
10
|
-
The protocol is symmetrical: this means that there is only one type of message, in constrast to _Request-Response_ kind of protocols such as `HTTP`. Sending a message is called `dispatch` in the JSTP vocabulary. As JSTP is built upon Web Sockets, is also by design asynchronous, meaning that a Dispatch is not necessarily follow by any kind of response by the receiver. To facilitate the follow up in communication threads, JSTP provides a `token` header which we suggest to fill with a control hash (a similar concept to HTTP's Etag header). As much of the headers, the `token` header is extensible to an array capable of containing several tokens ordered by priority (is still to be seen is all JSTP headers by default will support or not multiple values).
|
11
|
-
|
12
|
-
The headers types, available protocol methods, resource taxonomy and message body are designed to be 100% compatible with REST (implying that system that make use of JSTP for their network communications may fall back to plain HTTP if technical limitations require it). Headers are not bound to include all of the same data that HTTP regular _Requests_ or _Responses_, but can.
|
13
|
-
|
14
|
-
An sample Dispatch will look like:
|
15
|
-
|
16
|
-
{
|
17
|
-
"protocol": ["JSTP", "0.1"]
|
18
|
-
"method": "POST",
|
19
|
-
"resource": [
|
20
|
-
"session.manager",
|
21
|
-
"User"
|
22
|
-
],
|
23
|
-
"timestamp": 1357334118,
|
24
|
-
"token": 3523902859084057289594,
|
25
|
-
"referer": [
|
26
|
-
"browser",
|
27
|
-
"Registerer"
|
28
|
-
],
|
29
|
-
"body": {
|
30
|
-
"login": "xavier",
|
31
|
-
"email": "xavier@fetcher.com",
|
32
|
-
"password": "secret"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
A **JSTP Dispatch** can also be formatted in a short hand notation similar to that of an HTTP Request. The previous example can be presented as follows:
|
37
|
-
|
38
|
-
POST session.manager/User JSTP/0.1
|
39
|
-
timestamp: 1357334118
|
40
|
-
token: 3523902859084057289594
|
41
|
-
referer: browser/Registerer
|
42
|
-
|
43
|
-
login: xavier
|
44
|
-
email: xavier@fetcher.com
|
45
|
-
password: secret
|
46
|
-
|
47
|
-
Gateways
|
48
|
-
--------
|
49
|
-
|
50
|
-
Every JSTP server knows its own hostname, which should match the first string in the resource array of the message. If the host as received in the message does not corresponds to this server, it should look up for the right server and dispatch it.
|
51
7
|
|
52
8
|
API
|
53
9
|
---
|
@@ -69,7 +25,6 @@ The API of the JSTP Ruby Gem remained undocumented, mainly because right now it
|
|
69
25
|
- The engine should automatically forward ingoing dispatches that carry a different hostname from the one of this node to the corresponding node. In this way, each JSTP Node is automatically a gateway.
|
70
26
|
- There should be a DSL in the Controller class for creating aahnd sending a JSTP Dispatch. The library should be able to recognize when an outgoing dispatch is actually aimed at self, so it gets mapped correctly without the need to generate network activity. This DSL should provide also an easy way to switch outgoing strategies.
|
71
27
|
- The message as passed to the Controller's initializer should be made into a Private Class Data. In this context, I should explore a little the idea of mapping the ingoing Dispatch into a class.
|
72
|
-
- Test implementation with Oj JSON parser/dumper.
|
73
28
|
- The Dispatch class should have a Writer an Reader that make it possible to log and parse dispatches from the abbreviated, similar-to-HTTP syntax.
|
74
29
|
- [distant future] Support for SSL/TLS.
|
75
30
|
|
data/jstp.gemspec
CHANGED
data/lib/jstp.rb
CHANGED
data/lib/jstp/version.rb
CHANGED
data/lib/reader/jstp/dispatch.rb
CHANGED
data/lib/writer/jstp/dispatch.rb
CHANGED
@@ -62,7 +62,7 @@ module Writer
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def json
|
65
|
-
|
65
|
+
JSON.dump @source
|
66
66
|
end
|
67
67
|
|
68
68
|
def string
|
@@ -85,10 +85,10 @@ module Writer
|
|
85
85
|
response += "\n"
|
86
86
|
if @source.body.is_a? Hash
|
87
87
|
@source.body.each do |key, value|
|
88
|
-
response += "#{key}: #{
|
88
|
+
response += "#{key}: #{JSON.dump(value)}\n"
|
89
89
|
end
|
90
90
|
else
|
91
|
-
response +=
|
91
|
+
response += JSON.dump @source.body
|
92
92
|
end
|
93
93
|
end
|
94
94
|
response
|
@@ -98,7 +98,7 @@ module Writer
|
|
98
98
|
unless @source.body
|
99
99
|
"#{@source.method} #{@source.resource.join('/')}"
|
100
100
|
else
|
101
|
-
"#{@source.method} #{@source.resource.join('/')}?#{
|
101
|
+
"#{@source.method} #{@source.resource.join('/')}?#{JSON.dump(@source.body)}"
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jstp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: em-websocket
|
@@ -93,22 +93,6 @@ dependencies:
|
|
93
93
|
- - ! '>='
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
|
-
- !ruby/object:Gem::Dependency
|
97
|
-
name: oj
|
98
|
-
requirement: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
|
-
requirements:
|
101
|
-
- - ! '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :runtime
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
|
-
requirements:
|
109
|
-
- - ! '>='
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '0'
|
112
96
|
- !ruby/object:Gem::Dependency
|
113
97
|
name: rspec
|
114
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
183
|
version: '0'
|
200
184
|
requirements: []
|
201
185
|
rubyforge_project:
|
202
|
-
rubygems_version: 1.8.
|
186
|
+
rubygems_version: 1.8.24
|
203
187
|
signing_key:
|
204
188
|
specification_version: 3
|
205
189
|
summary: Reference implementation for the sketch protocol JSTP
|