aeron-driver/src/main/java/io/aeron/driver/PublicationImage.java
int insertPacket(
        final int termId,
        final int termOffset,
        final UnsafeBuffer buffer,
        final int length,
        final int transportIndex,
        final InetSocketAddress srcAddress)
    {
        final boolean isHeartbeat = DataHeaderFlyweight.isHeartbeat(buffer, length);
        final long packetPosition = computePosition(termId, termOffset, positionBitsToShift, initialTermId);
        final long proposedPosition = isHeartbeat ? packetPosition : packetPosition + length;

        if (!isFlowControlUnderRun(packetPosition) && !isFlowControlOverRun(proposedPosition))
        {
            trackConnection(transportIndex, srcAddress, lastPacketTimestampNs);

            if (isHeartbeat)
            {
                if (DataHeaderFlyweight.isEndOfStream(buffer) && !isEndOfStream && allEos(transportIndex))
                {
                    LogBufferDescriptor.endOfStreamPosition(rawLog.metaData(), proposedPosition);
                    isEndOfStream = true;
                }

                heartbeatsReceived.incrementOrdered();
            }
            else
            {
                final UnsafeBuffer termBuffer = termBuffers[indexByPosition(packetPosition, positionBitsToShift)];
                TermRebuilder.insert(termBuffer, termOffset, buffer, length);
            }

            lastPacketTimestampNs = cachedNanoClock.nanoTime();
            hwmPosition.proposeMaxOrdered(proposedPosition);
        }

        return length;
    }
int insertPacket(
        final int termId,
        final int termOffset,
        final UnsafeBuffer buffer,
        final int length,
        final int transportIndex,
        final InetSocketAddress srcAddress)
    {
        final boolean isHeartbeat = DataHeaderFlyweight.isHeartbeat(buffer, length);
        final long packetPosition = computePosition(termId, termOffset, positionBitsToShift, initialTermId);
        final long proposedPosition = isHeartbeat ? packetPosition : packetPosition + length;

        if (!isFlowControlUnderRun(packetPosition) && !isFlowControlOverRun(proposedPosition))
        {
            trackConnection(transportIndex, srcAddress, lastPacketTimestampNs);

            if (isHeartbeat)
            {
                if (DataHeaderFlyweight.isEndOfStream(buffer) && !isEndOfStream && allEos(transportIndex))
                {
                    LogBufferDescriptor.endOfStreamPosition(rawLog.metaData(), proposedPosition);
                    isEndOfStream = true;
                }

                heartbeatsReceived.incrementOrdered();
            }
            else
            {
                final UnsafeBuffer termBuffer = termBuffers[indexByPosition(packetPosition, positionBitsToShift)];
                TermRebuilder.insert(termBuffer, termOffset, buffer, length);
            }

            lastPacketTimestampNs = cachedNanoClock.nanoTime();
            hwmPosition.proposeMaxOrdered(proposedPosition);
        }

        return length;
    }
Insert frame into term buffer.

@param termId         for the data packet to insert into the appropriate term.
@param termOffset     for the start of the packet in the term.
@param buffer         for the data packet to insert into the appropriate term.
@param length         of the data packet
@param transportIndex which the packet came from.
@param srcAddress     which the packet came from.
@return number of bytes applied as a result of this insertion.