Implement network lifecycle teardown and logout (#57)
All checks were successful
Native code generation / deterministic (push) Successful in 12m4s
Imaging and meshing gate / native (push) Successful in 4m3s
Native Rust workspace compile / compile (push) Successful in 4m6s

This commit is contained in:
2026-08-09 19:11:21 +00:00
parent 3951bdb809
commit 1fd127bd8a
7 changed files with 1068 additions and 65 deletions

View File

@@ -66,6 +66,35 @@ the last simulator reports `SimShutdown`. Explicit shutdown preserves the
caller-provided reason/message and sends `CloseCircuit` only for client or
network-timeout shutdowns.
Promoting an already-connected simulator is a controlled handoff. The manager
first sends a reliable `UseCircuitCode` followed by the agent/session/circuit
identified `CompleteAgentMovement`, installs the new seed capability, swaps
`CurrentSim`, and finally raises `SimChanged` with the previous simulator. The
old simulator remains tracked until an explicit disconnect so multi-simulator
traffic can continue. A completed shutdown leaves the manager reusable: a later
connection creates fresh workers and transports rather than retaining canceled
ones. Connection attempts made while logout or teardown is still active fail
with `InvalidOperation`, preventing a reentrant reconnect from racing resource
cleanup.
`RequestLogout`, blocking `Logout`, runtime-neutral `LogoutAsync`, and
nonblocking `BeginLogout` all send the native `LogoutRequest` packet at most
once per active handshake. A matching `LogoutReply` is accepted only for the
current agent and session, raises `LoggedOut` with the returned inventory IDs,
and then performs a client-initiated shutdown. Blocking calls wait for that
ordered teardown; asynchronous calls additionally observe caller cancellation.
`BeginLogout` raises an empty `LoggedOut` only after a bounded network-timeout
teardown when no reply arrives, matching the reference ordering.
Teardown is idempotent and ordered. It cancels active login and logout waits,
disconnects non-current simulators before the current simulator, stops manager
workers, clears connection/circuit/session/seed state and parsed login secrets,
then raises one `Disconnected` event and marks shutdown complete. Reentrant and
repeated shutdown calls do not repeat events. Nonblocking logout waiters observe
the lifecycle cancellation and terminate rather than retaining the manager or
client; their last detached error remains available through
`NetworkManager::last_logout_error` for diagnostics.
## Login behavior
The native login path constructs the reference LLSD request, including the C#
@@ -92,6 +121,8 @@ cargo test -p libremetaverse --test network_manager
They cover login hashing, redirects, cancellation and initial handoff alongside
ACK-gated circuit setup, typed handshake reply/state, ping response, CAPS enable,
UDP disable, current/seed selection, callback ordering and filtering, RAII
unregistration, runtime-neutral async calls, concurrent registration/removal,
reentrant/concurrent disconnect, and keepalive timeout reasons.
UDP disable, current/seed selection, controlled region handoff, reconnect after
teardown, all three logout wait modes, reply validation and event order, callback
ordering and filtering, RAII unregistration, runtime-neutral async calls,
concurrent registration/removal, reentrant/concurrent disconnect, and keepalive
timeout reasons.