From 7efa2c74a766e8827d3a3e39ac1bd1a1c4d54171 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 23 Jun 2009 06:20:31 +0000 Subject: [PATCH] Tidy up name handling a bit more: when setUsername() is called on a PresentsSession, we don't need to or want to change our auth name, we can and should operate entirely on ClientObject.username. The ClientManager maintains two mappings: "current username" -> ClientObject (which is what needs to change when setUsername or updateUsername is called) and "authname" -> PresentsSession which has always been just the authname and has never changed during the course of a session. PresentsSession.getUsername() goes away and PresentsSession.getAuthName() always returns the name that was used to authenticate the session. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5838 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/peer/server/PeerManager.java | 4 +-- .../presents/server/ClientManager.java | 2 +- .../presents/server/PresentsSession.java | 32 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/java/com/threerings/presents/peer/server/PeerManager.java b/src/java/com/threerings/presents/peer/server/PeerManager.java index f23899bc5..cc8c741f1 100644 --- a/src/java/com/threerings/presents/peer/server/PeerManager.java +++ b/src/java/com/threerings/presents/peer/server/PeerManager.java @@ -878,7 +878,7 @@ public abstract class PeerManager // we scan through the list instead of relying on ClientInfo.getKey() because we want // derived classes to be able to override that for lookups that happen way more frequently // than logging off - Name username = client.getUsername(); + Name username = client.getAuthName(); for (ClientInfo clinfo : _nodeobj.clients) { if (clinfo.username.equals(username)) { _nodeobj.startTransaction(); @@ -1038,7 +1038,7 @@ public abstract class PeerManager */ protected void initClientInfo (PresentsSession client, ClientInfo info) { - info.username = client.getUsername(); + info.username = client.getAuthName(); } /** diff --git a/src/java/com/threerings/presents/server/ClientManager.java b/src/java/com/threerings/presents/server/ClientManager.java index fa037f619..657800955 100644 --- a/src/java/com/threerings/presents/server/ClientManager.java +++ b/src/java/com/threerings/presents/server/ClientManager.java @@ -532,7 +532,7 @@ public class ClientManager // remove the client from the username map PresentsSession rc; synchronized (_usermap) { - rc = _usermap.remove(session.getUsername()); + rc = _usermap.remove(session.getAuthName()); } // sanity check just because we can diff --git a/src/java/com/threerings/presents/server/PresentsSession.java b/src/java/com/threerings/presents/server/PresentsSession.java index 2b5744051..cbb92de2a 100644 --- a/src/java/com/threerings/presents/server/PresentsSession.java +++ b/src/java/com/threerings/presents/server/PresentsSession.java @@ -147,11 +147,12 @@ public class PresentsSession } /** - * Returns the username with which this client instance is associated. + * Returns the username with which this client authenticated. Note: if {@link #setUsername} has + * been called this may differ from {@link #getClientObject}.username. */ - public Name getUsername () + public Name getAuthName () { - return _username; + return _authname; } /** @@ -231,7 +232,8 @@ public class PresentsSession // switching, so freak out if (_clobj == null) { log.warning("Client disappeared before we could complete the switch to a " + - "new client object", "ousername", _username, "nusername", username); + "new client object", "ousername", clobj.username, + "nusername", username); _clmgr.releaseClientObject(username); Exception error = new Exception("Early withdrawal"); resolutionFailed(username, error); @@ -265,10 +267,9 @@ public class PresentsSession _clobj.postMessage(ClientObject.CLOBJ_CHANGED, args); // release our old client object; this will destroy it - _clmgr.releaseClientObject(_username); + _clmgr.releaseClientObject(_clobj.username); // update our internal fields - _username = username; _clobj = clobj; // call down to any derived classes @@ -282,7 +283,7 @@ public class PresentsSession public void resolutionFailed (Name username, Exception reason) { log.warning("Unable to resolve new client object", - "oldname", _username, "newname", username, "reason", reason, reason); + "oldname", _clobj.username, "newname", username, "reason", reason, reason); // let our listener know we're hosed if (ucl != null) { @@ -306,8 +307,7 @@ public class PresentsSession */ public boolean updateUsername (Name username) { - if (_clmgr.renameClientObject(_username, username)) { - _username = username; + if (_clmgr.renameClientObject(_clobj.username, username)) { return true; } return false; @@ -347,7 +347,7 @@ public class PresentsSession } // release (and destroy) our client object - _clmgr.releaseClientObject(_username); + _clmgr.releaseClientObject(_clobj.username); // we only report that our session started if we managed to resolve our client object, // so we only report that it ended in the same circumstance @@ -467,13 +467,13 @@ public class PresentsSession */ protected void startSession (Name authname, AuthRequest req, Connection conn, Object authdata) { - _username = authname; + _authname = authname; _areq = req; _authdata = authdata; setConnection(conn); // resolve our client object before we get fully underway - _clmgr.resolveClientObject(_username, this); + _clmgr.resolveClientObject(_authname, this); // make a note of our session start time _sessionStamp = System.currentTimeMillis(); @@ -895,8 +895,8 @@ public class PresentsSession protected String who () { - return (_username == null) ? "null" : - (_username.getClass().getSimpleName() + "(" + _username + ")"); + return (_authname == null) ? "null" : + (_authname.getClass().getSimpleName() + "(" + _authname + ")"); } /** @@ -1076,7 +1076,7 @@ public class PresentsSession // send a pong response using the transport with which the message was received PingRequest req = (PingRequest)msg; if (PING_DEBUG) { - log.info("Got ping, ponging", "client", client._username); + log.info("Got ping, ponging", "client", client.getAuthName()); } client.safePostMessage(new PongResponse(req.getUnpackStamp(), req.getTransport())); } @@ -1125,7 +1125,7 @@ public class PresentsSession protected AuthRequest _areq; protected Object _authdata; - protected Name _username; + protected Name _authname; protected Connection _conn; protected ClientObject _clobj; protected IntMap _subscrips = IntMaps.newHashIntMap();