Skip to content

Commit c5464ba

Browse files
authored
Cleanup for v0.8 (#43)
1 parent e354c33 commit c5464ba

File tree

7 files changed

+150
-73
lines changed

7 files changed

+150
-73
lines changed

ReadME.md renamed to README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22

33
![Pylint_score](./pylint.svg)
44

5-
[![Ubuntu Build](http://54.144.142.244:8080/buildStatus/icon?job=nostpy-build-containers-docker-compose-up&subject=Ubuntu%20Build)](http://54.144.142.244:8080/job/nostpy-build-containers-docker-compose-up/)
6-
7-
[![Ubuntu Build](http://54.144.142.244:8080/buildStatus/icon?job=nostpy-build-containers-docker-compose-up/branch/optimize&subject=Dev%20Branch)](http://54.144.142.244:8080/job/nostpy-build-containers-docker-compose-up/)
8-
9-
10-
A simple and easy to deploy nostr relay using `asyncio` & `websockets` to server Nostr clients
5+
A purely Python, easy to deploy nostr relay using `asyncio` & `websockets` to server Nostr clients
116

127
## Description
138

149
![Image 2023-09-15 at 9 53 46 AM](https://github.com/UTXOnly/nost-py/assets/49233513/724cfbeb-03a0-4d10-b0d1-6b638ac153c4)
1510

1611

1712

18-
A containerized Python relay paried with a Postgres databse, reachable via a NGINX reverse proxy. This has been tested on [Coracle](https://coracle.social), [Iris.to](https://Iris.to) and [Snort.social](https://Snort.social) clients and works for the NIPS listed below.
13+
A containerized Python relay paried with a Postgres databse, reachable via a NGINX reverse proxy. This has been tested on [Nostrudel](https://nostrudel.ninja/), [Iris.to](https://Iris.to) and [Snort.social](https://Snort.social) clients and works for the NIPS listed below.
1914

2015
Numerous branches in development, trying to improve performance, reliability and ease of use. The Datadog branch deploys a Datadog agent container to collect logs, metrics and traces to better observe application performance.
2116

@@ -45,6 +40,9 @@ DD_API_KEY=<YOUR_DATADOG_API_KEY>
4540
DOMAIN_NAME=<YOUR_DOMAIN_NAME>
4641
HEX_PUBKEY=<YOUR_HEX_PUBLIC_KEY_FOR_NIP_11>
4742
CONTACT=<YOUR_EMAIL_OR_NPUB>
43+
ENV_FILE_PATH=./docker_stuff/.env
44+
NGINX_FILE_PATH=/etc/nginx/sites-available/default
45+
VERSION=v0.8
4846
4947
```
5048

@@ -58,12 +56,18 @@ python3 menu.py
5856

5957
This will bring up the menu below and you can control the program from there!
6058

59+
**Usage notes**
60+
* Option 1 `Execute server setup script` needs to be run to create the `relay_service` user and set proper file permissions
61+
* After creating the `.env` that file is meant to stay encrypted(encrypted suring `Execute server script`), option2 `Start Nostpy relay` will not run unless the file is encypted
62+
* You can encrypt/decrypt the file with option 5
63+
6164

6265

6366
![Image 2023-09-15 at 8 44 45 AM](https://github.com/UTXOnly/nost-py/assets/49233513/ee40d91c-2e6a-48a8-a0a8-c14e25e8ff07)
6467

6568

66-
![image](https://github.com/UTXOnly/nost-py/assets/49233513/c970f4a8-8af3-4b23-a6fe-3fc9bac49ec0)
69+
![Screenshot from 2024-02-23 21-15-49](https://github.com/UTXOnly/nost-py/assets/49233513/2119a053-3ebf-42b5-a996-2ccb87651c9e)
70+
6771

6872

6973
### Install demo
@@ -83,14 +87,15 @@ This is relay is actively worked on, it's is only a proof of concept right now.
8387
- [x] NIP-01: Basic protocol flow description
8488
- [x] NIP-02: Contact list and petnames
8589
- [x] NIP-04: Encrypted Direct Message
86-
- [] NIP-09: Event deletion
90+
- [x] NIP-09: Event deletion
8791
- [x] NIP-11: Relay information document
8892
- [] NIP-11a: Relay Information Document Extensions
89-
- [] NIP-12: Generic tag queries
9093
- [] NIP-13: Proof of Work
9194
- [x] NIP-15: End of Stored Events Notice
9295
- [x] NIP-16: Event Treatment
9396
- [x] NIP-25: Reactions
97+
- [x] NIP-50: Search Capability
98+
- [x] NIP-99: Classified Listings
9499

95100
### Contributing
96101

build_env.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@
22

33
try:
44
subprocess.run(["sudo", "apt-get", "update", "-y"], check=True)
5-
subprocess.run(["sudo", "apt-get", "install", "-y", "docker-compose", "nginx", "certbot", "python3.10-venv", "python3-certbot-nginx", "acl"], check=True)
6-
7-
subprocess.run(['python3', '-m', 'venv', 'snmpenv'], check=True)
8-
5+
subprocess.run(
6+
[
7+
"sudo",
8+
"apt-get",
9+
"install",
10+
"-y",
11+
"docker-compose",
12+
"nginx",
13+
"certbot",
14+
"python3.10-venv",
15+
"python3-certbot-nginx",
16+
"acl",
17+
],
18+
check=True,
19+
)
20+
21+
subprocess.run(["python3", "-m", "venv", "snmpenv"], check=True)
22+
923
# Activate the virtual environment and run subsequent commands within it (runs prepare server script in venv)
10-
activate_cmd = '. snmpenv/bin/activate && '
24+
activate_cmd = ". snmpenv/bin/activate && "
1125
commands = [
12-
'pip install --upgrade pip',
13-
'pip install -r requirements.txt',
14-
'python prepare_server.py'
26+
"pip install --upgrade pip",
27+
"pip install -r requirements.txt",
28+
"python prepare_server.py",
1529
]
1630
for cmd in commands:
17-
subprocess.run(['sudo', 'bash', '-c', activate_cmd + cmd], check=True)
31+
subprocess.run(["sudo", "bash", "-c", activate_cmd + cmd], check=True)
1832

1933
except subprocess.CalledProcessError as e:
2034
print(f"An error occurred while executing the command: {e}")

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## v0.8
2+
3+
**Enhancements**
4+
* Completed feature request [#37 [FR] Support for NIP-50 (search capability) for both content and tags](https://github.com/UTXOnly/nost-py/issues/37)
5+
* Support for [NIP-50](https://github.com/nostr-protocol/nips/blob/master/50.md#nip-50) search queries
6+
* Searches `tags` and `content` fields
7+
* Compatible with searching [NIP-99 Classified Listings](https://github.com/nostr-protocol/nips/blob/master/99.md)
8+
9+
**Bug fixes**
10+
* Fixed [#39 [BUG] Escape characters included in tag query](https://github.com/UTXOnly/nost-py/issues/39)
11+
* Fixed [#40 unbounded query limit](https://github.com/UTXOnly/nost-py/issues/40)
12+
113
## v0.7
214
**Enhancements**
315
* Re-added redis cache to serve frequent queries faster

docker_stuff/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ HEX_PUBKEY=<YOUR_HEX_PUBKEY>
1313
1414
ENV_FILE_PATH=./docker_stuff/.env
1515
NGINX_FILE_PATH=/etc/nginx/sites-available/default
16-
VERSION=v0.6
16+
VERSION=v0.8

menu.py

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,35 @@
88
def print_color(text, color):
99
print(f"\033[1;{color}m{text}\033[0m")
1010

11+
1112
# Function to start Nostpy relay
1213
def start_nostpy_relay():
1314
try:
1415
success, pass_holder = file_encryption.decrypt_file("./docker_stuff/.env")
1516
if not success:
16-
print("Decryption failed, file is not encrypted please encrypt file and rerun command")
17+
print(
18+
"Decryption failed, file is not encrypted please encrypt file and rerun command"
19+
)
1720
return
18-
21+
1922
os.chdir("./docker_stuff")
2023
file_path = "./postgresql/"
21-
24+
2225
if os.path.exists(file_path):
23-
subprocess.run(["sudo", "setfacl", "-R", "-m", "u:relay_service:rwx", file_path], check=True)
26+
subprocess.run(
27+
["sudo", "setfacl", "-R", "-m", "u:relay_service:rwx", file_path],
28+
check=True,
29+
)
2430
else:
2531
print("File does not exist. Skipping the command.")
2632

2733
subprocess.run(["ls", "-al"], check=True)
2834
subprocess.run(["groups", "relay_service"], check=True)
29-
subprocess.run(["sudo", "-u", "relay_service", "docker-compose", "up", "-d"], check=True)
35+
subprocess.run(
36+
["sudo", "-u", "relay_service", "docker-compose", "up", "-d"], check=True
37+
)
3038
os.chdir("..")
31-
39+
3240
# Re-encrypt env file to keep it encrypted when not in use
3341
file_encryption.encrypt_file(filename="./docker_stuff/.env", key=pass_holder)
3442
except subprocess.CalledProcessError as e:
@@ -37,12 +45,15 @@ def start_nostpy_relay():
3745
print(f"Error occurred during decryption: {e}")
3846
return
3947

48+
4049
# Function to destroy all Docker containers and images
4150
def destroy_containers_and_images():
4251
try:
4352
# Change directory to the Docker stuff folder
4453
os.chdir("./docker_stuff")
45-
subprocess.run(["sudo", "-u", "relay_service", "docker-compose", "down"], check=True)
54+
subprocess.run(
55+
["sudo", "-u", "relay_service", "docker-compose", "down"], check=True
56+
)
4657

4758
# Delete container images by their name
4859
image_names = [
@@ -55,20 +66,36 @@ def destroy_containers_and_images():
5566
]
5667

5768
for image_name in image_names:
58-
subprocess.run(["sudo", "-u", "relay_service", "docker", "image", "rm", "-f", image_name], check=True)
69+
subprocess.run(
70+
[
71+
"sudo",
72+
"-u",
73+
"relay_service",
74+
"docker",
75+
"image",
76+
"rm",
77+
"-f",
78+
image_name,
79+
],
80+
check=True,
81+
)
5982
os.chdir("..")
6083
except subprocess.CalledProcessError as e:
6184
print_color(f"Error occurred: {e}", "31")
6285

86+
6387
def stop_containers():
6488
try:
6589
# Change directory to the Docker stuff folder
6690
os.chdir("./docker_stuff")
67-
subprocess.run(["sudo", "-u", "relay_service", "docker-compose", "down"], check=True)
91+
subprocess.run(
92+
["sudo", "-u", "relay_service", "docker-compose", "down"], check=True
93+
)
6894
os.chdir("..")
6995
except subprocess.CalledProcessError as e:
7096
print_color(f"Error occurred: {e}", "31")
7197

98+
7299
# Function to switch branches
73100
def switch_branches():
74101
try:
@@ -79,20 +106,24 @@ def switch_branches():
79106
except subprocess.CalledProcessError as e:
80107
print_color(f"Error occurred: {e}", "31")
81108

109+
82110
# Function to execute setup.py script
83111
def execute_setup_script():
84112
try:
85113
subprocess.run(["python3", "build_env.py"], check=True)
86114
except subprocess.CalledProcessError as e:
87115
print_color(f"Error occurred: {e}", "31")
88116

117+
89118
def decrypt_env():
90119
while True:
91120
print_color("\n1) Decrypt file", "32")
92121
print_color("2) Encrypt file", "31")
93122
print_color("3) Return to main menu", "33")
94-
option = input("\nEnter 1 to decrypt, 2 to encrypt the file, or 3 to return to the main menu: \n")
95-
123+
option = input(
124+
"\nEnter 1 to decrypt, 2 to encrypt the file, or 3 to return to the main menu: \n"
125+
)
126+
96127
if option == "1":
97128
print_color("Decrypting your .env file", "32")
98129
file_encryption.decrypt_file(encrypted_filename="./docker_stuff/.env")
@@ -105,46 +136,36 @@ def decrypt_env():
105136
else:
106137
print_color("Invalid option. Please enter either 1, 2, or 3.", "31")
107138

139+
108140
def setup_dbm():
109-
110-
#try:
111-
# pkg_resources.get_distribution('psycopg2-binary')
112-
# print("psycopg2-binary is already installed")
113-
#except pkg_resources.DistributionNotFound:
114-
# try:
115-
# subprocess.run(["pip3", "install", "psycopg2-binary==2.9.1"], check=True)
116-
# print("psycopg2-binary successfully installed")
117-
# except subprocess.CalledProcessError as e:
118-
# print(f"Error occurred while installing psycopg2-binary: {e}")
119-
120141
try:
121-
#subprocess.run(["python3", "./docker_stuff/dbm_setup.py"], check=True)
122-
subprocess.run(['python3', '-m', 'venv', 'snmpenv'], check=True)
142+
subprocess.run(["python3", "-m", "venv", "snmpenv"], check=True)
123143

124-
activate_cmd = '. snmpenv/bin/activate && '
125-
commands = [
126-
'python ./docker_stuff/dbm_setup.py'
127-
]
144+
activate_cmd = ". snmpenv/bin/activate && "
145+
commands = ["python ./docker_stuff/dbm_setup.py"]
128146
for cmd in commands:
129-
subprocess.run(['bash', '-c', activate_cmd + cmd], check=True)
147+
subprocess.run(["bash", "-c", activate_cmd + cmd], check=True)
130148
except subprocess.CalledProcessError as e:
131149
print(f"Error occurred while running dbm_setup.py: {e}")
132150

133151

134-
135-
136-
137152
while True:
138-
print_color("\n##########################################################################################", "31")
139-
print_color(""" \n
153+
print_color(
154+
"\n##########################################################################################",
155+
"31",
156+
)
157+
print_color(
158+
""" \n
140159
███╗ ██╗ ██████╗ ███████╗████████╗██████╗ ██╗ ██╗
141160
████╗ ██║██╔═══██╗██╔════╝╚══██╔══╝██╔══██╗╚██╗ ██╔╝
142161
██╔██╗ ██║██║ ██║███████╗ ██║ ██████╔╝ ╚████╔╝
143162
██║╚██╗██║██║ ██║╚════██║ ██║ ██╔═══╝ ╚██╔╝
144163
██║ ╚████║╚██████╔╝███████║ ██║ ██║ ██║
145164
╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝
146165
147-
""" , "34")
166+
""",
167+
"34",
168+
)
148169
print("\nPlease select an option:\n")
149170
print_color("1) Execute server setup script", "33")
150171
print_color("2) Start Nostpy relay", "32")
@@ -155,7 +176,6 @@ def setup_dbm():
155176
print_color("7) Setup database monitoring", "32")
156177
print_color("8) Exit menu", "31")
157178

158-
159179
options = {
160180
"1": execute_setup_script,
161181
"2": start_nostpy_relay,
@@ -164,9 +184,9 @@ def setup_dbm():
164184
"5": decrypt_env,
165185
"6": stop_containers,
166186
"7": setup_dbm,
167-
"8": lambda: print_color("Exited menu", "31")
187+
"8": lambda: print_color("Exited menu", "31"),
168188
}
169-
189+
170190
try:
171191
choice = input("\nEnter an option number (1-8): ")
172192
if choice in options:

0 commit comments

Comments
 (0)