C# Класс 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.
Наследование: IDht
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
DEGREE int
DELAY int
DhtLog System.Diagnostics.BooleanSwitch
MAJORITY int
Node Brunet.Node

Защищенные свойства (Protected)

Свойство Тип Описание
_adgs_table System.Collections.Hashtable
_adps_table System.Collections.Hashtable
_online bool
_rpc RpcManager
_sync object

Открытые методы

Метод Описание
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

Защищенные методы

Метод Описание
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.

Описание методов

AsyncCreate() публичный Метод

public AsyncCreate ( MemBlock key, MemBlock value, int ttl, Channel returns ) : void
key MemBlock
value MemBlock
ttl int
returns Channel
Результат void

AsyncGet() публичный Метод

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
Результат void

AsyncPut() публичный Метод

public AsyncPut ( MemBlock key, MemBlock value, int ttl, Channel returns ) : void
key MemBlock
value MemBlock
ttl int
returns Channel
Результат void

AsyncPut() публичный Метод

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.
Результат void

Create() публичный Метод

public Create ( MemBlock key, MemBlock value, int ttl ) : bool
key MemBlock
value MemBlock
ttl int
Результат bool

Dht() публичный Метод

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.
Результат System

Dht() публичный Метод

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. ///
Результат System

Dht() публичный Метод

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.
Результат System

Get() публичный Метод

public Get ( MemBlock key ) : System.Collections.Hashtable[]
key MemBlock
Результат System.Collections.Hashtable[]

GetCloseHandler() защищенный Метод

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.
Результат void

GetEnqueueHandler() публичный Метод

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.
Результат void

GetFollowUp() защищенный Метод

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.
Результат void

GetLeaveEarly() защищенный Метод

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
Результат void

MapToRing() публичный Метод

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.
Результат MemBlock[]

Put() публичный Метод

public Put ( MemBlock key, MemBlock value, int ttl ) : bool
key MemBlock
value MemBlock
ttl int
Результат bool

Put() публичный Метод

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.
Результат bool

PutCloseHandler() публичный Метод

public PutCloseHandler ( Object o, EventArgs args ) : void
o Object The channel used by put.
args System.EventArgs Unused.
Результат void

StateChangeHandler() защищенный Метод

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
Результат void

Описание свойств

DEGREE публичное свойство

How many replications are made.
public int DEGREE
Результат int

DELAY публичное свойство

How long to wait for synchronous results.
public int DELAY
Результат int

DhtLog публичное статическое свойство

The log enabler for the dht.
public static BooleanSwitch,System.Diagnostics DhtLog
Результат System.Diagnostics.BooleanSwitch

MAJORITY публичное свойство

floor(DEGREE/2) + 1, the amount of positive results for a successful operation
public int MAJORITY
Результат int

Node публичное свойство

The node to provide services for.
public Node,Brunet Node
Результат Brunet.Node

_adgs_table защищенное свойство

The state table for asynchronos gets.
protected Hashtable,System.Collections _adgs_table
Результат System.Collections.Hashtable

_adps_table защищенное свойство

The state table for asynchronous puts.
protected Hashtable,System.Collections _adps_table
Результат System.Collections.Hashtable

_online защищенное свойство

True unless node is in offline, leaving, or disconnected
protected bool _online
Результат bool

_rpc защищенное свойство

The RpcManager to perform transactions through.
protected RpcManager _rpc
Результат RpcManager

_sync защищенное свойство

Lock for the dht put/get state tables.
protected object _sync
Результат object