Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional parameter '--ledger-socks-proxy' #1342

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aries_cloudagent/askar/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def init_ledger_pool(self):
pool_name = self.settings.get("ledger.pool_name", "default")
keepalive = int(self.settings.get("ledger.keepalive", 5))
read_only = bool(self.settings.get("ledger.read_only", False))
socks_proxy = self.settings.get("ledger.socks_proxy")
if read_only:
LOGGER.error("Note: setting ledger to read-only mode")
genesis_transactions = self.settings.get("ledger.genesis_transactions")
Expand All @@ -73,6 +74,7 @@ def init_ledger_pool(self):
cache=cache,
genesis_transactions=genesis_transactions,
read_only=read_only,
socks_proxy=socks_proxy,
)

def bind_providers(self):
Expand Down
17 changes: 17 additions & 0 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,21 @@ def add_arguments(self, parser: ArgumentParser):
env_var="ACAPY_LEDGER_KEEP_ALIVE",
help="Specifies how many seconds to keep the ledger open. Default: 5",
)
parser.add_argument(
"--ledger-socks-proxy",
type=str,
dest="ledger_socks_proxy",
metavar="<host:port>",
required=False,
env_var="ACAPY_LEDGER_SOCKS_PROXY",
help=(
"Specifies the socks proxy (NOT http proxy) hostname and port in format "
"'hostname:port'. This is an optional parameter to be passed to ledger "
"pool configuration and ZMQ in case if aca-py is running "
"in a corporate/private network behind a corporate proxy and will "
"connect to the public (outside of corporate network) ledger pool"
),
)

def get_settings(self, args: Namespace) -> dict:
"""Extract ledger settings."""
Expand All @@ -678,6 +693,8 @@ def get_settings(self, args: Namespace) -> dict:
settings["ledger.pool_name"] = args.ledger_pool_name
if args.ledger_keepalive:
settings["ledger.keepalive"] = args.ledger_keepalive
if args.ledger_socks_proxy:
settings["ledger.socks_proxy"] = args.ledger_socks_proxy

return settings

Expand Down
11 changes: 10 additions & 1 deletion aries_cloudagent/ledger/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def provide(self, settings: BaseSettings, injector: BaseInjector):
pool_name = settings.get("ledger.pool_name", "default")
keepalive = int(settings.get("ledger.keepalive", 5))
read_only = bool(settings.get("ledger.read_only", False))
socks_proxy = settings.get("ledger.socks_proxy")

if read_only:
LOGGER.warning("Note: setting ledger to read-only mode")
Expand All @@ -65,6 +66,7 @@ def provide(self, settings: BaseSettings, injector: BaseInjector):
cache=cache,
genesis_transactions=genesis_transactions,
read_only=read_only,
socks_proxy=socks_proxy,
)

return ledger_pool
Expand All @@ -83,6 +85,7 @@ def __init__(
cache_duration: int = 600,
genesis_transactions: str = None,
read_only: bool = False,
socks_proxy: str = None,
):
"""
Initialize an IndySdkLedgerPool instance.
Expand All @@ -94,6 +97,7 @@ def __init__(
cache_duration: The TTL for ledger cache entries
genesis_transactions: The ledger genesis transaction as a string
read_only: Prevent any ledger write operations
socks_proxy: Specifies socks proxy for ZMQ to connect to ledger pool
"""
self.checked = checked
self.opened = False
Expand All @@ -108,6 +112,7 @@ def __init__(
self.name = name
self.taa_cache = None
self.read_only = read_only
self.socks_proxy = socks_proxy

async def create_pool_config(
self, genesis_transactions: str, recreate: bool = False
Expand Down Expand Up @@ -164,7 +169,11 @@ async def open(self):
with IndyErrorHandler(
f"Exception opening pool ledger {self.name}", LedgerConfigError
):
self.handle = await indy.pool.open_pool_ledger(self.name, "{}")
pool_config = json.dumps({})
if self.socks_proxy is not None:
pool_config = json.dumps({"socks_proxy": self.socks_proxy})
LOGGER.debug("Open pool with config: %s", pool_config)
self.handle = await indy.pool.open_pool_ledger(self.name, pool_config)
self.opened = True

async def close(self):
Expand Down
5 changes: 4 additions & 1 deletion aries_cloudagent/ledger/indy_vdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(
cache_duration: int = 600,
genesis_transactions: str = None,
read_only: bool = False,
socks_proxy: str = None,
):
"""
Initialize an IndyLedger instance.
Expand All @@ -90,6 +91,7 @@ def __init__(
cache_duration: The TTL for ledger cache entries
genesis_transactions: The ledger genesis transaction as a string
read_only: Prevent any ledger write operations
socks_proxy: Specifies socks proxy for ZMQ to connect to ledger pool
"""
self.ref_count = 0
self.ref_lock = asyncio.Lock()
Expand All @@ -105,6 +107,7 @@ def __init__(
self.init_config = bool(genesis_transactions)
self.taa_cache: str = None
self.read_only: bool = read_only
self.socks_proxy: str = socks_proxy

@property
def cfg_path(self) -> Path:
Expand Down Expand Up @@ -188,7 +191,7 @@ async def open(self):
txns = self.genesis_txns
cached = False

self.handle = await open_pool(transactions=txns)
self.handle = await open_pool(transactions=txns, socks_proxy=self.socks_proxy)
upd_txns = _normalize_txns(await self.handle.get_transactions())
if not cached or upd_txns != txns:
try:
Expand Down