mediachain / concat

Mediachain daemons
MIT License
42 stars 13 forks source link

mcnode: Refactoring and offline nodes #17

Closed vyzo closed 7 years ago

vyzo commented 7 years ago

Heavily refactors mcnode by splitting into multiple files and implements offline node behavior.

The node now starts offline by default, and it can transition to online (listening to the network) or public (online + registered with the directory) through the /status REST API. Before a node can transition to public, a directory must be configured through the /config/dir REST API.

Here is an example:

shell0 $ mcnode
2016/09/23 17:13:07 Loading identity from /tmp/mcnode/identity
2016/09/23 17:13:07 ID: QmWwnVop4hHB3K6z2vuUgU9rh5VrDwMnwuiP9LZew7NzUK
2016/09/23 17:13:07 Loading statement /tmp/mcnode/stmt/QmWwnVop4hHB3K6z2vuUgU9rh5VrDwMnwuiP9LZew7NzUK:1474465964:0
2016/09/23 17:13:07 Loading statement /tmp/mcnode/stmt/QmWwnVop4hHB3K6z2vuUgU9rh5VrDwMnwuiP9LZew7NzUK:1474465972:1
2016/09/23 17:13:07 Loading statement /tmp/mcnode/stmt/QmWwnVop4hHB3K6z2vuUgU9rh5VrDwMnwuiP9LZew7NzUK:1474625144:0
2016/09/23 17:13:07 Node is offline
2016/09/23 17:13:07 Serving client interface at 127.0.0.1:9002
....

# check status
shell1 $ curl http://127.0.0.1:9002/status
offline
# configure the directory
shell1 $ curl -H "Content-Type: application/text" -d '/ip4/127.0.0.1/tcp/9000/QmZkHSwRd29Eq3XcfUVt3AzGNXUtgjf6eGqdSk56EXZtBb' http://127.0.0.1:9002/config/dir
OK
# tell the node to go public
shell1 $ curl http://127.0.0.1:9002/status/public
public 
# take the node back offline
shell1 $ curl http://127.0.0.1:9002/status/offline
offline
yusefnapora commented 7 years ago

Big 👍 on the refactor; the code is much easier to follow now :)

yusefnapora commented 7 years ago

For setting the status, can we make that a POST instead of GET /status/public? I feel like state changes via GET is a REST no-no 😄

vyzo commented 7 years ago

Per our discussion: POST is the canonical method for setting the state in /status/{state} but the implementation also happens to accept GET as well :)

Eventually we can add some proper method discremination (the gorilla mux certainly supports it), but I don't want to complicate yet.

yusefnapora commented 7 years ago

Cool, then I say 👍 to this PR. I'll add the new commands to the aleph REST client in a little bit

vyzo commented 7 years ago

client support merged in aleph; merging.