mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
Port the relay-socket fixes from quartz's BasicOkHttpWebSocket into Amber's fork while keeping the Tor/timeout-aware needsReconnect(): - Answer a relay-initiated CLOSE frame (onClosing -> close(1000)) so OkHttp completes the handshake and reports onClosed at once instead of leaving the socket half-closed until the ping timeout. - Guarantee a single terminal report per session via an AtomicBoolean claimed by onClosed/onFailure/disconnect, so late callbacks after disconnect no longer reach the relay client. - disconnect() claims the session and synthesizes onClosed(1000, "client disconnect") synchronously, covering the case where OkHttp's cancel() raises no callback at all. - connect() is idempotent (socket != null || ended -> return) and onOpen/onMessage drop stale events after the session ended. - Mark socket/usingOkHttp @Volatile; they are written and read across OkHttp callback threads. Add the upstream close-handshake regression test (raw RFC 6455 loopback relay, no new dependencies); both tests fail on the previous implementation.