public void Handle(NodeListManager nodeListManager) { int bytesRead; // Read 4 byte header var buffer = new byte[_headerSize]; while ((bytesRead = TryReadChunk(buffer)) == _headerSize) { string commandText = Encoding.UTF8.GetString(buffer); Console.WriteLine($"Command '{commandText}' received"); switch (commandText) { case "GNDS": var bytesToSend = nodeListManager.GetNodeList().ToByteArray(); //send payload length _socketConnection.Send(BitConverter.GetBytes(bytesToSend.Length)); _socketConnection.Send(bytesToSend); _socketConnection.Send(endBytes); Console.WriteLine($"Sent nodelist."); //add this requester to my node list IPEndPoint remoteIpEndPoint = _socketConnection.RemoteEndPoint as IPEndPoint; if (remoteIpEndPoint != null) { nodeListManager.AddNodeToList(remoteIpEndPoint.Address); } Console.WriteLine(nodeListManager.ToString()); break; default: break; } } }
public Application(int port, int maxConnections, int statusInterval, string logFilePath, NodeListManager nodeListManager) { _statusInterval = statusInterval; _listener = new LocalhostSocketListener(port, maxConnections); _nodeListManager = nodeListManager; }