private TCP MatchTCPSession(IPv4 srcAddress, ushort srcPort, IPv4 destAddress, ushort destPort, byte hash) { ChainedHashNode chainedHashNode = chainedHash[hash]; VTable.Assert(chainedHashNode != null); TCP tcpSession = chainedHashNode.sideCache; if ((tcpSession != null) && IsTCPSessionMatch(tcpSession, srcAddress, srcPort, destAddress, destPort)) { DebugPrint("Found TCP session in cache\n"); return(tcpSession); } tcpSession = null; LinkedListNode currentNode = chainedHashNode.linkedList.head; int numMatches = 0; while (currentNode != null) { TCP tmpTcpSession = currentNode.theObject as TCP; DebugStub.Assert(tmpTcpSession != null); VTable.Assert(tmpTcpSession != null); numMatches++; if (IsTCPSessionMatch(tmpTcpSession, srcAddress, srcPort, destAddress, destPort)) { DebugPrint("Found TCP session -- {0} matches required\n", numMatches); chainedHashNode.sideCache = tmpTcpSession; tcpSession = tmpTcpSession; break; } currentNode = currentNode.nxt; } return(tcpSession); }
public LinkedListNode InsertNewSession(TCP tcpSession) { byte hash = Hash(tcpSession.localIPAddress, tcpSession.remoteIPAddress, tcpSession.localPort, tcpSession.remotePort); ChainedHashNode chainedHashNode = chainedHash[hash]; VTable.Assert(chainedHashNode != null); //XXX check for duplicates! return(chainedHashNode.linkedList.InsertHead(tcpSession)); }
public ChainedHash(bool activeMatch) { DebugPrint("New chained hash --> active {0}\n", activeMatch); this.activeMatch = activeMatch; chainedHashSize = defaultHashSize; chainedHash = new ChainedHashNode[chainedHashSize]; for (int i = 0; i < chainedHashSize; i++) { chainedHash[i] = new ChainedHashNode(); } }
public bool RemoveTcpSession(TCP tcpSession, LinkedListNode tcpLLNode) //requires tcpSession.chainedHashLLNode != null; { byte hash = Hash(tcpSession.localIPAddress, tcpSession.remoteIPAddress, tcpSession.localPort, tcpSession.remotePort); ChainedHashNode chainedHashNode = chainedHash[hash]; VTable.Assert(chainedHashNode != null); if (tcpSession == chainedHashNode.sideCache) { chainedHashNode.sideCache = null; } LinkedList linkedList = chainedHashNode.linkedList; VTable.Assert(linkedList != null); TCP returnedSession = linkedList.Remove(tcpLLNode) as TCP; DebugStub.Assert(tcpSession == returnedSession); VTable.Assert(tcpSession == returnedSession); return(true); }