C# Class Persistence.KademliaRepository

Class implementig a specialized repository that will be used by kademlia peer to store information need by the DHT. Kademlia repository use two distinct collection to implements the three tier representation of knowledge. The first collection contains keywords which are small enough to be exchanged frequently on the network; each keyword has a list of related tags. A tag is related to a keyword if this word is used in one or more of the following tag fields: title, author and album. There's a list of semanticless word that cannot be used as keyword. The second collection contains resources which are composed of complete tag information and a list of DHT elements (read Kademlia node references). This resources are necessary for the Transport Layer in order to identify the location of possible suppliers for a given track.
Inheritance: IDisposable
ファイルを表示 Open project: zencoders/sambatyon Class Usage Examples

Public Methods

Method Description
ContainsTag ( string tagid ) : bool

Checks if the repository contains a given tag

ContainsUrl ( string tagid, Uri url ) : bool

Checks if the given resource contains the Url in its supplier list

DeleteTag ( string tid ) : bool

Deletes a tag with a given identifier. This method finds all keywords containing a reference to the tag to be deleted and removes the tag identifier from the keyword's list; then it search for keywords that has an empty list and deletes them. At the end the method removes the resource from the repository

DiscardSemanticlessWords ( string str ) : string

This methods removes all duplicated white space and then removes all semanticless words.

Dispose ( ) : void

Method used to dispose the repository

Expire ( ) : void

Method that removes the expired elements from the DHT. This method search for expired element and add it to a structure, then delete all the expired elements and if a resource remanins without any supplier will be deleted too.

Get ( string tagid ) : KademliaResource

Returns the Resource identified by the given taghash.

GetAllElements ( ) : LinkedList

Returns a list of all resources of the repository.

GetPublicationTime ( string tagid, Uri url ) : System.DateTime

Returns the publication time of a Dht Element related to a Resource.

KademliaRepository ( string repType = "Raven", RepositoryConfiguration conf = null, string elementValidity = "1", string semanticFilter = KademliaRepository.DefaultSemanticFilterRegexString ) : System

Constructor for the Kademlia Repository. This begins with compiling regular expressions for whitespace and semanticless words and setting timespan sing the given values (if they are not passed, it uses the default). Then instantiates the repository of the fiven type and creates two indexes over the instantiatied repository. The first index is used to find keywords with an empty tag list; the second one is used to query keyword using tag identifier. Both indexes are necessary in order to cleanly delete resources and keywords from the repository

Put ( string tagid, Uri url, System.DateTime pubtime ) : bool

Method that implements the registration of a peer as supplier for a given resource. This method just load the resource and adds the Dht Element if it's not already in the suppliers list.

RefreshResource ( string tagid, Uri url, System.DateTime pubtime ) : bool

Sets the publication time of a Dht Element in order to avoid expiration

SearchFor ( string query ) : Persistence.KademliaResource[]

Performs search query over the repository. This split query in pieces and search for keywords that contains those pieces. Then for each keyword the method loads all the related resource.

StoreResource ( CompleteTag tag, Uri peer, System.DateTime pubtime ) : bool

Stores a tag as resource into the kademlia repository. If the resource already exists the method tries to add the given Url (with the desired publication time) to the list of suppliers for that resource; if the url is already known the method does nothing. If the resource is new first the method adds it to the repository and then generates a set of keywords related to the new resource. For each generated keyword, if this is already in the repository the tag identifier (that is the resource identifier too) will be added to the related tags list, if the keyword doesn't exist it will be created and its related tags list will contains only the new resource.

Private Methods

Method Description
generatePrimaryKey ( CompleteTag tag ) : string[]

Generates a clean list (without semanticless words) of keyword related to the given tag

Method Details

ContainsTag() public method

Checks if the repository contains a given tag
public ContainsTag ( string tagid ) : bool
tagid string Resource Identifier to search
return bool

ContainsUrl() public method

Checks if the given resource contains the Url in its supplier list
public ContainsUrl ( string tagid, Uri url ) : bool
tagid string Resource identifier
url System.Uri Url of the supplier
return bool

DeleteTag() public method

Deletes a tag with a given identifier. This method finds all keywords containing a reference to the tag to be deleted and removes the tag identifier from the keyword's list; then it search for keywords that has an empty list and deletes them. At the end the method removes the resource from the repository
public DeleteTag ( string tid ) : bool
tid string Identifier of the tag to be deleted
return bool

DiscardSemanticlessWords() public method

This methods removes all duplicated white space and then removes all semanticless words.
public DiscardSemanticlessWords ( string str ) : string
str string String to be cleaned
return string

Dispose() public method

Method used to dispose the repository
public Dispose ( ) : void
return void

Expire() public method

Method that removes the expired elements from the DHT. This method search for expired element and add it to a structure, then delete all the expired elements and if a resource remanins without any supplier will be deleted too.
public Expire ( ) : void
return void

Get() public method

Returns the Resource identified by the given taghash.
public Get ( string tagid ) : KademliaResource
tagid string Identifier of the resource to get
return KademliaResource

GetAllElements() public method

Returns a list of all resources of the repository.
public GetAllElements ( ) : LinkedList
return LinkedList

GetPublicationTime() public method

Returns the publication time of a Dht Element related to a Resource.
public GetPublicationTime ( string tagid, Uri url ) : System.DateTime
tagid string Resource Identifier
url System.Uri Url of the Dht Element
return System.DateTime

KademliaRepository() public method

Constructor for the Kademlia Repository. This begins with compiling regular expressions for whitespace and semanticless words and setting timespan sing the given values (if they are not passed, it uses the default). Then instantiates the repository of the fiven type and creates two indexes over the instantiatied repository. The first index is used to find keywords with an empty tag list; the second one is used to query keyword using tag identifier. Both indexes are necessary in order to cleanly delete resources and keywords from the repository
public KademliaRepository ( string repType = "Raven", RepositoryConfiguration conf = null, string elementValidity = "1", string semanticFilter = KademliaRepository.DefaultSemanticFilterRegexString ) : System
repType string Name of the repository type. The default repository type is RavenDB ("Raven")
conf RepositoryConfiguration Repository Configureation
elementValidity string Validity period of a Dht Element. Default value is 24 hours (1 day). The validity must /// be expressed in timespan format as described in MSDN reference for this type.
semanticFilter string Regular expression that will be used to remove semanticless word.
return System

Put() public method

Method that implements the registration of a peer as supplier for a given resource. This method just load the resource and adds the Dht Element if it's not already in the suppliers list.
public Put ( string tagid, Uri url, System.DateTime pubtime ) : bool
tagid string Resource Identifier
url System.Uri Url of the supplier
pubtime System.DateTime Publication Time for the supplier
return bool

RefreshResource() public method

Sets the publication time of a Dht Element in order to avoid expiration
public RefreshResource ( string tagid, Uri url, System.DateTime pubtime ) : bool
tagid string Resource Identifier
url System.Uri URL of the Dht Element to refresh
pubtime System.DateTime Publication time to set
return bool

SearchFor() public method

Performs search query over the repository. This split query in pieces and search for keywords that contains those pieces. Then for each keyword the method loads all the related resource.
public SearchFor ( string query ) : Persistence.KademliaResource[]
query string Query string
return Persistence.KademliaResource[]

StoreResource() public method

Stores a tag as resource into the kademlia repository. If the resource already exists the method tries to add the given Url (with the desired publication time) to the list of suppliers for that resource; if the url is already known the method does nothing. If the resource is new first the method adds it to the repository and then generates a set of keywords related to the new resource. For each generated keyword, if this is already in the repository the tag identifier (that is the resource identifier too) will be added to the related tags list, if the keyword doesn't exist it will be created and its related tags list will contains only the new resource.
public StoreResource ( CompleteTag tag, Uri peer, System.DateTime pubtime ) : bool
tag CompleteTag Tag to store in the kademlia resource
peer System.Uri Url of the supplier
pubtime System.DateTime Publication TIme
return bool