C# Class DistributedFileSystem.SwarmChunkAvailability

Show file Open project: MarcFletcher/NetworkComms.Net

Public Methods

Method Description
AddOrUpdateCachedPeerChunkFlags ( ConnectionInfo connectionInfo, ChunkFlags latestChunkFlags, bool superPeer = false, bool setIPEndPointOnline = true ) : void

Adds or updates a peer to the local availability list. Useful for when a peer informs us of an updated availability.

AllPeerEndPoints ( ) : string[]

Returns an array containing all known peer endpoints in the format locaIP:port

AllPeerIdentifiers ( ) : string[]

Returns an array containing the network identifiers of every peer in this swarm

BroadcastItemRemoval ( string itemCheckSum, bool removeSwarmWide ) : void

Broadcast to all known peers that the local DFS is removing the specified item.

BroadcastLocalAvailability ( string itemCheckSum ) : void

Updates all peers in the swarm that we have updated a chunk

CachedNonLocalChunkExistences ( byte totalChunksInItem, PeerInfo>.Dictionary &nonLocalPeerAvailability ) : Dictionary>

Builds a dictionary of chunk availability throughout the current swarm for chunks we don't have locally. Keys are chunkIndex, peer network identifier, and peer total chunk count

ChunkHealthMetric ( byte chunkIndex, byte totalNumChunks ) : double

Metric used to determine the health of a chunk and whether swarm will benefit from a broadcasted update. A value greater than 1 signifies a healthy chunk availability.

ClearAllLocalAvailabilityFlags ( ) : void

Clear all chunk availability flags for the local peer

CloseConnectionsToCompletedPeers ( byte totalNumChunks ) : void

Closes established connections with completed peers as they are now redundant.

GetNewTimeoutCount ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : int

Returns the new timeout count value after incrementing the timeout count for the provided peer IPEndPoint.

IPEndPointBusy ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : bool

Get the provided peer IPEndPoint busy status

IPEndPointOnline ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : bool

Get the provided peer IPEndPoint online status

NumCompletePeersInSwarm ( byte totalItemChunks, bool excludeSuperPeers = false ) : int

The number of complete peers in this swarm.

NumPeersInSwarm ( bool excludeSuperPeers = false ) : int

The number of peers in this swarm

PeerChunkAvailability ( ShortGuid peerIdentifier ) : ChunkFlags

Returns the chunk flag availability of the requested peer.

PeerContactAllowed ( ShortGuid peerIdentifier, IPEndPoint peerEndPoint, bool superPeer ) : bool

Single method for determining if contact can be made with the request peer. Prevents loop back contact via matching identifier and currentLocalListenEndPoints. Finally uses the DFS.AllowedPeerIPS and DFS.DisallowedPeerIPS if set.

PeerExistsInSwarm ( IPEndPoint peerIPEndPoint ) : bool

Returns true if a peer with the provided IPEndPoint exists in the swarm

PeerExistsInSwarm ( ShortGuid networkIdentifier ) : bool

Returns true if a peer with the provided networkIdentifier exists in this SwarmChunkAvailability

PeerHasChunk ( ShortGuid networkIdentifier, byte chunkIndex ) : bool

Returns true if the specified peer has the specified chunkIndex.

PeerIsComplete ( ShortGuid networkIdentifier, byte totalNumChunks ) : bool

Returns true if a peer has a complete copy of the DFS item

PeerIsSuperPeer ( ShortGuid networkIdentifier ) : bool

Returns true if the specified peer is a super peer

RecordLocalChunkCompletion ( byte chunkIndex ) : void

Records a chunk as available for the local peer

RemoveOldPeerAtEndPoint ( ShortGuid currentActivePeerIdentifier, IPEndPoint currentActivePeerEndPoint ) : void

Removes any peers which have the same endPoint as the provided currentActivePeerEndPoint except one with matching currentActivePeerIdentifier

RemovePeerIPEndPointFromSwarm ( ShortGuid networkIdentifier, IPEndPoint peerEndPoint, bool forceRemoveWholePeer = false ) : void

Deletes knowledge of a peer IPEndPoint from our local swarm chunk availability. If peerEndPoint.Address is IPAddress.Any then the entire peer will be deleted.

SetIPEndPointBusy ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : void

Set the provided peer IPEndPoint busy status to busy

SetIPEndPointOffline ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : void

Set the provided peer IPEndPoint as offline

SetLocalChunkFlag ( byte chunkIndex, bool setAvailable ) : void

Sets our local availability

SwarmChunkAvailability ( List sourceConnectionInfoList, byte totalNumChunks ) : System

Creates a new instance of SwarmChunkAvailability

ThreadSafeSerialise ( ) : byte[]

Serialise this swarm chunk availability in a thread safe manner

UpdatePeerAvailability ( string itemCheckSum, int cascadeDepth, int responseWaitMS = 5000, Action buildLog = null ) : void

Update the chunk availability by contacting all existing peers. If a cascade depth greater than 1 is provided will also contact each peers peers.

Private Methods

Method Description
AfterSerialise ( ) : void
BeforeSerialise ( ) : void
SwarmChunkAvailability ( ) : System

Blank constructor used for serialisation

Method Details

AddOrUpdateCachedPeerChunkFlags() public method

Adds or updates a peer to the local availability list. Useful for when a peer informs us of an updated availability.
public AddOrUpdateCachedPeerChunkFlags ( ConnectionInfo connectionInfo, ChunkFlags latestChunkFlags, bool superPeer = false, bool setIPEndPointOnline = true ) : void
connectionInfo ConnectionInfo The connectionInfo of the remote peer
latestChunkFlags ChunkFlags The new chunk flags
superPeer bool True if this peer is a superPeer
setIPEndPointOnline bool Set the relevant IPEndPoint online as a result of updating chunk flags
return void

AllPeerEndPoints() public method

Returns an array containing all known peer endpoints in the format locaIP:port
public AllPeerEndPoints ( ) : string[]
return string[]

AllPeerIdentifiers() public method

Returns an array containing the network identifiers of every peer in this swarm
public AllPeerIdentifiers ( ) : string[]
return string[]

BroadcastItemRemoval() public method

Broadcast to all known peers that the local DFS is removing the specified item.
public BroadcastItemRemoval ( string itemCheckSum, bool removeSwarmWide ) : void
itemCheckSum string The checksum associated with this item
removeSwarmWide bool True if the item should be removed by all peers, swarm wide
return void

BroadcastLocalAvailability() public method

Updates all peers in the swarm that we have updated a chunk
public BroadcastLocalAvailability ( string itemCheckSum ) : void
itemCheckSum string The checksum associated with this item
return void

CachedNonLocalChunkExistences() public method

Builds a dictionary of chunk availability throughout the current swarm for chunks we don't have locally. Keys are chunkIndex, peer network identifier, and peer total chunk count
public CachedNonLocalChunkExistences ( byte totalChunksInItem, PeerInfo>.Dictionary &nonLocalPeerAvailability ) : Dictionary>
totalChunksInItem byte The total number of chunks in this item
nonLocalPeerAvailability PeerInfo>.Dictionary A quick reference dictionary for matching ConnectionInfo with PeerInfo
return Dictionary>

ChunkHealthMetric() public method

Metric used to determine the health of a chunk and whether swarm will benefit from a broadcasted update. A value greater than 1 signifies a healthy chunk availability.
public ChunkHealthMetric ( byte chunkIndex, byte totalNumChunks ) : double
chunkIndex byte The relevant chunk index
totalNumChunks byte The total number of chunks in this item
return double

ClearAllLocalAvailabilityFlags() public method

Clear all chunk availability flags for the local peer
public ClearAllLocalAvailabilityFlags ( ) : void
return void

CloseConnectionsToCompletedPeers() public method

Closes established connections with completed peers as they are now redundant.
public CloseConnectionsToCompletedPeers ( byte totalNumChunks ) : void
totalNumChunks byte The total number of chunks in this item
return void

GetNewTimeoutCount() public method

Returns the new timeout count value after incrementing the timeout count for the provided peer IPEndPoint.
public GetNewTimeoutCount ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : int
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
peerIPEndPoint System.Net.IPEndPoint The relevant IPEndPoint
return int

IPEndPointBusy() public method

Get the provided peer IPEndPoint busy status
public IPEndPointBusy ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : bool
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
peerIPEndPoint System.Net.IPEndPoint The relevant IPEndPoint
return bool

IPEndPointOnline() public method

Get the provided peer IPEndPoint online status
public IPEndPointOnline ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : bool
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
peerIPEndPoint System.Net.IPEndPoint The relevant IPEndPoint
return bool

NumCompletePeersInSwarm() public method

The number of complete peers in this swarm.
public NumCompletePeersInSwarm ( byte totalItemChunks, bool excludeSuperPeers = false ) : int
totalItemChunks byte The total number of chunks in this item
excludeSuperPeers bool True if super peers should be excluded from the count.
return int

NumPeersInSwarm() public method

The number of peers in this swarm
public NumPeersInSwarm ( bool excludeSuperPeers = false ) : int
excludeSuperPeers bool True if super peers should be excluded from the count.
return int

PeerChunkAvailability() public method

Returns the chunk flag availability of the requested peer.
public PeerChunkAvailability ( ShortGuid peerIdentifier ) : ChunkFlags
peerIdentifier NetworkCommsDotNet.Tools.ShortGuid The relevant network identifier
return ChunkFlags

PeerContactAllowed() public method

Single method for determining if contact can be made with the request peer. Prevents loop back contact via matching identifier and currentLocalListenEndPoints. Finally uses the DFS.AllowedPeerIPS and DFS.DisallowedPeerIPS if set.
public PeerContactAllowed ( ShortGuid peerIdentifier, IPEndPoint peerEndPoint, bool superPeer ) : bool
peerIdentifier NetworkCommsDotNet.Tools.ShortGuid The relevant network identifier
peerEndPoint System.Net.IPEndPoint The relevant IPEndPoint
superPeer bool True if this peer is a super peer
return bool

PeerExistsInSwarm() public method

Returns true if a peer with the provided IPEndPoint exists in the swarm
public PeerExistsInSwarm ( IPEndPoint peerIPEndPoint ) : bool
peerIPEndPoint System.Net.IPEndPoint The relevant IPEndPoint
return bool

PeerExistsInSwarm() public method

Returns true if a peer with the provided networkIdentifier exists in this SwarmChunkAvailability
public PeerExistsInSwarm ( ShortGuid networkIdentifier ) : bool
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
return bool

PeerHasChunk() public method

Returns true if the specified peer has the specified chunkIndex.
public PeerHasChunk ( ShortGuid networkIdentifier, byte chunkIndex ) : bool
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
chunkIndex byte The desired chunkIndex
return bool

PeerIsComplete() public method

Returns true if a peer has a complete copy of the DFS item
public PeerIsComplete ( ShortGuid networkIdentifier, byte totalNumChunks ) : bool
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
totalNumChunks byte The total number of chunks in this item
return bool

PeerIsSuperPeer() public method

Returns true if the specified peer is a super peer
public PeerIsSuperPeer ( ShortGuid networkIdentifier ) : bool
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
return bool

RecordLocalChunkCompletion() public method

Records a chunk as available for the local peer
public RecordLocalChunkCompletion ( byte chunkIndex ) : void
chunkIndex byte The relevant chunkIndex
return void

RemoveOldPeerAtEndPoint() public method

Removes any peers which have the same endPoint as the provided currentActivePeerEndPoint except one with matching currentActivePeerIdentifier
public RemoveOldPeerAtEndPoint ( ShortGuid currentActivePeerIdentifier, IPEndPoint currentActivePeerEndPoint ) : void
currentActivePeerIdentifier NetworkCommsDotNet.Tools.ShortGuid The NetworkIdenfier of the known active peer
currentActivePeerEndPoint System.Net.IPEndPoint The endPoint of the known active peer
return void

RemovePeerIPEndPointFromSwarm() public method

Deletes knowledge of a peer IPEndPoint from our local swarm chunk availability. If peerEndPoint.Address is IPAddress.Any then the entire peer will be deleted.
public RemovePeerIPEndPointFromSwarm ( ShortGuid networkIdentifier, IPEndPoint peerEndPoint, bool forceRemoveWholePeer = false ) : void
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
peerEndPoint System.Net.IPEndPoint The relevant IPEndPoint
forceRemoveWholePeer bool If true every IPEndPoint is removed for the provided network identifier
return void

SetIPEndPointBusy() public method

Set the provided peer IPEndPoint busy status to busy
public SetIPEndPointBusy ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : void
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
peerIPEndPoint System.Net.IPEndPoint The relevant IPEndPoint
return void

SetIPEndPointOffline() public method

Set the provided peer IPEndPoint as offline
public SetIPEndPointOffline ( ShortGuid networkIdentifier, IPEndPoint peerIPEndPoint ) : void
networkIdentifier NetworkCommsDotNet.Tools.ShortGuid The network identifier of the relevant peer
peerIPEndPoint System.Net.IPEndPoint The relevant IPEndPoint
return void

SetLocalChunkFlag() public method

Sets our local availability
public SetLocalChunkFlag ( byte chunkIndex, bool setAvailable ) : void
chunkIndex byte The chunk index flag to update
setAvailable bool The availability of the provided chunk
return void

SwarmChunkAvailability() public method

Creates a new instance of SwarmChunkAvailability
public SwarmChunkAvailability ( List sourceConnectionInfoList, byte totalNumChunks ) : System
sourceConnectionInfoList List A list of sources. Possibly multiple peers each with multiple IPEndPoints.
totalNumChunks byte The total number of chunks in the associated DFS item, used for initialising peer chunkflags
return System

ThreadSafeSerialise() public method

Serialise this swarm chunk availability in a thread safe manner
public ThreadSafeSerialise ( ) : byte[]
return byte[]

UpdatePeerAvailability() public method

Update the chunk availability by contacting all existing peers. If a cascade depth greater than 1 is provided will also contact each peers peers.
public UpdatePeerAvailability ( string itemCheckSum, int cascadeDepth, int responseWaitMS = 5000, Action buildLog = null ) : void
itemCheckSum string The checksum associated with this item. This will be used when contacting other peers /// for an update.
cascadeDepth int The depth of the update cascade. 0 - Contact only known peers for an update. 1 - Contact /// known peers and retrieve their known peers as well. >1 - Not implemented.
responseWaitMS int The maximum time to wait for the first update reply to be received before continuing.
buildLog Action An optional build log that can be updated with the progress of this method.
return void