(sock, data, addr)
| 280 | |
| 281 | |
| 282 | def _handle_refresh_request(sock, data, addr): |
| 283 | tid = data[8:20] |
| 284 | key = (addr[0], addr[1]) |
| 285 | attrs = _parse_attrs(data) |
| 286 | |
| 287 | if not _check_turn_auth(sock, data, attrs, tid, addr, MSG_REFRESH_ERROR): |
| 288 | return |
| 289 | |
| 290 | alloc = _allocations.get(key) |
| 291 | if alloc is None or alloc.is_expired(): |
| 292 | err = _build_error_attr(437, b'No Allocation') |
| 293 | sock.sendto(_build_response(MSG_REFRESH_ERROR, tid, err), addr) |
| 294 | return |
| 295 | |
| 296 | lf_bytes = _get_attr(attrs, ATTR_LIFETIME) |
| 297 | lifetime = struct.unpack('!I', lf_bytes)[0] if lf_bytes else TURN_DEFAULT_LIFETIME |
| 298 | |
| 299 | if lifetime == 0: |
| 300 | print("Explicit deallocation from %s:%d" % addr, flush=True) |
| 301 | _delete_allocation(key) |
| 302 | else: |
| 303 | alloc.refresh(lifetime) |
| 304 | |
| 305 | sock.sendto(_build_response(MSG_REFRESH_SUCCESS, tid, _build_lifetime_attr(lifetime)), addr) |
| 306 | |
| 307 | |
| 308 | def _handle_create_permission_request(sock, data, addr): |
no test coverage detected