public TcpSession !ReInitializeSession(TcpSession !tcp) { tcp.ReInitialize(this); Core.Instance().RegisterSession(this, tcp); return(tcp); }
// Find the relevant session for this connection protected TcpSession FindSession(IPFormat.IPHeader !ipHeader, ref TcpFormat.TcpHeader tcpHeader) { // Get the session table ArrayList sessions = Core.Instance().GetSessions(this); if (sessions == null) { return(null); } // First priority is a full match (Loc/Rem X Addr/Port all match), // but next priority is a "passive" match (a Broadcast to "me"). TcpSession passiveSession = null; // this is the passive session lock (sessions.SyncRoot) { // BUGBUG: This should use HashTables (KeyedCollections // TODO // BUGBUG: if we get Generics) for Performance reasons. // TODO // BUGBUG: We need one for full and one for passive. // TODO // BUGBUG: The full hashtable uses local and remote // TODO // BUGBUG: addresses as the keys and can be limited to // TODO // BUGBUG: sessions without Remote Broadcast addresses; // TODO // BUGBUG: the passive hashtable is limited to sessions // TODO // BUGBUG: with Remote Broadcast addresses and uses the // TODO // BUGBUG: local address only as the key. // TODO // BUGBUG: Note that this is done for every TCP Packet. // TODO foreach (TcpSession !tcpSession in sessions) { bool matchLocal = (tcpSession.LocalAddress == ipHeader.Destination) && (tcpSession.LocalPort == tcpHeader.destPort); // Both full and passive matches require full Local match. if (matchLocal) { // Check the Remote Match for a Full Match bool matchRemote = (tcpSession.RemoteAddress == ipHeader.Source) && (tcpSession.RemotePort == tcpHeader.sourcePort); // If a full match (local && remote) return the session. if (matchRemote) { return(tcpSession); } // Check for "Broadcast" address. bool matchBroadcast = (tcpSession.RemoteAddress == IPv4.Broadcast) && (tcpSession.RemotePort == 0); // No full match, but save passiveSession // if matchLocal && matchBroadcast. if (matchBroadcast) { passiveSession = tcpSession; } } } } // If we didn't find an exact match, return // the passive match, if any (may be null). return(passiveSession); }