コード例 #1
0
        public NetworkTcpSession(Packets.TcpPacket tcpSynPacket, NetworkHost clientHost, NetworkHost serverHost, ISessionProtocolFinderFactory protocolFinderFactory)
        {
            if (tcpSynPacket.FlagBits.Synchronize) //It's normal to start the session with a SYN flag
            {
                FiveTuple fiveTuple = new FiveTuple(clientHost, tcpSynPacket.SourcePort, serverHost, tcpSynPacket.DestinationPort, FiveTuple.TransportProtocol.TCP);
                this.flow = new NetworkFlow(fiveTuple, tcpSynPacket.ParentFrame.Timestamp, tcpSynPacket.ParentFrame.Timestamp, 0, 0);
                //this.synPacketTimestamp=tcpSynPacket.ParentFrame.Timestamp;
                //this.clientHost=clientHost;
                //this.serverHost=serverHost;
                //this.clientTcpPort=tcpSynPacket.SourcePort;
                //this.serverTcpPort=tcpSynPacket.DestinationPort;

                this.synPacketReceived    = false;
                this.synAckPacketReceived = false;
                this.finPacketReceived    = false;
                this.clientToServerFinPacketSequenceNumber = UInt32.MaxValue;
                this.serverToClientFinPacketSequenceNumber = UInt32.MaxValue;
                this.sessionEstablished = false;
                this.sessionClosed      = false;

                this.startFrameNumber = tcpSynPacket.ParentFrame.FrameNumber;

                this.clientToServerTcpDataStream = null;
                this.serverToClientTcpDataStream = null;


                this.protocolFinder = protocolFinderFactory.CreateProtocolFinder(this.flow, this.startFrameNumber);
            }
            else
            {
                throw new Exception("SYN flag not set on TCP packet");
            }
        }
コード例 #2
0
 public NetworkFlow(FiveTuple fiveTuple, DateTime startTime, DateTime endTime, long bytesSentClient, long bytesSentServer)
 {
     this.FiveTuple       = fiveTuple;
     this.StartTime       = startTime;
     this.EndTime         = endTime;
     this.BytesSentClient = bytesSentClient;
     this.BytesSentServer = bytesSentServer;
 }
コード例 #3
0
        public FileTransfer.FileStreamAssembler MergeAsStereoWavAssembler(AudioStream other)
        {
            uint sampleRate = 8000;

            FileTransfer.WavFileAssembler mergedAssembler = new FileTransfer.WavFileAssembler("MergedAudioStreams-" + FiveTuple.GetHashCode() + ".wav", this.fileStreamAssemblerList, this.FiveTuple, FileTransfer.FileStreamTypes.RTP, this.initialFrameNumber, this.StartTime, sampleRate);
            //figure out if sample rates match with sampleTicks etc.
            //double thisSampleRateSkew = this.GetSampleTicksPerSecond() / sampleRate;
            //double otherSampleRateSkew = other.GetSampleTicksPerSecond() / sampleRate;

            //if (thisSampleRateSkew > 0.9 && thisSampleRateSkew < 1.11 && otherSampleRateSkew > 0.9 && otherSampleRateSkew < 1.11) {
            //figure out the correct start time and lock that to a sampleTick
            double nanosecondHundredsPerSample = 10000000.0 / sampleRate;//8000Hz => 1250

            SampleChunkInfo thisTimeReference        = this.GetMinJitterTimeReference(sampleRate);
            TimeSpan        thisTicksReferenceOffset = new TimeSpan((long)(nanosecondHundredsPerSample * ((int)thisTimeReference.SampleTick - this.sampleInfo[0].SampleTick)));
            DateTime        thisFirstSampleTimestamp = thisTimeReference.Timestamp.Subtract(thisTicksReferenceOffset);

            SampleChunkInfo otherTimeReference        = other.GetMinJitterTimeReference(sampleRate);
            TimeSpan        otherTicksReferenceOffset = new TimeSpan((long)(nanosecondHundredsPerSample * ((int)otherTimeReference.SampleTick - other.sampleInfo[0].SampleTick)));
            DateTime        otherFirstSampleTimestamp = otherTimeReference.Timestamp.Subtract(otherTicksReferenceOffset);

            long thisSampleTicksOffset, otherSampleTicksOffset;

            if (thisFirstSampleTimestamp < otherFirstSampleTimestamp)
            {
                thisSampleTicksOffset  = this.sampleInfo[0].SampleTick;
                otherSampleTicksOffset = otherTimeReference.SampleTick - (long)(otherTimeReference.Timestamp.Subtract(thisFirstSampleTimestamp).Ticks / nanosecondHundredsPerSample);
            }
            else
            {
                thisSampleTicksOffset  = thisTimeReference.SampleTick - (long)(thisTimeReference.Timestamp.Subtract(otherFirstSampleTimestamp).Ticks / nanosecondHundredsPerSample);
                otherSampleTicksOffset = other.sampleInfo[0].SampleTick;
            }

            var thisLastTuple  = this.sampleInfo[this.sampleInfo.Count - 1];
            var otherLastTuple = other.sampleInfo[other.sampleInfo.Count - 1];

            //uint metaDataLength = 0;
            mergedAssembler.TryActivate();



            //nSamples might be incorrect here
            Pcm16BitSampleStream thisStream  = new Pcm16BitSampleStream(this, thisSampleTicksOffset, true);
            Pcm16BitSampleStream otherStream = new Pcm16BitSampleStream(other, otherSampleTicksOffset, true);

            //uint nSamples = (uint)Math.Max(thisLastTuple.SampleTick + thisLastTuple.DataLength - thisSampleTicksOffset, otherLastTuple.SampleTick + otherLastTuple.DataLength - otherSampleTicksOffset);
            uint nSamples = mergedAssembler.CountSamplesInStreams(thisStream, otherStream);

            //reset positions
            thisStream.Position  = 0;
            otherStream.Position = 0;

            mergedAssembler.WriteSampleStreamToFile(nSamples, thisStream, otherStream);

            //mergedAssembler.FinishAssembling();
            return(mergedAssembler);
        }
コード例 #4
0
        /*
         * public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, AudioFormat format,
         *  FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber) {
         */
        public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, PacketParser.PacketHandlers.RtpPacketHandler.RtpPayloadType format, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber)
        {
            this.SourceHost      = sourceHost;
            this.DestinationHost = destinationHost;
            this.Format          = format;
            //this.Assembler = assembler;
            this.fileStreamAssemblerList = fileStreamAssemblerList;
            this.FiveTuple          = fiveTuple;
            this.initialFrameNumber = initialFrameNumber;
            this.sampleCount        = 0;
            //The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.
            //The GetTempFileName method will raise an IOException if no unique temporary file name is available.To resolve this error, delete all unneeded temporary files.
            this.tempFileName = System.IO.Path.GetTempFileName();
            FileTransfer.FileStreamAssemblerList.TempFileHandlers.Add(this);

            this.tempFileStream = new System.IO.FileStream(tempFileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read, 262144);
            this.sampleInfo     = new List <SampleChunkInfo>();
        }
コード例 #5
0
 public bool EqualsIgnoreDirection(FiveTuple other)
 {
     return(this.EqualsIgnoreDirection(other.ClientHost.IPAddress, other.ClientPort, other.ServerHost.IPAddress, other.ServerPort, other.Transport));
 }
コード例 #6
0
        /// <summary>
        /// Creates a truncated TCP session where the initial 3 way handshake is missing
        /// </summary>
        /// <param name="sourceHost"></param>
        /// <param name="destinationHost"></param>
        /// <param name="tcpPacket"></param>
        public NetworkTcpSession(NetworkHost sourceHost, NetworkHost destinationHost, Packets.TcpPacket tcpPacket, ISessionProtocolFinderFactory protocolFinderFactory)
        {
            //this part is used to create a cropped (truncated) session where the beginning is missing!
            //this.synPacketTimestamp=tcpPacket.ParentFrame.Timestamp;
            this.synPacketReceived    = true;
            this.synAckPacketReceived = true;
            this.finPacketReceived    = false;
            this.sessionEstablished   = false;//I will change this one soon,...
            this.sessionClosed        = false;

            this.startFrameNumber = tcpPacket.ParentFrame.FrameNumber;

            this.clientToServerTcpDataStream = null;
            this.serverToClientTcpDataStream = null;


            //now let's do a qualified guess of who is the server and who is client...

            FiveTuple fiveTuple;

            System.Collections.Generic.List <ApplicationLayerProtocol> sourcePortProtocols      = new List <ApplicationLayerProtocol>(TcpPortProtocolFinder.GetProbableApplicationLayerProtocols(tcpPacket.SourcePort, tcpPacket.SourcePort));
            System.Collections.Generic.List <ApplicationLayerProtocol> destinationPortProtocols = new List <ApplicationLayerProtocol>(TcpPortProtocolFinder.GetProbableApplicationLayerProtocols(tcpPacket.DestinationPort, tcpPacket.DestinationPort));
            if (sourcePortProtocols.Count > destinationPortProtocols.Count)  //packet is server -> client
            //this.clientHost=destinationHost;
            //this.serverHost=sourceHost;
            //this.clientTcpPort=tcpPacket.DestinationPort;
            //this.serverTcpPort=tcpPacket.SourcePort;
            {
                fiveTuple = new FiveTuple(destinationHost, tcpPacket.DestinationPort, sourceHost, tcpPacket.SourcePort, FiveTuple.TransportProtocol.TCP);
                this.flow = new NetworkFlow(fiveTuple, tcpPacket.ParentFrame.Timestamp, tcpPacket.ParentFrame.Timestamp, 0, 0);
                this.SetEstablished(tcpPacket.AcknowledgmentNumber, tcpPacket.SequenceNumber);
            }
            else if (destinationPortProtocols.Count > 0)  //packet is client -> server
            //this.clientHost=sourceHost;
            //this.serverHost=destinationHost;
            //this.clientTcpPort=tcpPacket.SourcePort;
            //this.serverTcpPort=tcpPacket.DestinationPort;

            {
                fiveTuple = new FiveTuple(sourceHost, tcpPacket.SourcePort, destinationHost, tcpPacket.DestinationPort, FiveTuple.TransportProtocol.TCP);
                this.flow = new NetworkFlow(fiveTuple, tcpPacket.ParentFrame.Timestamp, tcpPacket.ParentFrame.Timestamp, 0, 0);
                this.SetEstablished(tcpPacket.SequenceNumber, tcpPacket.AcknowledgmentNumber);
            }
            else if (tcpPacket.SourcePort < tcpPacket.DestinationPort)//packet is server -> client
            //this.clientHost=destinationHost;
            //this.serverHost=sourceHost;
            //this.clientTcpPort=tcpPacket.DestinationPort;
            //this.serverTcpPort=tcpPacket.SourcePort;

            {
                fiveTuple = new FiveTuple(destinationHost, tcpPacket.DestinationPort, sourceHost, tcpPacket.SourcePort, FiveTuple.TransportProtocol.TCP);
                this.flow = new NetworkFlow(fiveTuple, tcpPacket.ParentFrame.Timestamp, tcpPacket.ParentFrame.Timestamp, 0, 0);
                this.SetEstablished(tcpPacket.AcknowledgmentNumber, tcpPacket.SequenceNumber);
            }
            else  //packet is client -> server
                  //this.clientHost=sourceHost;
                  //this.serverHost=destinationHost;
                  //this.clientTcpPort=tcpPacket.SourcePort;
                  //this.serverTcpPort=tcpPacket.DestinationPort;

            {
                fiveTuple = new FiveTuple(sourceHost, tcpPacket.SourcePort, destinationHost, tcpPacket.DestinationPort, FiveTuple.TransportProtocol.TCP);
                this.flow = new NetworkFlow(fiveTuple, tcpPacket.ParentFrame.Timestamp, tcpPacket.ParentFrame.Timestamp, 0, 0);
                this.SetEstablished(tcpPacket.SequenceNumber, tcpPacket.AcknowledgmentNumber);
            }

            this.protocolFinder = protocolFinderFactory.CreateProtocolFinder(this.flow, this.startFrameNumber);
        }
コード例 #7
0
 public NetworkFlow(FiveTuple fiveTuple, DateTime startTime) : this(fiveTuple, startTime, startTime, 0, 0)
 {
     //nothing more required
 }
コード例 #8
0
        /*
         * public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, AudioFormat format,
         *  FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber) {
         */
        public AudioStream(NetworkHost sourceHost, NetworkHost destinationHost, PacketParser.PacketHandlers.RtpPacketHandler.RtpPayloadType format, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, long initialFrameNumber)
        {
            this.SourceHost      = sourceHost;
            this.DestinationHost = destinationHost;
            this.Format          = format;
            //this.Assembler = assembler;
            this.fileStreamAssemblerList = fileStreamAssemblerList;
            this.FiveTuple          = fiveTuple;
            this.initialFrameNumber = initialFrameNumber;

            this.sampleCount = 0;
            this.tempFS      = new System.IO.FileStream(System.IO.Path.GetTempFileName(), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.Read, 262144);
            this.sampleInfo  = new List <SampleChunkInfo>();
        }