| 198 | } |
| 199 | |
| 200 | void Stream::HandleNextPacket (Packet * packet) |
| 201 | { |
| 202 | if (m_Status == eStreamStatusTerminated) |
| 203 | { |
| 204 | m_LocalDestination.DeletePacket (packet); |
| 205 | return; |
| 206 | } |
| 207 | m_NumReceivedBytes += packet->GetLength (); |
| 208 | if (!m_SendStreamID) |
| 209 | { |
| 210 | m_SendStreamID = packet->GetReceiveStreamID (); |
| 211 | if (!m_RemoteIdentity && !packet->from && packet->GetNACKCount () == 8 && // first incoming packet |
| 212 | memcmp (packet->GetNACKs (), m_LocalDestination.GetOwner ()->GetIdentHash (), 32)) |
| 213 | { |
| 214 | LogPrint (eLogWarning, "Streaming: Destination mismatch for ", m_LocalDestination.GetOwner ()->GetIdentHash ().ToBase32 ()); |
| 215 | m_LocalDestination.DeletePacket (packet); |
| 216 | return; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | if (!packet->IsNoAck ()) // ack received |
| 221 | ProcessAck (packet); |
| 222 | |
| 223 | int32_t receivedSeqn = packet->GetSeqn (); |
| 224 | if (!receivedSeqn && m_LastReceivedSequenceNumber >= 0) |
| 225 | { |
| 226 | uint16_t flags = packet->GetFlags (); |
| 227 | if (flags) |
| 228 | // plain ack with options |
| 229 | ProcessOptions (flags, packet); |
| 230 | else |
| 231 | // plain ack |
| 232 | { |
| 233 | LogPrint (eLogDebug, "Streaming: Plain ACK received"); |
| 234 | if (m_IsImmediateAckRequested) |
| 235 | { |
| 236 | auto ts = i2p::util::GetMillisecondsSinceEpoch (); |
| 237 | if (m_IsFirstRttSample) |
| 238 | { |
| 239 | m_RTT = ts - m_LastSendTime; |
| 240 | m_IsFirstRttSample = false; |
| 241 | } |
| 242 | else |
| 243 | m_RTT = (m_RTT + (ts - m_LastSendTime)) / 2; |
| 244 | m_IsImmediateAckRequested = false; |
| 245 | } |
| 246 | } |
| 247 | m_LocalDestination.DeletePacket (packet); |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | LogPrint (eLogDebug, "Streaming: Received seqn=", receivedSeqn, " on sSID=", m_SendStreamID); |
| 252 | if (m_ReceiveQueue.size () > m_MaxWindowSize*3) |
| 253 | { |
| 254 | LogPrint (eLogDebug, "Streaming: ReceiveQueue is full, delete packet"); |
| 255 | m_LocalDestination.DeletePacket (packet); |
| 256 | m_IsChoking3 = true; |
| 257 | if (!m_IsAckSendScheduled) |
nothing calls this directly
no test coverage detected