feat(network): add selectable privacy-preserving discovery
This commit is contained in:
parent
9cf0c8fc9c
commit
4d31fd1517
26 changed files with 959 additions and 153 deletions
|
|
@ -485,17 +485,30 @@ func join_direct(endpoint_text: String) -> bool:
|
|||
if not endpoint.is_valid():
|
||||
_fail(endpoint.error_message)
|
||||
return false
|
||||
return join_route(ConnectionRoute.direct(endpoint))
|
||||
|
||||
|
||||
func join_route(route: ConnectionRoute) -> bool:
|
||||
if (
|
||||
state != State.INACTIVE
|
||||
or not _profile_ready
|
||||
or _profile == null
|
||||
or _spawn_service == null
|
||||
or route == null
|
||||
or not route.is_valid()
|
||||
):
|
||||
return false
|
||||
_operation_generation += 1
|
||||
var generation: int = _operation_generation
|
||||
_current_route = ConnectionRoute.direct(endpoint)
|
||||
_current_route = route
|
||||
_set_state(
|
||||
State.CONNECTING,
|
||||
"Connecting to %s..." % endpoint.normalized_display
|
||||
"Connecting to %s..." % route.display_description
|
||||
)
|
||||
_replace_transport()
|
||||
var error: Error = _transport.connect_to_route(_current_route)
|
||||
if error != OK:
|
||||
_fail("Could not begin the direct connection.")
|
||||
_fail("Could not begin the connection.")
|
||||
return false
|
||||
multiplayer.multiplayer_peer = _transport.get_multiplayer_peer()
|
||||
_connection_deadline = (
|
||||
|
|
@ -597,11 +610,23 @@ func get_current_endpoint() -> ConnectionEndpoint:
|
|||
return (
|
||||
_current_route.direct_endpoint
|
||||
if _current_route != null
|
||||
and _current_route.kind == ConnectionRoute.Kind.DIRECT
|
||||
and _current_route.kind in [
|
||||
ConnectionRoute.Kind.DIRECT,
|
||||
ConnectionRoute.Kind.DISCOVERY_DIRECT,
|
||||
ConnectionRoute.Kind.DISCOVERY_RELAY,
|
||||
]
|
||||
else null
|
||||
)
|
||||
|
||||
|
||||
func is_current_route_discovery() -> bool:
|
||||
return _current_route != null and _current_route.is_discovery_join()
|
||||
|
||||
|
||||
func is_current_route_relay() -> bool:
|
||||
return _current_route != null and _current_route.is_relay()
|
||||
|
||||
|
||||
func get_last_server_metadata() -> Dictionary:
|
||||
return {
|
||||
"server_display_name": _last_server_display_name,
|
||||
|
|
@ -1226,11 +1251,16 @@ func receive_server_identity_proof(data: Dictionary) -> void:
|
|||
_pending_server_proof = data.duplicate(true)
|
||||
_server_identity_fingerprint = fingerprint
|
||||
_server_identity_public_key = public_pem
|
||||
var verification := _server_trust.verify(
|
||||
get_current_endpoint(), fingerprint
|
||||
var verification := (
|
||||
_server_trust.verify_identity(fingerprint)
|
||||
if is_current_route_discovery()
|
||||
else _server_trust.verify(get_current_endpoint(), fingerprint)
|
||||
)
|
||||
if verification == ServerTrustStore.Verification.MATCH:
|
||||
_server_trust.touch(get_current_endpoint())
|
||||
if is_current_route_discovery():
|
||||
_server_trust.touch_identity(fingerprint)
|
||||
else:
|
||||
_server_trust.touch(get_current_endpoint())
|
||||
_send_client_identity_proof()
|
||||
return
|
||||
_set_state(
|
||||
|
|
@ -1238,9 +1268,12 @@ func receive_server_identity_proof(data: Dictionary) -> void:
|
|||
"Confirm this server identity before continuing.",
|
||||
)
|
||||
_connection_deadline = 0.0
|
||||
var expected := str(
|
||||
_server_trust.get_record(get_current_endpoint()).get("fingerprint", "")
|
||||
var trust_record: Dictionary = (
|
||||
_server_trust.get_identity_record(fingerprint)
|
||||
if is_current_route_discovery()
|
||||
else _server_trust.get_record(get_current_endpoint())
|
||||
)
|
||||
var expected := str(trust_record.get("fingerprint", ""))
|
||||
server_trust_required.emit(
|
||||
get_current_route_display(),
|
||||
expected,
|
||||
|
|
@ -1255,11 +1288,15 @@ func resolve_server_trust(accepted: bool) -> void:
|
|||
if not accepted:
|
||||
cancel_connection()
|
||||
return
|
||||
if not _server_trust.trust(
|
||||
get_current_endpoint(),
|
||||
str(_pending_server_proof["server_fingerprint"]),
|
||||
"straywild",
|
||||
):
|
||||
var fingerprint := str(_pending_server_proof["server_fingerprint"])
|
||||
var trusted := (
|
||||
_server_trust.trust_identity(fingerprint, get_current_route_display())
|
||||
if is_current_route_discovery()
|
||||
else _server_trust.trust(
|
||||
get_current_endpoint(), fingerprint, "straywild"
|
||||
)
|
||||
)
|
||||
if not trusted:
|
||||
_fail_identity("The server identity could not be pinned.")
|
||||
return
|
||||
_set_state(State.AUTHENTICATING, "Authenticating identity...")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue