Changeset 487

Show
Ignore:
Timestamp:
08/12/08 09:34:09 (5 months ago)
Author:
heyadayo
Message:

Added server-side configurable ping timeouts/intervals that are propogated to the client at runtime; the client abides these timeouts by triggering onclose after the specified timeout. Closes tickets 21, 42, and 43

Location:
trunk/daemon
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/daemon/orbited-debug.cfg

    r486 r487  
    22reactor=epoll 
    33proxy.enabled=1 
     4session.ping_interval = 5 
     5session.ping_timeout = 5 
    46 
    57[listen] 
     
    1921* -> localhost:6163 
    2022* -> localhost:7 
    21 localhost:8001 -> localhost:6667 
     23* -> localhost:6667 
    2224 
    2325[logging] 
  • trunk/daemon/orbited.cfg

    r486 r487  
    33#reactor=epoll 
    44proxy.enabled=1 
     5session.ping_interval = 40 
     6session.ping_timeout = 30 
    57 
    68[listen] 
  • trunk/daemon/orbited/cometsession.py

    r486 r487  
    140140    hostHeader = property(lambda s: s.transportProtocol.hostHeader) 
    141141     
     142    def _get_pingTimeout(self): 
     143        return self.transportProtocol._pingTimeout 
     144     
     145    def _get_pingInterval(self): 
     146        return self.transportProtocol._pingInterval 
     147     
     148    def _set_pingTimeout(self, v): 
     149        self.transportProtocol.pingTimeout = v 
     150        self.transportProtocol.send(TCPOption('pingTimeout', v)) 
     151         
     152    def _set_pingInterval(self, v): 
     153        self.transportProtocol.pingInterval = v 
     154        self.transportProtocol.send(TCPOption('pingInterval', v)) 
     155         
     156    # Determines timeout interval after ping has been sent 
     157    pingTimeout = property(_get_pingTimeout, _set_pingTimeout) 
     158    # Determines interval to wait before sending a ping 
     159    pingInterval = property(_get_pingInterval, _set_pingInterval) 
     160     
     161     
    142162class TCPConnectionResource(resource.Resource): 
    143  
     163    pingTimeout = 30 
     164    pingInterval = 30 
    144165    logger = logging.get_logger('orbited.cometsession.TCPConnectionResource') 
    145  
    146     # Determines timeout interval after ping has been sent 
    147     pingTimeout = 40 
    148     # Determines interval to wait before sending a ping 
    149     # since the last time we heard from the client. 
    150     pingInterval = 40 
    151166 
    152167    def __init__(self, root, key, peer, host, hostHeader, **options): 
     
    381396        elif isinstance(data, TCPClose): 
    382397            self.cometTransport.sendPacket('close', str(packetId)) 
     398        elif isinstance(data, TCPOption): 
     399            self.cometTransport.sendPacket('opt', str(packetId), data.payload) 
    383400        else: 
    384401            self.cometTransport.sendPacket('data', str(packetId), base64.b64encode(data)) 
     
    392409#        self.cometTransport.sendPacket('id', ackId) 
    393410         
     411 
     412     
     413 
     414         
     415         
    394416class TCPPing(object): 
    395417    pass 
     
    398420    pass 
    399421 
     422class TCPOption(object): 
     423    def __init__(self, name, val): 
     424        self.payload = str(name) + ',' + str(val) 
     425         
    400426class TCPResource(resource.Resource): 
    401427     
  • trunk/daemon/orbited/config.py

    r486 r487  
    1010        #'proxy.enabled': '1', 
    1111 
    12         'pid.location': '/tmp/orbited.pid' 
     12        'pid.location': '/tmp/orbited.pid', 
     13        'session.ping_interval': '30', 
     14        'session.ping_timeout': '30' 
    1315    }, 
    1416 
  • trunk/daemon/orbited/proxy.py

    r486 r487  
    1212    'Unauthorized': 106, 
    1313} 
     14pingTimeout  = int(config.map['[global]']['session.ping_timeout']) 
     15pingInterval = int(config.map['[global]']['session.ping_interval']) 
     16 
    1417 
    1518class ProxyIncomingProtocol(Protocol): 
     
    2326    def connectionMade(self): 
    2427        # TODO: add handshake timer 
     28        self.transport.pingTimeout = pingTimeout 
     29        self.transport.pingInterval = pingInterval 
    2530        self.logger.debug("connectionMade") 
    2631        self.state = 'handshake' 
  • trunk/daemon/orbited/static/Orbited.js

    r485 r487  
    350350    var handshakeTimer = null; 
    351351    var cometTransport = null; 
     352    var pingInterval = 30000; 
     353    var pingTimeout = 30000; 
     354    var timeoutTimer = null; 
    352355    var lastPacketId = 0 
    353356    var sending = false; 
     
    376379                    sessionKey = xhr.responseText; 
    377380;;;                 self.logger.debug('session key is: ', sessionKey) 
     381                    resetTimeout(); 
    378382                    sessionUrl = new Orbited.URL(_url) 
    379383                    // START new URL way 
     
    524528                        break;                     
    525529                } 
    526         } 
     530                break; 
     531            case 'opt': 
     532                var args = frame.data.split(',') 
     533                switch(args[0]) { 
     534                    case 'pingTimeout': 
     535                        pingTimeout = parseInt(args[1])*1000 
     536                        break 
     537                    case 'pingInterval': 
     538                        pingInterval = parseInt(args[1])*1000 
     539                        break; 
     540                    default: 
     541;;;                     self.logger.warn('unknown opt key', args[0]) 
     542                        break; 
     543                } 
     544        } 
     545        resetTimeout(); 
    527546    } 
    528547    var transportOnClose = function() { 
     
    606625    var doClose = function(code) { 
    607626;;;     self.logger.debug('doClose', code) 
     627        unsetTimeout(); 
    608628        self.readyState = self.READY_STATE_CLOSED; 
    609629        cometTransport.onReadFrame = function() {} 
     
    615635        self.onclose(code); 
    616636 
     637    } 
     638 
     639    var resetTimeout = function() { 
     640        unsetTimeout(); 
     641        timeoutTimer = window.setTimeout(timedOut, pingInterval + pingTimeout); 
     642    } 
     643    var unsetTimeout = function() { 
     644        window.clearTimeout(timeoutTimer); 
     645 
     646    } 
     647    var timedOut = function() { 
     648        doClose(Orbited.Errors.ConnectionTimeout) 
    617649    } 
    618650}; 
     
    10891121                        break; 
    10901122                    case 4: 
     1123                        var doReconnect = true; 
    10911124                        try { 
    1092                             xhr.status 
     1125                            if (xhr.status === null) { 
     1126                                doReconnect = true; 
     1127                            } 
     1128                            else { 
     1129                                doReconnect = false; 
     1130                            } 
    10931131                        } 
    10941132                        catch(e) { 
     1133                        } 
     1134                        if (doReconnect) { 
    10951135                            // Expoential backoff: Every time we fail to  
    10961136                            // reconnect, double the interval. 
     
    10991139//                            self.logger.debug('retryInterval', retryInterval) 
    11001140                            window.clearTimeout(heartbeatTimer); 
    1101                             window.setTimeout(reconnect, retryInterval) 
     1141                            retryTimer = window.setTimeout(reconnect, retryInterval) 
    11021142                            return; 
    11031143                        } 
    1104  
    11051144                        switch(xhr.status) { 
    11061145                            case 200: