Skip to content

Commit

Permalink
Multiple PeerConnections with the same nodeId but different PeerAddre…
Browse files Browse the repository at this point in the history
…ss (#1422)
  • Loading branch information
vivien-apple authored and shana-apple committed Jul 28, 2020
1 parent a26ce1f commit 1642652
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/transport/PeerConnections.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ class PeerConnections
state->SetLastActivityTimeMs(mTimeSource.GetCurrentMonotonicTimeMs());
}

/// Convenience method to expired a peer connection state and fired the related callback
void MarkConnectionExpired(PeerConnectionState * state)
{
if (OnConnectionExpired)
{
OnConnectionExpired(*state, mConnectionExpiredArgument);
}

*state = PeerConnectionState(PeerAddress::Uninitialized());
}

/**
* Iterates through all active connections and expires any connection with an idle time
* larger than the given amount.
Expand All @@ -157,13 +168,7 @@ class PeerConnections
continue; // not expired
}

if (OnConnectionExpired)
{
OnConnectionExpired(mStates[i], mConnectionExpiredArgument);
}

// Connection is assumed expired, marking it as invalid
mStates[i] = PeerConnectionState(PeerAddress::Uninitialized());
MarkConnectionExpired(&mStates[i]);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/transport/SecureSessionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ void SecureSessionMgr::HandleDataReceived(const MessageHeader & header, const Pe
{
if (!connection->mPeerConnections.FindPeerConnectionState(peerAddress, &state))
{
if (header.GetSourceNodeId().HasValue())
{
// If the data is from a new address BUT the node id is the same as a previous
// connection, mark the previous connection invalid in order to not have duplicate node ids.
if (connection->mPeerConnections.FindPeerConnectionState(header.GetSourceNodeId().Value(), &state))
{
connection->mPeerConnections.MarkConnectionExpired(state);
}
}

ChipLogProgress(Inet, "New peer connection received.");

err = connection->AllocateNewConnection(header, peerAddress, &state);
Expand Down

0 comments on commit 1642652

Please sign in to comment.