readme.md 6.72 KB
Newer Older
Aral Balkan's avatar
Aral Balkan committed
1
2
3
4
# Waystone

> But mostly because it felt like the right thing to do, and that is reason enough.

5
6
7
8
9
10
11
12
13
14
# Manual pre-installation step

## OS-X

You will need to install:

  * [boot2docker](http://docs.docker.com/installation/mac/)

(This is a .pkg installer so I’ve kept it out of the installation script for now.)

15
16
17
18
# Installation

	./install

19
This will set up your development system for Waystone and also run Pulse for the first time. Continue to the Configuration section to complete your setup.
20
21
22
23
24

(Note: on Linux systems, make sure g++ is installed. All other dependencies will be installed by the script.)

# Configuration

25
26
**TODO:** Implement automatic PulseAPIKey generation and discovery ala Heartbeat. Also: DeviceID

27
28
29
30
The installation script will create an empty config.json file in the root of the project folder.

	{
		"PulseAPIKey": "",
31
32
		"DeviceID": "",
		"UseAccessCodes": false,
33
34
35
36
37
38
39
40
	}

To configure your Waystone installation, go to the Pulse Web UI at `http://localhost:8080`. The installation script should have run Pulse for you. If it's not running, you can find it in the `node_modules/indie-pulse-process/` folder (make sure you run the correct binary for your platform).

Once you're in the Web UI, go into the gear menu and select Show ID. This is the Device ID you need to copy as the value for the "DeviceID" key in the configuration file.

Next, select the Settings option from the gear menu and, in the resulting dialog box, click the button that reads "Generate" under the API Key section. This will generate your API key. Copy that key as the value for the "PulseAPIKey" key in the configuration file. 

41
42
**Access codes** If you want to limit the people who can access a Waystone instance, use access codes. This way, you can give out invitations to people to join.

43
44
45
46
47
48
# Running (and for testing during development)

	./dev

This will run the server.

49
50
**Note:** Since Waystone will most likely be deployed on a Linux-based system, the way we develop is to run Ubuntu under VMWare with the Waystone folder shared with the guest operating system. We develop on OS X and test on Ubuntu.

Aral Balkan's avatar
Aral Balkan committed
51
# REST API
Aral Balkan's avatar
Aral Balkan committed
52

Aral Balkan's avatar
Aral Balkan committed
53
Traditional REST API. Messages received are not trusted and replies should not be trusted either. For trusted messages, we use [Pulse](https://ind.ie/pulse) and the [Teleportation API](#teleportation-api).
Aral Balkan's avatar
Aral Balkan committed
54
55
56
57
58
59
60

All methods receive and return serialised JSON.

### GET

#### isHandleAvailable

Aral Balkan's avatar
Aral Balkan committed
61
62
*Checks if the passed handle is available for use.*

Aral Balkan's avatar
Aral Balkan committed
63
64
Expects a handle to check:
 
65
	/handle
Aral Balkan's avatar
Aral Balkan committed
66
67
68
69
70
71
72

Returns:

	{
		"handleIsAvailable": Boolean
	}

Aral Balkan's avatar
Aral Balkan committed
73
74
75
76
77
78
#### getDeviceId

*Returns the device ID of the Waystone instance.*

Expects: 

79
	/
Aral Balkan's avatar
Aral Balkan committed
80
81
82
83
84
85
86

Returns:

	{
		"deviceId": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
87
88
89
90
### POST 

#### addPerson

Aral Balkan's avatar
Aral Balkan committed
91
92
*Adds the passed person to Waystone* 

Aral Balkan's avatar
Aral Balkan committed
93
94
95
96
97
98
99
Expects a person:

	{
		"handle": "String",
		"name": "String",
		"bio": "String",
		"photo": "Base64EncodedString",
Aral Balkan's avatar
Aral Balkan committed
100
		"deviceId": "String",
Aral Balkan's avatar
Aral Balkan committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
		"email": "(optional) String"
	}

Returns:
	
	{
		"success": Boolean,
		"error (optional)": 
		{
			"code": Number,
			"message": "String"
		}		
	}

Aral Balkan's avatar
Aral Balkan committed
115
116
117
#### confirmNewDeviceForPerson

*Registers a request to confirm that a new device should be added to the person’s account.* 
Aral Balkan's avatar
Aral Balkan committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

Expects a device to add to a person:

	{	
		device:
		{
			"id": "String",
			"name": "String",

		},
		person:
		{
			"handle": "String"
		}
	}

Returns:

	{
		"success": Boolean,
		"error (optional)": 
		{
			"code": Number,
			"message": "String"
		}		
	}

Aral Balkan's avatar
Aral Balkan committed
145
146
147
**Note:** *`success = true` means that the request to register the new device has been successfully stored and will be relayed to the user via the Teleportation API for confirmation. The person will have to approve the request either via a notification on the native client (by way of the Teleportation API) or via email if they have that option enabled as a backup.*

# <a name='teleportation-api'></a>Teleportation API 
Aral Balkan's avatar
Aral Balkan committed
148

Aral Balkan's avatar
Aral Balkan committed
149
Messages dropped in specific folders are teleported automatically by Pulse to the recipients. These are trusted messages between authenticated devices. The message are files. The message names are the file names and the message bodies are the file contents. All message bodies are in serialised JSON format.
Aral Balkan's avatar
Aral Balkan committed
150

Aral Balkan's avatar
Aral Balkan committed
151
Message names are automatically prefixed with a timestamp and the handle of the sender in the following format:
Aral Balkan's avatar
Aral Balkan committed
152

Aral Balkan's avatar
Aral Balkan committed
153
154
155
156
157
158
159
160
161
162
163
164
	<datetime>__<messageName>

Where:

	<datetime> = 	ISO 8601 combined date and time string with timezone 
					with colons escaped by underscores for better cross-platform
					file name compability.

Example:

	1980-10-14T00_59_59-04_00__confirm_new_device

165
166
167
168
169
170
171
172
173
174
175
176
177
178
## Message-Acknowledge-Delete (MAD) pattern

Messaging in the Teleportation API uses the MAD pattern:

1. First party writes a message
2. Second party writes an acknowledgement message
3. First party deletes the message (now that it has been acknowledged)

The second party should only acknowledge the message once it has safely received it and loaded it into memory to act on it.

Acknowledgement messages have the form:

	<datetime>__ack__<originalMessageDatetime>__<originalMessageName>

Aral Balkan's avatar
Aral Balkan committed
179
180
181
## From Waystone to a person

### Adding a new device.
Aral Balkan's avatar
Aral Balkan committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195

#### verify_new_device

Asks person to verify that they asked for the device with the presented ID and name.

Message body:

	{
		"id": "String",
		"name": "String"
	}

Reply with (either):

Aral Balkan's avatar
Aral Balkan committed
196
197
 * [confirm_new_device](#confirm-new-device)
 * [deny_new_device](#deny-new-device)
Aral Balkan's avatar
Aral Balkan committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

*Notes:*

  1. Not replying will eventually result in the request being forgotten.
  2. If you confirm the new device, its device ID will be added to the list of approved devices for that person and the person will get a `new_device_verified` message.

#### new_device_verified

Confirms that the person’s new device has been verified.

Message body:

	{
		"id": "String",
		"name": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
215
216
217
### Friendship

#### friendship_request
Aral Balkan's avatar
Aral Balkan committed
218

Aral Balkan's avatar
Aral Balkan committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
A notification that the sender is requesting friendship.

Message body:
	
	{
		"from": "handle"
	}

#### friendship_acceptance

A notification that your friendship request has been accepted by sender.

Message body:

	{
		"from": "handle"
	}

## From a person to Waystone

### Adding a new device

#### <a name='confirm-new-device'></a>confirm_new_device
Aral Balkan's avatar
Aral Balkan committed
242
243
244
245
246
247
248
249
250

Confirm that you want to add the device with the passed ID to your Ind.ie account. The device will gain full access to your Ind.ie account. This is a response to the `verify_new_device` message.

Message body:

	{
		"id": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
251
#### <a name='deny-new-device'></a>deny_new_device
Aral Balkan's avatar
Aral Balkan committed
252
253
254
255
256
257
258
259
260

Deny access to the device with the passed ID to your Ind.ie account. This is a response to the `verify_new_device` message.

Message body:

	{
		"id": "String"
	}

Aral Balkan's avatar
Aral Balkan committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
### Friendship

#### friendship_request

A friendship request to be relayed to the specified person.

Message body:
	
	{
		"to": "handle"
	}

#### friendship_acceptance

A request to relay that you have accepted the specified person’s friendship request.

Message body:
Aral Balkan's avatar
Aral Balkan committed
278

Aral Balkan's avatar
Aral Balkan committed
279
280
281
	{
		"to": "handle"
	}