parent
9c834d6091
commit
72fce87088
@ -15,6 +15,7 @@ from ipaddress import ip_address
|
|||||||
from lib.coins import Coin
|
from lib.coins import Coin
|
||||||
from lib.env_base import EnvBase
|
from lib.env_base import EnvBase
|
||||||
import lib.util as lib_util
|
import lib.util as lib_util
|
||||||
|
import server.version as version
|
||||||
|
|
||||||
|
|
||||||
NetIdentity = namedtuple('NetIdentity', 'host tcp_port ssl_port nick_suffix')
|
NetIdentity = namedtuple('NetIdentity', 'host tcp_port ssl_port nick_suffix')
|
||||||
@ -147,6 +148,22 @@ class Env(EnvBase):
|
|||||||
'_tor',
|
'_tor',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def server_features(self):
|
||||||
|
'''Return the server features dictionary.'''
|
||||||
|
hosts = {identity.host: {'tcp_port': identity.tcp_port,
|
||||||
|
'ssl_port': identity.ssl_port}
|
||||||
|
for identity in self.identities}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'hosts': hosts,
|
||||||
|
'pruning': None,
|
||||||
|
'server_version': version.VERSION,
|
||||||
|
'protocol_min': version.PROTOCOL_MIN,
|
||||||
|
'protocol_max': version.PROTOCOL_MAX,
|
||||||
|
'genesis_hash': self.coin.GENESIS_HASH,
|
||||||
|
'hash_function': 'sha256',
|
||||||
|
}
|
||||||
|
|
||||||
def peer_discovery_enum(self):
|
def peer_discovery_enum(self):
|
||||||
pd = self.default('PEER_DISCOVERY', 'on').strip().lower()
|
pd = self.default('PEER_DISCOVERY', 'on').strip().lower()
|
||||||
if pd in ('off', ''):
|
if pd in ('off', ''):
|
||||||
|
|||||||
@ -28,24 +28,6 @@ STALE_SECS = 24 * 3600
|
|||||||
WAKEUP_SECS = 300
|
WAKEUP_SECS = 300
|
||||||
|
|
||||||
|
|
||||||
def peers_from_env(env):
|
|
||||||
'''Return a list of peers from the environment settings.'''
|
|
||||||
hosts = {identity.host: {'tcp_port': identity.tcp_port,
|
|
||||||
'ssl_port': identity.ssl_port}
|
|
||||||
for identity in env.identities}
|
|
||||||
features = {
|
|
||||||
'hosts': hosts,
|
|
||||||
'pruning': None,
|
|
||||||
'server_version': version.VERSION,
|
|
||||||
'protocol_min': version.PROTOCOL_MIN,
|
|
||||||
'protocol_max': version.PROTOCOL_MAX,
|
|
||||||
'genesis_hash': env.coin.GENESIS_HASH,
|
|
||||||
'hash_function': 'sha256',
|
|
||||||
}
|
|
||||||
|
|
||||||
return [Peer(ident.host, features, 'env') for ident in env.identities]
|
|
||||||
|
|
||||||
|
|
||||||
class PeerSession(JSONSession):
|
class PeerSession(JSONSession):
|
||||||
'''An outgoing session to a peer.'''
|
'''An outgoing session to a peer.'''
|
||||||
|
|
||||||
@ -250,7 +232,10 @@ class PeerManager(util.LoggedClass):
|
|||||||
self.irc = IRC(env, self)
|
self.irc = IRC(env, self)
|
||||||
else:
|
else:
|
||||||
self.irc = None
|
self.irc = None
|
||||||
self.myselves = peers_from_env(env)
|
|
||||||
|
# Our clearnet and Tor Peers, if any
|
||||||
|
self.myselves = [Peer(ident.host, env.server_features(), 'env')
|
||||||
|
for ident in env.identities]
|
||||||
self.retry_event = asyncio.Event()
|
self.retry_event = asyncio.Event()
|
||||||
# Peers have one entry per hostname. Once connected, the
|
# Peers have one entry per hostname. Once connected, the
|
||||||
# ip_addr property is either None, an onion peer, or the
|
# ip_addr property is either None, an onion peer, or the
|
||||||
|
|||||||
@ -245,7 +245,7 @@ class ElectrumX(SessionBase):
|
|||||||
|
|
||||||
def server_features(self):
|
def server_features(self):
|
||||||
'''Returns a dictionary of server features.'''
|
'''Returns a dictionary of server features.'''
|
||||||
return self.controller.peer_mgr.my_clearnet_peer().features
|
return self.env.server_features()
|
||||||
|
|
||||||
def block_get_chunk(self, index):
|
def block_get_chunk(self, index):
|
||||||
'''Return a chunk of block headers as a hexadecimal string.
|
'''Return a chunk of block headers as a hexadecimal string.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user