Skip to main content

Hub server

A hub server is the control plane of a NanoPing setup: nodes authenticate with it, and every node on the same hub can find and manage the others. Use this service to list the nodes on the hub, follow them as they come and go, remove nodes, and approve or reject nodes that ask to join. The node hosting the API must host the hub server or be authenticated with one, otherwise calls fail with FailedPrecondition.

Get nodes​

Get the nodes authenticated with the hub server, optionally filtered.

GET/v1/nodes
Query parameters
  • metadata_filtersmap<string, NodeMetadataItem>

    Metadata filters keyed by metadata key. A node is included only if it has every key with an equal value of the same type. Leave empty to not filter by metadata.

  • service_filtersNodeService[]

    Service filters. A node is included only if it offers every listed service. Leave empty to not filter by service.

Example
import { NanopingClient } from "@nanoping/api";

const client = new NanopingClient({ baseUrl: "http://127.0.0.1:10565" });

const response = await client.hubServer.getNodes({
metadataFilters: {
key: {
bytesValue: ""
}
},
serviceFilters: [
"HUB_SERVER"
]
});
POST/v1/nodes/search
Request body
  • metadataFiltersmap<string, NodeMetadataItem>

    Metadata filters keyed by metadata key. A node is included only if it has every key with an equal value of the same type. Leave empty to not filter by metadata.

  • serviceFiltersNodeService[]

    Service filters. A node is included only if it offers every listed service. Leave empty to not filter by service.

Example
import { NanopingClient } from "@nanoping/api";

const client = new NanopingClient({ baseUrl: "http://127.0.0.1:10565" });

const response = await client.hubServer.getNodes({
metadataFilters: {
key: {
bytesValue: ""
}
},
serviceFilters: [
"HUB_SERVER"
]
});
Response
  • nodesNode[]

    The nodes matching the filters.

Remove node​

Remove a node from the hub server. This disconnects the node from the hub server and removes it from its networks.

DELETE/v1/nodes/{node_id}
Path parameters
  • node_idstring

    Id of the node to remove.

Example
import { NanopingClient } from "@nanoping/api";

const client = new NanopingClient({ baseUrl: "http://127.0.0.1:10565" });

await client.hubServer.removeNode({
nodeId: "3f2b1c9e-8d4a-4f6b-9c2e-1a7d5e8b0c4f"
});
Response

No fields.

Stream nodes​

Stream the nodes authenticated with the hub server. The matching nodes are sent first, followed by an update every time a node is authenticated, deauthenticated, connects, disconnects or changes its details. Updates are not filtered. The stream stays open until the caller closes it.

GET/v1/streams/nodes

Server-sent events. A : ready comment is sent when the stream is ready, then each message is a data: line holding the response below. A failure after that is an error event.

Query parameters
  • metadata_filtersmap<string, NodeMetadataItem>

    Metadata filters keyed by metadata key. A node is included only if it has every key with an equal value of the same type. Leave empty to not filter by metadata.

  • service_filtersNodeService[]

    Service filters. A node is included only if it offers every listed service. Leave empty to not filter by service.

Example
import { NanopingClient } from "@nanoping/api";

const client = new NanopingClient({ baseUrl: "http://127.0.0.1:10565" });

for await (const response of client.hubServer.streamNodes({
metadataFilters: {
key: {
bytesValue: ""
}
},
serviceFilters: [
"HUB_SERVER"
]
})) {
}
POST/v1/streams/nodes

Server-sent events. A : ready comment is sent when the stream is ready, then each message is a data: line holding the response below. A failure after that is an error event.

Request body
  • metadataFiltersmap<string, NodeMetadataItem>

    Metadata filters keyed by metadata key. A node is included only if it has every key with an equal value of the same type. Leave empty to not filter by metadata.

  • serviceFiltersNodeService[]

    Service filters. A node is included only if it offers every listed service. Leave empty to not filter by service.

Example
import { NanopingClient } from "@nanoping/api";

const client = new NanopingClient({ baseUrl: "http://127.0.0.1:10565" });

for await (const response of client.hubServer.streamNodes({
metadataFilters: {
key: {
bytesValue: ""
}
},
serviceFilters: [
"HUB_SERVER"
]
})) {
}
Response messages
  • initialResponseStreamNodesInitialResponseone of response

    Sent once as the first message, with the nodes matching the filters when the stream opened.

  • updateResponseStreamNodesUpdateResponseone of response

    Sent for every later change to a node.

Authentication by requests​

Receive the authentication requests sent to the hub server on the node hosting the API, and accept or reject each one. Nothing is sent when the stream opens. A request is sent each time a node asks to authenticate, and the caller answers it by sending an answer for that request.

Use this on the node hosting the hub server to decide which nodes may join. Every node that calls authenticate by request arrives as a request. Answer it before the request times out; the node's call returns as soon as the answer is in.

WS/v1/streams/hub-server/authentication-requests

WebSocket. Send each request below as a JSON text message. Each message received holds a result with the response below, or an error.

Messages sent
  • requestIduint64

    Id of the request being answered, as received in the request.

  • acceptbool

    True to accept the request, false to reject it.

Example
import { NanopingClient, answerJoinRequests } from "@nanoping/api";

const client = new NanopingClient({ baseUrl: "http://127.0.0.1:10565" });

// Let nodes named "edge-node-1" join, and reject the rest. Runs until the
// signal aborts.
const stop = new AbortController();
await answerJoinRequests(client, (request) => request.node?.name === "edge-node-1", { signal: stop.signal });
Response messages
  • nodeNode

    Information about the node asking to authenticate.

  • requestIduint64

    Id of the request, used when answering it.