mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-14 18:12:25 +03:00
Make IPv4 mandatory in session files
This commit is contained in:
parent
d60ebbe6ea
commit
58c0a5bc24
|
@ -323,7 +323,7 @@ async def connect(self: 'TelegramClient') -> None:
|
||||||
self._sender.auth_key.key = dc.auth
|
self._sender.auth_key.key = dc.auth
|
||||||
|
|
||||||
if not await self._sender.connect(self._connection(
|
if not await self._sender.connect(self._connection(
|
||||||
str(ipaddress.ip_address(dc.ipv6 or dc.ipv4)),
|
str(ipaddress.ip_address((self._use_ipv6 and dc.ipv6) or dc.ipv4)),
|
||||||
dc.port,
|
dc.port,
|
||||||
dc.id,
|
dc.id,
|
||||||
loggers=self._log,
|
loggers=self._log,
|
||||||
|
|
|
@ -107,8 +107,8 @@ class SQLiteSession(Session):
|
||||||
if old == 7:
|
if old == 7:
|
||||||
self._mk_tables(c)
|
self._mk_tables(c)
|
||||||
c.execute('''
|
c.execute('''
|
||||||
insert into datacenter (id, ip, port, auth)
|
insert into datacenter (id, ipv4, ipv6, port, auth)
|
||||||
select dc_id, server_address, port, auth_key
|
select dc_id, server_address, server_address, port, auth_key
|
||||||
from sessions
|
from sessions
|
||||||
''')
|
''')
|
||||||
c.execute('''
|
c.execute('''
|
||||||
|
@ -152,7 +152,8 @@ class SQLiteSession(Session):
|
||||||
c,
|
c,
|
||||||
'''datacenter (
|
'''datacenter (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
ip text not null,
|
ipv4 text not null,
|
||||||
|
ipv6 text,
|
||||||
port integer not null,
|
port integer not null,
|
||||||
auth blob not null
|
auth blob not null
|
||||||
)''',
|
)''',
|
||||||
|
@ -179,9 +180,10 @@ class SQLiteSession(Session):
|
||||||
|
|
||||||
async def insert_dc(self, dc: DataCenter):
|
async def insert_dc(self, dc: DataCenter):
|
||||||
self._execute(
|
self._execute(
|
||||||
'insert or replace into datacenter values (?,?,?,?)',
|
'insert or replace into datacenter values (?,?,?,?,?)',
|
||||||
dc.id,
|
dc.id,
|
||||||
str(ipaddress.ip_address(dc.ipv6 or dc.ipv4)),
|
str(ipaddress.ip_address(dc.ipv4)),
|
||||||
|
str(ipaddress.ip_address(dc.ipv6)) if dc.ipv6 else None,
|
||||||
dc.port,
|
dc.port,
|
||||||
dc.auth
|
dc.auth
|
||||||
)
|
)
|
||||||
|
@ -189,12 +191,11 @@ class SQLiteSession(Session):
|
||||||
async def get_all_dc(self) -> List[DataCenter]:
|
async def get_all_dc(self) -> List[DataCenter]:
|
||||||
c = self._cursor()
|
c = self._cursor()
|
||||||
res = []
|
res = []
|
||||||
for (id, ip, port, auth) in c.execute('select * from datacenter'):
|
for (id, ipv4, ipv6, port, auth) in c.execute('select * from datacenter'):
|
||||||
ip = ipaddress.ip_address(ip)
|
|
||||||
res.append(DataCenter(
|
res.append(DataCenter(
|
||||||
id=id,
|
id=id,
|
||||||
ipv4=int(ip) if ip.version == 4 else None,
|
ipv4=int(ipaddress.ip_address(ipv4)),
|
||||||
ipv6=int(ip) if ip.version == 6 else None,
|
ipv6=int(ipaddress.ip_address(ipv6)) if ipv6 else None,
|
||||||
port=port,
|
port=port,
|
||||||
auth=auth,
|
auth=auth,
|
||||||
))
|
))
|
||||||
|
|
|
@ -15,7 +15,7 @@ class DataCenter:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
id: int,
|
id: int,
|
||||||
ipv4: Optional[int],
|
ipv4: int,
|
||||||
ipv6: Optional[int],
|
ipv6: Optional[int],
|
||||||
port: int,
|
port: int,
|
||||||
auth: bytes
|
auth: bytes
|
||||||
|
|
Loading…
Reference in New Issue
Block a user