Skip to content
Permalink
Browse files

Update README on command line options and permissions, and make the -…

…i command line not exit after initialization
  • Loading branch information...
pixelspark committed Dec 4, 2017
1 parent fa0235e commit d50ad677e0386904f9b7141f324ef75dff40eaa4
Showing with 38 additions and 47 deletions.
  1. +2 −9 README.md
  2. +36 −38 Sources/Catena/main.swift
@@ -81,7 +81,7 @@ The following command starts Catena and initializes a new chain (replace 'debug'
a release version):

````
./.build/debug/Catena -p 8338 -m -c -s 'my seed string'
./.build/debug/Catena -p 8338 -m -i -s 'my seed string'
````

The -i switch tells Catena to initialize a chain (this deletes any persisted data, which is stored by default in catena.sqlite in the current directory). The -s switch provides Catena with a string that tells it which genesis block to accept. To enable block mining, add the '-m' command line switch.
@@ -127,14 +127,7 @@ you to use to connect as root.

### Permissions

By default, only the 'root' user created during initialization has any rights on the database. Add rows to the 'grants' table to
create more 'users' (identified by public key). For example (as root):

````
CREATE TABLE test(foo INT);
INSERT INTO grants(kind, user, table) VALUES ('insert', $invoker, 'test');
INSERT INTO test(foo) VALUES (1337);
````
By default, any user can execute a `CREATE DATABASE` statement; this creates a database, of which the invoker becomes the owner. The invoker can subsequently use `GRANT` and `REVOKE` statements to grant other users rights on the database.

More granular permissions can be granted by using *template* grants. These grant a user the permission to execute
a certain parametrized query with self-chosen parameter values. The template query is hashed and stored in the
@@ -19,7 +19,7 @@ let queryPortOption = IntOption(shortFlag: "q", longFlag: "query-port", helpMess
let peersOption = MultiStringOption(shortFlag: "j", longFlag: "join", helpMessage: "Peer URL to connect to ('ws://nodeid@hostname:port')")
let mineOption = BoolOption(shortFlag: "m", longFlag: "mine", helpMessage: "Enable mining of blocks")
let logOption = StringOption(shortFlag: "v", longFlag: "log", helpMessage: "The log level: debug, verbose, info, warning (default: info)")
let initializeOption = BoolOption(shortFlag: "i", longFlag: "initialize", helpMessage: "Perform all initialization steps, then exit before starting the node.")
let initializeOption = BoolOption(shortFlag: "i", longFlag: "initialize", helpMessage: "Re-initialize the node before starting it.")
let noReplayOption = BoolOption(shortFlag: "n", longFlag: "no-replay", helpMessage: "Do not replay database operations, just participate and validate transactions (default: false)")
let nodeDatabaseFileOption = StringOption(longFlag: "node-database", required: false, helpMessage: "Backing database file for instance database (default: catena-node.sqlite)")
let noLocalPeersOption = BoolOption(longFlag: "no-local-discovery", helpMessage: "Disable local peer discovery")
@@ -180,49 +180,47 @@ do {
}

// Query server
if !initializeOption.value {
let queryServerV4 = NodeQueryServer(agent: agent, port: queryPortOption.value ?? (netPort+1), family: .ipv4)
let queryServerV6 = NodeQueryServer(agent: agent, port: queryPortOption.value ?? (netPort+1), family: .ipv6)
queryServerV6.run()
queryServerV4.run()

node.miner.isEnabled = mineOption.value

// Check whether local discovery should be enabled
if !noLocalPeersOption.value {
var hostname = Data(count: 255)
let hostnameString = try hostname.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<CChar>) -> String in
try posix(gethostname(bytes, 255))
return String(cString: bytes)
}

if !hostnameString.hasSuffix(".local") {
Log.info("[LocalDiscovery] Not enabling local discovery as host (\(hostnameString)) is not in local domain.")
}
else {
node.announceLocally = true
node.discoverLocally = true
}
let queryServerV4 = NodeQueryServer(agent: agent, port: queryPortOption.value ?? (netPort+1), family: .ipv4)
let queryServerV6 = NodeQueryServer(agent: agent, port: queryPortOption.value ?? (netPort+1), family: .ipv6)
queryServerV6.run()
queryServerV4.run()

node.miner.isEnabled = mineOption.value

// Check whether local discovery should be enabled
if !noLocalPeersOption.value {
var hostname = Data(count: 255)
let hostnameString = try hostname.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<CChar>) -> String in
try posix(gethostname(bytes, 255))
return String(cString: bytes)
}

Log.info("Node URL: \(node.url.absoluteString)")
Swift.print("\r\nPGPASSWORD=\(rootIdentity.privateKey.stringValue) psql -h localhost -p \(netPort+1) -U \(rootIdentity.publicKey.stringValue)\r\n")
if !hostnameString.hasSuffix(".local") {
Log.info("[LocalDiscovery] Not enabling local discovery as host (\(hostnameString)) is not in local domain.")
}
else {
node.announceLocally = true
node.discoverLocally = true
}
}

node.start(blocking: false)
Log.info("Node URL: \(node.url.absoluteString)")
Swift.print("\r\nPGPASSWORD=\(rootIdentity.privateKey.stringValue) psql -h localhost -p \(netPort+1) -U \(rootIdentity.publicKey.stringValue)\r\n")

// Set up signal handler
signal(SIGINT, SIG_IGN)
node.start(blocking: false)

let sigintSrc = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
sigintSrc.setEventHandler {
exit(0)
}
sigintSrc.resume()
// Set up signal handler
signal(SIGINT, SIG_IGN)

// Run
withExtendedLifetime(node) {
RunLoop.main.run()
}
let sigintSrc = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
sigintSrc.setEventHandler {
exit(0)
}
sigintSrc.resume()

// Run
withExtendedLifetime(node) {
RunLoop.main.run()
}
}
catch {

0 comments on commit d50ad67

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.