Browse Source
interface: make localhost exempt from ip-range bucketing
master
SomberNight
5 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
1 changed files with
4 additions and
2 deletions
-
electrum/interface.py
|
|
@ -31,7 +31,7 @@ import asyncio |
|
|
|
import socket |
|
|
|
from typing import Tuple, Union, List, TYPE_CHECKING, Optional, Set, NamedTuple |
|
|
|
from collections import defaultdict |
|
|
|
from ipaddress import IPv4Network, IPv6Network, ip_address, IPv6Address |
|
|
|
from ipaddress import IPv4Network, IPv6Network, ip_address, IPv6Address, IPv4Address |
|
|
|
import itertools |
|
|
|
import logging |
|
|
|
import hashlib |
|
|
@ -794,11 +794,13 @@ class Interface(Logger): |
|
|
|
if self.is_tor(): |
|
|
|
return BUCKET_NAME_OF_ONION_SERVERS |
|
|
|
try: |
|
|
|
ip_addr = ip_address(self.ip_addr()) |
|
|
|
ip_addr = ip_address(self.ip_addr()) # type: Union[IPv4Address, IPv6Address] |
|
|
|
except ValueError: |
|
|
|
return '' |
|
|
|
if not ip_addr: |
|
|
|
return '' |
|
|
|
if ip_addr.is_loopback: # localhost is exempt |
|
|
|
return '' |
|
|
|
if ip_addr.version == 4: |
|
|
|
slash16 = IPv4Network(ip_addr).supernet(prefixlen_diff=32-16) |
|
|
|
return str(slash16) |
|
|
|