def services_to_run(self): def default_part(protocol, part): return default_services.get(protocol, {}).get(part) # if env SERVICES not set then get it from /home/<myusername>/.fairchains/<myFairChains>.electrumx.json if (os.environ.get('SERVICES') == None): result = [ Service('rpc', '127.0.0.1:8002'), Service('ssl', '127.0.0.1:8004') ] default_services = { protocol: { ServicePart.HOST: 'all_interfaces' } for protocol in self.KNOWN_PROTOCOLS } default_services['rpc'] = { ServicePart.HOST: 'localhost', ServicePart.PORT: 8000 } services = self._parse_services( self.default('SERVICES', self.coin.SERVICES), default_part) # Find onion hosts for service in services: if str(service.host).endswith('.onion'): raise ServiceError(f'bad host for SERVICES: {service}') print('\nAvailable SERVICES') print(services) return services
def test_REPORT_SERVICES(): setup_base_env() e = Env() assert e.report_services == [] # This has a blank entry between commas os.environ['REPORT_SERVICES'] = 'tcp://foo.bar:1234,,ws://1.2.3.4:567' e = Env() assert e.report_services == [ Service('tcp', NetAddress('foo.bar', 1234)), Service('ws', NetAddress('1.2.3.4', 567)), ]
def test_SERVICES(): setup_base_env() e = Env() assert e.services == [] # This has a blank entry between commas os.environ['SERVICES'] = 'tcp://foo.bar:1234,,ws://1.2.3.4:567,rpc://[::1]:700' e = Env() assert e.services == [ Service('tcp', NetAddress('foo.bar', 1234)), Service('ws', NetAddress('1.2.3.4', 567)), Service('rpc', NetAddress('::1', 700)), ]
def _parse_services(self, services_str, default_func): result = [] for service_str in services_str.split(','): if not service_str: continue try: service = Service.from_string(service_str, default_func=default_func) except Exception as e: raise ServiceError(f'"{service_str}" invalid: {e}') from None if service.protocol not in self.KNOWN_PROTOCOLS: raise ServiceError(f'"{service_str}" invalid: unknown protocol') result.append(service) # Find duplicate addresses service_map = {service.address: [] for service in result} for service in result: service_map[service.address].append(service) for address, services in service_map.items(): if len(services) > 1: raise ServiceError(f'address {address} has multiple services') return result