Nodes
A node is a process runningstellarium-ts. It does three things:
- Hosts internal resources: the functions you register with
node.register(), which run in your process. - Remembers external resources and peers it has learned about from other nodes. These are stored in
requestscript.db, a SQLite file created in the working directory on startup, or in Postgres. - Runs RequestScript requests submitted to
POST /v1/run, calling resources locally or forwarding them to the peer that hosts them.
Resources
A resource is a named set of functions.path and name together form its fully qualified name, such as com.example.Weather. Each function declares its RequestScript parameter types and return type.
website and description, and each function and parameter an optional description, so callers can tell what it does.
When a node shares its resources, it publishes each resource’s path, name, baseUrl, website and description, and function signatures (name, returnType, description, parameters, and any paymentManifest or restricted flag). Function implementations never leave the node that hosts them.
A function can optionally carry a payment manifest that sets its price. See Payments.
Requests
A RequestScriptrequest binds resources with const <name>: <path>.<ResourceName> and calls their functions with named arguments:
value or error set. If a resource throws or its peer can’t be reached, the program gets an error and keeps running, so the request as a whole still succeeds.
Calls run one at a time, in source order. A request’s latency is the sum of its calls.
When a node runs this:
- If
com.example.Weatheris registered on this process, itsexecruns locally. - If it was learned from a peer, the node forwards the call to that peer’s
{baseUrl}/v1/run/resourceand returns the result.
Joining a network
PassstartingPeer to node.start() to bootstrap from a node that is already running. Once the node is listening, it:
1
Copies the peer list
GET {startingPeer}/v1/self, then every page of GET {startingPeer}/v1/peers. It stores the starting peer and every peer it doesn’t know yet. Known peers are left alone, so this is safe on every restart, and a run cut off partway through completes on the next one.2
Copies the resource list
Every page of
GET {startingPeer}/v1/resources. Each resource it doesn’t know yet is stored with the baseUrl that peer advertised. Known resources are left alone.3
Announces itself
Sends a signed
PUT /v1/peers to every known peer with its baseUrl and public key.4
Broadcasts its resources
Sends a signed
PUT /v1/all-resources to every known peer with its internal resources.SIGNING_PRIVATE_KEY and expire after 10 minutes. A receiving node refuses any whose expiry has passed or is more than an hour away.
- Peer announcements must be signed by the key they announce, so a peer can only speak for itself. A known peer can change its base URL and name. A new key can’t take a base URL or name that another peer holds (
409). - Resource broadcasts are accepted only from a known peer, and only for resources served from that peer’s own base URL that no other peer owns. The rest are listed in the response’s
rejectedfield. An accepted resource replaces what was stored for it, including its functions, prices and descriptions.
Resource names are first come, first served. The first peer to publish
com.example.Weather from its base URL owns that name on the nodes that store it, and nothing proves it is the rightful owner. See the open problems in the whitepaper.