persist recent peers. implement dns seed bootstrapping.
dns seeds are currently disabled though, as they always seem to return mainnet nodes.
This commit is contained in:
@@ -46,6 +46,7 @@ import aiohttp
|
||||
from aiohttp_socks import SocksConnector, SocksVer
|
||||
from aiorpcx import TaskGroup
|
||||
import certifi
|
||||
import dns.resolver
|
||||
|
||||
from .i18n import _
|
||||
from .logging import get_logger, Logger
|
||||
@@ -1174,3 +1175,17 @@ def list_enabled_bits(x: int) -> Sequence[int]:
|
||||
binary = bin(x)[2:]
|
||||
rev_bin = reversed(binary)
|
||||
return tuple(i for i, b in enumerate(rev_bin) if b == '1')
|
||||
|
||||
|
||||
def resolve_dns_srv(host: str):
|
||||
srv_records = dns.resolver.query(host, 'SRV')
|
||||
# priority: prefer lower
|
||||
# weight: tie breaker; prefer higher
|
||||
srv_records = sorted(srv_records, key=lambda x: (x.priority, -x.weight))
|
||||
|
||||
def dict_from_srv_record(srv):
|
||||
return {
|
||||
'host': str(srv.target),
|
||||
'port': srv.port,
|
||||
}
|
||||
return [dict_from_srv_record(srv) for srv in srv_records]
|
||||
|
||||
Reference in New Issue
Block a user