C# Class Kademlia.LocalStorage

Stores key/value pairs assigned to our node. Automatically handles persistence to disk.
Show file Open project: zencoders/sambatyon

Public Methods

Method Description
Contains ( ID key, ID hash ) : bool

Do we have the specified value for the given key?

ContainsKey ( ID key ) : bool

Do we have any data for the given key?

ContainsTag ( ID tag_id ) : bool
ContainsUrl ( ID tag_id, Uri uri ) : bool
Expire ( ) : void

Expire old entries

Get ( ID key ) : IList

Get all data values for the given key, or an empty list.

Get ( ID key, ID hash ) : string

Get a particular value by key and hash, or null.

GetAllElements ( ) : IList
GetHashes ( ID key ) : IList

Gets a list of all value hashes for the given key It's a copy, iterate all you want.

GetKeys ( ) : IList

Get all IDs, so we can go through and republish everything. It's a copy so you can iterate it all you want.

GetPublicationTime ( ID tag_id, Uri uri ) : DateTime
GetPublicationTime ( ID key, ID hash ) : DateTime?

Returns when the given value was last inserted by its original publisher, or null if the value isn't present.

LocalStorage ( ) : System

Make a new LocalStorage. Uses the executing assembly's name to determine the filename for on-disk storage. If another LocalStorage on the machine is already using that file, we use a temp directory.

Put ( ID key, ID hash, string val, DateTime timestamp, TimeSpan keepFor ) : void

Store a key/value pair published originally at the given UTC timestamp. Value is kept until keepTime past timestamp.

Put ( ID tag_id, Uri uri, DateTime publicationTime ) : void
RefreshResource ( ID tag_id, Uri uri, DateTime timestamp ) : void
Restamp ( ID key, ID hash, DateTime newStamp, TimeSpan newKeep ) : void

Change the timing information on an existing entry, if extant.

SearchFor ( string query ) : KademliaResource[]
StoreResource ( CompleteTag tag, Uri uri, DateTime publicationTime ) : void

Private Methods

Method Description
BackgroundSave ( ) : void

Save the store in the background. PRECONSITION: We have the mutex and diskFilename is set.

CreatePath ( string path ) : void

Create all folders in a path, if missing.

PathFor ( ID key, ID hash ) : string

Where should we save a particular value?

SaveIndex ( ) : void

Save the index now.

Method Details

Contains() public method

Do we have the specified value for the given key?
public Contains ( ID key, ID hash ) : bool
key ID
hash ID
return bool

ContainsKey() public method

Do we have any data for the given key?
public ContainsKey ( ID key ) : bool
key ID
return bool

ContainsTag() public method

public ContainsTag ( ID tag_id ) : bool
tag_id ID
return bool

ContainsUrl() public method

public ContainsUrl ( ID tag_id, Uri uri ) : bool
tag_id ID
uri Uri
return bool

Expire() public method

Expire old entries
public Expire ( ) : void
return void

Get() public method

Get all data values for the given key, or an empty list.
public Get ( ID key ) : IList
key ID
return IList

Get() public method

Get a particular value by key and hash, or null.
public Get ( ID key, ID hash ) : string
key ID
hash ID
return string

GetAllElements() public method

public GetAllElements ( ) : IList
return IList

GetHashes() public method

Gets a list of all value hashes for the given key It's a copy, iterate all you want.
public GetHashes ( ID key ) : IList
key ID
return IList

GetKeys() public method

Get all IDs, so we can go through and republish everything. It's a copy so you can iterate it all you want.
public GetKeys ( ) : IList
return IList

GetPublicationTime() public method

public GetPublicationTime ( ID tag_id, Uri uri ) : DateTime
tag_id ID
uri Uri
return DateTime

GetPublicationTime() public method

Returns when the given value was last inserted by its original publisher, or null if the value isn't present.
public GetPublicationTime ( ID key, ID hash ) : DateTime?
key ID
hash ID
return DateTime?

LocalStorage() public method

Make a new LocalStorage. Uses the executing assembly's name to determine the filename for on-disk storage. If another LocalStorage on the machine is already using that file, we use a temp directory.
public LocalStorage ( ) : System
return System

Put() public method

Store a key/value pair published originally at the given UTC timestamp. Value is kept until keepTime past timestamp.
public Put ( ID key, ID hash, string val, DateTime timestamp, TimeSpan keepFor ) : void
key ID
hash ID The hash of the value
val string
timestamp DateTime
keepFor TimeSpan
return void

Put() public method

public Put ( ID tag_id, Uri uri, DateTime publicationTime ) : void
tag_id ID
uri Uri
publicationTime DateTime
return void

RefreshResource() public method

public RefreshResource ( ID tag_id, Uri uri, DateTime timestamp ) : void
tag_id ID
uri Uri
timestamp DateTime
return void

Restamp() public method

Change the timing information on an existing entry, if extant.
public Restamp ( ID key, ID hash, DateTime newStamp, TimeSpan newKeep ) : void
key ID
hash ID
newStamp DateTime
newKeep TimeSpan
return void

SearchFor() public method

public SearchFor ( string query ) : KademliaResource[]
query string
return KademliaResource[]

StoreResource() public method

public StoreResource ( CompleteTag tag, Uri uri, DateTime publicationTime ) : void
tag CompleteTag
uri Uri
publicationTime DateTime
return void