C# Class DistributedFileSystem.DFS

Provides functionality to rapidly distribute large files across a cluster of peers.
Mostrar archivo Open project: MarcFletcher/NetworkComms.Net

Private Properties

Property Type Description
CheckForChunkDataCacheTimeouts void
DFS System
DFSConnectionShutdown void
ElapsedTimerWorker void
IncomingChunkAvailabilityRequest void
IncomingChunkInterestReplyData void
IncomingChunkInterestReplyInfo void
IncomingChunkInterestRequest void
IncomingItemRemovalUpdate void
IncomingLocalItemBuild void
IncomingPeerChunkAvailabilityUpdate void
IncomingRemoteItemLinkRequest void
KnownPeersRequest void
KnownPeersUpdate void
LinkModeWorker void
LoadAllowedDisallowedPeerIPs void
RequestLocalItemBuilds void

Public Methods

Method Description
AddItem ( DistributedItem itemToAdd ) : DistributedItem

Adds a distributed item to the local cache and informs any known peers of the item availability

AllLocalDFSItemKeys ( bool completeItemsOnly = true ) : string[]

Returns all item MD5 checksums for DFS items

AllLocalDFSItemsWithBuildTime ( bool completeItemsOnly = true ) : DateTime>.Dictionary

Returns a dictionary of DFS items along with corresponding ItemBuildCompleted times

CheckForSharedItems ( string peerIP, int peerPort ) : void

Communicates with the provided peer to see if any item swarms can be linked. This is a single link event, possibly use InitialiseDFSLink() for a maintained link.

CloseConnectionToCompletedPeers ( ) : void

Closes all connections to peers who have completed items

DisableLogging ( ) : void

Disable logging in networkComms

EnableLogging ( ILogger logger ) : void

Enable logging in networkComms using the provided logging adaptor

GetDistributedItemByChecksum ( string itemCheckSum ) : DistributedItem

Returns the distributed item with a matching itemCheckSum. Returns null if item is not found.

GetDistributedItemByIdentifier ( string itemIdentifier ) : DistributedItem

Returns the distributed item with a matching itemIdentifier. Returns null if item is not found.

Initialise ( int initialPort, bool rangeRandomPortFailover = true ) : void

Initialises the DFS

InitialiseDFSLink ( string linkTargetIP, int linkTargetPort, DFSLinkMode linkMode ) : void

Initialises this DFS peer to repeat all items available on the linkTargetIP

ItemAlreadyInLocalCache ( DistributedItem item ) : bool

Returns true if the provided item is already present within the swarm

ItemAlreadyInLocalCache ( string itemCheckSum ) : bool

Returns true if an item with a matching itemCheckSum is present within the local cache

MostRecentlyCompletedItem ( ) : DistributedItem

Returns the most recently completed item in the DFS. Returns null if there are no DFS items.

PushItemToPeer ( Connection peerConnection, DistributedItem itemToDistribute, string completedPacketType ) : void

Introduces a new item into the swarm and sends a build command to the originating requester

RemoveAllItemsFromLocalOnly ( bool broadcastRemoval = false ) : void

Removes all items from local only

RemoveAllItemsFromLocalOnly ( string ItemTypeStr, bool broadcastRemoval = false ) : void

Remove any items from the DFS with a matching itemTypeStr

RemoveItem ( string itemCheckSum, bool broadcastRemoval = true, bool removeSwarmWide = false ) : void

Remove an item from the DFS. Possibly swarmWide and with or without a removal broadcast

Shutdown ( ) : void

Shutdown the DFS. All local DFS items are deleted.

Private Methods

Method Description
CheckForChunkDataCacheTimeouts ( ) : void

Flick through the chunk data cache and remove any items that have timed out

DFS ( ) : System
DFSConnectionShutdown ( Connection connection ) : void

If a connection is disconnected we want to make sure we handle it within the DFS

ElapsedTimerWorker ( ) : void

Runs in the background to estimate the elapsed time of the application. We can't use DateTime as elapsed time should not include time during which process was suspended

IncomingChunkAvailabilityRequest ( PacketHeader packetHeader, Connection connection, string itemCheckSum ) : void

UDP - A remote peer is requesting chunk availability for this local peer

IncomingChunkInterestReplyData ( PacketHeader packetHeader, Connection connection, byte incomingData ) : void

TCP - Received when a peer sends us the data portion of a chunk possibly following a request

IncomingChunkInterestReplyInfo ( PacketHeader packetHeader, Connection connection, ChunkAvailabilityReply incomingReply ) : void

UDP and TCP - Received when a peer sends us a chunk data information possibly following a request

IncomingChunkInterestRequest ( PacketHeader packetHeader, Connection connection, ChunkAvailabilityRequest incomingRequest ) : void

UDP - Received when a peer request a chunk

IncomingItemRemovalUpdate ( PacketHeader packetHeader, Connection connection, ItemRemovalUpdate itemRemovalUpdate ) : void

UDP - A remote peer is informing us that they no longer have an item

IncomingLocalItemBuild ( PacketHeader packetHeader, Connection connection, ItemAssemblyConfig assemblyConfig ) : void

TCP - Received by this DFS if a server is telling this instance to build a local file

IncomingPeerChunkAvailabilityUpdate ( PacketHeader packetHeader, Connection connection, PeerChunkAvailabilityUpdate updateDetails ) : void

UDP - A remote peer is announcing that it has an updated availability of chunks

IncomingRemoteItemLinkRequest ( PacketHeader packetHeader, Connection connection, DFSLinkRequest linkRequestData ) : void

TCP - A remote peer is trying to link DFS items

KnownPeersRequest ( PacketHeader packetHeader, Connection connection, string itemCheckSum ) : void

UDP - Used by a client when requesting a list of known peers

KnownPeersUpdate ( PacketHeader packetHeader, Connection connection, KnownPeerEndPoints peerList ) : void

UDP - The response to a DFS_KnownPeersRequest

LinkModeWorker ( ) : void

Background worker thread which maintains the link depending on the selected link mode

LoadAllowedDisallowedPeerIPs ( ) : void
RequestLocalItemBuilds ( PacketHeader packetHeader, Connection connection, string itemCheckSums ) : void

TCP - A remote peer has request a push of the provided itemCheckSums. This method is used primarily when in repeater mode

Method Details

AddItem() public static method

Adds a distributed item to the local cache and informs any known peers of the item availability
public static AddItem ( DistributedItem itemToAdd ) : DistributedItem
itemToAdd DistributedItem The item to add
return DistributedItem

AllLocalDFSItemKeys() public static method

Returns all item MD5 checksums for DFS items
public static AllLocalDFSItemKeys ( bool completeItemsOnly = true ) : string[]
completeItemsOnly bool If true only returns checksums for completed items
return string[]

AllLocalDFSItemsWithBuildTime() public static method

Returns a dictionary of DFS items along with corresponding ItemBuildCompleted times
public static AllLocalDFSItemsWithBuildTime ( bool completeItemsOnly = true ) : DateTime>.Dictionary
completeItemsOnly bool If true only returns information for completed items
return DateTime>.Dictionary

CheckForSharedItems() public static method

Communicates with the provided peer to see if any item swarms can be linked. This is a single link event, possibly use InitialiseDFSLink() for a maintained link.
public static CheckForSharedItems ( string peerIP, int peerPort ) : void
peerIP string The IPAddress of the peer
peerPort int The port of the peer
return void

CloseConnectionToCompletedPeers() public static method

Closes all connections to peers who have completed items
public static CloseConnectionToCompletedPeers ( ) : void
return void

DisableLogging() public static method

Disable logging in networkComms
public static DisableLogging ( ) : void
return void

EnableLogging() public static method

Enable logging in networkComms using the provided logging adaptor
public static EnableLogging ( ILogger logger ) : void
logger ILogger
return void

GetDistributedItemByChecksum() public static method

Returns the distributed item with a matching itemCheckSum. Returns null if item is not found.
public static GetDistributedItemByChecksum ( string itemCheckSum ) : DistributedItem
itemCheckSum string The item MD5 checksum to match
return DistributedItem

GetDistributedItemByIdentifier() public static method

Returns the distributed item with a matching itemIdentifier. Returns null if item is not found.
public static GetDistributedItemByIdentifier ( string itemIdentifier ) : DistributedItem
itemIdentifier string The item identifier to match
return DistributedItem

Initialise() public static method

Initialises the DFS
public static Initialise ( int initialPort, bool rangeRandomPortFailover = true ) : void
initialPort int The local listen port to use
rangeRandomPortFailover bool True if a random port should be select if the initialPort is unavailable
return void

InitialiseDFSLink() public static method

Initialises this DFS peer to repeat all items available on the linkTargetIP
public static InitialiseDFSLink ( string linkTargetIP, int linkTargetPort, DFSLinkMode linkMode ) : void
linkTargetIP string The IPAddress corresponding with the link seed
linkTargetPort int The port corresponding with the link seed
linkMode DFSLinkMode The link mode to be used
return void

ItemAlreadyInLocalCache() public static method

Returns true if the provided item is already present within the swarm
public static ItemAlreadyInLocalCache ( DistributedItem item ) : bool
item DistributedItem The relevant DFS item
return bool

ItemAlreadyInLocalCache() public static method

Returns true if an item with a matching itemCheckSum is present within the local cache
public static ItemAlreadyInLocalCache ( string itemCheckSum ) : bool
itemCheckSum string The relevant item MD5 checksum
return bool

MostRecentlyCompletedItem() public static method

Returns the most recently completed item in the DFS. Returns null if there are no DFS items.
public static MostRecentlyCompletedItem ( ) : DistributedItem
return DistributedItem

PushItemToPeer() public static method

Introduces a new item into the swarm and sends a build command to the originating requester
public static PushItemToPeer ( Connection peerConnection, DistributedItem itemToDistribute, string completedPacketType ) : void
peerConnection Connection The peer which requested the DFS item
itemToDistribute DistributedItem The item to be distributed
completedPacketType string The packet type to use once the item has been fully assembled
return void

RemoveAllItemsFromLocalOnly() public static method

Removes all items from local only
public static RemoveAllItemsFromLocalOnly ( bool broadcastRemoval = false ) : void
broadcastRemoval bool If true all peers will be notified that we are removing all items.
return void

RemoveAllItemsFromLocalOnly() public static method

Remove any items from the DFS with a matching itemTypeStr
public static RemoveAllItemsFromLocalOnly ( string ItemTypeStr, bool broadcastRemoval = false ) : void
ItemTypeStr string The item type string to match
broadcastRemoval bool If true all peers will be notified that we are removing matching items.
return void

RemoveItem() public static method

Remove an item from the DFS. Possibly swarmWide and with or without a removal broadcast
public static RemoveItem ( string itemCheckSum, bool broadcastRemoval = true, bool removeSwarmWide = false ) : void
itemCheckSum string The checksum corresponding with the item to remove
broadcastRemoval bool If true all peers will be notified that we are removing this item.
removeSwarmWide bool True if this item should be removed swarm wide
return void

Shutdown() public static method

Shutdown the DFS. All local DFS items are deleted.
public static Shutdown ( ) : void
return void