Added an extra step to the datagram negotation process. Before

the server starts sending datagrams willy-nilly, it must wait for 
a (reliable) go-ahead from the client.  Otherwise, it's possible 
that the server may be successfully receiving datagrams but not 
sending them.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5792 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2009-05-21 04:16:41 +00:00
parent 0f70a5c8d2
commit 6dd16483be
5 changed files with 75 additions and 3 deletions
@@ -63,6 +63,7 @@ import com.threerings.presents.net.PingRequest;
import com.threerings.presents.net.PongResponse;
import com.threerings.presents.net.SubscribeRequest;
import com.threerings.presents.net.ThrottleUpdatedMessage;
import com.threerings.presents.net.TransmitDatagramsRequest;
import com.threerings.presents.net.UnsubscribeRequest;
import com.threerings.presents.net.UnsubscribeResponse;
import com.threerings.presents.net.UpdateThrottleMessage;
@@ -1085,6 +1086,18 @@ public class PresentsSession
}
}
/**
* Processes datagram transmission requests.
*/
protected static class TransmitDatagramsDispatcher implements MessageDispatcher
{
public void dispatch (PresentsSession client, Message msg)
{
log.debug("Client requested datagram transmission", "client", client);
client.getConnection().setTransmitDatagrams(true);
}
}
/**
* Processes throttle updated messages.
*/
@@ -1158,6 +1171,7 @@ public class PresentsSession
_disps.put(UnsubscribeRequest.class, new UnsubscribeDispatcher());
_disps.put(ForwardEventRequest.class, new ForwardEventDispatcher());
_disps.put(PingRequest.class, new PingDispatcher());
_disps.put(TransmitDatagramsRequest.class, new TransmitDatagramsDispatcher());
_disps.put(ThrottleUpdatedMessage.class, new ThrottleUpdatedDispatcher());
_disps.put(LogoffRequest.class, new LogoffDispatcher());
}
@@ -121,6 +121,22 @@ public class Connection implements NetEventHandler
return (_channel == null) ? null : _channel.socket().getInetAddress();
}
/**
* Sets whether we should transmit datagrams.
*/
public void setTransmitDatagrams (boolean transmit)
{
_transmitDatagrams = transmit;
}
/**
* Checks whether we should transmit datagrams.
*/
public boolean getTransmitDatagrams ()
{
return _transmitDatagrams;
}
/**
* Returns the address to which datagrams should be sent or null if no datagram address has
* been established.
@@ -435,6 +451,7 @@ public class Connection implements NetEventHandler
protected InetSocketAddress _datagramAddress;
protected byte[] _datagramSecret;
protected boolean _transmitDatagrams;
protected MessageDigest _digest;
protected DatagramSequencer _sequencer;
@@ -61,6 +61,7 @@ import com.threerings.presents.annotation.AuthInvoker;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ConMgrStats;
import com.threerings.presents.net.Message;
import com.threerings.presents.net.PongResponse;
import com.threerings.presents.server.Authenticator;
import com.threerings.presents.server.ChainedAuthenticator;
import com.threerings.presents.server.ClientManager;
@@ -902,9 +903,11 @@ public class ConnectionManager extends LoopingThread
}
try {
// send it as a datagram if hinted and possible
if (!msg.getTransport().isReliable() && conn.getDatagramAddress() != null &&
postDatagram(conn, msg)) {
// send it as a datagram if hinted and possible (pongs must be sent as part of the
// negotation process)
if (!msg.getTransport().isReliable() &&
(conn.getTransmitDatagrams() || msg instanceof PongResponse) &&
postDatagram(conn, msg)) {
return;
}