@aria-cli/wireguard 1.0.38 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap-authority.d.ts +2 -0
- package/dist/bootstrap-authority.js +47 -0
- package/dist/bootstrap-tls.d.ts +14 -0
- package/dist/bootstrap-tls.js +69 -0
- package/dist/db-owner-fencing.d.ts +10 -0
- package/dist/db-owner-fencing.js +44 -0
- package/dist/derp-relay.d.ts +75 -0
- package/dist/derp-relay.js +311 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +100 -0
- package/dist/nat.d.ts +84 -0
- package/dist/nat.js +397 -0
- package/dist/network-state-store.d.ts +46 -0
- package/dist/network-state-store.js +248 -0
- package/dist/network.d.ts +590 -0
- package/dist/network.js +3391 -0
- package/dist/peer-discovery.d.ts +133 -0
- package/dist/peer-discovery.js +486 -0
- package/dist/resilient-tunnel.d.ts +70 -0
- package/dist/resilient-tunnel.js +389 -0
- package/dist/route-ownership.d.ts +23 -0
- package/dist/route-ownership.js +79 -0
- package/dist/tunnel.d.ts +141 -0
- package/dist/tunnel.js +474 -0
- package/index.js +52 -52
- package/npm/darwin-arm64/package.json +1 -1
- package/npm/darwin-x64/package.json +1 -1
- package/npm/linux-arm64-gnu/package.json +1 -1
- package/npm/linux-x64-gnu/package.json +1 -1
- package/npm/win32-x64-msvc/package.json +1 -1
- package/package.json +13 -20
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NetworkStateStore — canonical, machine-scoped persistence for network control-plane state.
|
|
4
|
+
*
|
|
5
|
+
* All network-adjacent durable state (peers, signing keys, revocations, nonces, trust)
|
|
6
|
+
* lives in ONE canonical store at ARIA_HOME/network/state.db, independent of any
|
|
7
|
+
* arion-specific Memoria DB. This eliminates the split-brain where peer state could
|
|
8
|
+
* drift across multiple DB paths.
|
|
9
|
+
*
|
|
10
|
+
* PeerRegistry, RevocationStore, and other network stores all use the Database
|
|
11
|
+
* returned by getDatabase().
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.NetworkStateStore = void 0;
|
|
48
|
+
exports.canonicalNetworkStatePath = canonicalNetworkStatePath;
|
|
49
|
+
const fs = __importStar(require("node:fs"));
|
|
50
|
+
const path = __importStar(require("node:path"));
|
|
51
|
+
const network_runtime_1 = require("@aria-cli/tools/network-runtime");
|
|
52
|
+
/**
|
|
53
|
+
* Canonical schema for the network state DB.
|
|
54
|
+
*
|
|
55
|
+
* Only creates tables that PeerRegistry depends on (it does NO schema creation).
|
|
56
|
+
* Other stores (RevocationStore, PeerTrustStore, PeerSigningKeyStore,
|
|
57
|
+
* InviteConsumeLedger, DurableReplayGuard, etc.) create their own tables
|
|
58
|
+
* via ensureTable() in their constructors — they're self-managing.
|
|
59
|
+
*/
|
|
60
|
+
const NETWORK_PEERS_TABLE_SQL = `
|
|
61
|
+
CREATE TABLE IF NOT EXISTS network_peers (
|
|
62
|
+
node_id TEXT PRIMARY KEY,
|
|
63
|
+
public_key TEXT NOT NULL,
|
|
64
|
+
name TEXT NOT NULL,
|
|
65
|
+
endpoint_host TEXT,
|
|
66
|
+
endpoint_port INTEGER,
|
|
67
|
+
endpoint_revision INTEGER NOT NULL DEFAULT 0,
|
|
68
|
+
control_endpoint_host TEXT,
|
|
69
|
+
control_endpoint_port INTEGER,
|
|
70
|
+
control_tls_ca_fingerprint TEXT,
|
|
71
|
+
preshared_key TEXT,
|
|
72
|
+
allowed_ips TEXT DEFAULT '0.0.0.0/0',
|
|
73
|
+
invite_token TEXT,
|
|
74
|
+
status TEXT DEFAULT 'active',
|
|
75
|
+
last_handshake INTEGER,
|
|
76
|
+
created_at INTEGER,
|
|
77
|
+
updated_at INTEGER,
|
|
78
|
+
signing_public_key TEXT
|
|
79
|
+
);`;
|
|
80
|
+
const NETWORK_PEERS_INDEX_SQL = `
|
|
81
|
+
CREATE INDEX IF NOT EXISTS idx_network_peers_name ON network_peers(name);
|
|
82
|
+
CREATE INDEX IF NOT EXISTS idx_network_peers_status ON network_peers(status);
|
|
83
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_network_peers_public_key
|
|
84
|
+
ON network_peers(public_key);
|
|
85
|
+
`;
|
|
86
|
+
const SCHEMA_SQL = `
|
|
87
|
+
-- Peer registry canonical hard-cut schema
|
|
88
|
+
${NETWORK_PEERS_TABLE_SQL}
|
|
89
|
+
|
|
90
|
+
-- Token replay protection (used by PeerRegistry.claimToken/releaseToken)
|
|
91
|
+
CREATE TABLE IF NOT EXISTS token_claims (
|
|
92
|
+
nonce TEXT PRIMARY KEY,
|
|
93
|
+
claimed_at INTEGER NOT NULL
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
-- Pending tunnel/pair requests (used by PeerRegistry.listByStatus)
|
|
97
|
+
CREATE TABLE IF NOT EXISTS pending_tunnel (
|
|
98
|
+
id TEXT PRIMARY KEY,
|
|
99
|
+
peer_name TEXT NOT NULL,
|
|
100
|
+
peer_public_key TEXT NOT NULL,
|
|
101
|
+
status TEXT DEFAULT 'pending',
|
|
102
|
+
created_at INTEGER NOT NULL,
|
|
103
|
+
updated_at INTEGER
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
-- Schema version tracking
|
|
107
|
+
CREATE TABLE IF NOT EXISTS network_schema_version (
|
|
108
|
+
version INTEGER NOT NULL
|
|
109
|
+
);
|
|
110
|
+
`;
|
|
111
|
+
const CURRENT_SCHEMA_VERSION = 6;
|
|
112
|
+
class NetworkStateStore {
|
|
113
|
+
options;
|
|
114
|
+
db = null;
|
|
115
|
+
dbPath;
|
|
116
|
+
constructor(options) {
|
|
117
|
+
this.options = options;
|
|
118
|
+
this.dbPath = options.dbPath ?? path.join(options.ariaHome, "network", "state.db");
|
|
119
|
+
}
|
|
120
|
+
/** Canonical path to the network state DB */
|
|
121
|
+
get path() {
|
|
122
|
+
return this.dbPath;
|
|
123
|
+
}
|
|
124
|
+
/** Whether the store has been opened */
|
|
125
|
+
get isOpen() {
|
|
126
|
+
return this.db !== null;
|
|
127
|
+
}
|
|
128
|
+
/** Open the database, creating schema if needed */
|
|
129
|
+
open() {
|
|
130
|
+
if (this.db)
|
|
131
|
+
return this.db;
|
|
132
|
+
// Ensure directory exists
|
|
133
|
+
const dir = path.dirname(this.dbPath);
|
|
134
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
135
|
+
// Dynamic import better-sqlite3 (same pattern as PeerRegistry)
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
137
|
+
const BetterSqlite3 = require("better-sqlite3");
|
|
138
|
+
this.db = new BetterSqlite3(this.dbPath);
|
|
139
|
+
try {
|
|
140
|
+
this.db.pragma("journal_mode = WAL");
|
|
141
|
+
this.db.pragma("busy_timeout = 5000");
|
|
142
|
+
// Create schema
|
|
143
|
+
this.db.exec(SCHEMA_SQL);
|
|
144
|
+
this.reconcilePeerTableSchema(this.db);
|
|
145
|
+
this.db.exec(NETWORK_PEERS_INDEX_SQL);
|
|
146
|
+
// Track schema version
|
|
147
|
+
const versionRow = this.db
|
|
148
|
+
.prepare("SELECT version FROM network_schema_version LIMIT 1")
|
|
149
|
+
.get();
|
|
150
|
+
if (!versionRow) {
|
|
151
|
+
this.db
|
|
152
|
+
.prepare("INSERT INTO network_schema_version (version) VALUES (?)")
|
|
153
|
+
.run(CURRENT_SCHEMA_VERSION);
|
|
154
|
+
}
|
|
155
|
+
else if (versionRow.version < CURRENT_SCHEMA_VERSION) {
|
|
156
|
+
this.db
|
|
157
|
+
.prepare("UPDATE network_schema_version SET version = ?")
|
|
158
|
+
.run(CURRENT_SCHEMA_VERSION);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
this.db.close();
|
|
163
|
+
this.db = null;
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
return this.db;
|
|
167
|
+
}
|
|
168
|
+
reconcilePeerTableSchema(db) {
|
|
169
|
+
const tableRow = db
|
|
170
|
+
.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name='network_peers'")
|
|
171
|
+
.get();
|
|
172
|
+
if (!tableRow?.sql)
|
|
173
|
+
return;
|
|
174
|
+
const tableSql = tableRow.sql.toLowerCase();
|
|
175
|
+
const hasLegacyStatusCheck = tableSql.includes("check") && !tableSql.includes("pending_verification");
|
|
176
|
+
const columns = db.prepare("PRAGMA table_info(network_peers)").all();
|
|
177
|
+
const columnNames = new Set(columns.map((column) => column.name));
|
|
178
|
+
const primaryKey = columns.find((column) => column.pk === 1)?.name;
|
|
179
|
+
const requiredColumns = [
|
|
180
|
+
"public_key",
|
|
181
|
+
"node_id",
|
|
182
|
+
"name",
|
|
183
|
+
"endpoint_host",
|
|
184
|
+
"endpoint_port",
|
|
185
|
+
"endpoint_revision",
|
|
186
|
+
"control_endpoint_host",
|
|
187
|
+
"control_endpoint_port",
|
|
188
|
+
"control_tls_ca_fingerprint",
|
|
189
|
+
"preshared_key",
|
|
190
|
+
"allowed_ips",
|
|
191
|
+
"invite_token",
|
|
192
|
+
"status",
|
|
193
|
+
"last_handshake",
|
|
194
|
+
"created_at",
|
|
195
|
+
"updated_at",
|
|
196
|
+
"signing_public_key",
|
|
197
|
+
];
|
|
198
|
+
const missingColumns = requiredColumns.filter((column) => !columnNames.has(column));
|
|
199
|
+
const legacySchemaProblems = [];
|
|
200
|
+
if (hasLegacyStatusCheck) {
|
|
201
|
+
legacySchemaProblems.push("legacy status check");
|
|
202
|
+
}
|
|
203
|
+
if (columnNames.has("message_port")) {
|
|
204
|
+
legacySchemaProblems.push("message_port column");
|
|
205
|
+
}
|
|
206
|
+
if (columnNames.has("peer_id")) {
|
|
207
|
+
legacySchemaProblems.push("legacy peer_id column");
|
|
208
|
+
}
|
|
209
|
+
if (primaryKey !== "node_id") {
|
|
210
|
+
legacySchemaProblems.push(`primary key is ${primaryKey ?? "missing"}`);
|
|
211
|
+
}
|
|
212
|
+
if (missingColumns.length > 0) {
|
|
213
|
+
legacySchemaProblems.push(`missing columns: ${missingColumns.join(", ")}`);
|
|
214
|
+
}
|
|
215
|
+
if (legacySchemaProblems.length === 0) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
throw new Error(`Legacy network_peers schema requires hard reset: ${legacySchemaProblems.join(", ")}`);
|
|
219
|
+
}
|
|
220
|
+
/** Get the underlying Database handle (opens if needed) */
|
|
221
|
+
getDatabase() {
|
|
222
|
+
return this.open();
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Claim the owner epoch for this runtime on the shared network state DB.
|
|
226
|
+
* Must be called after open() and before any durable writes.
|
|
227
|
+
* Throws StaleOwnerError if a newer generation already owns the DB.
|
|
228
|
+
*/
|
|
229
|
+
claimOwnerEpoch(generation) {
|
|
230
|
+
const db = this.open();
|
|
231
|
+
(0, network_runtime_1.claimDbOwnerEpoch)(db, generation);
|
|
232
|
+
}
|
|
233
|
+
/** Close the database */
|
|
234
|
+
close() {
|
|
235
|
+
if (this.db) {
|
|
236
|
+
this.db.close();
|
|
237
|
+
this.db = null;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.NetworkStateStore = NetworkStateStore;
|
|
242
|
+
/**
|
|
243
|
+
* Resolve the canonical network state DB path for a given ARIA home.
|
|
244
|
+
*/
|
|
245
|
+
function canonicalNetworkStatePath(ariaHome) {
|
|
246
|
+
return path.join(ariaHome, "network", "state.db");
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=network-state-store.js.map
|