Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos and ensure odd-numbered channels have odd numbers #587

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ message ChatMessage {
}
```

A *message_id* of zero (or omitted) indicates that the recipient doesn't expect acknowledgement.
A *message_id* of zero (or omitted) indicates that the sender doesn't expect acknowledgement.

If *message_id* is non-zero, the recipient should acknowledge receiving this message by sending
*ChatAcknowledge*. Unacknowledged messages may be re-sent with the same *message_id*, and the
Expand Down
5 changes: 2 additions & 3 deletions src/protocol/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ bool ConnectionPrivate::writePacket(int channelId, const QByteArray &data)

int ConnectionPrivate::availableOutboundChannelId()
{
// Server opens even-nubmered channels, client opens odd-numbered
// Server opens even-numbered channels, client opens odd-numbered
bool evenNumbered = (direction == Connection::ServerSide);
const int minId = evenNumbered ? 2 : 1;
const int maxId = evenNumbered ? (UINT16_MAX-1) : UINT16_MAX;
Expand All @@ -470,8 +470,7 @@ int ConnectionPrivate::availableOutboundChannelId()
// Find an unused id, trying a maximum of 100 times, using a random step to avoid collision
for (int i = 0; i < 100 && channels.contains(nextOutboundChannelId); i++) {
nextOutboundChannelId += 1 + (qrand() % 200);
if (evenNumbered)
nextOutboundChannelId += nextOutboundChannelId % 2;
nextOutboundChannelId += (nextOutboundChannelId % 2) + (evenNumbered ? 0 : 1);
if (nextOutboundChannelId > maxId)
nextOutboundChannelId = minId;
}
Expand Down