From 407ffcd1d31e87b6aefb20eef751d9ca42c68647 Mon Sep 17 00:00:00 2001 From: Sparkss Date: Mon, 13 Oct 2025 14:54:30 +0800 Subject: [PATCH 1/2] Add libp2p relay server CLI command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add 'isek run relay' command to start libp2p circuit relay server - Support custom port configuration (default: 9090) - Include comprehensive error handling and validation - Update README with new CLI commands - Exclude isek0.3/ directory from git tracking ๐Ÿค– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .gitignore | 1 + README.md | 8 ++++--- isek/cli.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8af4833..46a6ba8 100644 --- a/.gitignore +++ b/.gitignore @@ -115,6 +115,7 @@ venv/ ENV/ env.bak/ venv.bak/ +isek0.3/ # Spyder project settings .spyderproject diff --git a/README.md b/README.md index a4cf55b..febf2b1 100644 --- a/README.md +++ b/README.md @@ -151,9 +151,11 @@ In the examples folder, follow the examples from level 1 to level 10, and you sh ## ๐Ÿงช CLI Commands ```bash -isek setup # Install Python and JavaScript dependencies -isek clean # Clean temporary files -isek --help # View available commands +isek setup # Install Python and JavaScript dependencies +isek clean # Clean temporary files +isek run relay # Start a libp2p circuit relay server (default port: 9090) +isek run relay --port=8080 # Start relay on custom port +isek --help # View available commands ``` --- diff --git a/isek/cli.py b/isek/cli.py index 4a94f8d..c910f9f 100644 --- a/isek/cli.py +++ b/isek/cli.py @@ -68,6 +68,70 @@ def registry(): main() +@cli.group() +def run(): + """Run ISEK servers and services""" + + +@run.command() +@click.option( + "--port", default=9090, type=int, help="Port for the relay server (default: 9090)" +) +def relay(port): + """Start a libp2p circuit relay server""" + import importlib.resources + + # Find the p2p directory + try: + p2p_resource = importlib.resources.files("isek").joinpath("protocol/p2p") + p2p_dir = Path(str(p2p_resource)) + except Exception: + # Fallback to development environment path + p2p_dir = Path(__file__).parent / "protocol" / "p2p" + + relay_script = p2p_dir / "relay.js" + + # Check if relay.js exists + if not relay_script.exists(): + click.secho(f"โœ— Relay script not found at {relay_script}", fg="red") + sys.exit(1) + + # Check if Node.js is installed + try: + subprocess.run(["node", "--version"], check=True, capture_output=True) + except (subprocess.CalledProcessError, FileNotFoundError): + click.secho("โœ— Node.js is required to run the relay server", fg="red") + click.secho(" Please install Node.js from https://nodejs.org/", fg="yellow") + sys.exit(1) + + # Check if node_modules exists + if not (p2p_dir / "node_modules").exists(): + click.secho("โœ— JavaScript dependencies not installed", fg="red") + click.secho( + " Please run 'isek setup' first to install dependencies", fg="yellow" + ) + sys.exit(1) + + # Validate port range + if port <= 0 or port >= 65536: + click.secho(f"โœ— Invalid port: {port}. Must be between 1 and 65535", fg="red") + sys.exit(1) + + click.secho(f"๐Ÿš€ Starting libp2p relay server on port {port}...", fg="blue") + click.secho(" Press Ctrl+C to stop", fg="yellow") + + # Run the relay server + try: + subprocess.run( + ["node", str(relay_script), f"--port={port}"], cwd=p2p_dir, check=True + ) + except KeyboardInterrupt: + click.secho("\nโœ“ Relay server stopped", fg="green") + except subprocess.CalledProcessError as e: + click.secho(f"\nโœ— Relay server failed: {e}", fg="red") + sys.exit(e.returncode) + + @cli.command() def setup(): """Install ISEK Python and JavaScript dependencies""" From e93918935b95e1871927b0051f255ec1d16a2742 Mon Sep 17 00:00:00 2001 From: Sparkss Date: Mon, 13 Oct 2025 15:06:24 +0800 Subject: [PATCH 2/2] Update eth-account dependency version constraint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Pin eth-account to >=0.8.0,<0.9.0 for compatibility - Includes relay CLI command functionality ๐Ÿค– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- isek/cli.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/isek/cli.py b/isek/cli.py index 4a94f8d..c910f9f 100644 --- a/isek/cli.py +++ b/isek/cli.py @@ -68,6 +68,70 @@ def registry(): main() +@cli.group() +def run(): + """Run ISEK servers and services""" + + +@run.command() +@click.option( + "--port", default=9090, type=int, help="Port for the relay server (default: 9090)" +) +def relay(port): + """Start a libp2p circuit relay server""" + import importlib.resources + + # Find the p2p directory + try: + p2p_resource = importlib.resources.files("isek").joinpath("protocol/p2p") + p2p_dir = Path(str(p2p_resource)) + except Exception: + # Fallback to development environment path + p2p_dir = Path(__file__).parent / "protocol" / "p2p" + + relay_script = p2p_dir / "relay.js" + + # Check if relay.js exists + if not relay_script.exists(): + click.secho(f"โœ— Relay script not found at {relay_script}", fg="red") + sys.exit(1) + + # Check if Node.js is installed + try: + subprocess.run(["node", "--version"], check=True, capture_output=True) + except (subprocess.CalledProcessError, FileNotFoundError): + click.secho("โœ— Node.js is required to run the relay server", fg="red") + click.secho(" Please install Node.js from https://nodejs.org/", fg="yellow") + sys.exit(1) + + # Check if node_modules exists + if not (p2p_dir / "node_modules").exists(): + click.secho("โœ— JavaScript dependencies not installed", fg="red") + click.secho( + " Please run 'isek setup' first to install dependencies", fg="yellow" + ) + sys.exit(1) + + # Validate port range + if port <= 0 or port >= 65536: + click.secho(f"โœ— Invalid port: {port}. Must be between 1 and 65535", fg="red") + sys.exit(1) + + click.secho(f"๐Ÿš€ Starting libp2p relay server on port {port}...", fg="blue") + click.secho(" Press Ctrl+C to stop", fg="yellow") + + # Run the relay server + try: + subprocess.run( + ["node", str(relay_script), f"--port={port}"], cwd=p2p_dir, check=True + ) + except KeyboardInterrupt: + click.secho("\nโœ“ Relay server stopped", fg="green") + except subprocess.CalledProcessError as e: + click.secho(f"\nโœ— Relay server failed: {e}", fg="red") + sys.exit(e.returncode) + + @cli.command() def setup(): """Install ISEK Python and JavaScript dependencies""" diff --git a/pyproject.toml b/pyproject.toml index 51b5745..a757ef7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ dependencies = [ # Web3/Ethereum dependencies "web3>=6.0.0", - "eth-account>=0.9.0", + "eth-account>=0.8.0,<0.9.0", ] [project.scripts]