C# Class TransportService.TransportProtocol

Inheritance: ITransportProtocol
Mostrar archivo Open project: zencoders/sambatyon Class Usage Examples

Public Methods

Method Description
GetChunk ( ChunkRequest chkrq ) : void

Method used to request the download of a chunk from the network. When it is invoked from a remote peer it gets the chunk from the file and calls back the ReturnChunk method of the requestor.

ReStart ( ) : void

Method used to restart the download without reinitializing the buffer and other inner structures.

ReturnChunk ( ChunkResponse chkrs ) : void

Method used to return chunk to requestors. When it is invoked from a remote peer it invokes the saveOnBuffer method to store the chunk into the buffer. At the end this method reset the peer status.

Start ( string RID, int begin, long length, float>.Dictionary peerQueue, Stream s ) : void

Start method of the class. This method allows the thread to start the procedure of download of a remote resource in a separate thread. It initialize all attributes related to the resource.

Stop ( ) : void

Method used to stop the download.

TransportProtocol ( Uri uri, Persistence trackRepository ) : System

Constructor of the class. It builds the TransportProtocol sublayer, initializing its common attributes using the app settings in xml file.

Private Methods

Method Description
doWork ( ) : void

Method that actively downloads the resource from the network. This method runs while the file is not completely downloaded or a stop have been requested.

fullyDownloaded ( ) : bool

Method used to understand at each step if the download is complete. The download is complete when the number of chunk in DOWNLOADED state is equal to the size of buffer.

getNextChunk ( ) : void

Method used to require the next chunk to the network. It selects the best peer to whom ask the chunk, it calculates the next chunk to get and then invokes the chunk from the remote peer.

getRemoteChunk ( ChunkRequest chkrq, string address ) : void

Method used to require the chunk to the remote peer.

nextChunkToGet ( ) : int

Method used to find the index of the next chunk to get from the network.

saveOnBuffer ( int CID, byte payload ) : void

Method used to save the chunk arrived to the buffer inside the object. If the chunk arrived is the waited chunk, the nextArrived event is released. If the chunk arrived have an identificator greater to the waited the chunk is buffered and then all chunks in dirty state between the waited chunk and the arrived chunk is set to CLEAN state.

writeOnStream ( Object o, NextArrivedEventArgs e ) : void

Method having a signature that match the one required by delegate to execute. This method is used to write the newly arrived chunk to the stream. If the chunk enables other following chunks to been written to the stream the method itself writes the other chunks to the stream.

Method Details

GetChunk() public method

Method used to request the download of a chunk from the network. When it is invoked from a remote peer it gets the chunk from the file and calls back the ReturnChunk method of the requestor.
public GetChunk ( ChunkRequest chkrq ) : void
chkrq TransportService.Messages.ChunkRequest Message used to pass information about the Chunk requested
return void

ReStart() public method

Method used to restart the download without reinitializing the buffer and other inner structures.
public ReStart ( ) : void
return void

ReturnChunk() public method

Method used to return chunk to requestors. When it is invoked from a remote peer it invokes the saveOnBuffer method to store the chunk into the buffer. At the end this method reset the peer status.
public ReturnChunk ( ChunkResponse chkrs ) : void
chkrs TransportService.Messages.ChunkResponse Message used to transport the payload of a chunk
return void

Start() public method

Start method of the class. This method allows the thread to start the procedure of download of a remote resource in a separate thread. It initialize all attributes related to the resource.
public Start ( string RID, int begin, long length, float>.Dictionary peerQueue, Stream s ) : void
RID string Identificator of the resource
begin int Start point from the beginning of the file to begin download
length long >Total length in bytes of the resource
peerQueue float>.Dictionary PeerQueue of peers containing the resource with a score associated to each peer
s Stream Stream where the resource is written
return void

Stop() public method

Method used to stop the download.
public Stop ( ) : void
return void

TransportProtocol() public method

Constructor of the class. It builds the TransportProtocol sublayer, initializing its common attributes using the app settings in xml file.
public TransportProtocol ( Uri uri, Persistence trackRepository ) : System
uri System.Uri The URI of the transport layer
trackRepository Persistence The repository used to represent tracks over the network
return System