| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 part of dart.io; | 5 part of dart.io; | 
| 6 | 6 | 
| 7 const String _DART_SESSION_ID = "DARTSESSID"; | 7 const String _DART_SESSION_ID = "DARTSESSID"; | 
| 8 | 8 | 
| 9 // A _HttpSession is a node in a double-linked list, with _next and _prev being | 9 // A _HttpSession is a node in a double-linked list, with _next and _prev being | 
| 10 // the previous and next pointers. | 10 // the previous and next pointers. | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 65 // Private class used to manage all the active sessions. The sessions are stored | 65 // Private class used to manage all the active sessions. The sessions are stored | 
| 66 // in two ways: | 66 // in two ways: | 
| 67 // | 67 // | 
| 68 //  * In a map, mapping from ID to HttpSession. | 68 //  * In a map, mapping from ID to HttpSession. | 
| 69 //  * In a linked list, used as a timeout queue. | 69 //  * In a linked list, used as a timeout queue. | 
| 70 class _HttpSessionManager { | 70 class _HttpSessionManager { | 
| 71   _HttpSessionManager() : _sessions = {}; | 71   _HttpSessionManager() : _sessions = {}; | 
| 72 | 72 | 
| 73   String createSessionId() { | 73   String createSessionId() { | 
| 74     const int _KEY_LENGTH = 16;  // 128 bits. | 74     const int _KEY_LENGTH = 16;  // 128 bits. | 
| 75     var data = _getRandomBytes(_KEY_LENGTH); | 75     var data = _IOCrypto.getRandomBytes(_KEY_LENGTH); | 
| 76     return CryptoUtils.bytesToHex(data); | 76     return CryptoUtils.bytesToHex(data); | 
| 77   } | 77   } | 
| 78 | 78 | 
| 79   _HttpSession getSession(String id) { | 79   _HttpSession getSession(String id) { | 
| 80     return _sessions[id]; | 80     return _sessions[id]; | 
| 81   } | 81   } | 
| 82 | 82 | 
| 83   _HttpSession createSession() { | 83   _HttpSession createSession() { | 
| 84     var id = createSessionId(); | 84     var id = createSessionId(); | 
| 85     // TODO(ajohnsen): Consider adding a limit and throwing an exception. | 85     // TODO(ajohnsen): Consider adding a limit and throwing an exception. | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 165       _timer.cancel(); | 165       _timer.cancel(); | 
| 166       _timer = null; | 166       _timer = null; | 
| 167     } | 167     } | 
| 168   } | 168   } | 
| 169 | 169 | 
| 170   Map<String, _HttpSession> _sessions; | 170   Map<String, _HttpSession> _sessions; | 
| 171   int _sessionTimeout = 20 * 60;  // 20 mins. | 171   int _sessionTimeout = 20 * 60;  // 20 mins. | 
| 172   _HttpSession _head; | 172   _HttpSession _head; | 
| 173   _HttpSession _tail; | 173   _HttpSession _tail; | 
| 174   Timer _timer; | 174   Timer _timer; | 
| 175 |  | 
| 176   external static Uint8List _getRandomBytes(int count); |  | 
| 177 } | 175 } | 
| 178 | 176 | 
| OLD | NEW | 
|---|