public void RedirectFrame(string destAddress, ushort destPort, byte[] frame) { if (!nodeConnections.TryGetValue(destAddress, out NodeConnection connection)) { GUIWindow.PrintLog("The Node to which the message is attempted to be redirected is not connected!"); return; } //GUIWindow.PrintLog("Redirecting message to " + destAddress + ":" + destPort); connection.SendMessage(frame); }
public ConnectionListener() { cloudIP = Dns.GetHostEntry(ip).AddressList[0]; server = new TcpListener(cloudIP, cloudPort); try { server.Start(); GUIWindow.PrintLog("Server launched, waiting for clients..."); } catch (Exception ex) { GUIWindow.PrintLog(ex.ToString()); } StartListening(); }
private void RedirectFrame(string srcAddress, ushort srcPort, Frame frame) { string targetAddress = ""; ushort targetPort = 0; Tuple <int, string, int, string, int> target = null; foreach (Tuple <int, string, int, string, int> tuple in Program.connectionTable) { if (tuple.Item2.Equals(srcAddress) && tuple.Item3 == srcPort) { targetAddress = tuple.Item4; targetPort = (ushort)tuple.Item5; target = tuple; } else if (tuple.Item4.Equals(srcAddress) && tuple.Item5 == srcPort) { targetAddress = tuple.Item2; targetPort = (ushort)tuple.Item3; target = tuple; } } if (targetAddress.Length == 0) { GUIWindow.PrintLog("Could not find a link that contains a Node with given address and port"); return; } else if (Program.brokenConnections.Contains(target)) { GUIWindow.PrintLog("Redirecting message to " + targetAddress + ":" + targetPort); GUIWindow.PrintLog("Connection is not working! Packet is lost!"); return; } frame.RouterInPort = targetPort; GUIWindow.PrintLog("Redirecting message to " + targetAddress + ":" + targetPort); connectionListener.RedirectFrame(targetAddress, targetPort, SerializeObject(frame)); }
private void ReceiveMessages() { while (true) { byte[] receivedBufferL = new byte[16384]; try { stream.Read(receivedBufferL, 0, receivedBufferL.Length); } catch { break; } byte[] receivedBuffer = new byte[8192]; Buffer.BlockCopy(receivedBufferL, 0, receivedBuffer, 0, receivedBuffer.Length); Frame frame = (Frame)DeserializeObject(receivedBuffer); if (frame.Message.Equals("_register_")) { Register(frame.SourceIP); continue; } else if (frame.Message.Equals("_disconnect_")) { GUIWindow.PrintLog("Node " + ipAddress + " has disconnected from the server"); connectionListener.DisconnectNode(ipAddress); stream.Close(); continue; } GUIWindow.PrintLog("Received message from " + frame.SourceIP.Split('/')[0] + ":" + frame.SourcePort); RedirectFrame(frame.SourceIP.Split('/')[0], frame.SourcePort, frame); } }
public void RegisterNode(string ip, NodeConnection connection) { nodeConnections.Add(ip, connection); GUIWindow.PrintLog("Node " + ip + " has connected to the server"); }
public GUIWindow() { InitializeComponent(); instance = this; FillConnectionTable(); }