Skip to content

Commit a0d9b07

Browse files
feat(PeerConnection): add IsIncoming to determine the peer that initiated the connection
1 parent ccb63af commit a0d9b07

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

PeerTalk/src/PeerConnection.cs

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public class PeerConnection : IDisposable
5353
/// </value>
5454
public Key LocalPeerKey { get; set; }
5555

56+
/// <summary>
57+
/// Determine which peer (local or remote) initiated the connection.
58+
/// </summary>
59+
/// <value>
60+
/// <b>true</b> if the <see cref="RemotePeer"/> initiated the connection;
61+
/// otherwise, <b>false</b>.
62+
/// </value>
63+
public bool IsIncoming { get; set; }
64+
5665
/// <summary>
5766
/// The duplex stream between the two peers.
5867
/// </summary>

PeerTalk/src/Swarm.cs

+2
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ async Task<PeerConnection> DialAsync(Peer remote, MultiAddress addr, Cancellatio
577577
remote.ConnectedAddress = addr;
578578
var connection = new PeerConnection
579579
{
580+
IsIncoming = false,
580581
LocalPeer = LocalPeer,
581582
// TODO: LocalAddress
582583
LocalPeerKey = LocalPeerKey,
@@ -746,6 +747,7 @@ async void OnRemoteConnect(Stream stream, MultiAddress local, MultiAddress remot
746747

747748
var connection = new PeerConnection
748749
{
750+
IsIncoming = true,
749751
LocalPeer = LocalPeer,
750752
LocalAddress = local,
751753
LocalPeerKey = LocalPeerKey,

0 commit comments

Comments
 (0)