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
This commit is contained in:
Michael Bayne
2009-06-23 06:20:31 +00:00
parent 0df7b9681a
commit 7efa2c74a7
3 changed files with 19 additions and 19 deletions
@@ -878,7 +878,7 @@ public abstract class PeerManager
// we scan through the list instead of relying on ClientInfo.getKey() because we want // 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 // derived classes to be able to override that for lookups that happen way more frequently
// than logging off // than logging off
Name username = client.getUsername(); Name username = client.getAuthName();
for (ClientInfo clinfo : _nodeobj.clients) { for (ClientInfo clinfo : _nodeobj.clients) {
if (clinfo.username.equals(username)) { if (clinfo.username.equals(username)) {
_nodeobj.startTransaction(); _nodeobj.startTransaction();
@@ -1038,7 +1038,7 @@ public abstract class PeerManager
*/ */
protected void initClientInfo (PresentsSession client, ClientInfo info) protected void initClientInfo (PresentsSession client, ClientInfo info)
{ {
info.username = client.getUsername(); info.username = client.getAuthName();
} }
/** /**
@@ -532,7 +532,7 @@ public class ClientManager
// remove the client from the username map // remove the client from the username map
PresentsSession rc; PresentsSession rc;
synchronized (_usermap) { synchronized (_usermap) {
rc = _usermap.remove(session.getUsername()); rc = _usermap.remove(session.getAuthName());
} }
// sanity check just because we can // sanity check just because we can
@@ -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 // switching, so freak out
if (_clobj == null) { if (_clobj == null) {
log.warning("Client disappeared before we could complete the switch to a " + 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); _clmgr.releaseClientObject(username);
Exception error = new Exception("Early withdrawal"); Exception error = new Exception("Early withdrawal");
resolutionFailed(username, error); resolutionFailed(username, error);
@@ -265,10 +267,9 @@ public class PresentsSession
_clobj.postMessage(ClientObject.CLOBJ_CHANGED, args); _clobj.postMessage(ClientObject.CLOBJ_CHANGED, args);
// release our old client object; this will destroy it // release our old client object; this will destroy it
_clmgr.releaseClientObject(_username); _clmgr.releaseClientObject(_clobj.username);
// update our internal fields // update our internal fields
_username = username;
_clobj = clobj; _clobj = clobj;
// call down to any derived classes // call down to any derived classes
@@ -282,7 +283,7 @@ public class PresentsSession
public void resolutionFailed (Name username, Exception reason) { public void resolutionFailed (Name username, Exception reason) {
log.warning("Unable to resolve new client object", 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 // let our listener know we're hosed
if (ucl != null) { if (ucl != null) {
@@ -306,8 +307,7 @@ public class PresentsSession
*/ */
public boolean updateUsername (Name username) public boolean updateUsername (Name username)
{ {
if (_clmgr.renameClientObject(_username, username)) { if (_clmgr.renameClientObject(_clobj.username, username)) {
_username = username;
return true; return true;
} }
return false; return false;
@@ -347,7 +347,7 @@ public class PresentsSession
} }
// release (and destroy) our client object // 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, // 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 // 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) protected void startSession (Name authname, AuthRequest req, Connection conn, Object authdata)
{ {
_username = authname; _authname = authname;
_areq = req; _areq = req;
_authdata = authdata; _authdata = authdata;
setConnection(conn); setConnection(conn);
// resolve our client object before we get fully underway // 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 // make a note of our session start time
_sessionStamp = System.currentTimeMillis(); _sessionStamp = System.currentTimeMillis();
@@ -895,8 +895,8 @@ public class PresentsSession
protected String who () protected String who ()
{ {
return (_username == null) ? "null" : return (_authname == null) ? "null" :
(_username.getClass().getSimpleName() + "(" + _username + ")"); (_authname.getClass().getSimpleName() + "(" + _authname + ")");
} }
/** /**
@@ -1076,7 +1076,7 @@ public class PresentsSession
// send a pong response using the transport with which the message was received // send a pong response using the transport with which the message was received
PingRequest req = (PingRequest)msg; PingRequest req = (PingRequest)msg;
if (PING_DEBUG) { 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())); client.safePostMessage(new PongResponse(req.getUnpackStamp(), req.getTransport()));
} }
@@ -1125,7 +1125,7 @@ public class PresentsSession
protected AuthRequest _areq; protected AuthRequest _areq;
protected Object _authdata; protected Object _authdata;
protected Name _username; protected Name _authname;
protected Connection _conn; protected Connection _conn;
protected ClientObject _clobj; protected ClientObject _clobj;
protected IntMap<ClientProxy> _subscrips = IntMaps.newHashIntMap(); protected IntMap<ClientProxy> _subscrips = IntMaps.newHashIntMap();