Compare commits

...

49 Commits

Author SHA1 Message Date
Tristan B. Kildaire 0f75841600 Upgraded 2020-07-20 19:45:25 +02:00
Tristan B. Kildaire 5fc42a6ef9 ACTUALLY updated bformat 2020-06-17 08:25:23 +02:00
Tristan B. Kildaire 72139e70c3 Updated bformat. 2020-06-17 08:24:48 +02:00
Tristan B. Kildaire ac56eb7689 Added TODO for further thread safety changes to come. 2020-06-16 18:50:50 +02:00
Tristan B. Kildaire d19b552997 Migrated successfully to new bformat. 2020-06-16 18:46:54 +02:00
Tristan B. Kildaire 261448159f Had a mistake migrating to the new bformat, now migrated almost. 2020-06-16 18:46:26 +02:00
Tristan B. Kildaire c4a4d46264 Upgraded to new bformat v1.0.5 2020-06-16 18:46:07 +02:00
Tristan B. Kildaire c7f701e8f6 Use correct bformat version. 2020-06-16 18:39:50 +02:00
Tristan B. Kildaire b783d98ea7 `addConnection` is now threadsafe. 2020-06-16 18:35:00 +02:00
Tristan B. Kildaire 5c13fa3c77 Using new `addConnection` which aims to be thread safe. 2020-06-16 18:32:17 +02:00
Tristan B. Kildaire 60cd993472 Added stub function `addConnection` to the BesterServer type for thread safe Connection object array appending. 2020-06-16 18:29:42 +02:00
Tristan B. Kildaire aec7144106 Converted missing bmessage `sendMessage` call. 2020-06-16 18:20:45 +02:00
Tristan B. Kildaire 9db02f607b Updated to new bmessage API. 2020-06-16 18:19:46 +02:00
Tristan B. Kildaire c646b4bf20 Updated vibe-d 2020-06-16 18:10:18 +02:00
Tristan B. Kildaire 88af27c3cb Stripepd whitespace from username. 2020-05-15 16:47:18 +02:00
Tristan B. Kildaire 2b54142439 Cleaned up and added TODOs 2020-05-15 16:31:35 +02:00
Tristan B. Kildaire 0b5ca124d6 Use new shutdown and send a fatal message. 2020-05-15 16:06:40 +02:00
Tristan B. Kildaire 71632ec1f3 Added comment.
Remove dunused function.
2020-05-15 15:54:37 +02:00
Tristan B. Kildaire 80b0772fd8 Removed some TODOs 2020-05-15 15:52:33 +02:00
Tristan B. Kildaire 32d35cec71 Added "messageType" field to header that is constructed in SEND_CLIENTS for sending to clients. 2020-05-15 12:50:50 +02:00
Tristan B. Kildaire a22b65f7c4 Renamed "responseType" field to "messageType" field. 2020-05-15 12:49:26 +02:00
Tristan B. Kildaire 615ebc823a Set "responseType" field for status reports. 2020-05-15 12:48:23 +02:00
Tristan B. Kildaire 8d0256d105 Added return as to not expect a payload along with the autnetication. 2020-05-14 16:00:23 +02:00
Tristan B. Kildaire 4e091e2f2d Removed todo 2020-05-14 14:25:46 +02:00
Tristan B. Kildaire 06c406ef86 Added todo. 2020-05-14 14:23:57 +02:00
Tristan B. Kildaire 00c16b68da Send special status report "auth_special" id for authentication. 2020-05-14 14:15:01 +02:00
Tristan B. Kildaire 1ade3365b1 Use shutdown instead. 2020-05-14 14:03:54 +02:00
Tristan B. Kildaire 95577698b8 Added ID forwarding. 2020-05-14 11:22:41 +02:00
Tristan B. Kildaire be2953595d Added status report to SEND_SERVERS 2020-05-14 11:12:58 +02:00
Tristan B. Kildaire ea25aabf26 Send status report after SEND_CLIENTS 2020-05-14 11:12:17 +02:00
Tristan B. Kildaire 2993f74b05 Adding new function to send status reports on errors or sucesses. 2020-05-14 11:08:27 +02:00
Tristan B. Kildaire cc934e5ec8 Fixed test handler. 2020-05-14 10:55:51 +02:00
Tristan B. Kildaire e0e7d5ffd0 Refactored. 2020-05-14 00:48:52 +02:00
Tristan B. Kildaire 89f51e5944 Updated test case to take the `id` field into account. 2020-05-14 00:41:24 +02:00
Tristan B. Kildaire fc33bd0b69 Refactored message dispatch. 2020-05-14 00:39:45 +02:00
Tristan B. Kildaire 955cc6d21d Shutdown on general format error. 2020-05-14 00:36:12 +02:00
Tristan B. Kildaire 9f1e63367c Return false. 2020-05-14 00:27:37 +02:00
Tristan B. Kildaire a9ee569314 Removed unused variable and returned `true`. 2020-05-14 00:24:27 +02:00
Tristan B. Kildaire 4442c62ae7 Misplaced sendErrorReport call. 2020-05-14 00:20:57 +02:00
Tristan B. Kildaire 70df082f9a Added dummy response with new `id` and `status` system. 2020-05-14 00:17:13 +02:00
Tristan B. Kildaire 27ada909d6 Send error reports on errors. 2020-05-14 00:05:04 +02:00
Tristan B. Kildaire 1d7f0b8ac2 Created `sendErrorReport` function. 2020-05-14 00:01:36 +02:00
Tristan B. Kildaire 3e570e8066 Added comment and fixed compilation error. 2020-05-13 23:40:16 +02:00
Tristan B. Kildaire 79cfe50353 Shutdown connecction on fatal protocol error. 2020-05-13 23:11:14 +02:00
Tristan B. Kildaire 007e15caa4 Added todo 2020-05-13 23:02:44 +02:00
Tristan B. Kildaire cc359a14f0 Added `"id"` field requirement to `"payload"` block. 2020-05-13 23:00:24 +02:00
Tristan B. Kildaire d5e3a86842 Cleaned up. 2020-05-12 20:50:26 +02:00
Tristan B. Kildaire bd4846bf61 Code clean up. 2020-05-12 20:41:25 +02:00
Tristan B. Kildaire d19a7809ca wip 2020-05-09 18:04:36 +02:00
11 changed files with 259 additions and 101 deletions

View File

@ -5,8 +5,8 @@
],
"copyright": "Copyright © 2020, Tristan B. Kildaire",
"dependencies": {
"bformat": "1.0.4",
"vibe-d": "0.9.0-alpha.4"
"bformat": "1.0.8",
"vibe-d": "0.9.0-beta.1"
},
"description": "Bester protocol daemon. ",
"license": "AGPL v3",

View File

@ -1,19 +1,19 @@
{
"fileVersion": 1,
"versions": {
"bformat": "1.0.4",
"bformat": "1.0.8",
"botan": "1.12.18",
"botan-math": "1.0.3",
"diet-ng": "1.7.2",
"eventcore": "0.8.50",
"eventcore": "0.9.6",
"libasync": "0.8.6",
"libevent": "2.0.2+2.0.16",
"memutils": "1.0.4",
"mir-linux-kernel": "1.0.1",
"openssl": "1.1.6+1.0.1g",
"stdx-allocator": "2.77.5",
"taggedalgebraic": "0.11.13",
"vibe-core": "1.9.1",
"vibe-d": "0.9.0-alpha.4"
"taggedalgebraic": "0.11.16",
"vibe-core": "1.9.2",
"vibe-d": "0.9.0-beta.1"
}
}

View File

@ -1,6 +1,6 @@
{
"network" : {
"types" : ["unix", "tcp4", "tcp6"],
"types" : ["tcp4", "tcp6"],
"unix" : {
"address" : "besterUNIXSock"
},

View File

@ -63,6 +63,10 @@ public final class BesterConnection : Thread
debugPrint("New client handler spawned for " ~ clientConnection.remoteAddress().toAddrString());
}
/**
* Shutdown the BesterConnection by stopping
* the read-write loop and closing the socket.
*/
public void shutdown()
{
/* TODO: Send message posssibly, think about this for listeners and informers (etc.) too */
@ -74,6 +78,9 @@ public final class BesterConnection : Thread
return username ~ "@" ~ clientConnection.remoteAddress().toAddrString();
}
/**
* Returns an array of the username and password.
*/
public string[] getCredentials()
{
return [username, password];
@ -83,7 +90,7 @@ public final class BesterConnection : Thread
private void run()
{
debugPrint("<<< Begin read/send loop >>>");
while(isActive) /*TODO: Remove and also make the stting of this kak not be closing socket */
while(isActive)
{
/* Received JSON message */
JSONValue receivedMessage;
@ -103,7 +110,7 @@ public final class BesterConnection : Thread
if(connectionType == Scope.SERVER)
{
debugPrint("Server connection done, closing BesterConnection.");
isActive = false;
shutdown();
}
}
catch(BesterException exception)
@ -146,19 +153,42 @@ public final class BesterConnection : Thread
}
/* TODO: Comment [], rename [] */
/**
* Dispatches the message to the correct message handler.
*
* Returns `true` on success or partial success, `false`
* on fatal protocol error.
*/
private bool dispatchMessage(Scope scopeField, JSONValue payloadBlock)
{
/* Status of dispatch */
bool dispatchStatus = true;
/* The payload type */
string payloadType;
/* TODO: Bounds checking, type checking */
/* The payload data */
JSONValue payloadData;
/* Get the payload type */
string payloadType = payloadBlock["type"].str;
debugPrint("Payload type is \"" ~ payloadType ~ "\"");
/* The payload tag */
string payloadTag;
/* Get the payload data */
JSONValue payloadData = payloadBlock["data"];
/* Attempt to parse protocol-critical fields */
try
{
/* Get the payload type */
payloadType = payloadBlock["type"].str;
debugPrint("Payload type is \"" ~ payloadType ~ "\"");
/* Get the payload data */
payloadData = payloadBlock["data"];
/* Get the payload tag */
payloadTag = payloadBlock["id"].str();
}
catch(JSONException e)
{
debugPrint("Fatal error when processing packet, missing fields");
return false;
}
/* Lookup the payloadType handler */
MessageHandler chosenHandler = server.findHandler(payloadType);
@ -166,7 +196,36 @@ public final class BesterConnection : Thread
/* Check if it is a dummy type */
if(cmp(payloadType, "dummy") == 0)
{
/* Construct a dummy response */
JSONValue dummyMessage;
/* Construct a header block */
JSONValue headerBlock;
headerBlock["status"] = "0";
/* Attach the header block */
dummyMessage["header"] = headerBlock;
/* Construct the payload block */
JSONValue dummyPayloadBlock;
dummyPayloadBlock["data"] = null;
dummyPayloadBlock["type"] = payloadType;
dummyPayloadBlock["id"] = payloadTag;
/* Attach the payload block */
dummyMessage["payload"] = dummyPayloadBlock;
try
{
/* Send the message */
sendMessage(clientConnection, dummyMessage);
}
catch(NetworkException e)
{
debugPrint("Error sending status message, fatal closing connection");
/* TODO: We should deactivate the connection when this happens */
return false;
}
}
/* Check if the payload is a built-in command */
else if(cmp(payloadType, "builtin") == 0)
@ -188,13 +247,15 @@ public final class BesterConnection : Thread
debugPrint("Closing socket...");
isActive = false;
sendStatus(0, JSONValue());
// sendStatus(0, JSONValue());
}
else
{
debugPrint("Invalid built-in command type");
/* TODO: Generate error response */
dispatchStatus = false;
// dispatchStatus = false;
/* TODO: Send a response as the "builtin" message handler */
}
}
/* If an external handler is found (i.e. not a built-in command) */
@ -211,52 +272,76 @@ public final class BesterConnection : Thread
/* TODO: Continue here, we will make all error handling do on construction as to make this all more compact */
debugPrint("<<< Message Handler [" ~ chosenHandler.getPluginName() ~ "] response >>>\n\n" ~ handlerResponse.toString());
/* Execute the message handler's command (as per its reply) */
handlerResponse.execute(this);
/* Execute the message handler's command (as per its reply) and pass in the tag */
handlerResponse.execute(this, payloadTag);
}
catch(ResponseError e)
{
/* In the case of an error with the message handler, send an error to the client/server */
/* TODO: Send error here */
//JSONValue errorResponse;
//errorResponse["dd"] = 2;
//debugPrint("Response error");
dispatchStatus = false;
/* TODO: Clean up comments */
/* Send error message to client */
sendStatusReport(StatusType.FAILURE, payloadTag);
}
/* TODO: Be more specific with errors and reporting in the future */
catch(Exception e)
{
/* TODO: Remove me */
debugPrint("fhjhfsdjhfdjhgsdkjh UUUUH:" ~e.toString());
dispatchStatus = false;
/* Send error message to client */
sendStatusReport(StatusType.FAILURE, payloadTag);
}
debugPrint("Handler section done (for client)");
/* TODO: Handle response */
}
/* If no message handler for the specified type could be found */
else
{
/* TODO: Implement error handling */
debugPrint("No handler available for payload type \"" ~ payloadType ~ "\"");
/* Send error message to client */
JSONValue handlerName = payloadType;
sendStatus(1, handlerName);
dispatchStatus = false;
sendStatusReport(StatusType.FAILURE, payloadTag);
}
return dispatchStatus;
return true;
}
/* Send a status message to the client */
public void sendStatus(uint code, JSONValue data)
/**
* Type of the status report.
* Either 0 (for success) or 1 (for failure).
*/
public enum StatusType
{
/* Construct a status message */
SUCCESS,
FAILURE
}
/**
* Send a status report for the message with id
* `id` of type `StatusType`.
*/
public void sendStatusReport(StatusType statusType, string id)
{
/* Construct the response */
JSONValue statusMessage;
JSONValue statusBlock;
statusBlock["code"] = to!(string)(code);
statusBlock["data"] = data;
statusMessage["status"] = statusBlock;
/* Construct the header block */
JSONValue headerBlock;
headerBlock["status"] = statusType == 0 ? "good" : "bad";
headerBlock["messageType"] = "statusReport";
/* Attach the header block */
statusMessage["header"] = headerBlock;
/* Create the payload block */
JSONValue payloadBlock;
payloadBlock["id"] = id;
/* Attach the payload block */
statusMessage["payload"] = payloadBlock;
try
{
@ -293,23 +378,29 @@ public final class BesterConnection : Thread
return Scope.UNKNOWN;
}
/**
* Sends an error message on fatal error.
* Used before client shutdown on such
* an error.
*/
private void sendFatalMessage()
{
/* TODO: Implement me */
}
/* Process the received message */
private void processMessage(JSONValue jsonMessage)
{
/* Attempt to convert the message to JSON */
try
{
/* Convert message to JSON */
debugPrint("<<< Received JSON >>>\n\n" ~ jsonMessage.toPrettyString());
/* TODO: Bounds checking, type checking */
/* Get the header */
JSONValue headerBlock = jsonMessage["header"];
/**
* Check to see if this connection is currently "untyped".
*
@ -330,8 +421,11 @@ public final class BesterConnection : Thread
/* TODO: Send message back about an invalid scope */
/* TODO: End this here */
isActive = false;
/* Send fatal message */
sendFatalMessage();
/* Stop the read/write loop */
shutdown();
return;
}
else if(scopeField == Scope.CLIENT)
@ -367,7 +461,10 @@ public final class BesterConnection : Thread
this.password = password;
/* Send error message to client */
sendStatus(5, JSONValue());
// sendStatus(5, JSONValue());
/* TODO: Send authentication success */
sendStatusReport(StatusType.SUCCESS, "auth_special");
}
/* If authentication failed due to malformed message or incorrect details */
else
@ -378,11 +475,11 @@ public final class BesterConnection : Thread
*/
debugPrint("Authenticating the user failed, sending error and closing connection.");
/* Send error message to client */
sendStatus(2, JSONValue());
/* Send fatal message */
sendFatalMessage();
/* Stop the read/write loop */
isActive = false;
shutdown();
return;
}
}
@ -393,35 +490,46 @@ public final class BesterConnection : Thread
/* Set the connection type to `scopeField` */
connectionType = scopeField;
}
/* Attempt to get the payload block and dispatch the message */
bool dispatchStatus;
if(connectionType == Scope.CLIENT)
{
return;
}
}
/* Get the `payload` block */
JSONValue payloadBlock = jsonMessage["payload"];
debugPrint("<<< Payload is >>>\n\n" ~ payloadBlock.toPrettyString());
/* Dispatch the message */
dispatchStatus = dispatchMessage(connectionType, payloadBlock);
/* TODO: Catch error here and not inside dispatchMessage, gets rid of the need for this if statement */
if(dispatchStatus)
/**
* Dispatch the message. If a fatal failure is
* detected then the connection will be shutdown.
*/
if(dispatchMessage(connectionType, payloadBlock))
{
debugPrint("Dispatch succeeded");
}
else
{
/* TODO: Error handling */
debugPrint("Dispatching failed...");
debugPrint("Dispatch failed, deactivating connection...");
/* Send fatal message */
sendFatalMessage();
/* Shutdown the connection */
shutdown();
}
}
/* If the attempt to convert the message to JSON fails */
catch(JSONException exception)
{
debugPrint("General format error");
sendStatus(3, JSONValue());
debugPrint("Fatal format error, deactivating connection...");
/* Send fatal message */
sendFatalMessage();
/* Shutdown the connection */
shutdown();
}
}
}

View File

@ -1,6 +1,6 @@
module handlers.response;
import std.json : JSONValue, JSONException, parseJSON;
import std.json : JSONValue, JSONException, parseJSON, toJSON;
import std.conv : to;
import utils.debugging : debugPrint;
import std.string : cmp;
@ -14,7 +14,10 @@ import std.string : split;
import server.server : BesterServer;
import handlers.commands : Command;
/* The type of the command the message handler wants us to run */
/**
* The type of the command the message handler wants
* us to run
*/
private enum CommandType : ubyte
{
/* Simple message flow (always end point) */
@ -155,10 +158,8 @@ public final class HandlerResponse
* Executes the command. Either `sendClients`, `sendServers`
* or `sendHandler`.
*/
public void execute(BesterConnection originalRequester)
public void execute(BesterConnection originalRequester, string messageID)
{
/* TODO: Implement me */
/* If the command is SEND_CLIENTS */
if(commandType == CommandType.SEND_CLIENTS)
{
@ -176,16 +177,12 @@ public final class HandlerResponse
BesterConnection[] connectionList = originalRequester.server.getClients(clients);
//debugPrint("Users matched online on server: " ~ to!(string)(connectionList));
/* The fully response message to send back */
JSONValue clientPayload;
// /* Set the `handlerName` field of the header block */
// JSONValue handlerName;
// handlerName["handlerName"] = handler.getPluginName();
/* Set the header of the response */
JSONValue headerBlock;
headerBlock["messageType"] = "receivedMessage";
clientPayload["header"] = headerBlock;
/* Set the payload of the response */
@ -196,10 +193,11 @@ public final class HandlerResponse
/**
* Loop through each BesterConnection in connectionList and
* send the message-handler payload response message to each
* of them.
*/
* Loop through each BesterConnection in connectionList and
* send the message-handler payload response message to each
* of them.
*/
bool allSuccess = true;
for(ulong i = 0; i < connectionList.length; i++)
{
/* Get the conneciton */
@ -219,17 +217,23 @@ public final class HandlerResponse
catch(SocketOSException exception)
{
/**
* If there was an error sending to the client, this can happen
* if the client has disconnected but hasn't yet been removed from
* the connections array and hence we try to send on a dead socket
* or get the remoteAddress on a dead socket, which causes a
* SocketOSException to be called.
*/
debugPrint("Attempted interacting with dead socket");
* If there was an error sending to the client, this can happen
* if the client has disconnected but hasn't yet been removed from
* the connections array and hence we try to send on a dead socket
* or get the remoteAddress on a dead socket, which causes a
* SocketOSException to be called.
*/
debugPrint("Attempted interacting with dead socket");
allSuccess = false;
}
}
debugPrint("SEND_CLIENTS: Completed run");
/**
* Send a status report here.
*/
originalRequester.sendStatusReport(cast(BesterConnection.StatusType)!allSuccess, messageID);
}
else if (commandType == CommandType.SEND_SERVERS)
{
@ -248,12 +252,8 @@ public final class HandlerResponse
/* The fully response message to send back */
JSONValue serverPayload;
/* Set the `scope` field of the header block */
JSONValue scopeField = "server";
/* Set the header of the response */
JSONValue headerBlock;
// headerBlock["handlerName"] = handler.getPluginName();
headerBlock["scope"] = "server";
serverPayload["header"] = headerBlock;
@ -265,6 +265,7 @@ public final class HandlerResponse
/* Attempt connecting to each server and sending the payload */
bool allSuccess = true;
for(ulong i = 0; i < servers.length; i++)
{
/* Get the current server address and port */
@ -294,10 +295,16 @@ public final class HandlerResponse
{
/* TODO: Be more specific with the above exception type */
debugPrint("Error whilst sending payload to server: " ~ e.toString());
allSuccess = false;
}
}
debugPrint("SEND_SERVERS: Completed run");
/**
* Send a status report here.
*/
originalRequester.sendStatusReport(cast(BesterConnection.StatusType)!allSuccess, messageID);
}
else if (commandType == CommandType.SEND_HANDLER)
{
@ -312,7 +319,7 @@ public final class HandlerResponse
HandlerResponse handlerResponse = chosenHandler.handleMessage(messageResponse["data"]);
/* Execute the code (this here, recursive) */
handlerResponse.execute(originalRequester);
handlerResponse.execute(originalRequester, messageID);
debugPrint("SEND_HANDLER: Completed run");
}

View File

@ -79,7 +79,7 @@ public class BesterListener : Thread
besterConnection.start();
/* Add this client to the list of connected clients */
server.clients ~= besterConnection;
server.addConnection(besterConnection);
}
/* Close the socket */

View File

@ -3,7 +3,7 @@ module server.informer.client;
import core.thread : Thread;
import server.server : BesterServer;
import std.socket;
import bmessage;
import utils.message : receiveMessage, sendMessage;
import std.json;
import utils.debugging;
import std.string;
@ -77,7 +77,6 @@ public final class BesterInformerClient : Thread
active = false;
result = null; /* TODO: JSOn default value */
}
/* TODO: Add any more new command here */
/* If the command is invalid */
else
{

View File

@ -4,6 +4,7 @@ import utils.debugging : debugPrint;
import std.conv : to;
import std.socket : Socket, AddressFamily, SocketType, ProtocolType, parseAddress;
import core.thread : Thread;
import core.sync.mutex;
import std.stdio : writeln, File;
import std.json : JSONValue, parseJSON, JSONException, JSONType, toJSON;
import std.string : cmp, strip;
@ -40,6 +41,7 @@ public final class BesterServer
* Connected clients.
*/
public BesterConnection[] clients;
private Mutex clientsMutex;
/**
* The informer server.
@ -88,6 +90,31 @@ public final class BesterServer
return matchedUsers;
}
/**
* Adds a new Connection, `connection`, to the server.
*/
public void addConnection(BesterConnection connection)
{
/**
* Lock the mutex so that only one listener thread
* may access the array at a time.
*/
clientsMutex.lock();
/**
* Append the connection to the array
*/
clients ~= connection;
/**
* Release the mutex so other listeners can now append
* to the array.
*/
clientsMutex.unlock();
}
/* TODO: Add more thread sfaety here and abroad */
/**
* Adds a listener, `listener`, to this server's
* listener set.
@ -111,6 +138,9 @@ public final class BesterServer
debugPrint("Setting up message handlers...");
setupHandlers(config["handlers"]);
setupDatabase(config["database"]);
/* Initialize the `clients` array mutex */
clientsMutex = new Mutex();
}
/* TODO: Add comment, implement me */
@ -229,7 +259,7 @@ public final class BesterServer
bool authed = true;
/* Strip the username of whitespace (TODO: Should we?) */
//username = strip(username);
username = strip(username);
/* Make sure username and password are not empty */
if(cmp(username, "") != 0 && cmp(password, "") != 0)

View File

@ -14,10 +14,15 @@ import bmessage : bformatreceiveMessage = receiveMessage, bformatsendMessage = s
*/
public void receiveMessage(Socket originator, ref JSONValue receiveMessage)
{
if(!bformatreceiveMessage(originator, receiveMessage))
/* The received bytes */
byte[] receivedBytes;
if(!bformatreceiveMessage(originator, receivedBytes))
{
throw new NetworkException(originator);
}
receiveMessage = parseJSON(cast(string)receivedBytes);
}
/**
@ -31,8 +36,11 @@ public void receiveMessage(Socket originator, ref JSONValue receiveMessage)
*/
public void sendMessage(Socket recipient, JSONValue jsonMessage)
{
if(!bformatsendMessage(recipient, jsonMessage))
if(!bformatsendMessage(recipient, cast(byte[])toJSON(jsonMessage)))
{
throw new NetworkException(recipient);
}
}
}
/* TODO: Hash message: Next-gen implementation */

View File

@ -8,18 +8,24 @@ def sendAs(username):
d.connect(("127.0.0.1",2223))
# 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":"type1", "id" : "lol"}})
print(len(bys), bys)
d.send(len(bys).to_bytes(4, "little"))
d.send(bys.encode())
# Loop prompt and sending of message to tbk
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":"type1", "id":"lol"}})
print(len(bys), bys)
d.send(len(bys).to_bytes(4, "little"))
d.send(bys.encode())
length=int.from_bytes(list(d.recv(4)), "little")
print(length)
receivedDataBytes = d.recv(length)
receivedData = list(receivedDataBytes)
print(receivedDataBytes.decode())
# Now we can do it again (without authentication)

View File

@ -25,7 +25,7 @@ def runTest():
"header" : {
"status" : "0",
"command" : {"type" : "sendClients", "data": ["deavmi"]}
}, "data" : "length of your data: " + str(len(receivedBys)) + "\"" + receivedBys + "\"" })
}, "data" : "length of your data: " + str(len(receivedBys)) + "\"" + str(receivedBys) + "\"" })
print(s.send(len(bys).to_bytes(4, "little")))
print(s.send(bys.encode()))