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
|
|
@ -3,22 +3,65 @@ extends RefCounted
|
|||
|
||||
enum Kind {
|
||||
DIRECT,
|
||||
DISCOVERY_DIRECT,
|
||||
DISCOVERY_RELAY,
|
||||
}
|
||||
|
||||
var kind: Kind = Kind.DIRECT
|
||||
var direct_endpoint: ConnectionEndpoint
|
||||
var display_description: String = ""
|
||||
var discovery_room_id: String = ""
|
||||
|
||||
|
||||
static func direct(endpoint: ConnectionEndpoint) -> ConnectionRoute:
|
||||
var route := ConnectionRoute.new()
|
||||
route.kind = Kind.DIRECT
|
||||
route.direct_endpoint = endpoint
|
||||
route.display_description = "direct server" if endpoint != null else ""
|
||||
return route
|
||||
|
||||
|
||||
static func discovery_direct(
|
||||
endpoint: ConnectionEndpoint,
|
||||
room_id: String,
|
||||
room_name: String,
|
||||
) -> ConnectionRoute:
|
||||
var route := ConnectionRoute.new()
|
||||
route.kind = Kind.DISCOVERY_DIRECT
|
||||
route.direct_endpoint = endpoint
|
||||
route.discovery_room_id = room_id
|
||||
var cleaned_name := room_name.strip_edges()
|
||||
route.display_description = (
|
||||
endpoint.normalized_display if endpoint != null else ""
|
||||
cleaned_name if not cleaned_name.is_empty() else "public room"
|
||||
)
|
||||
return route
|
||||
|
||||
|
||||
static func discovery_relay(
|
||||
endpoint: ConnectionEndpoint,
|
||||
room_id: String,
|
||||
room_name: String,
|
||||
) -> ConnectionRoute:
|
||||
var route := discovery_direct(endpoint, room_id, room_name)
|
||||
route.kind = Kind.DISCOVERY_RELAY
|
||||
return route
|
||||
|
||||
|
||||
func is_valid() -> bool:
|
||||
return kind == Kind.DIRECT and direct_endpoint != null and direct_endpoint.is_valid()
|
||||
return (
|
||||
kind in [Kind.DIRECT, Kind.DISCOVERY_DIRECT, Kind.DISCOVERY_RELAY]
|
||||
and direct_endpoint != null
|
||||
and direct_endpoint.is_valid()
|
||||
and (
|
||||
kind == Kind.DIRECT
|
||||
or not discovery_room_id.is_empty()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
func is_discovery_join() -> bool:
|
||||
return kind in [Kind.DISCOVERY_DIRECT, Kind.DISCOVERY_RELAY]
|
||||
|
||||
|
||||
func is_relay() -> bool:
|
||||
return kind == Kind.DISCOVERY_RELAY
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue