C# Class Brunet.Services.Dht.Dht

This class provides a client interface to the dht, the servers only work together on a neighboring basis but not on a whole system basis. It is up to the client to provide fault tolerance. This class does it by naive replication.
This class implements the fault tolerant portion of the Dht by using naive replication as well as fixing holes in the dht. A hole occurs when enough data results are received during a get to confirm existence, but not all the results returned a value. In the case of a hole, a put will be used to place the data back to seal the hole.
Inheritance: IDht
Mostrar archivo Open project: pstjuste/brunet Class Usage Examples

Public Properties

Property Type Description
DEGREE int
DELAY int
DhtLog System.Diagnostics.BooleanSwitch
MAJORITY int
Node Brunet.Node

Protected Properties

Property Type Description
_adgs_table System.Collections.Hashtable
_adps_table System.Collections.Hashtable
_online bool
_rpc RpcManager
_sync object

Public Methods

Method Description
AsyncCreate ( MemBlock key, MemBlock value, int ttl, Channel returns ) : void
AsyncGet ( MemBlock key, Channel returns ) : void This starts the get process by sending dht.Get to all the remote end points that contain the key we're looking up. The next step is is when the results are placed in the channel and GetEnqueueHandler is called or GetCloseHandler is called. This means the get needs to be stateful, that information is stored in the _adgs_table.
AsyncPut ( MemBlock key, MemBlock value, int ttl, Channel returns ) : void
AsyncPut ( MemBlock key, MemBlock value, int ttl, Channel returns, bool unique ) : void

This is the generic Put that is used by both the regular Put and Create methods. The use of the unique variable differentiates the two. This is asynchronous. Results are stored in the Channel returns. Creates and Puts return true if successful or exception if there are network errors in adding the entry, creates also fail if a previous entry exists. The work of determining success is handled in PutEnqueueHandler and PutCloseHandler.

Create ( MemBlock key, MemBlock value, int ttl ) : bool
Dht ( Node node ) : System

A default Dht client provides a DEGREE of 1 and a sychronous wait time of up to 60 seconds.

Dht ( Node node, int degree ) : System

Allows the user to specify the power of two of degrees to use. That is if degree=n, DEGREE for the dht is 2^n.

Dht ( Node node, int degree, int delay ) : System

Allows the user to specify the power of two of degrees to use. That is if degree=n, DEGREE for the dht is 2^n.

Get ( MemBlock key ) : System.Collections.Hashtable[]
GetEnqueueHandler ( Object o, EventArgs args ) : void

This is called as a result of a successful retrieval of data from a remote end point and performs follow up gets for remaining values

This adds the results to the entry in the _adgs_table. Once a value has been received by a majority of nodes, it is enqueued into the requestors returns channel. If not all results were retrieved follow up gets are performed, this is determined by looking at the state of the token, a non-null token implies there are remaining results.

MapToRing ( byte key ) : MemBlock[]

Get the hash of the first key and add 1/DEGREE * Address space to each successive key. The results are the positions in the ring where the data should be stored.

Put ( MemBlock key, MemBlock value, int ttl ) : bool
Put ( MemBlock key, MemBlock value, int ttl, bool unique ) : bool

This is the sychronous version of the generic Put used by both the Put and Create methods. The use of the unique variable differentiates the two. Returns true if successful or an exception if there are network errors in adding the entry, creates also fail if a previous entry exists.

PutCloseHandler ( Object o, EventArgs args ) : void

Protected Methods

Method Description
GetCloseHandler ( object o, EventArgs args ) : void

This is called by the Get callbacks when all the results for a get have come in. This looks at the results, finds holes, and does a follow up put to place the data back into the dht via GetFollowUp.

GetFollowUp ( AsDhtGetState adgs ) : void

Restores any of the Dht results that don't return all their values. We only get here at the end of a Dht return operation.

This analyzes the holes and fills them in individually. This only fills holes where there was a positive result (MAJORITY of results received).

GetLeaveEarly ( AsDhtGetState adgs ) : void

This helps us leave the Get early if we either have no results or our remaining results will not reach a majority due to too many nodes missing data. This closes the clients returns queue.

StateChangeHandler ( Node n, Node state ) : void

We're online once we are seeking connections, we're offline once Disconnect has been called.

Method Details

AsyncCreate() public method

public AsyncCreate ( MemBlock key, MemBlock value, int ttl, Channel returns ) : void
key MemBlock
value MemBlock
ttl int
returns Channel
return void

AsyncGet() public method

This starts the get process by sending dht.Get to all the remote end points that contain the key we're looking up. The next step is is when the results are placed in the channel and GetEnqueueHandler is called or GetCloseHandler is called. This means the get needs to be stateful, that information is stored in the _adgs_table.
public AsyncGet ( MemBlock key, Channel returns ) : void
key MemBlock
returns Channel
return void

AsyncPut() public method

public AsyncPut ( MemBlock key, MemBlock value, int ttl, Channel returns ) : void
key MemBlock
value MemBlock
ttl int
returns Channel
return void

AsyncPut() public method

This is the generic Put that is used by both the regular Put and Create methods. The use of the unique variable differentiates the two. This is asynchronous. Results are stored in the Channel returns. Creates and Puts return true if successful or exception if there are network errors in adding the entry, creates also fail if a previous entry exists. The work of determining success is handled in PutEnqueueHandler and PutCloseHandler.
public AsyncPut ( MemBlock key, MemBlock value, int ttl, Channel returns, bool unique ) : void
key MemBlock The index to store the value at.
value MemBlock The value to store.
ttl int The dht lease time for the key:value pair.
returns Channel The Channel where the result will be placed.
unique bool True to do a create, false otherwise.
return void

Create() public method

public Create ( MemBlock key, MemBlock value, int ttl ) : bool
key MemBlock
value MemBlock
ttl int
return bool

Dht() public method

A default Dht client provides a DEGREE of 1 and a sychronous wait time of up to 60 seconds.
public Dht ( Node node ) : System
node Brunet.Node The node to provide service for.
return System

Dht() public method

Allows the user to specify the power of two of degrees to use. That is if degree=n, DEGREE for the dht is 2^n.
public Dht ( Node node, int degree ) : System
node Brunet.Node The node to provide service for.
degree int n where DEGREE=2^n amount of replications to perform. ///
return System

Dht() public method

Allows the user to specify the power of two of degrees to use. That is if degree=n, DEGREE for the dht is 2^n.
public Dht ( Node node, int degree, int delay ) : System
node Brunet.Node The node to provide service for.
degree int n where DEGREE=2^n amount of replications to /// perform.
delay int User specified delay for synchronous calls in /// seconds.
return System

Get() public method

public Get ( MemBlock key ) : System.Collections.Hashtable[]
key MemBlock
return System.Collections.Hashtable[]

GetCloseHandler() protected method

This is called by the Get callbacks when all the results for a get have come in. This looks at the results, finds holes, and does a follow up put to place the data back into the dht via GetFollowUp.
protected GetCloseHandler ( object o, EventArgs args ) : void
o object The channel representing a specific get.
args System.EventArgs Unused.
return void

GetEnqueueHandler() public method

This is called as a result of a successful retrieval of data from a remote end point and performs follow up gets for remaining values
This adds the results to the entry in the _adgs_table. Once a value has been received by a majority of nodes, it is enqueued into the requestors returns channel. If not all results were retrieved follow up gets are performed, this is determined by looking at the state of the token, a non-null token implies there are remaining results.
public GetEnqueueHandler ( Object o, EventArgs args ) : void
o Object The channel used to store the results.
args System.EventArgs Unused.
return void

GetFollowUp() protected method

Restores any of the Dht results that don't return all their values. We only get here at the end of a Dht return operation.
This analyzes the holes and fills them in individually. This only fills holes where there was a positive result (MAJORITY of results received).
protected GetFollowUp ( AsDhtGetState adgs ) : void
adgs AsDhtGetState The AsDhtGetState to analyze for follow up.
return void

GetLeaveEarly() protected method

This helps us leave the Get early if we either have no results or our remaining results will not reach a majority due to too many nodes missing data. This closes the clients returns queue.
protected GetLeaveEarly ( AsDhtGetState adgs ) : void
adgs AsDhtGetState The AsDhtGetState to qualify for leaving early
return void

MapToRing() public method

Get the hash of the first key and add 1/DEGREE * Address space to each successive key. The results are the positions in the ring where the data should be stored.
public MapToRing ( byte key ) : MemBlock[]
key byte The key to index.
return MemBlock[]

Put() public method

public Put ( MemBlock key, MemBlock value, int ttl ) : bool
key MemBlock
value MemBlock
ttl int
return bool

Put() public method

This is the sychronous version of the generic Put used by both the Put and Create methods. The use of the unique variable differentiates the two. Returns true if successful or an exception if there are network errors in adding the entry, creates also fail if a previous entry exists.
public Put ( MemBlock key, MemBlock value, int ttl, bool unique ) : bool
key MemBlock The index to store the value at.
value MemBlock The value to store.
ttl int The dht lease time for the key:value pair.
unique bool True to do a create, false otherwise.
return bool

PutCloseHandler() public method

public PutCloseHandler ( Object o, EventArgs args ) : void
o Object The channel used by put.
args System.EventArgs Unused.
return void

StateChangeHandler() protected method

We're online once we are seeking connections, we're offline once Disconnect has been called.
protected StateChangeHandler ( Node n, Node state ) : void
n Brunet.Node
state Brunet.Node
return void

Property Details

DEGREE public_oe property

How many replications are made.
public int DEGREE
return int

DELAY public_oe property

How long to wait for synchronous results.
public int DELAY
return int

DhtLog public_oe static_oe property

The log enabler for the dht.
public static BooleanSwitch,System.Diagnostics DhtLog
return System.Diagnostics.BooleanSwitch

MAJORITY public_oe property

floor(DEGREE/2) + 1, the amount of positive results for a successful operation
public int MAJORITY
return int

Node public_oe property

The node to provide services for.
public Node,Brunet Node
return Brunet.Node

_adgs_table protected_oe property

The state table for asynchronos gets.
protected Hashtable,System.Collections _adgs_table
return System.Collections.Hashtable

_adps_table protected_oe property

The state table for asynchronous puts.
protected Hashtable,System.Collections _adps_table
return System.Collections.Hashtable

_online protected_oe property

True unless node is in offline, leaving, or disconnected
protected bool _online
return bool

_rpc protected_oe property

The RpcManager to perform transactions through.
protected RpcManager _rpc
return RpcManager

_sync protected_oe property

Lock for the dht put/get state tables.
protected object _sync
return object