private Router() { _localProtocolDispatcher = new PUPProtocolDispatcher(); _routingTable = new RoutingTable(); // // Look up our own network in the table and get our port. // If we don't have an entry in the table, disable routing. // RoutingTableEntry ourNetwork = _routingTable.GetAddressForNetworkNumber(DirectoryServices.Instance.LocalNetwork); _gatewayUdpClientLock = new ReaderWriterLockSlim(); if (ourNetwork == null) { Log.Write(LogType.Warning, LogComponent.Routing, "networks.txt does not contain a definition for our network ({0}). Gateway routing disabled.", DirectoryServices.Instance.LocalNetwork); _gatewayUdpClient = null; } else { _gatewayUdpPort = ourNetwork.Port; // Start the external network receiver. BeginExternalReceive(); } }
private void RoutePacketExternally(PUP p) { RoutingTableEntry destinationNetworkEntry = _routingTable.GetAddressForNetworkNumber(p.DestinationPort.Network); if (destinationNetworkEntry != null) { // // Send this out through the external network interface. // if (_gatewayUdpClient != null) { Log.Write(LogType.Verbose, LogComponent.Routing, "-> PUP routed to {0}:{1}, type {2} source {3} destination {4}.", destinationNetworkEntry.HostAddress, destinationNetworkEntry.Port, p.Type, p.SourcePort, p.DestinationPort); try { _gatewayUdpClientLock.EnterWriteLock(); _gatewayUdpClient.Send(p.RawData, p.RawData.Length, destinationNetworkEntry.HostAddress, destinationNetworkEntry.Port); } catch (Exception e) { Log.Write(LogType.Error, LogComponent.Routing, "Gateway UDP client send failed, error {0}. Continuing.", e.Message); } finally { _gatewayUdpClientLock.ExitWriteLock(); } } } else { // // We don't know where to send this, drop it instead. // Log.Write( LogType.Verbose, LogComponent.Routing, "Outgoing PUP is for unknown network {0}, dropping.", p.DestinationPort.Network); } }
/// <summary> /// Returns the inter-network number for the network served by the given /// host address. Returns 0 (undefined network) if no number is defined /// for the given address. /// </summary> /// <param name="address"></param> /// <returns></returns> public byte GetNetworkNumberForAddress(RoutingTableEntry address) { throw new NotImplementedException(); }