-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
68 lines (54 loc) · 2.29 KB
/
config.py
File metadata and controls
68 lines (54 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Global configuration and identity
import os
import socket
import base64
# util function to get (returns) the local IP address
def get_local_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# connect to a public server to determine outbound IP
# creates fake connection to Google's public DNS server "("8.8.8.8", 80)"
s.connect(("8.8.8.8", 80))
return s.getsockname()[0] # local IP assigned by router
except Exception:
# loopback if detection fails
return "127.0.0.1" # localhost
finally:
s.close()
# Network Configuration
VERBOSE = True
PORT = 50999 # port used for LSNP communication
BROADCAST_IP = "<broadcast>" # IP for broadcasting to local subnet
BUFFER_SIZE = 65535 # max size for incoming UDP packets
# Avatar Config
AVATAR_TYPE = "image/png" # MIME type (optional)
AVATAR_ENCODING = "base64" # Encoding (optional)
# You can load the image only once and encode it to base64
def load_avatar_base64(path="avatar.png"):
try:
with open(path, "rb") as img_file:
encoded = base64.b64encode(img_file.read()).decode("utf-8")
print(f"[CONFIG] Avatar loaded from '{path}' ({AVATAR_TYPE}, {AVATAR_ENCODING})")
return encoded
except FileNotFoundError:
print(f"[CONFIG] No avatar file found at '{path}'. Skipping avatar.")
return None
AVATAR_DATA = load_avatar_base64("assets/avatar.png")
# User Identity (EDIT THIS)
LOCAL_IP = get_local_ip() # local IP
USER_ID = f"jansen@{LOCAL_IP}" # full user ID
DISPLAY_NAME = "Jay Mortega"[:50] # name shown in GUI/logs
STATUS = "Exploring LSNP!"[:100] # default status message
# Token & Messaging Settings
TOKEN_TTL = 3600 # token time-to-live (1 hour)
MESSAGE_EXPIRY = 3600 # maximum age of incoming messages (1 hour)
# Default Token Scopes by Feature
DEFAULT_SCOPE = {
"post": "broadcast", # posts to the network
"dm": "chat", # dm
"follow": "follow", # follow/unfollow
"like": "broadcast", # likes/unlikes
"file": "file", # file transfer
"group": "group", # group management
"game": "game" # tic tac toe
}