'TCP dispatch'

def TCP(self, addr, tcp, ts, **kwargs):

    self.decodedbytes += len(str(tcp))
    self.count += 1
    try:
        conn = self.find(addr)
        if self.ignore_handshake:
            if (not conn):
                conn = self.track(addr, ts=ts, state='init', **kwargs)
            if ((conn.nextoffset['cs'] is None) and (addr == conn.addr)):
                conn.nextoffset['cs'] = (tcp.seq + 1)
            elif ((conn.nextoffset['sc'] is None) and (addr != conn.addr)):
                conn.nextoffset['sc'] = (tcp.seq + 1)
            self.track(addr, str(tcp.data), ts, state='established', offset=tcp.seq, **kwargs)
        else:
            if ((tcp.flags == dpkt.tcp.TH_SYN) or (tcp.flags == ((dpkt.tcp.TH_SYN | dpkt.tcp.TH_CWR) | dpkt.tcp.TH_ECE))):
                if conn:
                    self.close(conn, ts)
                conn = self.track(addr, ts=ts, state='init', **kwargs)
                if conn:
                    conn.nextoffset['cs'] = (tcp.seq + 1)
            elif (tcp.flags == (dpkt.tcp.TH_SYN | dpkt.tcp.TH_ACK)):
                if (conn and (tcp.ack == conn.nextoffset['cs'])):
                    conn.nextoffset['sc'] = (tcp.seq + 1)
                    conn.state = 'established'
            if (conn and (conn.state == 'established')):
                self.track(addr, str(tcp.data), ts, state='established', offset=tcp.seq, **kwargs)
        if (conn and (tcp.flags & (dpkt.tcp.TH_FIN | dpkt.tcp.TH_RST))):
            conn.closeIP(addr[0])
        if (conn and conn.connectionClosed()):
            self.close(conn, ts)
    except Exception as e:
        self._exc(e)
