diff --git a/LoadTest/RunClients.cs b/LoadTest/RunClients.cs index b2c1115..6d291fa 100644 --- a/LoadTest/RunClients.cs +++ b/LoadTest/RunClients.cs @@ -16,7 +16,7 @@ public class RunClients public static void StartClients(string host, int port, int clientAmount, int seconds) { - Log.Error("starting " + clientAmount + " clients..."); + Log.Error("[Telepathy] Starting " + clientAmount + " clients..."); // start n clients and get queue messages all in this thread string message = "Sometimes we just need a good networking library"; @@ -35,14 +35,14 @@ public static void StartClients(string host, int port, int clientAmount, int sec clients.Add(client); Thread.Sleep(15); } - Log.Info("started all clients"); + Log.Info("[Telepathy] Started all clients"); // make sure that all clients connected successfully. otherwise // the sleep might be too small, or other reasons. no point in // load testing if the connect failed already. if (!clients.All(cl => cl.Connected)) { - Log.Info("not all clients were connected successfully. aborting."); + Log.Info("[Telepathy] Not all clients were connected successfully. aborting."); return; } @@ -76,7 +76,7 @@ public static void StartClients(string host, int port, int clientAmount, int sec long bandwithIn = dataReceived * 1000 / (stopwatch.ElapsedMilliseconds * 1024); long bandwithOut = messagesSent * messageBytes.Length * 1000 / (stopwatch.ElapsedMilliseconds * 1024); - Log.Info(string.Format("Thread[" + Thread.CurrentThread.ManagedThreadId + "]: Client in={0} ({1} KB/s) out={2} ({3} KB/s), ReceiveQueueAvg={4}", + Log.Info(string.Format("[Telepathy] Thread[" + Thread.CurrentThread.ManagedThreadId + "]: Client in={0} ({1} KB/s) out={2} ({3} KB/s), ReceiveQueueAvg={4}", messagesReceived, bandwithIn, messagesSent, diff --git a/LoadTest/RunServer.cs b/LoadTest/RunServer.cs index 26070e8..1d5e363 100644 --- a/LoadTest/RunServer.cs +++ b/LoadTest/RunServer.cs @@ -24,7 +24,7 @@ public static void StartServer(int port, int seconds) server.Start(port); int serverFrequency = 60; - Log.Info("started server"); + Log.Info("[Telepathy] Started server"); Stopwatch stopwatch = Stopwatch.StartNew(); @@ -43,7 +43,7 @@ public static void StartServer(int port, int seconds) // report every 10 seconds if (stopwatch.ElapsedMilliseconds > 1000 * 2) { - Log.Info(string.Format("Thread[" + Thread.CurrentThread.ManagedThreadId + "]: Server in={0} ({1} KB/s) out={0} ({1} KB/s) ReceiveQueue={2}", messagesReceived, (dataReceived * 1000 / (stopwatch.ElapsedMilliseconds * 1024)), server.ReceivePipeTotalCount.ToString())); + Log.Info(string.Format("[Telepathy] Thread[" + Thread.CurrentThread.ManagedThreadId + "]: Server in={0} ({1} KB/s) out={0} ({1} KB/s) ReceiveQueue={2}", messagesReceived, (dataReceived * 1000 / (stopwatch.ElapsedMilliseconds * 1024)), server.ReceivePipeTotalCount.ToString())); stopwatch.Stop(); stopwatch = Stopwatch.StartNew(); messagesReceived = 0; diff --git a/Telepathy/Client.cs b/Telepathy/Client.cs index b2a1c85..44fa0b5 100644 --- a/Telepathy/Client.cs +++ b/Telepathy/Client.cs @@ -153,7 +153,7 @@ static void ReceiveThreadFunction(ClientConnectionState state, string ip, int po { // this happens if (for example) the ip address is correct // but there is no server running on that ip/port - Log.Info("Client Recv: failed to connect to ip=" + ip + " port=" + port + " reason=" + exception); + Log.Info("[Telepathy] Client Recv: failed to connect to ip=" + ip + " port=" + port + " reason=" + exception); } catch (ThreadInterruptedException) { @@ -171,7 +171,7 @@ static void ReceiveThreadFunction(ClientConnectionState state, string ip, int po catch (Exception exception) { // something went wrong. probably important. - Log.Error("Client Recv Exception: " + exception); + Log.Error("[Telepathy] Client Recv Exception: " + exception); } // add 'Disconnected' event to receive pipe so that the caller // knows that the Connect failed. otherwise they will never know @@ -200,7 +200,7 @@ public void Connect(string ip, int port) // not if already started if (Connecting || Connected) { - Log.Warning("Telepathy Client can not create connection because an existing connection is connecting or connected"); + Log.Warning("[Telepathy] Client can not create connection because an existing connection is connecting or connected"); return; } @@ -287,17 +287,17 @@ public bool Send(ArraySegment message) else { // log the reason - Log.Warning($"Client.Send: sendPipe reached limit of {SendQueueLimit}. This can happen if we call send faster than the network can process messages. Disconnecting to avoid ever growing memory & latency."); + Log.Warning($"[Telepathy] Client.Send: sendPipe reached limit of {SendQueueLimit}. This can happen if we call send faster than the network can process messages. Disconnecting to avoid ever growing memory & latency."); // just close it. send thread will take care of the rest. state.client.Close(); return false; } } - Log.Error("Client.Send: message too big: " + message.Count + ". Limit: " + MaxMessageSize); + Log.Error("[Telepathy] Client.Send: message too big: " + message.Count + ". Limit: " + MaxMessageSize); return false; } - Log.Warning("Client.Send: not connected!"); + Log.Warning("[Telepathy] Client.Send: not connected!"); return false; } diff --git a/Telepathy/Server.cs b/Telepathy/Server.cs index 0b4ada7..067dcb6 100644 --- a/Telepathy/Server.cs +++ b/Telepathy/Server.cs @@ -95,7 +95,7 @@ void Listen(int port) //listener.Server.SendTimeout = SendTimeout; //listener.Server.ReceiveTimeout = ReceiveTimeout; listener.Start(); - Log.Info("Server: listening port=" + port); + Log.Info("[Telepathy] Server: listening port=" + port); // keep accepting new clients while (true) @@ -138,7 +138,7 @@ void Listen(int port) } catch (Exception exception) { - Log.Error("Server send thread exception: " + exception); + Log.Error("[Telepathy] Server send thread exception: " + exception); } }); sendThread.IsBackground = true; @@ -172,7 +172,7 @@ void Listen(int port) } catch (Exception exception) { - Log.Error("Server client thread exception: " + exception); + Log.Error("[Telepathy] Server client thread exception: " + exception); } }); receiveThread.IsBackground = true; @@ -183,18 +183,18 @@ void Listen(int port) { // UnityEditor causes AbortException if thread is still // running when we press Play again next time. that's okay. - Log.Info("Server thread aborted. That's okay. " + exception); + Log.Info("[Telepathy] Server thread aborted. That's okay. " + exception); } catch (SocketException exception) { // calling StopServer will interrupt this thread with a // 'SocketException: interrupted'. that's okay. - Log.Info("Server Thread stopped. That's okay. " + exception); + Log.Info("[Telepathy] Server Thread stopped. That's okay. " + exception); } catch (Exception exception) { // something went wrong. probably important. - Log.Error("Server Exception: " + exception); + Log.Error("[Telepathy] Server Exception: " + exception); } } @@ -215,7 +215,7 @@ public bool Start(int port) // start the listener thread // (on low priority. if main thread is too busy then there is not // much value in accepting even more clients) - Log.Info("Server: Start port=" + port); + Log.Info("[Telepathy] Server: Start port=" + port); listenerThread = new Thread(() => { Listen(port); }); listenerThread.IsBackground = true; listenerThread.Priority = ThreadPriority.BelowNormal; @@ -228,7 +228,7 @@ public void Stop() // only if started if (!Active) return; - Log.Info("Server: stopping..."); + Log.Info("[Telepathy] Server: stopping..."); // stop listening to connections so that no one can connect while we // close the client connections @@ -295,7 +295,7 @@ public bool Send(int connectionId, ArraySegment message) else { // log the reason - Log.Warning($"Server.Send: sendPipe for connection {connectionId} reached limit of {SendQueueLimit}. This can happen if we call send faster than the network can process messages. Disconnecting this connection for load balancing."); + Log.Warning($"[Telepathy] Server.Send: sendPipe for connection {connectionId} reached limit of {SendQueueLimit}. This can happen if we call send faster than the network can process messages. Disconnecting this connection for load balancing."); // just close it. send thread will take care of the rest. connection.client.Close(); @@ -311,7 +311,7 @@ public bool Send(int connectionId, ArraySegment message) //Logger.Log("Server.Send: invalid connectionId: " + connectionId); return false; } - Log.Error("Server.Send: message too big: " + message.Count + ". Limit: " + MaxMessageSize); + Log.Error("[Telepathy] Server.Send: message too big: " + message.Count + ". Limit: " + MaxMessageSize); return false; } @@ -334,7 +334,7 @@ public bool Disconnect(int connectionId) { // just close it. send thread will take care of the rest. connection.client.Close(); - Log.Info("Server.Disconnect connectionId:" + connectionId); + Log.Info("[Telepathy] Server.Disconnect connectionId:" + connectionId); return true; } return false; diff --git a/Telepathy/ThreadFunctions.cs b/Telepathy/ThreadFunctions.cs index 6f026c9..066a932 100644 --- a/Telepathy/ThreadFunctions.cs +++ b/Telepathy/ThreadFunctions.cs @@ -34,7 +34,7 @@ public static bool SendMessagesBlocking(NetworkStream stream, byte[] payload, in catch (Exception exception) { // log as regular message because servers do shut down sometimes - Log.Info("Send: stream.Write exception: " + exception); + Log.Info("[Telepathy] Send: stream.Write exception: " + exception); return false; } } @@ -47,7 +47,7 @@ public static bool ReadMessageBlocking(NetworkStream stream, int MaxMessageSize, // buffer needs to be of Header + MaxMessageSize if (payloadBuffer.Length != 4 + MaxMessageSize) { - Log.Error($"ReadMessageBlocking: payloadBuffer needs to be of size 4 + MaxMessageSize = {4 + MaxMessageSize} instead of {payloadBuffer.Length}"); + Log.Error($"[Telepathy] ReadMessageBlocking: payloadBuffer needs to be of size 4 + MaxMessageSize = {4 + MaxMessageSize} instead of {payloadBuffer.Length}"); return false; } @@ -68,7 +68,7 @@ public static bool ReadMessageBlocking(NetworkStream stream, int MaxMessageSize, // read exactly 'size' bytes for content (blocking) return stream.ReadExactly(payloadBuffer, size); } - Log.Warning("ReadMessageBlocking: possible header attack with a header of: " + size + " bytes."); + Log.Warning("[Telepathy] ReadMessageBlocking: possible header attack with a header of: " + size + " bytes."); return false; } @@ -139,7 +139,7 @@ public static void ReceiveLoop(int connectionId, TcpClient client, int MaxMessag if (receivePipe.Count(connectionId) >= QueueLimit) { // log the reason - Log.Warning($"receivePipe reached limit of {QueueLimit} for connectionId {connectionId}. This can happen if network messages come in way faster than we manage to process them. Disconnecting this connection for load balancing."); + Log.Warning($"[Telepathy] receivePipe reached limit of {QueueLimit} for connectionId {connectionId}. This can happen if network messages come in way faster than we manage to process them. Disconnecting this connection for load balancing."); // IMPORTANT: do NOT clear the whole queue. we use one // queue for all connections. @@ -155,7 +155,7 @@ public static void ReceiveLoop(int connectionId, TcpClient client, int MaxMessag // something went wrong. the thread was interrupted or the // connection closed or we closed our own connection or ... // -> either way we should stop gracefully - Log.Info("ReceiveLoop: finished receive function for connectionId=" + connectionId + " reason: " + exception); + Log.Info("[Telepathy] ReceiveLoop: finished receive function for connectionId=" + connectionId + " reason: " + exception); } finally { @@ -226,7 +226,7 @@ public static void SendLoop(int connectionId, TcpClient client, MagnificentSendP // something went wrong. the thread was interrupted or the // connection closed or we closed our own connection or ... // -> either way we should stop gracefully - Log.Info("SendLoop Exception: connectionId=" + connectionId + " reason: " + exception); + Log.Info("[Telepathy] SendLoop Exception: connectionId=" + connectionId + " reason: " + exception); } finally {