Implemented Synapse Ping as heartbeat for connection between synapse and RMASS Bridge. Also implemented set online action to update RMASS presence

This commit is contained in:
Lyncoln
2026-10-30 17:19:03 -04:00
parent b3094f75a9
commit 2c2a41fafb
5 changed files with 122 additions and 76 deletions
+4 -11
View File
@@ -7,14 +7,6 @@ from core.runtime.createruntime import outputs
def buildListener(listener, self):
if self.path == "/_matrix/app/v1/ping":
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(b"{}")
return
if self.path.startswith(listener.acceptpath):
#Prints can used buildlog for listener runtime
@@ -32,12 +24,13 @@ def buildListener(listener, self):
allow, status_code = buildFirewall(listener, outputs)
if allow:
from core.execution.createthread import buildThread
#from core.execution.createthread import buildThread
from core.execution.executioncontract import executeContract
logging.info(outputs["firewall_allowed"])
thread = buildThread(listener.execute)
#thread = buildThread(listener.execute)
executeContract(listener.execute)
self.send_response(status_code)
+69 -56
View File
@@ -8,90 +8,103 @@ from .dispatcher import dispatchRequest
from .createresponse import buildResponse
from plugins.rmass.listeners import synapselistener
from core.server.createlistener import buildListener
#from plugins.rmass.actions import pingsynapse
from plugins.rmass.actions import synapsesetbridgeonline
port = int(os.environ.get("SERVER_PORT", 19001))
class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
#lifecycles = {}
print("POST request received")
if self.path == "/_matrix/app/v1/ping":
max_request_size = 1024
from core.execution.createthread import buildThread
thread = buildThread(synapsesetbridgeonline)
content_length = self.headers.get("Content-Length")
# Check whether Content-Length exists
if content_length is None:
response = {
"status": "error",
"message": "Content length required"
}
status = 411
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"{}")
return
else:
# Attempt to convert the header into an integer
try:
length = int(content_length)
except ValueError:
length = None
#lifecycles = {}
print("POST request received")
# Validate the converted length
if length is None:
max_request_size = 1024
content_length = self.headers.get("Content-Length")
# Check whether Content-Length exists
if content_length is None:
response = {
"status": "error",
"message": "Invalid Content-Length"
"message": "Content length required"
}
status = 400
elif length < 0:
response = {
"status": "error",
"message": "Bad Request"
}
status = 400
elif length > max_request_size:
response = {
"status": "error",
"message": "Content exceeds maximum request size"
}
status = 413
status = 411
else:
# Content-Length is valid, so read the body
data = self.rfile.read(length)
# Attempt to convert the header into an integer
try:
request = json.loads(data)
length = int(content_length)
except ValueError:
length = None
except json.JSONDecodeError:
# Validate the converted length
if length is None:
response = {
"status": "error",
"message": "Invalid JSON received"
"message": "Invalid Content-Length"
}
status = 400
elif length < 0:
response = {
"status": "error",
"message": "Bad Request"
}
status = 400
elif length > max_request_size:
response = {
"status": "error",
"message": "Content exceeds maximum request size"
}
status = 413
else:
# Only valid JSON reaches the dispatcher
thread, lifecycles, module, mode = dispatchRequest(
request, lifecycles
)
# Content-Length is valid, so read the body
data = self.rfile.read(length)
response = buildResponse(module, thread, mode)
status = 200
try:
request = json.loads(data)
# Serialize the response
responsebytes = json.dumps(response).encode("utf-8")
except json.JSONDecodeError:
response = {
"status": "error",
"message": "Invalid JSON received"
}
status = 400
# Send one HTTP response
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(responsebytes)))
self.end_headers()
else:
# Only valid JSON reaches the dispatcher
thread, lifecycles, module, mode = dispatchRequest(
request, lifecycles
)
self.wfile.write(responsebytes)
response = buildResponse(module, thread, mode)
status = 200
# Serialize the response
responsebytes = json.dumps(response).encode("utf-8")
# Send one HTTP response
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(responsebytes)))
self.end_headers()
self.wfile.write(responsebytes)
def do_PUT(self):
+9 -7
View File
@@ -5,8 +5,8 @@ import os
from core.server.server import startServer
from core.execution.createthread import buildThread
from plugins.rmass.monitors import rmassmonitor
#from plugins.rmass.actions import refresh_tokens
from plugins.rmass.operations import token_update
from plugins.rmass.actions import pingsynapse
from core.console import console
from rich.logging import RichHandler
@@ -28,6 +28,13 @@ logging.basicConfig(
import login
import synapsemessagepush
thread = threading.Thread(
target=startServer,
name="RMASS Bridge Server"
)
thread.start()
pingsynapse.mode = "continuous"
rmassmonitor.mode = "continuous"
token_update.mode = "continuous"
#refresh_tokens.mode = "continuous"
@@ -38,9 +45,4 @@ thread = buildThread(rmassmonitor)
thread = buildThread(token_update)
thread = threading.Thread(
target=startServer,
#args=(module, lifecycles)
name="RMASS Bridge Server"
)
thread.start()
thread = buildThread(pingsynapse)
+4 -2
View File
@@ -1,11 +1,13 @@
name = "Synapse Wake"
name = "Synapse Ping"
kind = "action"
alias = "synapseping"
alias = "pingsynapse"
showstatus = True
sleeptime = 15
isrequest = True
method = "POST"
@@ -0,0 +1,36 @@
name = "Set RMASS Bridge Online"
kind = "action"
alias = "setrmassbridgeonline"
showstatus = True
#sleeptime = 15
isrequest = True
method = "PUT"
path = [
"https://loxthelion.com/_matrix/client/v3/presence/@rmass_bridge:loxthelion.com/status",
]
headers = {
"Authorization": {
"os": "AS_TOKEN",
"prefix": "Bearer ",
},
"Content-Type": "application/json",
}
keys = [
{
"keytitle": "presence",
"keyvalue": "online",
},
{
"keytitle": "status_msg",
"keyvalue": "RMASS Bridge Connected",
},
]