Three things:
- Inject the auth Invoker. - Inject the Authenticator and formalize the chaining authenticator pattern. - Simplify PeerNode creation and make the PeerAuthenticator a chainer. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5162 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -31,6 +31,7 @@ import com.threerings.presents.net.AuthRequest;
|
||||
import com.threerings.presents.net.AuthResponse;
|
||||
import com.threerings.presents.net.AuthResponseData;
|
||||
import com.threerings.presents.server.Authenticator;
|
||||
import com.threerings.presents.server.ChainedAuthenticator;
|
||||
import com.threerings.presents.server.net.AuthingConnection;
|
||||
|
||||
import com.threerings.presents.peer.net.PeerCreds;
|
||||
@@ -41,33 +42,20 @@ import static com.threerings.presents.Log.log;
|
||||
* Handles authentication of peer servers and passes non-peer authentication requests through to a
|
||||
* normal authenticator.
|
||||
*/
|
||||
public class PeerAuthenticator extends Authenticator
|
||||
public class PeerAuthenticator extends ChainedAuthenticator
|
||||
{
|
||||
/**
|
||||
* Creates an authenticator that will handle peer authentications and pass non-peer
|
||||
* authentications through to the supplied delegate.
|
||||
*/
|
||||
public PeerAuthenticator (PeerManager nodemgr, Authenticator delegate)
|
||||
public PeerAuthenticator (PeerManager nodemgr)
|
||||
{
|
||||
_peermgr = nodemgr;
|
||||
_delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticateConnection (AuthingConnection conn)
|
||||
@Override // from abstract ChainedAuthenticator
|
||||
protected boolean shouldHandleConnection (AuthingConnection conn)
|
||||
{
|
||||
// if this is a peer server, we check their credentials specially
|
||||
AuthRequest req = conn.getAuthRequest();
|
||||
if (req.getCredentials() instanceof PeerCreds) {
|
||||
super.authenticateConnection(conn);
|
||||
|
||||
} else {
|
||||
// otherwise pass the request on to our delegate
|
||||
_delegate.authenticateConnection(conn);
|
||||
}
|
||||
return (conn.getAuthRequest().getCredentials() instanceof PeerCreds);
|
||||
}
|
||||
|
||||
// from abstract Authenticator
|
||||
@Override // from abstract Authenticator
|
||||
protected void processAuthentication (AuthingConnection conn, AuthResponse rsp)
|
||||
throws PersistenceException
|
||||
{
|
||||
|
||||
@@ -219,7 +219,7 @@ public class PeerManager
|
||||
_sharedSecret = sharedSecret;
|
||||
|
||||
// wire ourselves into the server
|
||||
_conmgr.setAuthenticator(new PeerAuthenticator(this, _conmgr.getAuthenticator()));
|
||||
_conmgr.addChainedAuthenticator(new PeerAuthenticator(this));
|
||||
_clmgr.setClientFactory(new PeerClientFactory(this, _clmgr.getClientFactory()));
|
||||
|
||||
// create our node object
|
||||
@@ -840,6 +840,7 @@ public class PeerManager
|
||||
PeerNode peer = _peers.get(record.nodeName);
|
||||
if (peer == null) {
|
||||
_peers.put(record.nodeName, peer = createPeerNode(record));
|
||||
peer.init(this, _omgr, record);
|
||||
}
|
||||
peer.refresh(record);
|
||||
}
|
||||
@@ -943,7 +944,7 @@ public class PeerManager
|
||||
*/
|
||||
protected PeerNode createPeerNode (NodeRecord record)
|
||||
{
|
||||
return new PeerNode(this, record);
|
||||
return new PeerNode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.threerings.presents.client.BlockingCommunicator;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.ClientObserver;
|
||||
import com.threerings.presents.client.Communicator;
|
||||
import com.threerings.presents.server.PresentsDObjectMgr;
|
||||
import com.threerings.presents.server.PresentsServer;
|
||||
|
||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||
@@ -55,11 +56,12 @@ public class PeerNode
|
||||
/** This peer's node object. */
|
||||
public NodeObject nodeobj;
|
||||
|
||||
public PeerNode (PeerManager peermgr, NodeRecord record)
|
||||
public void init (PeerManager peermgr, PresentsDObjectMgr omgr, NodeRecord record)
|
||||
{
|
||||
_peermgr = peermgr;
|
||||
_omgr = omgr;
|
||||
_record = record;
|
||||
_client = new Client(null, PresentsServer.omgr) {
|
||||
_client = new Client(null, _omgr) {
|
||||
protected void convertFromRemote (DObject target, DEvent event) {
|
||||
super.convertFromRemote(target, event);
|
||||
// rewrite the event's target oid using the oid currently configured on the
|
||||
@@ -68,7 +70,7 @@ public class PeerNode
|
||||
event.setTargetOid(target.getOid());
|
||||
// assign an eventId to this event so that our stale event detection code can
|
||||
// properly deal with it
|
||||
event.eventId = PresentsServer.omgr.getNextEventId(true);
|
||||
event.eventId = PeerNode.this._omgr.getNextEventId(true);
|
||||
}
|
||||
protected Communicator createCommunicator () {
|
||||
// TODO: make a custom communicator that uses the ClientManager NIO system to do
|
||||
@@ -268,6 +270,7 @@ public class PeerNode
|
||||
}
|
||||
|
||||
protected PeerManager _peermgr;
|
||||
protected PresentsDObjectMgr _omgr;
|
||||
protected NodeRecord _record;
|
||||
protected Client _client;
|
||||
protected long _lastConnectStamp;
|
||||
|
||||
Reference in New Issue
Block a user