python-pylan 0.0.2__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_pylan-0.0.3/.claude/rules/engineering.md +43 -0
- python_pylan-0.0.3/.editorconfig +21 -0
- python_pylan-0.0.3/.flake8 +8 -0
- python_pylan-0.0.3/.gemini/settings.json +8 -0
- {python_pylan-0.0.2 → python_pylan-0.0.3}/.gitignore +4 -0
- python_pylan-0.0.3/CLAUDE.md +19 -0
- python_pylan-0.0.3/GEMINI.md +74 -0
- {python_pylan-0.0.2 → python_pylan-0.0.3}/PKG-INFO +13 -3
- python_pylan-0.0.3/TODO.md +86 -0
- python_pylan-0.0.3/assets/icon.ico +0 -0
- python_pylan-0.0.3/assets/icon.png +0 -0
- python_pylan-0.0.3/assets/logo.svg +51 -0
- python_pylan-0.0.3/pylan/__init__.py +18 -0
- python_pylan-0.0.3/pylan/__main__.py +29 -0
- python_pylan-0.0.3/pylan/cli/__init__.py +25 -0
- python_pylan-0.0.3/pylan/cli/cli.py +36 -0
- python_pylan-0.0.3/pylan/cli/receive.py +201 -0
- python_pylan-0.0.3/pylan/cli/scan.py +103 -0
- python_pylan-0.0.3/pylan/cli/send.py +106 -0
- python_pylan-0.0.3/pylan/client/__init__.py +14 -0
- python_pylan-0.0.3/pylan/core/__init__.py +103 -0
- python_pylan-0.0.3/pylan/core/discovery.py +475 -0
- python_pylan-0.0.3/pylan/core/handshake.py +145 -0
- python_pylan-0.0.3/pylan/core/models.py +77 -0
- python_pylan-0.0.3/pylan/core/net.py +88 -0
- python_pylan-0.0.3/pylan/core/protocol.py +132 -0
- python_pylan-0.0.3/pylan/core/transfer.py +420 -0
- python_pylan-0.0.3/pylan/errors/__init__.py +28 -0
- python_pylan-0.0.3/pylan/errors/base.py +13 -0
- python_pylan-0.0.3/pylan/main.py +6 -0
- python_pylan-0.0.3/pylan/ui/__init__.py +21 -0
- python_pylan-0.0.3/pylan/ui/app.py +188 -0
- python_pylan-0.0.3/pylan/ui/assets/icon.ico +0 -0
- python_pylan-0.0.3/pylan/ui/assets/icon.png +0 -0
- python_pylan-0.0.3/pylan/ui/assets/logo.svg +51 -0
- python_pylan-0.0.3/pylan/ui/components/__init__.py +14 -0
- python_pylan-0.0.3/pylan/ui/components/file_picker.py +243 -0
- python_pylan-0.0.3/pylan/ui/components/navbar.py +250 -0
- python_pylan-0.0.3/pylan/ui/components/peer_tile.py +152 -0
- python_pylan-0.0.3/pylan/ui/components/transfer_row.py +224 -0
- python_pylan-0.0.3/pylan/ui/state.py +823 -0
- python_pylan-0.0.3/pylan/ui/views/__init__.py +13 -0
- python_pylan-0.0.3/pylan/ui/views/home_view.py +245 -0
- python_pylan-0.0.3/pylan/ui/views/receive_view.py +249 -0
- python_pylan-0.0.3/pylan/ui/views/send_view.py +200 -0
- python_pylan-0.0.3/pylan/ui/views/settings_view.py +233 -0
- python_pylan-0.0.3/pylan/utils/utils.py +21 -0
- python_pylan-0.0.3/pyproject.toml +63 -0
- python_pylan-0.0.3/tests/__init__.py +6 -0
- python_pylan-0.0.3/tests/test_cli_receive.py +300 -0
- python_pylan-0.0.3/tests/test_cli_scan.py +118 -0
- python_pylan-0.0.3/tests/test_cli_send.py +224 -0
- python_pylan-0.0.3/tests/test_discovery.py +391 -0
- python_pylan-0.0.3/tests/test_errors.py +30 -0
- python_pylan-0.0.3/tests/test_handshake.py +147 -0
- python_pylan-0.0.3/tests/test_protocol.py +125 -0
- python_pylan-0.0.3/tests/test_transfer.py +289 -0
- python_pylan-0.0.3/tests/test_ui/__init__.py +1 -0
- python_pylan-0.0.3/tests/test_ui/test_state.py +517 -0
- python_pylan-0.0.3/uv.lock +3730 -0
- python_pylan-0.0.2/pylan/__init__.py +0 -3
- python_pylan-0.0.2/pyproject.toml +0 -25
- python_pylan-0.0.2/requirements.txt +0 -1
- {python_pylan-0.0.2 → python_pylan-0.0.3}/.github/workflows/release.yml +0 -0
- {python_pylan-0.0.2 → python_pylan-0.0.3}/README.md +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Engineering rules
|
|
2
|
+
|
|
3
|
+
## Python and dependencies
|
|
4
|
+
|
|
5
|
+
- Support the declared minimum of Python 3.10; avoid syntax or library APIs
|
|
6
|
+
that require a newer version unless the project requirement is deliberately
|
|
7
|
+
changed.
|
|
8
|
+
- Follow neighboring code: four-space indentation, type annotations, clear
|
|
9
|
+
names, and concise docstrings on public APIs.
|
|
10
|
+
- Prefer the standard library and dependencies already declared in
|
|
11
|
+
`pyproject.toml`. When a dependency change is necessary, update
|
|
12
|
+
`pyproject.toml` and `uv.lock` consistently.
|
|
13
|
+
- Do not introduce lint, format, or type-check tooling as incidental cleanup.
|
|
14
|
+
|
|
15
|
+
## Network behavior and privacy
|
|
16
|
+
|
|
17
|
+
- Treat UDP datagrams and TCP responses as untrusted input. Check the expected
|
|
18
|
+
structure and values before using them.
|
|
19
|
+
- Preserve the established message header and payload format unless the task
|
|
20
|
+
explicitly calls for a protocol change; account for compatibility when
|
|
21
|
+
doing so.
|
|
22
|
+
- Keep network resource cleanup explicit and async task/concurrency behavior
|
|
23
|
+
bounded. Surface actionable errors using the existing logging or return
|
|
24
|
+
conventions rather than silently masking new failure cases.
|
|
25
|
+
- Keep discovery and sharing local-network oriented. Do not add broad scans
|
|
26
|
+
or remote-service behavior beyond the requested scope.
|
|
27
|
+
- Avoid logging payloads, secrets, or unnecessary device-identifying data.
|
|
28
|
+
Describe security properties accurately; do not imply unfinished goals are
|
|
29
|
+
already guarantees.
|
|
30
|
+
|
|
31
|
+
## Tests and changes
|
|
32
|
+
|
|
33
|
+
- Read the relevant code and tests before editing, and add tests for changed
|
|
34
|
+
behavior and important failure paths.
|
|
35
|
+
- Keep tests deterministic. Mock sockets, TCP streams, and timing instead of
|
|
36
|
+
relying on live network access.
|
|
37
|
+
- Run the most relevant test module first, followed by `uv run pytest` for
|
|
38
|
+
cross-cutting changes. If `uv` is unavailable, use `python -m pytest` in the
|
|
39
|
+
active project environment and state that substitution.
|
|
40
|
+
- Keep edits focused. Do not change unrelated code, generated files, or
|
|
41
|
+
documentation outside the scope of the behavior being changed.
|
|
42
|
+
- Review the diff before finishing and report the implementation, actual
|
|
43
|
+
validation results, and any known limitations.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
insert_final_newline = true
|
|
7
|
+
indent_style = space
|
|
8
|
+
indent_size = 4
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.{json,yml,yaml}]
|
|
12
|
+
indent_size = 2
|
|
13
|
+
|
|
14
|
+
[*.md]
|
|
15
|
+
trim_trailing_whitespace = false
|
|
16
|
+
|
|
17
|
+
[Makefile]
|
|
18
|
+
indent_style = tab
|
|
19
|
+
|
|
20
|
+
[{*.bat,*.cmd}]
|
|
21
|
+
end_of_line = crlf
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# PyLan
|
|
2
|
+
|
|
3
|
+
PyLan is an early-stage Python package for local-network file and data
|
|
4
|
+
sharing. The package supports Python 3.10 and newer; dependency metadata is
|
|
5
|
+
maintained in `pyproject.toml`, with the resolved environment in `uv.lock`.
|
|
6
|
+
|
|
7
|
+
Before making changes, inspect the relevant implementation and tests. Follow
|
|
8
|
+
the project-specific requirements in [`.claude/rules/engineering.md`](.claude/rules/engineering.md).
|
|
9
|
+
|
|
10
|
+
The key implementation areas are `pylan/core/protocol.py` (message framing),
|
|
11
|
+
`pylan/core/models.py` (device models and storage), and
|
|
12
|
+
`pylan/core/discovery.py` (multicast discovery and TCP probes). Preserve the
|
|
13
|
+
existing public API and wire format unless the requested change requires an
|
|
14
|
+
explicitly compatible update.
|
|
15
|
+
|
|
16
|
+
Tests are under `tests/` and use `unittest` test cases, runnable with pytest.
|
|
17
|
+
Prefer deterministic tests that mock network operations. For relevant
|
|
18
|
+
changes, run the focused tests and then `uv run pytest` when practical. State
|
|
19
|
+
clearly which checks were run and their results.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# PyLan project guidance
|
|
2
|
+
|
|
3
|
+
## Project overview
|
|
4
|
+
|
|
5
|
+
PyLan is an early-stage Python project for transferring files and other data
|
|
6
|
+
between nearby devices on a local network. It is intended to become both a
|
|
7
|
+
standalone application and a reusable package. Security and privacy are
|
|
8
|
+
important project goals, but do not describe planned or incomplete safeguards
|
|
9
|
+
as implemented.
|
|
10
|
+
|
|
11
|
+
The package requires Python 3.10 or newer. Dependencies and package metadata
|
|
12
|
+
are defined in `pyproject.toml`; `uv.lock` records the resolved environment.
|
|
13
|
+
|
|
14
|
+
## Repository map
|
|
15
|
+
|
|
16
|
+
- `pylan/core/protocol.py` implements the binary message header and payload
|
|
17
|
+
serialization.
|
|
18
|
+
- `pylan/core/models.py` defines discovery data models and the in-memory
|
|
19
|
+
device store.
|
|
20
|
+
- `pylan/core/discovery.py` implements multicast discovery, TCP probing, and
|
|
21
|
+
subnet scanning.
|
|
22
|
+
- `pylan/main.py` is the current console-script entry point; keep its
|
|
23
|
+
intentionally limited behavior in mind when making CLI changes.
|
|
24
|
+
- `tests/` contains the unit tests for protocol framing and peer discovery.
|
|
25
|
+
|
|
26
|
+
Keep changes within the relevant layer. Preserve existing public names and the
|
|
27
|
+
wire format unless a requested change explicitly requires a compatible
|
|
28
|
+
protocol update.
|
|
29
|
+
|
|
30
|
+
## Engineering expectations
|
|
31
|
+
|
|
32
|
+
- Match the surrounding Python style: four-space indentation, clear names,
|
|
33
|
+
useful type annotations, and focused docstrings for public APIs.
|
|
34
|
+
- Prefer small, testable changes and the standard library or existing
|
|
35
|
+
dependencies. Add a dependency only when the task requires it, and update
|
|
36
|
+
`pyproject.toml` and `uv.lock` together.
|
|
37
|
+
- Treat all network input as untrusted. Validate message shape and values
|
|
38
|
+
before using them; keep resource lifetimes explicit and asynchronous
|
|
39
|
+
concurrency bounded.
|
|
40
|
+
- Keep discovery and transfer behavior local-network scoped. Do not add
|
|
41
|
+
unrelated remote-service dependencies, broad network scanning, or claims
|
|
42
|
+
that the current implementation provides complete security.
|
|
43
|
+
- Avoid logging payload contents, secrets, or unnecessary personal/device
|
|
44
|
+
information.
|
|
45
|
+
- Tests should be deterministic and should mock sockets, connections, and
|
|
46
|
+
timing rather than depend on a live network.
|
|
47
|
+
- Do not add formatter, linter, or type-checker configuration unless requested
|
|
48
|
+
or needed for the change; the repository does not currently configure those
|
|
49
|
+
tools.
|
|
50
|
+
|
|
51
|
+
## Validation
|
|
52
|
+
|
|
53
|
+
Run the smallest relevant test selection, then the full unit suite when the
|
|
54
|
+
change affects shared behavior:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
uv run pytest tests/test_protocol.py
|
|
58
|
+
uv run pytest tests/test_discovery.py
|
|
59
|
+
uv run pytest
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
If `uv` is unavailable, use the project's active environment with
|
|
63
|
+
`python -m pytest` and report the command actually run. Do not claim a check
|
|
64
|
+
passed unless it was run successfully.
|
|
65
|
+
|
|
66
|
+
## Change workflow
|
|
67
|
+
|
|
68
|
+
1. Read the implementation and its tests before changing behavior.
|
|
69
|
+
2. Add or update tests for observable behavior, including error paths where
|
|
70
|
+
appropriate.
|
|
71
|
+
3. Keep the patch focused; do not rewrite unrelated files or generated
|
|
72
|
+
artifacts.
|
|
73
|
+
4. Review the final diff for accidental changes and summarize behavior,
|
|
74
|
+
validation, and any remaining limitations.
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-pylan
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: Cross-platform local network file and data sharing library.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Aryan-202/python-pylan
|
|
6
|
-
Author: Aryan Vishwakarma
|
|
6
|
+
Author-email: Aryan Vishwakarma <aryanvishwakarma275@gmail.com>
|
|
7
7
|
Classifier: Development Status :: 2 - Pre-Alpha
|
|
8
8
|
Classifier: Intended Audience :: Developers
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Requires-Dist: asyncio>=4.0.0
|
|
13
|
+
Requires-Dist: bleak>=3.0.2
|
|
14
|
+
Requires-Dist: certifi>=2026.10.23
|
|
15
|
+
Requires-Dist: click>=8.5.0
|
|
16
|
+
Requires-Dist: flet>=1.0.5
|
|
17
|
+
Requires-Dist: psutil>=7.2.2
|
|
18
|
+
Requires-Dist: pytest>=9.1.1
|
|
19
|
+
Requires-Dist: qrcode>=8.2
|
|
20
|
+
Requires-Dist: scapy>=2.8.0
|
|
21
|
+
Requires-Dist: zeroconf>=0.151.5
|
|
12
22
|
Description-Content-Type: text/markdown
|
|
13
23
|
|
|
14
24
|
# PyLan
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# TODO.md — Things need to be fixed for PyLan v0.0.3
|
|
2
|
+
|
|
3
|
+
## High Priority
|
|
4
|
+
|
|
5
|
+
- [ ] **Package & Dependency Decoupling (`pyproject.toml`)**
|
|
6
|
+
- [ ] Strip GUI (`flet`) and CLI (`click`, `rich`) dependencies out of core runtime requirements.
|
|
7
|
+
- [ ] Set up optional installation targets:
|
|
8
|
+
- [ ] `pip install pylan` (Core engine + lightweight SDK only)
|
|
9
|
+
- [ ] `pip install "pylan[cli]"` (Command-line tool)
|
|
10
|
+
- [ ] `pip install "pylan[ui]"` (Desktop graphical interface)
|
|
11
|
+
- [ ] `pip install "pylan[all]"` (Full bundle)
|
|
12
|
+
- [ ] Implement graceful import guards in entrypoints that suggest the missing extra if uninstalled.
|
|
13
|
+
|
|
14
|
+
- [ ] **Core Independence & Callback Extraction**
|
|
15
|
+
- [ ] Remove all UI and CLI imports from `pylan/core/`.
|
|
16
|
+
- [ ] Abstract progress tracking into standard callback protocols (`Callable[[int, int], None]`) instead of coupling to Rich or Flet UI widgets.
|
|
17
|
+
- [ ] Decouple `pylan/cli/` and `pylan/ui/` so both act purely as independent presentation layers consuming the public SDK.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Exception Hierarchy (`pylan/errors/`)
|
|
22
|
+
|
|
23
|
+
- [ ] **Define Base Exception**
|
|
24
|
+
- [ ] `base.py`: Root exception for all PyLan-related failures.
|
|
25
|
+
|
|
26
|
+
- [ ] **Discovery Exceptions (`pylan/errors/discovery.py`)**
|
|
27
|
+
- [ ] `DiscoveryError`: Base class for peer discovery failures.
|
|
28
|
+
- [ ] `PeerNotFoundError`: Raised when the target peer name or ID cannot be discovered on the subnet.
|
|
29
|
+
- [ ] `DiscoveryTimeoutError`: Raised when discovery scan expires without finding devices.
|
|
30
|
+
- [ ] `NetworkInterfaceError`: Raised when bound interface or multicast socket is unavailable.
|
|
31
|
+
- [ ] `InvalidServiceRecordError`: Raised when mDNS/multicast packet contains malformed peer payload.
|
|
32
|
+
|
|
33
|
+
- [ ] **Connection & Handshake Exceptions (`pylan/errors/connection.py`)**
|
|
34
|
+
- [ ] `PylanConnectionError`: Base class for transport connection errors.
|
|
35
|
+
- [ ] `PeerUnreachableError`: Raised when the target IP/port is unreachable or drops socket connection.
|
|
36
|
+
- [ ] `HandshakeError`: Base class for handshake phase errors.
|
|
37
|
+
- [ ] `HandshakeRejectedError`: Raised when the receiver explicitly declines incoming transfer.
|
|
38
|
+
- [ ] `HandshakeTimeoutError`: Raised when peer does not respond to the handshake proposal within timeout.
|
|
39
|
+
- [ ] `ProtocolVersionMismatchError`: Raised when client and peer use incompatible protocol versions.
|
|
40
|
+
- [ ] `AuthenticationFailedError`: Raised if pre-shared key, PIN, or peer token validation fails.
|
|
41
|
+
|
|
42
|
+
- [ ] **Transfer & Payload Exceptions (`pylan/errors/transfer.py`)**
|
|
43
|
+
- [ ] `TransferError`: Base class for file streaming errors.
|
|
44
|
+
- [ ] `TransferFailedError`: Generic failure during chunk streaming or socket writing.
|
|
45
|
+
- [ ] `TransferAbortedError`: Raised when transfer is aborted mid-stream by peer or local user.
|
|
46
|
+
- [ ] `TransferTimeoutError`: Raised when data stream stalls past read/write timeout.
|
|
47
|
+
- [ ] `ChecksumMismatchError`: Raised when file integrity check fails after transfer completes.
|
|
48
|
+
- [ ] `InsufficientStorageError`: Raised by receiver if target disk has inadequate free space.
|
|
49
|
+
- [ ] `FileAccessError`: Base class for local file system permission or path errors.
|
|
50
|
+
- [ ] `TransportFileNotFoundError`: Raised when requested payload does not exist on disk.
|
|
51
|
+
- [ ] `FileReadError`: Raised when local sender fails to read chunks from disk.
|
|
52
|
+
- [ ] `FileWriteError`: Raised when receiver fails to write chunks to disk.
|
|
53
|
+
|
|
54
|
+
- [ ] **Protocol & Framing Exceptions (`pylan/errors/protocol.py`)**
|
|
55
|
+
- [ ] `ProtocolError`: Base class for packet serialization and framing errors.
|
|
56
|
+
- [ ] `InvalidPacketError`: Raised when receiving corrupted or malformed packet header/body.
|
|
57
|
+
- [ ] `PacketHeaderTooShortError`: Raised when socket read delivers incomplete struct header.
|
|
58
|
+
- [ ] `MagicBytesMismatchError`: Raised when packet header magic header does not match expected signature.
|
|
59
|
+
- [ ] `PayloadTooLargeError`: Raised when incoming frame size exceeds protocol buffer limit.
|
|
60
|
+
|
|
61
|
+
- [ ] **Integrate Exceptions Across Modules**
|
|
62
|
+
- [ ] Export all exception classes through `pylan/errors/__init__.py`.
|
|
63
|
+
- [ ] Re-export top-level exceptions in `pylan/__init__.py` for public SDK consumption.
|
|
64
|
+
- [ ] Audit `pylan/core/discovery.py`, `pylan/core/handshake.py`, and `pylan/core/protocol.py` to replace generic exceptions with domain-specific classes.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Public Client API
|
|
69
|
+
|
|
70
|
+
- [ ] **Design High-Level Interface (`pylan/client.py` & `pylan/__init__.py`)**
|
|
71
|
+
- [ ] Implement sync wrapper methods:
|
|
72
|
+
- [ ] `pylan.send_file(file_path: Path | str, peer_name: str | None = None, peer_ip: str | None = None, port: int = ..., timeout: float = 30.0, on_progress: Callable | None = None) -> TransferResult`
|
|
73
|
+
- [ ] `pylan.receive_file(save_dir: Path | str = "./downloads", accept_all: bool = False, timeout: float | None = None, on_progress: Callable | None = None) -> TransferResult`
|
|
74
|
+
- [ ] `pylan.scan(timeout: float = 3.0) -> list[Peer]`
|
|
75
|
+
- [ ] Implement object-oriented client class:
|
|
76
|
+
- [ ] `PyLanClient` (Context manager supporting `.scan()`, `.connect()`, `.send()`, `.receive()`).
|
|
77
|
+
- [ ] Event callbacks: `on_peer_found`, `on_handshake_request`, `on_progress`, `on_complete`.
|
|
78
|
+
- [ ] Implement async equivalents (`AsyncPyLanClient`) for event loops, UI runtimes, and web services.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Verification & Tests
|
|
83
|
+
|
|
84
|
+
- [ ] Add isolated unit tests in `tests/test_errors.py` ensuring all custom exceptions inherit from `PyLanError`.
|
|
85
|
+
- [ ] Add packaging tests in `tests/test_packaging.py` validating `import pylan` runs in headless environments without `flet` or `click`.
|
|
86
|
+
- [ ] Add integration tests in `tests/test_public_api.py` validating `pylan.send_file` and `pylan.scan` error states.
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 100" width="400" height="100">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="pylan-grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="0%" stop-color="#00E5FF" />
|
|
5
|
+
<stop offset="50%" stop-color="#2979FF" />
|
|
6
|
+
<stop offset="100%" stop-color="#7C4DFF" />
|
|
7
|
+
</linearGradient>
|
|
8
|
+
<linearGradient id="glow-grad" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
9
|
+
<stop offset="0%" stop-color="#00E5FF" stop-opacity="0.8" />
|
|
10
|
+
<stop offset="100%" stop-color="#2979FF" stop-opacity="0.2" />
|
|
11
|
+
</linearGradient>
|
|
12
|
+
<filter id="glow" x="-20%" y="-20%" width="140%" height="140%">
|
|
13
|
+
<feGaussianBlur stdDeviation="4" result="blur" />
|
|
14
|
+
<feComposite in="SourceGraphic" in2="blur" operator="over" />
|
|
15
|
+
</filter>
|
|
16
|
+
</defs>
|
|
17
|
+
|
|
18
|
+
<!-- Node Icon Group -->
|
|
19
|
+
<g transform="translate(15, 10)">
|
|
20
|
+
<!-- Interconnecting Data Paths -->
|
|
21
|
+
<path d="M 40 25 L 65 55" stroke="url(#pylan-grad)" stroke-width="4" stroke-linecap="round" stroke-dasharray="2 6" opacity="0.8" />
|
|
22
|
+
<path d="M 40 25 L 15 55" stroke="url(#pylan-grad)" stroke-width="4" stroke-linecap="round" />
|
|
23
|
+
<path d="M 15 55 L 65 55" stroke="url(#pylan-grad)" stroke-width="4" stroke-linecap="round" />
|
|
24
|
+
<path d="M 40 55 L 40 30" stroke="#00E5FF" stroke-width="3" stroke-linecap="round" />
|
|
25
|
+
|
|
26
|
+
<!-- Top Node -->
|
|
27
|
+
<circle cx="40" cy="22" r="14" fill="#0D1117" stroke="url(#pylan-grad)" stroke-width="4" filter="url(#glow)" />
|
|
28
|
+
<circle cx="40" cy="22" r="6" fill="#00E5FF" />
|
|
29
|
+
|
|
30
|
+
<!-- Left Bottom Node -->
|
|
31
|
+
<circle cx="15" cy="58" r="12" fill="#0D1117" stroke="#2979FF" stroke-width="3.5" />
|
|
32
|
+
<circle cx="15" cy="58" r="5" fill="#2979FF" />
|
|
33
|
+
|
|
34
|
+
<!-- Right Bottom Node -->
|
|
35
|
+
<circle cx="65" cy="58" r="12" fill="#0D1117" stroke="#7C4DFF" stroke-width="3.5" />
|
|
36
|
+
<circle cx="65" cy="58" r="5" fill="#7C4DFF" />
|
|
37
|
+
|
|
38
|
+
<!-- Pulse Ring -->
|
|
39
|
+
<circle cx="40" cy="22" r="19" fill="none" stroke="#00E5FF" stroke-width="1.5" opacity="0.4" stroke-dasharray="4 4" />
|
|
40
|
+
</g>
|
|
41
|
+
|
|
42
|
+
<!-- Typography -->
|
|
43
|
+
<g transform="translate(110, 62)">
|
|
44
|
+
<text font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="44" font-weight="800" fill="#FFFFFF" letter-spacing="0.5">
|
|
45
|
+
Py<tspan fill="url(#pylan-grad)">Lan</tspan>
|
|
46
|
+
</text>
|
|
47
|
+
<text x="145" y="-2" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif" font-size="12" font-weight="600" fill="#00E5FF" letter-spacing="1.5" text-transform="uppercase">
|
|
48
|
+
LAN SHARE
|
|
49
|
+
</text>
|
|
50
|
+
</g>
|
|
51
|
+
</svg>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""PyLan - Fast, cross-platform local network file and data sharing.
|
|
2
|
+
|
|
3
|
+
PyLan provides peer discovery, framing protocols, and data transfer
|
|
4
|
+
mechanisms designed for local network environments. It operates both as an
|
|
5
|
+
extensible Python package and as a standalone command-line application or
|
|
6
|
+
graphical user interface.
|
|
7
|
+
|
|
8
|
+
Subpackages:
|
|
9
|
+
cli: Command-line interfaces for scanning, sending, and receiving.
|
|
10
|
+
core: Protocol framing, peer discovery engine, and data models.
|
|
11
|
+
ui: Flet desktop and web graphical user interface module.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
__version__: str = "0.0.3"
|
|
15
|
+
|
|
16
|
+
__all__: list[str] = [
|
|
17
|
+
"__version__",
|
|
18
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Main package entrypoint handling CLI vs GUI dispatch for PyLan."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main() -> None:
|
|
7
|
+
"""Dispatch execution to GUI or CLI based on command-line arguments."""
|
|
8
|
+
if len(sys.argv) > 1 and sys.argv[1] == "gui":
|
|
9
|
+
sys.argv.pop(1)
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import flet as ft
|
|
13
|
+
|
|
14
|
+
from pylan.ui.app import main as ui_main
|
|
15
|
+
|
|
16
|
+
assets_dir = str(Path(__file__).parent / "ui" / "assets")
|
|
17
|
+
app_fn = getattr(ft, "app", None)
|
|
18
|
+
if callable(app_fn):
|
|
19
|
+
app_fn(target=ui_main, assets_dir=assets_dir)
|
|
20
|
+
else:
|
|
21
|
+
ft.run(ui_main, assets_dir=assets_dir)
|
|
22
|
+
else:
|
|
23
|
+
from pylan.cli.cli import cli
|
|
24
|
+
|
|
25
|
+
cli()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
main()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Command-line interface commands and entry points for PyLan.
|
|
2
|
+
|
|
3
|
+
This package provides the console commands and interactive CLI workflows
|
|
4
|
+
for scanning nearby peers, transmitting files over framed TCP connections,
|
|
5
|
+
and hosting the background receiver daemon.
|
|
6
|
+
|
|
7
|
+
Modules:
|
|
8
|
+
cli: Root Click command group registering all CLI subcommands.
|
|
9
|
+
receive: TCP receiver daemon and multicast presence broadcaster.
|
|
10
|
+
scan: Staged local network scanner discovering active PyLan nodes.
|
|
11
|
+
send: Client transfer initiator negotiating and streaming files.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from pylan.cli.cli import cli, gui
|
|
15
|
+
from pylan.cli.receive import receive
|
|
16
|
+
from pylan.cli.scan import scan
|
|
17
|
+
from pylan.cli.send import send
|
|
18
|
+
|
|
19
|
+
__all__: list[str] = [
|
|
20
|
+
"cli",
|
|
21
|
+
"gui",
|
|
22
|
+
"receive",
|
|
23
|
+
"scan",
|
|
24
|
+
"send",
|
|
25
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Click root command group for PyLan CLI."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from pylan.cli.receive import receive
|
|
6
|
+
from pylan.cli.scan import scan
|
|
7
|
+
from pylan.cli.send import send
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@click.group()
|
|
11
|
+
def cli() -> None:
|
|
12
|
+
"""PyLan - Local network file transfer tool."""
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@click.command()
|
|
17
|
+
def gui() -> None:
|
|
18
|
+
"""Launch the PyLan desktop graphical interface."""
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
import flet as ft
|
|
22
|
+
|
|
23
|
+
from pylan.ui.app import main as ui_main
|
|
24
|
+
|
|
25
|
+
assets_dir = str(Path(__file__).parent.parent / "ui" / "assets")
|
|
26
|
+
app_fn = getattr(ft, "app", None)
|
|
27
|
+
if callable(app_fn):
|
|
28
|
+
app_fn(target=ui_main, assets_dir=assets_dir)
|
|
29
|
+
else:
|
|
30
|
+
ft.run(ui_main, assets_dir=assets_dir)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
cli.add_command(scan)
|
|
34
|
+
cli.add_command(receive)
|
|
35
|
+
cli.add_command(send)
|
|
36
|
+
cli.add_command(gui)
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Receiver daemon for the PyLan local network transfer system.
|
|
2
|
+
|
|
3
|
+
This module provides the core listener service for incoming discovery
|
|
4
|
+
handshakes and file transfers. It initializes a persistent TCP server to
|
|
5
|
+
handle probe requests and coordinates periodic multicast announcements to
|
|
6
|
+
ensure active visibility to scanning peers across the local subnet.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import json
|
|
11
|
+
import logging
|
|
12
|
+
import socket
|
|
13
|
+
|
|
14
|
+
import click
|
|
15
|
+
|
|
16
|
+
from pylan.core.discovery import (
|
|
17
|
+
DiscoveryEngine,
|
|
18
|
+
MSG_TYPE_PROBE_REQUEST,
|
|
19
|
+
MSG_TYPE_PROBE_RESPONSE,
|
|
20
|
+
)
|
|
21
|
+
from pylan.core.protocol import (
|
|
22
|
+
MSG_TYPE_TRANSFER_REJECT,
|
|
23
|
+
MSG_TYPE_TRANSFER_REQUEST,
|
|
24
|
+
pack_message,
|
|
25
|
+
read_frame,
|
|
26
|
+
)
|
|
27
|
+
from pylan.core.transfer import parse_transfer_request, receive_file
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def handle_transfer(
|
|
33
|
+
reader: asyncio.StreamReader,
|
|
34
|
+
writer: asyncio.StreamWriter,
|
|
35
|
+
initial_body: bytes,
|
|
36
|
+
output_dir: str,
|
|
37
|
+
) -> None:
|
|
38
|
+
"""Handle incoming file transfer stream."""
|
|
39
|
+
try:
|
|
40
|
+
metadata = parse_transfer_request(initial_body)
|
|
41
|
+
result = await receive_file(reader, writer, output_dir, metadata)
|
|
42
|
+
click.secho(
|
|
43
|
+
f"\nReceived file '{result.file_name}' -> {result.file_path}",
|
|
44
|
+
fg="green",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
except Exception as exc:
|
|
48
|
+
logger.debug("Transfer failed or was rejected: %s", exc)
|
|
49
|
+
try:
|
|
50
|
+
reject = pack_message(
|
|
51
|
+
MSG_TYPE_TRANSFER_REJECT, {"reason": str(exc)}
|
|
52
|
+
)
|
|
53
|
+
writer.write(reject)
|
|
54
|
+
await writer.drain()
|
|
55
|
+
except Exception:
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def handle_client(
|
|
60
|
+
reader: asyncio.StreamReader,
|
|
61
|
+
writer: asyncio.StreamWriter,
|
|
62
|
+
engine: DiscoveryEngine,
|
|
63
|
+
output_dir: str,
|
|
64
|
+
) -> None:
|
|
65
|
+
"""Process incoming framed TCP connections from remote PyLan nodes.
|
|
66
|
+
|
|
67
|
+
Reads and validates binary protocol headers, parses corresponding payload
|
|
68
|
+
bodies, and responds to discovery probes. Non-probe payloads and connection
|
|
69
|
+
errors are logged and cleanly closed without interrupting the server.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
reader: Async stream reader connected to the incoming client socket.
|
|
73
|
+
writer: Async stream writer connected to the incoming client socket.
|
|
74
|
+
engine: DiscoveryEngine instance representing this local peer.
|
|
75
|
+
output_dir: Filesystem path configured to store accepted transfers.
|
|
76
|
+
"""
|
|
77
|
+
try:
|
|
78
|
+
msg_type, body = await read_frame(reader)
|
|
79
|
+
|
|
80
|
+
if msg_type == MSG_TYPE_PROBE_REQUEST:
|
|
81
|
+
try:
|
|
82
|
+
peer_data = json.loads(body.decode("utf-8"))
|
|
83
|
+
logger.debug(
|
|
84
|
+
"Received probe request from %s",
|
|
85
|
+
peer_data.get("alias", "unknown"),
|
|
86
|
+
)
|
|
87
|
+
except Exception as exc:
|
|
88
|
+
logger.debug("Failed to decode probe payload: %s", exc)
|
|
89
|
+
|
|
90
|
+
response_payload = engine.get_announcement_payload()
|
|
91
|
+
reply = pack_message(MSG_TYPE_PROBE_RESPONSE, response_payload)
|
|
92
|
+
writer.write(reply)
|
|
93
|
+
await writer.drain()
|
|
94
|
+
elif msg_type == MSG_TYPE_TRANSFER_REQUEST:
|
|
95
|
+
await handle_transfer(reader, writer, body, output_dir)
|
|
96
|
+
else:
|
|
97
|
+
logger.debug("Received unhandled message type: %d", msg_type)
|
|
98
|
+
except (asyncio.IncompleteReadError, ConnectionResetError) as exc:
|
|
99
|
+
logger.debug("Peer disconnected unexpectedly: %s", exc)
|
|
100
|
+
except Exception as exc:
|
|
101
|
+
logger.debug("Error while handling client connection: %s", exc)
|
|
102
|
+
finally:
|
|
103
|
+
writer.close()
|
|
104
|
+
await writer.wait_closed()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
async def periodic_announce(
|
|
108
|
+
engine: DiscoveryEngine,
|
|
109
|
+
interval: float = 1.0,
|
|
110
|
+
) -> None:
|
|
111
|
+
"""Periodically broadcast multicast UDP announcements across the LAN.
|
|
112
|
+
|
|
113
|
+
Maintains an active presence on the local subnet by continuously invoking
|
|
114
|
+
multicast transmission at regular intervals. Runs until explicitly
|
|
115
|
+
cancelled during daemon shutdown.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
engine: DiscoveryEngine instance providing identity and announcements.
|
|
119
|
+
interval: Delay in seconds between consecutive multicast transmissions.
|
|
120
|
+
"""
|
|
121
|
+
while True:
|
|
122
|
+
try:
|
|
123
|
+
await engine.announce()
|
|
124
|
+
except asyncio.CancelledError:
|
|
125
|
+
break
|
|
126
|
+
except Exception as exc:
|
|
127
|
+
logger.debug("Multicast announcement broadcast failed: %s", exc)
|
|
128
|
+
await asyncio.sleep(interval)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
async def start_receiver_daemon(port: int, output_dir: str) -> None:
|
|
132
|
+
"""Start and supervise the PyLan receiver daemon lifecycle.
|
|
133
|
+
|
|
134
|
+
Binds the local TCP framing listener, joins the discovery multicast
|
|
135
|
+
group, and supervises the periodic announcement background task until
|
|
136
|
+
interrupted. Ensures transports and tasks are terminated cleanly.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
port: TCP port where incoming transfer connections will be accepted.
|
|
140
|
+
output_dir: Destination directory path for storing received data.
|
|
141
|
+
"""
|
|
142
|
+
engine = DiscoveryEngine(
|
|
143
|
+
alias=socket.gethostname(),
|
|
144
|
+
fingerprint="receiver-node",
|
|
145
|
+
tcp_port=port,
|
|
146
|
+
device_model="PyLan Desktop Node",
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
click.echo(f"Device alias : {socket.gethostname()}")
|
|
150
|
+
click.echo(f"Listening on : port {port}")
|
|
151
|
+
click.echo(f"Saving files : {output_dir}")
|
|
152
|
+
click.echo(
|
|
153
|
+
"Ready. Waiting for incoming discovery and file transfers "
|
|
154
|
+
"(Ctrl+C to stop)..."
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
transport = await engine.start_multicast_listener()
|
|
158
|
+
announce_task = asyncio.create_task(
|
|
159
|
+
periodic_announce(engine, interval=1.0)
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
server = await asyncio.start_server(
|
|
164
|
+
lambda r, w: handle_client(r, w, engine, output_dir),
|
|
165
|
+
host="0.0.0.0",
|
|
166
|
+
port=port,
|
|
167
|
+
)
|
|
168
|
+
async with server:
|
|
169
|
+
await server.serve_forever()
|
|
170
|
+
finally:
|
|
171
|
+
announce_task.cancel()
|
|
172
|
+
try:
|
|
173
|
+
await announce_task
|
|
174
|
+
except asyncio.CancelledError:
|
|
175
|
+
pass
|
|
176
|
+
|
|
177
|
+
if transport is not None:
|
|
178
|
+
transport.close()
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
@click.command()
|
|
182
|
+
@click.option(
|
|
183
|
+
"-p",
|
|
184
|
+
"--port",
|
|
185
|
+
default=44000,
|
|
186
|
+
type=int,
|
|
187
|
+
help="Port to listen for incoming connections.",
|
|
188
|
+
)
|
|
189
|
+
@click.option(
|
|
190
|
+
"-o",
|
|
191
|
+
"--output",
|
|
192
|
+
default="./downloads",
|
|
193
|
+
type=click.Path(),
|
|
194
|
+
help="Target folder where received files will be written.",
|
|
195
|
+
)
|
|
196
|
+
def receive(port: int, output: str) -> None:
|
|
197
|
+
"""Start PyLan in receiver mode to listen for peers and incoming files."""
|
|
198
|
+
try:
|
|
199
|
+
asyncio.run(start_receiver_daemon(port, output))
|
|
200
|
+
except KeyboardInterrupt:
|
|
201
|
+
click.echo("\nReceiver stopped.")
|