feat(network): add selectable privacy-preserving discovery

This commit is contained in:
Alexander Sellite 2026-09-01 10:21:26 -04:00
parent 9cf0c8fc9c
commit 4d31fd1517
26 changed files with 959 additions and 153 deletions

View file

@ -39,6 +39,17 @@ func verify(endpoint: ConnectionEndpoint, fingerprint: String) -> Verification:
)
func verify_identity(fingerprint: String) -> Verification:
_ensure_loaded()
if not NetworkIdentityCrypto.valid_fingerprint(fingerprint):
return Verification.CHANGED
return (
Verification.MATCH
if _records.has(_identity_key(fingerprint))
else Verification.FIRST_SEEN
)
func get_record(endpoint: ConnectionEndpoint) -> Dictionary:
_ensure_loaded()
if endpoint == null:
@ -46,6 +57,11 @@ func get_record(endpoint: ConnectionEndpoint) -> Dictionary:
return Dictionary(_records.get(endpoint.normalized_display, {})).duplicate(true)
func get_identity_record(fingerprint: String) -> Dictionary:
_ensure_loaded()
return Dictionary(_records.get(_identity_key(fingerprint), {})).duplicate(true)
func trust(
endpoint: ConnectionEndpoint,
fingerprint: String,
@ -74,6 +90,25 @@ func trust(
return _save()
func trust_identity(fingerprint: String, server_name: String = "") -> bool:
_ensure_loaded()
if not NetworkIdentityCrypto.valid_fingerprint(fingerprint):
return false
var key := _identity_key(fingerprint)
var now := int(Time.get_unix_time_from_system())
var previous: Dictionary = _records.get(key, {})
_records[key] = {
"route_kind": "discovery",
"identity_key": key,
"fingerprint": fingerprint,
"first_seen_unix": int(previous.get("first_seen_unix", now)),
"last_seen_unix": now,
"last_observed_server_name": server_name.left(80),
"trust_state": "pinned",
}
return _save()
func touch(endpoint: ConnectionEndpoint) -> void:
_ensure_loaded()
if endpoint == null:
@ -85,6 +120,15 @@ func touch(endpoint: ConnectionEndpoint) -> void:
_save()
func touch_identity(fingerprint: String) -> void:
_ensure_loaded()
var record: Dictionary = _records.get(_identity_key(fingerprint), {})
if record.is_empty():
return
record["last_seen_unix"] = int(Time.get_unix_time_from_system())
_save()
func _ensure_loaded() -> void:
if _loaded:
return
@ -108,12 +152,21 @@ func _ensure_loaded() -> void:
continue
var record: Dictionary = value
var endpoint := str(record.get("normalized_endpoint", ""))
var identity_key := str(record.get("identity_key", ""))
var fingerprint := str(record.get("fingerprint", ""))
if not endpoint.is_empty() and NetworkIdentityCrypto.valid_fingerprint(fingerprint):
if not NetworkIdentityCrypto.valid_fingerprint(fingerprint):
continue
if not endpoint.is_empty():
_records[endpoint] = record.duplicate(true)
elif identity_key == _identity_key(fingerprint):
_records[identity_key] = record.duplicate(true)
_expected_hash = PortableFileGuard.hash_file(_store_path)
static func _identity_key(fingerprint: String) -> String:
return "identity:%s" % fingerprint
func _save() -> bool:
if _write_blocked:
return false