114 lines
3.2 KiB
Markdown
114 lines
3.2 KiB
Markdown
# nu (ν)
|
||
|
||
# Running
|
||
|
||
## Configuration
|
||
|
||
The application can be configured using a `.env` file. Here are the available options:
|
||
|
||
`RESPONSE_TIMEOUT`
|
||
|
||
- Specifies the response timeout in seconds.
|
||
|
||
- Default: `5`
|
||
|
||
- Example: `RESPONSE_TIMEOUT=5`
|
||
|
||
`CLIENT_IDLE_TIMEOUT`
|
||
|
||
- Defines the client idle timeout in seconds.
|
||
|
||
- Default: `60`
|
||
|
||
- Example: `CLIENT_IDLE_TIMEOUT=60`
|
||
|
||
`VERBOSITY`
|
||
|
||
- Determines the logging verbosity level.
|
||
|
||
- Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL.
|
||
|
||
- Default: `INFO`
|
||
|
||
- Example: `VERBOSITY=DEBUG`
|
||
|
||
`SCAN_PORT_RANGE`
|
||
|
||
- Defines the port range to scan as `PORT:PORT` separated by colon (`:`).
|
||
|
||
- The ports must be valid and there must be exactly two of them.
|
||
|
||
- Example: `SCAN_PORT_RANGE=65525:65535`
|
||
|
||
`IP`
|
||
|
||
- Manually set the IP address.
|
||
|
||
- Example: `IP=127.0.0.1`
|
||
|
||
## Running
|
||
|
||
The application requires a few dependenices, specified in `requirements.txt`.
|
||
|
||
To install these dependencies run
|
||
|
||
```bash
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
Upon successful installation, the program is ready to run. The database used is SQLite, hence no SQL structure is needed to be imported, nor are any credentials required.
|
||
|
||
To run the app, run
|
||
|
||
```bash
|
||
python src/app.py
|
||
```
|
||
|
||
If the verbosity set in `.env` is `DEBUG`, the program will print many useful descriptions of it's actions together with a detailed location of the action including file, line and process name.
|
||
|
||
## Definitions
|
||
|
||
The program uses the following protocol over TCP
|
||
|
||
| Operation | Request Format | Response Format |
|
||
| ---------------------- | -------------------------------- | --------------- |
|
||
| Bank code | BC | BC \<ip\> |
|
||
| Account create | AC \<account\>/\<ip\> | AC |
|
||
| Account deposit | AD \<account\>/\<ip\> \<number\> | AD |
|
||
| Account withdrawal | AW \<account\>/\<ip\> \<number\> | AW |
|
||
| Account balance | AB \<account\>/\<ip\> | AB \<number\> |
|
||
| Account remove | AR \<account\>/\<ip\> | AR |
|
||
| Bank (total) amount | BA | BA \<number\> |
|
||
| Bank number of clients | BN | BN \<number\> |
|
||
|
||
Any of these commands may return an error message in format
|
||
|
||
`ER <message>`
|
||
|
||
## Sources
|
||
|
||
### Signal catching
|
||
|
||
- [Catch SIGTERM](https://dnmtechs.com/graceful-sigterm-signal-handling-in-python-3-best-practices-and-implementation/)
|
||
- [Windows termination signals](https://stackoverflow.com/a/35792192)
|
||
- ~~[Get ENUM name from value](https://stackoverflow.com/a/38716384)~~
|
||
Unused because of required compatibility with lower version python (3.9)
|
||
|
||
### Networking
|
||
|
||
- [Dynamically finding host IP address](https://stackoverflow.com/a/28950776)
|
||
- [IP Regex](https://ihateregex.io/expr/ip/)
|
||
|
||
### Database
|
||
|
||
- [SqlAlchemy session generator](https://stackoverflow.com/a/71053353)
|
||
- [Error handling decorator](https://chatgpt.com/share/67a46109-d38c-8005-ac36-677e6511ddcd)
|
||
|
||
### Platform specific problems
|
||
|
||
- [Windows sends partial data](https://stackoverflow.com/a/31754798)
|
||
|
||
### Threading
|
||
|
||
- [Events to stop scan](https://www.instructables.com/Starting-and-Stopping-Python-Threads-With-Events-i/)
|