NAME

Protocol::HAP::Store::File - the store contract over files

SYNOPSIS

use Protocol::HAP::Store::File;

my $store = Protocol::HAP::Store::File->new(
    path   => '/var/db/openhapd',
    logger => $logger,
);

$store->save_pairing('controller-id', $ltpk, 1);
my $pairings = $store->load_pairings;

DESCRIPTION

This module is the durable implementation of the store contract that Protocol/HAP/Store.pod documents. The state lives in one directory and survives a restart, which is what a paired accessory needs: a controller that sees c# go backwards drops the accessory.

The tier holds a sans-IO engine, and this module writes files. That is the point. Sans-IO describes Protocol::HAP::Server, and the store is the injected seam that keeps the engine pure.

CONSTRUCTOR

new(%args)

path

The state directory. The argument is required, and new dies without it. The caller owns the location, because a default path is host policy. new creates the directory with mode 0700 when it is absent.

logger

A logger with debug, info, warning, and error. The default is Protocol::HAP->null_logger, which drops every message.

FILES

Every write applies the mode at the open, before the first byte. A chmod after the write leaves a window in which the identity of the accessory is world-readable.

<path>/accessory_ltsk

The long-term secret key of the accessory, mode 0600.

<path>/accessory_ltpk

The long-term public key of the accessory, mode 0644.

<path>/pairings.db

One line for each paired controller, mode 0600. The format is controller_id:ltpk_hex:permissions. One process owns the store, so a read takes no lock.

<path>/state.json

The configuration number, the configuration digest, and the counter of pairing failures, mode 0600. The write goes through a sibling temporary file and a rename, so a reader sees the old content or the new content. A missing or corrupt file gives empty state, because a state file that a crash truncated must not stop the daemon that would rewrite it.

SEE ALSO

Protocol::HAP, Protocol::HAP::Store::Memory, Protocol/HAP/Store.pod, spec/HAP-Pairing.md