Class ConnectionManager
Manages the peer connections in a Swarm.
Inherited Members
Namespace: PeerTalk
Assembly: PeerTalk.dll
Syntax
public class ConnectionManager
Remarks
Enforces that only one connection exists to the Peer. This prevents the race condition when two simultaneously connect to each other.
TODO: Enforces a maximum number of open connections.
Properties
| Improve this Doc View SourceConnections
Gets the current active connections.
Declaration
public IEnumerable<PeerConnection> Connections { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<PeerConnection> |
Methods
| Improve this Doc View SourceAdd(PeerConnection)
Adds a new connection.
Declaration
public PeerConnection Add(PeerConnection connection)
Parameters
| Type | Name | Description |
|---|---|---|
| PeerConnection | connection | The PeerConnection to add. |
Returns
| Type | Description |
|---|---|
| PeerConnection | The connection that should be used. |
Remarks
If a connection already exists to the peer, the specified
connection is closed and existing connection
is returned.
Clear()
Removes and closes all connections.
Declaration
public void Clear()
IsConnected(Peer)
Determines if a connection exists to the specified peer.
Declaration
public bool IsConnected(Peer peer)
Parameters
| Type | Name | Description |
|---|---|---|
| Peer | peer | Another peer. |
Returns
| Type | Description |
|---|---|
| Boolean | true if there is a connection to the |
Remove(MultiHash)
Remove and close all connection to the peer ID.
Declaration
public bool Remove(MultiHash id)
Parameters
| Type | Name | Description |
|---|---|---|
| MultiHash | id | The ID of a Peer to remove. |
Returns
| Type | Description |
|---|---|
| Boolean | true if a connection was removed; otherwise, false. |
Remove(PeerConnection)
Remove a connection.
Declaration
public bool Remove(PeerConnection connection)
Parameters
| Type | Name | Description |
|---|---|---|
| PeerConnection | connection | The PeerConnection to remove. |
Returns
| Type | Description |
|---|---|
| Boolean | true if the connection was removed; otherwise, false. |
Remarks
The connection is removed from the list of
connections and is closed.
TryGet(Peer, out PeerConnection)
Gets the connection to the peer.
Declaration
public bool TryGet(Peer peer, out PeerConnection connection)
Parameters
| Type | Name | Description |
|---|---|---|
| Peer | peer | A peer. |
| PeerConnection | connection | The connection to the peer. |
Returns
| Type | Description |
|---|---|
| Boolean | true if a connection exists; otherwise false. |
Remarks
If the connection's underlaying Stream is closed, then the connection is removed.
Events
| Improve this Doc View SourcePeerDisconnected
Raised when a peer's connection is closed.
Declaration
public event EventHandler<MultiHash> PeerDisconnected
Event Type
| Type | Description |
|---|---|
| EventHandler<MultiHash> |