Media chunking fix; Removed high number dc detection
This commit is contained in:
parent
1433c2e881
commit
3fdce27fbb
|
|
@ -18,8 +18,8 @@ DEFAULT_PORT = 1080
|
||||||
log = logging.getLogger('tg-ws-proxy')
|
log = logging.getLogger('tg-ws-proxy')
|
||||||
|
|
||||||
_TCP_NODELAY = True
|
_TCP_NODELAY = True
|
||||||
_RECV_BUF = 131072
|
_RECV_BUF = 65536
|
||||||
_SEND_BUF = 131072
|
_SEND_BUF = 65536
|
||||||
_WS_POOL_SIZE = 4
|
_WS_POOL_SIZE = 4
|
||||||
_WS_POOL_MAX_AGE = 120.0
|
_WS_POOL_MAX_AGE = 120.0
|
||||||
|
|
||||||
|
|
@ -64,8 +64,6 @@ _IP_TO_DC: Dict[str, Tuple[int, bool]] = {
|
||||||
'149.154.171.5': (5, False),
|
'149.154.171.5': (5, False),
|
||||||
'91.108.56.102': (5, True), '91.108.56.128': (5, True),
|
'91.108.56.102': (5, True), '91.108.56.128': (5, True),
|
||||||
'91.108.56.151': (5, True),
|
'91.108.56.151': (5, True),
|
||||||
# DC203
|
|
||||||
'91.105.192.100': (203, False),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_dc_opt: Dict[int, Optional[str]] = {}
|
_dc_opt: Dict[int, Optional[str]] = {}
|
||||||
|
|
@ -377,7 +375,7 @@ def _dc_from_init(data: bytes) -> Tuple[Optional[int], bool]:
|
||||||
proto, dc_raw, plain.hex())
|
proto, dc_raw, plain.hex())
|
||||||
if proto in (0xEFEFEFEF, 0xEEEEEEEE, 0xDDDDDDDD):
|
if proto in (0xEFEFEFEF, 0xEEEEEEEE, 0xDDDDDDDD):
|
||||||
dc = abs(dc_raw)
|
dc = abs(dc_raw)
|
||||||
if 1 <= dc <= 1000:
|
if 1 <= dc <= 5:
|
||||||
return dc, (dc_raw < 0)
|
return dc, (dc_raw < 0)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log.debug("DC extraction failed: %s", exc)
|
log.debug("DC extraction failed: %s", exc)
|
||||||
|
|
@ -464,16 +462,9 @@ class _MsgSplitter:
|
||||||
|
|
||||||
|
|
||||||
def _ws_domains(dc: int, is_media) -> List[str]:
|
def _ws_domains(dc: int, is_media) -> List[str]:
|
||||||
"""
|
|
||||||
Return domain names to try for WebSocket connection to a DC.
|
|
||||||
|
|
||||||
DC 1-5: kws{N}[-1].web.telegram.org
|
|
||||||
DC >5: kws{N}[-1].telegram.org
|
|
||||||
"""
|
|
||||||
base = 'telegram.org' if dc > 5 else 'web.telegram.org'
|
|
||||||
if is_media is None or is_media:
|
if is_media is None or is_media:
|
||||||
return [f'kws{dc}-1.{base}', f'kws{dc}.{base}']
|
return [f'kws{dc}-1.web.telegram.org', f'kws{dc}.web.telegram.org']
|
||||||
return [f'kws{dc}.{base}', f'kws{dc}-1.{base}']
|
return [f'kws{dc}.web.telegram.org', f'kws{dc}-1.web.telegram.org']
|
||||||
|
|
||||||
|
|
||||||
class Stats:
|
class Stats:
|
||||||
|
|
@ -614,7 +605,7 @@ async def _bridge_ws(reader, writer, ws: RawWebSocket, label,
|
||||||
nonlocal up_bytes, up_packets
|
nonlocal up_bytes, up_packets
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
chunk = await reader.read(131072)
|
chunk = await reader.read(65536)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
_stats.bytes_up += len(chunk)
|
_stats.bytes_up += len(chunk)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue