@xtr-dev/rondevu-server 0.4.0 → 0.5.1
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/ADVANCED.md +502 -0
- package/README.md +136 -282
- package/dist/index.js +694 -733
- package/dist/index.js.map +4 -4
- package/migrations/0006_service_offer_refactor.sql +40 -0
- package/migrations/0007_simplify_schema.sql +54 -0
- package/migrations/0008_peer_id_to_username.sql +67 -0
- package/migrations/fresh_schema.sql +81 -0
- package/package.json +2 -1
- package/src/app.ts +38 -591
- package/src/config.ts +0 -13
- package/src/crypto.ts +103 -139
- package/src/rpc.ts +725 -0
- package/src/storage/d1.ts +169 -182
- package/src/storage/sqlite.ts +142 -168
- package/src/storage/types.ts +51 -95
- package/src/worker.ts +0 -6
- package/wrangler.toml +3 -3
- package/src/middleware/auth.ts +0 -51
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
-- V0.4.0 Migration: Refactor service-to-offer relationship
|
|
2
|
+
-- Change from one-to-one (service has offer_id) to one-to-many (offer has service_id)
|
|
3
|
+
|
|
4
|
+
-- Step 1: Add service_id column to offers table
|
|
5
|
+
ALTER TABLE offers ADD COLUMN service_id TEXT;
|
|
6
|
+
|
|
7
|
+
-- Step 2: Create new services table without offer_id
|
|
8
|
+
CREATE TABLE services_new (
|
|
9
|
+
id TEXT PRIMARY KEY,
|
|
10
|
+
username TEXT NOT NULL,
|
|
11
|
+
service_fqn TEXT NOT NULL,
|
|
12
|
+
created_at INTEGER NOT NULL,
|
|
13
|
+
expires_at INTEGER NOT NULL,
|
|
14
|
+
is_public INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
metadata TEXT,
|
|
16
|
+
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE,
|
|
17
|
+
UNIQUE(username, service_fqn)
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- Step 3: Copy data from old services table (if any exists)
|
|
21
|
+
INSERT INTO services_new (id, username, service_fqn, created_at, expires_at, is_public, metadata)
|
|
22
|
+
SELECT id, username, service_fqn, created_at, expires_at, is_public, metadata
|
|
23
|
+
FROM services;
|
|
24
|
+
|
|
25
|
+
-- Step 4: Drop old services table
|
|
26
|
+
DROP TABLE services;
|
|
27
|
+
|
|
28
|
+
-- Step 5: Rename new table to services
|
|
29
|
+
ALTER TABLE services_new RENAME TO services;
|
|
30
|
+
|
|
31
|
+
-- Step 6: Recreate indexes
|
|
32
|
+
CREATE INDEX IF NOT EXISTS idx_services_username ON services(username);
|
|
33
|
+
CREATE INDEX IF NOT EXISTS idx_services_fqn ON services(service_fqn);
|
|
34
|
+
CREATE INDEX IF NOT EXISTS idx_services_expires ON services(expires_at);
|
|
35
|
+
|
|
36
|
+
-- Step 7: Add index for service_id in offers
|
|
37
|
+
CREATE INDEX IF NOT EXISTS idx_offers_service ON offers(service_id);
|
|
38
|
+
|
|
39
|
+
-- Step 8: Add foreign key constraint (D1 doesn't enforce FK in ALTER, but good for documentation)
|
|
40
|
+
-- FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- V0.4.1 Migration: Simplify schema and add service discovery
|
|
2
|
+
-- Remove privacy layer (service_index) and add extracted fields for discovery
|
|
3
|
+
|
|
4
|
+
-- Step 1: Drop service_index table (privacy layer removal)
|
|
5
|
+
DROP TABLE IF EXISTS service_index;
|
|
6
|
+
|
|
7
|
+
-- Step 2: Create new services table with extracted fields for discovery
|
|
8
|
+
CREATE TABLE services_new (
|
|
9
|
+
id TEXT PRIMARY KEY,
|
|
10
|
+
service_fqn TEXT NOT NULL,
|
|
11
|
+
service_name TEXT NOT NULL,
|
|
12
|
+
version TEXT NOT NULL,
|
|
13
|
+
username TEXT NOT NULL,
|
|
14
|
+
created_at INTEGER NOT NULL,
|
|
15
|
+
expires_at INTEGER NOT NULL,
|
|
16
|
+
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE,
|
|
17
|
+
UNIQUE(service_fqn)
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- Step 3: Migrate existing data (if any) - parse FQN to extract components
|
|
21
|
+
-- Note: This migration assumes FQN format is already "service:version@username"
|
|
22
|
+
-- If there's old data with different format, manual intervention may be needed
|
|
23
|
+
INSERT INTO services_new (id, service_fqn, service_name, version, username, created_at, expires_at)
|
|
24
|
+
SELECT
|
|
25
|
+
id,
|
|
26
|
+
service_fqn,
|
|
27
|
+
-- Extract service_name: everything before first ':'
|
|
28
|
+
substr(service_fqn, 1, instr(service_fqn, ':') - 1) as service_name,
|
|
29
|
+
-- Extract version: between ':' and '@'
|
|
30
|
+
substr(
|
|
31
|
+
service_fqn,
|
|
32
|
+
instr(service_fqn, ':') + 1,
|
|
33
|
+
instr(service_fqn, '@') - instr(service_fqn, ':') - 1
|
|
34
|
+
) as version,
|
|
35
|
+
username,
|
|
36
|
+
created_at,
|
|
37
|
+
expires_at
|
|
38
|
+
FROM services
|
|
39
|
+
WHERE service_fqn LIKE '%:%@%'; -- Only migrate properly formatted FQNs
|
|
40
|
+
|
|
41
|
+
-- Step 4: Drop old services table
|
|
42
|
+
DROP TABLE services;
|
|
43
|
+
|
|
44
|
+
-- Step 5: Rename new table to services
|
|
45
|
+
ALTER TABLE services_new RENAME TO services;
|
|
46
|
+
|
|
47
|
+
-- Step 6: Create indexes for efficient querying
|
|
48
|
+
CREATE INDEX idx_services_fqn ON services(service_fqn);
|
|
49
|
+
CREATE INDEX idx_services_discovery ON services(service_name, version);
|
|
50
|
+
CREATE INDEX idx_services_username ON services(username);
|
|
51
|
+
CREATE INDEX idx_services_expires ON services(expires_at);
|
|
52
|
+
|
|
53
|
+
-- Step 7: Create index on offers for available offer filtering
|
|
54
|
+
CREATE INDEX IF NOT EXISTS idx_offers_available ON offers(answerer_peer_id) WHERE answerer_peer_id IS NULL;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
-- Migration: Convert peer_id to username in offers and ice_candidates tables
|
|
2
|
+
-- This migration aligns the database with the unified Ed25519 authentication system
|
|
3
|
+
|
|
4
|
+
-- Step 1: Recreate offers table with username instead of peer_id
|
|
5
|
+
CREATE TABLE offers_new (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
username TEXT NOT NULL,
|
|
8
|
+
service_id TEXT,
|
|
9
|
+
service_fqn TEXT,
|
|
10
|
+
sdp TEXT NOT NULL,
|
|
11
|
+
created_at INTEGER NOT NULL,
|
|
12
|
+
expires_at INTEGER NOT NULL,
|
|
13
|
+
last_seen INTEGER NOT NULL,
|
|
14
|
+
answerer_username TEXT,
|
|
15
|
+
answer_sdp TEXT,
|
|
16
|
+
answered_at INTEGER,
|
|
17
|
+
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE,
|
|
18
|
+
FOREIGN KEY (answerer_username) REFERENCES usernames(username) ON DELETE SET NULL
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
-- Step 2: Migrate data (if any) - peer_id becomes username
|
|
22
|
+
-- Note: This assumes peer_id values were already usernames in practice
|
|
23
|
+
INSERT INTO offers_new (id, username, service_id, service_fqn, sdp, created_at, expires_at, last_seen, answerer_username, answer_sdp, answered_at)
|
|
24
|
+
SELECT id, peer_id as username, service_id, NULL as service_fqn, sdp, created_at, expires_at, last_seen, answerer_peer_id as answerer_username, answer_sdp, answered_at
|
|
25
|
+
FROM offers;
|
|
26
|
+
|
|
27
|
+
-- Step 3: Drop old offers table
|
|
28
|
+
DROP TABLE offers;
|
|
29
|
+
|
|
30
|
+
-- Step 4: Rename new table
|
|
31
|
+
ALTER TABLE offers_new RENAME TO offers;
|
|
32
|
+
|
|
33
|
+
-- Step 5: Recreate indexes
|
|
34
|
+
CREATE INDEX idx_offers_username ON offers(username);
|
|
35
|
+
CREATE INDEX idx_offers_service ON offers(service_id);
|
|
36
|
+
CREATE INDEX idx_offers_expires ON offers(expires_at);
|
|
37
|
+
CREATE INDEX idx_offers_last_seen ON offers(last_seen);
|
|
38
|
+
CREATE INDEX idx_offers_answerer ON offers(answerer_username);
|
|
39
|
+
|
|
40
|
+
-- Step 6: Recreate ice_candidates table with username instead of peer_id
|
|
41
|
+
CREATE TABLE ice_candidates_new (
|
|
42
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
43
|
+
offer_id TEXT NOT NULL,
|
|
44
|
+
username TEXT NOT NULL,
|
|
45
|
+
role TEXT NOT NULL CHECK(role IN ('offerer', 'answerer')),
|
|
46
|
+
candidate TEXT NOT NULL,
|
|
47
|
+
created_at INTEGER NOT NULL,
|
|
48
|
+
FOREIGN KEY (offer_id) REFERENCES offers(id) ON DELETE CASCADE,
|
|
49
|
+
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
-- Step 7: Migrate ICE candidates data
|
|
53
|
+
INSERT INTO ice_candidates_new (offer_id, username, role, candidate, created_at)
|
|
54
|
+
SELECT offer_id, peer_id as username, role, candidate, created_at
|
|
55
|
+
FROM ice_candidates;
|
|
56
|
+
|
|
57
|
+
-- Step 8: Drop old ice_candidates table
|
|
58
|
+
DROP TABLE ice_candidates;
|
|
59
|
+
|
|
60
|
+
-- Step 9: Rename new table
|
|
61
|
+
ALTER TABLE ice_candidates_new RENAME TO ice_candidates;
|
|
62
|
+
|
|
63
|
+
-- Step 10: Recreate indexes
|
|
64
|
+
CREATE INDEX idx_ice_offer ON ice_candidates(offer_id);
|
|
65
|
+
CREATE INDEX idx_ice_username ON ice_candidates(username);
|
|
66
|
+
CREATE INDEX idx_ice_role ON ice_candidates(role);
|
|
67
|
+
CREATE INDEX idx_ice_created ON ice_candidates(created_at);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
-- Fresh schema for Rondevu v0.5.0+
|
|
2
|
+
-- Unified Ed25519 authentication - username/keypair only
|
|
3
|
+
-- This is the complete schema without migration steps
|
|
4
|
+
|
|
5
|
+
-- Drop existing tables if they exist
|
|
6
|
+
DROP TABLE IF EXISTS ice_candidates;
|
|
7
|
+
DROP TABLE IF EXISTS services;
|
|
8
|
+
DROP TABLE IF EXISTS offers;
|
|
9
|
+
DROP TABLE IF EXISTS usernames;
|
|
10
|
+
|
|
11
|
+
-- Usernames table (now required for all users, even anonymous)
|
|
12
|
+
CREATE TABLE usernames (
|
|
13
|
+
username TEXT PRIMARY KEY,
|
|
14
|
+
public_key TEXT NOT NULL UNIQUE,
|
|
15
|
+
claimed_at INTEGER NOT NULL,
|
|
16
|
+
expires_at INTEGER NOT NULL,
|
|
17
|
+
last_used INTEGER NOT NULL,
|
|
18
|
+
metadata TEXT,
|
|
19
|
+
CHECK(length(username) >= 3 AND length(username) <= 32)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
CREATE INDEX idx_usernames_expires ON usernames(expires_at);
|
|
23
|
+
CREATE INDEX idx_usernames_public_key ON usernames(public_key);
|
|
24
|
+
|
|
25
|
+
-- Services table with discovery fields
|
|
26
|
+
CREATE TABLE services (
|
|
27
|
+
id TEXT PRIMARY KEY,
|
|
28
|
+
service_fqn TEXT NOT NULL,
|
|
29
|
+
service_name TEXT NOT NULL,
|
|
30
|
+
version TEXT NOT NULL,
|
|
31
|
+
username TEXT NOT NULL,
|
|
32
|
+
created_at INTEGER NOT NULL,
|
|
33
|
+
expires_at INTEGER NOT NULL,
|
|
34
|
+
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE,
|
|
35
|
+
UNIQUE(service_name, version, username)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
CREATE INDEX idx_services_fqn ON services(service_fqn);
|
|
39
|
+
CREATE INDEX idx_services_discovery ON services(service_name, version);
|
|
40
|
+
CREATE INDEX idx_services_username ON services(username);
|
|
41
|
+
CREATE INDEX idx_services_expires ON services(expires_at);
|
|
42
|
+
|
|
43
|
+
-- Offers table (now uses username instead of peer_id)
|
|
44
|
+
CREATE TABLE offers (
|
|
45
|
+
id TEXT PRIMARY KEY,
|
|
46
|
+
username TEXT NOT NULL,
|
|
47
|
+
service_id TEXT,
|
|
48
|
+
service_fqn TEXT,
|
|
49
|
+
sdp TEXT NOT NULL,
|
|
50
|
+
created_at INTEGER NOT NULL,
|
|
51
|
+
expires_at INTEGER NOT NULL,
|
|
52
|
+
last_seen INTEGER NOT NULL,
|
|
53
|
+
answerer_username TEXT,
|
|
54
|
+
answer_sdp TEXT,
|
|
55
|
+
answered_at INTEGER,
|
|
56
|
+
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE,
|
|
57
|
+
FOREIGN KEY (answerer_username) REFERENCES usernames(username) ON DELETE SET NULL
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
CREATE INDEX idx_offers_username ON offers(username);
|
|
61
|
+
CREATE INDEX idx_offers_service ON offers(service_id);
|
|
62
|
+
CREATE INDEX idx_offers_expires ON offers(expires_at);
|
|
63
|
+
CREATE INDEX idx_offers_last_seen ON offers(last_seen);
|
|
64
|
+
CREATE INDEX idx_offers_answerer ON offers(answerer_username);
|
|
65
|
+
|
|
66
|
+
-- ICE candidates table (now uses username instead of peer_id)
|
|
67
|
+
CREATE TABLE ice_candidates (
|
|
68
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
69
|
+
offer_id TEXT NOT NULL,
|
|
70
|
+
username TEXT NOT NULL,
|
|
71
|
+
role TEXT NOT NULL CHECK(role IN ('offerer', 'answerer')),
|
|
72
|
+
candidate TEXT NOT NULL,
|
|
73
|
+
created_at INTEGER NOT NULL,
|
|
74
|
+
FOREIGN KEY (offer_id) REFERENCES offers(id) ON DELETE CASCADE,
|
|
75
|
+
FOREIGN KEY (username) REFERENCES usernames(username) ON DELETE CASCADE
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
CREATE INDEX idx_ice_offer ON ice_candidates(offer_id);
|
|
79
|
+
CREATE INDEX idx_ice_username ON ice_candidates(username);
|
|
80
|
+
CREATE INDEX idx_ice_role ON ice_candidates(role);
|
|
81
|
+
CREATE INDEX idx_ice_created ON ice_candidates(created_at);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xtr-dev/rondevu-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "DNS-like WebRTC signaling server with username claiming and service discovery",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@hono/node-server": "^1.19.6",
|
|
24
24
|
"@noble/ed25519": "^3.0.0",
|
|
25
|
+
"@xtr-dev/rondevu-client": "^0.13.0",
|
|
25
26
|
"better-sqlite3": "^12.4.1",
|
|
26
27
|
"hono": "^4.10.4"
|
|
27
28
|
}
|