src/coordinator/EndpointPath.bend

mylsm-lsm-store@0.6.0.1 · 24 lines · 4 definitions

1import Base
2import mylsm-lsm-store@0.6.0.1/src/StorageBytes.bend as StorageBytes
3
4# Keeps a local socket endpoint within macOS and Linux sockaddr path limits.
5type Decision is Data:
6  Endpoint{path: String}
7  PathTooLong{}
8
9# Returns whether one complete endpoint path fits the conservative byte limit.
10def admit_length(endpoint_bytes: Nat) -> Bool:
11  Nat.is_le(endpoint_bytes, 100n)
12
13# Appends the fixed owner endpoint name only when the path remains bounded.
14def endpoint.result(path: String, admitted: Bool) -> Decision:
15  match path:
16    case canonical:
17      match admitted:
18        case True{}: Endpoint{canonical ++ "/MYLSM.sock"}
19        case False{}: PathTooLong{}
20
21# Builds one endpoint from a path already resolved by the filesystem layer.
22def for_canonical_path(+canonical_path: String) -> Decision:
23  endpoint.result(canonical_path,
24    admit_length(Nat.add(StorageBytes.string_size(canonical_path), 11n)))