Class PeerConnection
A connection between two peers.
Implements
Inherited Members
Namespace: PeerTalk
Assembly: PeerTalk.dll
Syntax
public class PeerConnection : IDisposable
Remarks
A connection is used to exchange messages between peers.
Properties
| Improve this Doc View SourceBytesRead
Number of bytes read over the connection.
Declaration
public long BytesRead { get; }
Property Value
Type | Description |
---|---|
Int64 |
BytesWritten
Number of bytes written over the connection.
Declaration
public long BytesWritten { get; }
Property Value
Type | Description |
---|---|
Int64 |
IdentityEstablished
Signals that the identity of the remote endpoint is established.
Declaration
public TaskCompletionSource<Peer> IdentityEstablished { get; }
Property Value
Type | Description |
---|---|
TaskCompletionSource<Peer> |
Remarks
This can be awaited.
IsActive
Determines if the connection to the remote can be used.
Declaration
public bool IsActive { get; }
Property Value
Type | Description |
---|---|
Boolean | true if the connection is active. |
IsIncoming
Determine which peer (local or remote) initiated the connection.
Declaration
public bool IsIncoming { get; set; }
Property Value
Type | Description |
---|---|
Boolean | true if the RemotePeer initiated the connection; otherwise, false. |
LastUsed
When the connection was last used.
Declaration
public DateTime LastUsed { get; }
Property Value
Type | Description |
---|---|
DateTime |
LocalAddress
The local peer's end point.
Declaration
public MultiAddress LocalAddress { get; set; }
Property Value
Type | Description |
---|---|
MultiAddress |
LocalPeer
The local peer.
Declaration
public Peer LocalPeer { get; set; }
Property Value
Type | Description |
---|---|
Peer |
LocalPeerKey
The private key of the local peer.
Declaration
public Key LocalPeerKey { get; set; }
Property Value
Type | Description |
---|---|
Key | Used to prove the identity of the LocalPeer. |
MuxerEstablished
Signals that the muxer for the connection is established.
Declaration
public TaskCompletionSource<Muxer> MuxerEstablished { get; }
Property Value
Type | Description |
---|---|
TaskCompletionSource<Muxer> |
Remarks
This can be awaited.
Protocols
The protocols that the connection will handle.
Declaration
public Dictionary<string, Func<PeerConnection, Stream, CancellationToken, Task>> Protocols { get; }
Property Value
Type | Description |
---|---|
Dictionary<String, Func<PeerConnection, Stream, CancellationToken, Task>> | The key is a protocol name, such as "/mplex/6.7.0". The value is a function that will process the protocol message. |
See Also
| Improve this Doc View SourceRemoteAddress
The remote peer's end point.
Declaration
public MultiAddress RemoteAddress { get; set; }
Property Value
Type | Description |
---|---|
MultiAddress |
RemotePeer
The remote peer.
Declaration
public Peer RemotePeer { get; set; }
Property Value
Type | Description |
---|---|
Peer |
SecurityEstablished
Signals that the security for the connection is established.
Declaration
public TaskCompletionSource<bool> SecurityEstablished { get; }
Property Value
Type | Description |
---|---|
TaskCompletionSource<Boolean> |
Remarks
This can be awaited.
Stream
The duplex stream between the two peers.
Declaration
public Stream Stream { get; set; }
Property Value
Type | Description |
---|---|
Stream |
Methods
| Improve this Doc View SourceAddProtocol(IPeerProtocol)
Add a protocol that the connection will handle.
Declaration
public void AddProtocol(IPeerProtocol protocol)
Parameters
Type | Name | Description |
---|---|---|
IPeerProtocol | protocol | A peer protocol to add. |
AddProtocols(IEnumerable<IPeerProtocol>)
Add a seequence of protocols that the connection will handle.
Declaration
public void AddProtocols(IEnumerable<IPeerProtocol> protocols)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IPeerProtocol> | protocols | The peer protocols to add. |
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
TODO
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing |
EstablishProtocolAsync(String, Stream, CancellationToken)
TODO:
Declaration
public Task EstablishProtocolAsync(string name, Stream stream, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | name | |
Stream | stream | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task |
EstablishProtocolAsync(String, CancellationToken)
TODO:
Declaration
public Task EstablishProtocolAsync(string name, CancellationToken cancel)
Parameters
Type | Name | Description |
---|---|---|
String | name | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task |
InitiateAsync(IEnumerable<IEncryptionProtocol>, CancellationToken)
Establish the connection with the remote node.
Declaration
public Task InitiateAsync(IEnumerable<IEncryptionProtocol> securityProtocols, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IEncryptionProtocol> | securityProtocols | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task |
Remarks
This should be called when the local peer wants a connection with the remote peer.
ReadMessagesAsync(Stream, CancellationToken)
Starts reading messages from the remote peer on the specified stream.
Declaration
public Task ReadMessagesAsync(Stream stream, CancellationToken cancel)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | |
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task |
ReadMessagesAsync(CancellationToken)
Starts reading messages from the remote peer.
Declaration
public Task ReadMessagesAsync(CancellationToken cancel)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancel |
Returns
Type | Description |
---|---|
Task |
Events
| Improve this Doc View SourceClosed
Signals that the connection is closed (disposed).
Declaration
public event EventHandler<PeerConnection> Closed
Event Type
Type | Description |
---|---|
EventHandler<PeerConnection> |