Skip to content

Commit bca31bf

Browse files
committed
Deduplicate some code handling init/initAck
1 parent f6d4f61 commit bca31bf

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/sctp_association.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,7 @@ namespace SctpDc { namespace Sctp {
246246

247247
void Association::incomingChunk(const InitChunk &chunk)
248248
{
249-
lastRcvdTsn_ = chunk.initialTsn() - 1;
250-
peerVerificationTag_ = chunk.initiateTag();
251-
remoteWindowCredit_ = chunk.receiverWindowCredit();
252-
ssthresh_ = remoteWindowCredit_;
253-
inboundStreamsCount_ = chunk.inboundStreamsCount();
254-
outboundStreamsCount_ = chunk.outboundStreamsCount();
255-
249+
initRemote(chunk);
256250
if (peerVerificationTag_ == 0) {
257251
abort(Error::VerificationTag);
258252
return;
@@ -274,6 +268,18 @@ namespace SctpDc { namespace Sctp {
274268
sendFirstPriority(packet);
275269
}
276270

271+
void Association::initRemote(const InitChunk &chunk)
272+
{
273+
lastRcvdTsn_ = chunk.initialTsn() - 1;
274+
peerVerificationTag_ = chunk.initiateTag();
275+
remoteWindowCredit_ = chunk.receiverWindowCredit();
276+
ssthresh_ = remoteWindowCredit_;
277+
inboundStreamsCount_ = chunk.inboundStreamsCount();
278+
outboundStreamsCount_ = chunk.outboundStreamsCount();
279+
cwnd_ = std::min(4 * mtu_, std::max(2 * mtu_, 4380u));
280+
// TODO make congestion window controller
281+
}
282+
277283
void Association::incomingChunk(const InitAckChunk &chunk)
278284
{
279285
const auto cookie = chunk.parameter<CookieParameter>();
@@ -282,13 +288,7 @@ namespace SctpDc { namespace Sctp {
282288
return;
283289
}
284290

285-
// TODO it's a dup of the init block above
286-
lastRcvdTsn_ = chunk.initialTsn() - 1;
287-
peerVerificationTag_ = chunk.initiateTag();
288-
remoteWindowCredit_ = chunk.receiverWindowCredit();
289-
ssthresh_ = remoteWindowCredit_;
290-
inboundStreamsCount_ = chunk.inboundStreamsCount();
291-
outboundStreamsCount_ = chunk.outboundStreamsCount();
291+
initRemote(chunk);
292292

293293
Packet packet;
294294
packet.appendChunk<CookieEchoChunk>(cookie.value());

src/sctp_association.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace SctpDc { namespace Sctp {
8383
void trySend();
8484
QByteArray makeStateCookie();
8585
void setError(Error error);
86+
void initRemote(const InitChunk &chunk);
8687

8788
void incomingChunk(const InitChunk &chunk);
8889
void incomingChunk(const InitAckChunk &chunk);

0 commit comments

Comments
 (0)