OmnyStoreNode constructor

OmnyStoreNode({
  1. required Uri hubUri,
  2. required String nodeId,
  3. required OmnyStore store,
  4. Set<String> organizations = const {},
  5. String? publicBaseUrl,
  6. Map<String, String> labels = const {},
  7. int priority = 0,
  8. int? capacityBytes,
  9. Logger logger = const NoopLogger(),
  10. String? authToken,
  11. Duration heartbeatInterval = const Duration(seconds: 10),
  12. Duration sessionTimeout = const Duration(minutes: 10),
  13. ReconnectPolicy? reconnect,
  14. NodeRuntime? runtime,
  15. StoreRpcServer? rpc,
})

Creates a node.

authToken is sent as a bearer token on the WebSocket upgrade, so a hub with an authenticator admits only nodes it knows.

Implementation

OmnyStoreNode({
  required Uri hubUri,
  required this.nodeId,
  required this.store,
  Set<String> organizations = const {},
  this.publicBaseUrl,
  Map<String, String> labels = const {},
  this.priority = 0,
  this.capacityBytes,
  this.logger = const NoopLogger(),
  String? authToken,
  Duration heartbeatInterval = const Duration(seconds: 10),
  Duration sessionTimeout = const Duration(minutes: 10),
  ReconnectPolicy? reconnect,
  NodeRuntime? runtime,
  StoreRpcServer? rpc,
}) : organizations = Set.unmodifiable(organizations),
     labels = Map.unmodifiable(labels) {
  this.rpc =
      rpc ??
      StoreRpcServer(
        store: store,
        sessionTimeout: sessionTimeout,
        describeProvider: describe,
      );
  this.runtime =
      runtime ??
      NodeRuntime(
        NodeConfig(
          hubUri: hubUri,
          nodeId: NodeId(nodeId),
          // Advertised so a hub whose OmnyHub instance also hosts other kinds
          // of node can tell storage providers apart from the rest.
          capabilities: {StoreProtocol.capability},
          labels: this.labels,
          agentVersion: omnyStoreVersion,
          heartbeatInterval: heartbeatInterval,
          reconnect: reconnect,
          headers: {
            if (authToken != null) 'authorization': 'Bearer $authToken',
          },
          // The hub calls these actions; the RPC server answers them against
          // this node's own store.
          onRequest: (action, payload) => this.rpc.handle(action, payload),
          registerPayload: () async => {
            StoreProtocol.versionKey: StoreProtocol.version,
            StoreProtocol.descriptorKey: (await describe()).toJson(),
          },
          onRegistered: _onRegistered,
          // Capacity and usage ride along on the heartbeat, so placement
          // decisions use fresh numbers without the hub polling every node.
          heartbeatPayload: () async => {
            StoreProtocol.descriptorKey: (await describe()).toJson(),
          },
        ),
        logger: logger,
      );
}