Working handler to handler
This commit is contained in:
parent
69a399b928
commit
61e09c7602
|
@ -9,12 +9,12 @@
|
||||||
"address" : "0.0.0.0"
|
"address" : "0.0.0.0"
|
||||||
},
|
},
|
||||||
"tcp6" : {
|
"tcp6" : {
|
||||||
"port" : "2225",
|
"port" : "2224",
|
||||||
"address" : "::"
|
"address" : "::"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"handlers" : {
|
"handlers" : {
|
||||||
"availableTypes" : ["type1"],
|
"availableTypes" : ["type1", "type2"],
|
||||||
"typeMap" : {
|
"typeMap" : {
|
||||||
"type1" : {"handlerBinary" : "aBin", "unixDomainSocketPath" : "aSock"},
|
"type1" : {"handlerBinary" : "aBin", "unixDomainSocketPath" : "aSock"},
|
||||||
"type2" : {"handlerBinary" : "bBin", "unixDomainSocketPath" : "bSock"}
|
"type2" : {"handlerBinary" : "bBin", "unixDomainSocketPath" : "bSock"}
|
||||||
|
|
|
@ -179,6 +179,8 @@ public final class BesterConnection : Thread
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Collect return value */
|
/* TODO: Collect return value */
|
||||||
HandlerResponse handlerResponse = chosenHandler.handleMessage(payloadData);
|
HandlerResponse handlerResponse = chosenHandler.handleMessage(payloadData);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import utils.debugging : debugPrint;
|
||||||
import handlers.response;
|
import handlers.response;
|
||||||
import base.net;
|
import base.net;
|
||||||
import connection.message;
|
import connection.message;
|
||||||
|
import server.server : BesterServer;
|
||||||
|
|
||||||
public final class MessageHandler
|
public final class MessageHandler
|
||||||
{
|
{
|
||||||
|
@ -22,12 +23,15 @@ public final class MessageHandler
|
||||||
/* The UNIX domain socket path */
|
/* The UNIX domain socket path */
|
||||||
public string socketPath;
|
public string socketPath;
|
||||||
|
|
||||||
|
/* The BesterServer being used */
|
||||||
|
public BesterServer server;
|
||||||
|
|
||||||
public Socket getSocket()
|
public Socket getSocket()
|
||||||
{
|
{
|
||||||
return domainSocket;
|
return domainSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
this(string executablePath, string socketPath, string pluginName)
|
this(BesterServer server, string executablePath, string socketPath, string pluginName)
|
||||||
{
|
{
|
||||||
/* Set the plugin name */
|
/* Set the plugin name */
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
|
@ -37,6 +41,9 @@ public final class MessageHandler
|
||||||
|
|
||||||
/* Set the socket path */
|
/* Set the socket path */
|
||||||
this.socketPath = socketPath;
|
this.socketPath = socketPath;
|
||||||
|
|
||||||
|
/* Set the server this handler is associated with */
|
||||||
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getPluginName()
|
public string getPluginName()
|
||||||
|
@ -134,7 +141,7 @@ public final class MessageHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Implement me */
|
/* TODO: Implement me */
|
||||||
public static MessageHandler[] constructHandlers(JSONValue handlerBlock)
|
public static MessageHandler[] constructHandlers(BesterServer server, JSONValue handlerBlock)
|
||||||
{
|
{
|
||||||
/* List of loaded message handlers */
|
/* List of loaded message handlers */
|
||||||
MessageHandler[] handlers;
|
MessageHandler[] handlers;
|
||||||
|
@ -158,7 +165,7 @@ public final class MessageHandler
|
||||||
string[2] configuration = getConfigurationArray(pluginName, typeMap);
|
string[2] configuration = getConfigurationArray(pluginName, typeMap);
|
||||||
debugPrint("Module executable at: \"" ~ configuration[0] ~ "\"");
|
debugPrint("Module executable at: \"" ~ configuration[0] ~ "\"");
|
||||||
debugPrint("Module socket path at: \"" ~ configuration[1] ~ "\"");
|
debugPrint("Module socket path at: \"" ~ configuration[1] ~ "\"");
|
||||||
MessageHandler constructedMessageHandler = new MessageHandler(configuration[0], configuration[1], pluginName);
|
MessageHandler constructedMessageHandler = new MessageHandler(server, configuration[0], configuration[1], pluginName);
|
||||||
handlers ~= constructedMessageHandler;
|
handlers ~= constructedMessageHandler;
|
||||||
debugPrint("Module \"" ~ pluginName ~ "\" loaded");
|
debugPrint("Module \"" ~ pluginName ~ "\" loaded");
|
||||||
}
|
}
|
||||||
|
@ -206,6 +213,6 @@ public final class MessageHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return new HandlerResponse(this, response);
|
return new HandlerResponse(server, this, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -30,10 +30,9 @@ public final class HandlerResponse
|
||||||
/* The handler that caused such a response to be illicited */
|
/* The handler that caused such a response to be illicited */
|
||||||
private MessageHandler handler;
|
private MessageHandler handler;
|
||||||
|
|
||||||
/* The BesterServer being used */
|
private BesterServer server;
|
||||||
public static BesterServer server;
|
|
||||||
|
|
||||||
this(MessageHandler handler, JSONValue messageResponse)
|
this(BesterServer server, MessageHandler handler, JSONValue messageResponse)
|
||||||
{
|
{
|
||||||
/* Set the message-handler's response message */
|
/* Set the message-handler's response message */
|
||||||
this.messageResponse = messageResponse;
|
this.messageResponse = messageResponse;
|
||||||
|
@ -42,6 +41,7 @@ public final class HandlerResponse
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
|
|
||||||
writeln("Heyo ", server);
|
writeln("Heyo ", server);
|
||||||
|
this.server= server;
|
||||||
|
|
||||||
/* Attempt parsing the message and error checking it */
|
/* Attempt parsing the message and error checking it */
|
||||||
parse(messageResponse);
|
parse(messageResponse);
|
||||||
|
|
|
@ -72,20 +72,13 @@ public final class BesterServer
|
||||||
/* TODO: Bounds check and JSON type check */
|
/* TODO: Bounds check and JSON type check */
|
||||||
debugPrint("Setting up message handlers...");
|
debugPrint("Setting up message handlers...");
|
||||||
setupHandlers(config["handlers"]);
|
setupHandlers(config["handlers"]);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the `server` field in the HandlerResponse class
|
|
||||||
* to be this server.
|
|
||||||
*/
|
|
||||||
HandlerResponse.server = this;
|
|
||||||
writeln("jdfjfdhhjfh", HandlerResponse.server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupHandlers(JSONValue handlerBlock)
|
private void setupHandlers(JSONValue handlerBlock)
|
||||||
{
|
{
|
||||||
/* TODO: Implement me */
|
/* TODO: Implement me */
|
||||||
debugPrint("Constructing message handlers...");
|
debugPrint("Constructing message handlers...");
|
||||||
handlers = MessageHandler.constructHandlers(handlerBlock);
|
handlers = MessageHandler.constructHandlers(this, handlerBlock);
|
||||||
writeln(handlers[0].getPluginName());
|
writeln(handlers[0].getPluginName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ def sendAs(username):
|
||||||
d.connect(("127.0.0.1",2223))
|
d.connect(("127.0.0.1",2223))
|
||||||
|
|
||||||
# First do it and authenticate
|
# First do it and authenticate
|
||||||
bys=json.dumps({"header":{"authentication":{"username":username, "password":"passwd"}, "scope":"client"},"payload":{"data":{"bruhMsg":input("Enter message naaier: ")},"type":"type1"}})
|
bys=json.dumps({"header":{"authentication":{"username":username, "password":"passwd"}, "scope":"client"},"payload":{"data":{"bruhMsg":input("Enter message naaier: ")},"type":"type2"}})
|
||||||
print(len(bys), bys)
|
print(len(bys), bys)
|
||||||
d.send(len(bys).to_bytes(4, "little"))
|
d.send(len(bys).to_bytes(4, "little"))
|
||||||
d.send(bys.encode())
|
d.send(bys.encode())
|
||||||
|
|
||||||
# Loop prompt and sending of message to tbk
|
# Loop prompt and sending of message to tbk
|
||||||
while True:
|
while True:
|
||||||
bys=json.dumps({"header":{"authentication":{"username":"ddd", "password":"passwd"}, "scope":"client"},"payload":{"data":{"bruhMsg":input("Enter message naaier: ")},"type":"type1"}})
|
bys=json.dumps({"header":{"authentication":{"username":"ddd", "password":"passwd"}, "scope":"client"},"payload":{"data":{"bruhMsg":input("Enter message naaier: ")},"type":"type2"}})
|
||||||
print(len(bys), bys)
|
print(len(bys), bys)
|
||||||
d.send(len(bys).to_bytes(4, "little"))
|
d.send(len(bys).to_bytes(4, "little"))
|
||||||
d.send(bys.encode())
|
d.send(bys.encode())
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import socket
|
||||||
|
import json
|
||||||
|
|
||||||
|
def runTest():
|
||||||
|
d=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
d.bind("../aSock")
|
||||||
|
d.listen()
|
||||||
|
while True:
|
||||||
|
print("Waiting for connection to (this) handler...")
|
||||||
|
s = d.accept()[0]
|
||||||
|
|
||||||
|
size=int.from_bytes(s.recv(4), "little")
|
||||||
|
receivedBys = json.loads(s.recv(size).decode())
|
||||||
|
print(receivedBys)
|
||||||
|
|
||||||
|
#bys = json.dumps({
|
||||||
|
# "header" : {
|
||||||
|
# "status" : "0",
|
||||||
|
# "command" : {"type" : "sendClients", "data": ["tbk", "skippy"]}
|
||||||
|
# }, "data" : receivedBys })
|
||||||
|
#print(s.send(len(bys).to_bytes(4, "little")))
|
||||||
|
#print(s.send(bys.encode()))
|
||||||
|
|
||||||
|
bys = json.dumps({
|
||||||
|
"header" : {
|
||||||
|
"status" : "0",
|
||||||
|
"command" : {"type" : "sendServers", "data": ["10.1.0.7:2223"]}
|
||||||
|
}, "data" : receivedBys })
|
||||||
|
print(s.send(len(bys).to_bytes(4, "little")))
|
||||||
|
print(s.send(bys.encode()))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#bys = json.dumps({
|
||||||
|
# "header" : {
|
||||||
|
# "status" : "0",
|
||||||
|
# "command" : {"type" : "sendServers", "data": ["10.0.0.4:2223"]}
|
||||||
|
# }, "data" : receivedBys["bruhMsg"] })
|
||||||
|
#print(s.send(len(bys).to_bytes(4, "little")))
|
||||||
|
#print(s.send(bys.encode()))
|
||||||
|
|
||||||
|
|
||||||
|
print("Connection to (this) handler finished")
|
||||||
|
|
||||||
|
while True: pass
|
||||||
|
|
||||||
|
runTest()
|
|
@ -0,0 +1,37 @@
|
||||||
|
import socket
|
||||||
|
import json
|
||||||
|
|
||||||
|
def runTest():
|
||||||
|
d=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
d.bind("../bSock")
|
||||||
|
d.listen()
|
||||||
|
while True:
|
||||||
|
print("Waiting for connection to (this) handler...")
|
||||||
|
s = d.accept()[0]
|
||||||
|
|
||||||
|
size=int.from_bytes(s.recv(4), "little")
|
||||||
|
receivedBys = json.loads(s.recv(size).decode())
|
||||||
|
print(receivedBys)
|
||||||
|
|
||||||
|
bys = json.dumps({
|
||||||
|
"header" : {
|
||||||
|
"status" : "0",
|
||||||
|
"command" : {"type" : "sendHandler", "data": "type1"}
|
||||||
|
}, "data" : receivedBys["bruhMsg"] })
|
||||||
|
print(s.send(len(bys).to_bytes(4, "little")))
|
||||||
|
print(s.send(bys.encode()))
|
||||||
|
|
||||||
|
bys = json.dumps({
|
||||||
|
"header" : {
|
||||||
|
"status" : "0",
|
||||||
|
"command" : {"type" : "sendServers", "data": ["10.0.0.4:2223"]}
|
||||||
|
}, "data" : receivedBys["bruhMsg"] })
|
||||||
|
#print(s.send(len(bys).to_bytes(4, "little")))
|
||||||
|
#print(s.send(bys.encode()))
|
||||||
|
|
||||||
|
|
||||||
|
print("Connection to (this) handler finished")
|
||||||
|
|
||||||
|
while True: pass
|
||||||
|
|
||||||
|
runTest()
|
|
@ -17,15 +17,15 @@ def runTest():
|
||||||
"header" : {
|
"header" : {
|
||||||
"status" : "0",
|
"status" : "0",
|
||||||
"command" : {"type" : "sendClients", "data": ["tbk", "skippy"]}
|
"command" : {"type" : "sendClients", "data": ["tbk", "skippy"]}
|
||||||
}, "data" : receivedBys["bruhMsg"] })
|
}, "data" : receivedBys })
|
||||||
print(s.send(len(bys).to_bytes(4, "little")))
|
print(s.send(len(bys).to_bytes(4, "little")))
|
||||||
print(s.send(bys.encode()))
|
print(s.send(bys.encode()))
|
||||||
|
|
||||||
bys = json.dumps({
|
# bys = json.dumps({
|
||||||
"header" : {
|
# "header" : {
|
||||||
"status" : "0",
|
# "status" : "0",
|
||||||
"command" : {"type" : "sendServers", "data": ["10.0.0.4:2223"]}
|
# "command" : {"type" : "sendServers", "data": ["10.0.0.4:2223"]}
|
||||||
}, "data" : receivedBys["bruhMsg"] })
|
# }, "data" : receivedBys["bruhMsg"] })
|
||||||
#print(s.send(len(bys).to_bytes(4, "little")))
|
#print(s.send(len(bys).to_bytes(4, "little")))
|
||||||
#print(s.send(bys.encode()))
|
#print(s.send(bys.encode()))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue