C# Class Brunet.Services.Dht.TableServer

The TableServer provides the Dht server end point.
Besides providing entry points for dht operations such as Get, Put, and Create; it also contains the logic necessary to transfer keys when there is churn in the system, this is implemented in ConnectionHandler, DepartureHandler, and TransferState.
Inheritance: IRpcHandler
显示文件 Open project: johnynek/brunet Class Usage Examples

Protected Properties

Property Type Description
_data TableServerData
_left_addr Brunet.Address
_left_transfer_state TransferState
_node Brunet.Node
_online bool
_right_addr Brunet.Address
_right_transfer_state TransferState
_rpc RpcManager
_sync Object
_transfer_sync Object

Public Methods

Method Description
Get ( MemBlock key, byte token ) : IList

Retrieves data from the Dht.

First old entries for the key are deleted from the dht, second a look up is performed, and finally using the token a range of data is selectively returned.

HandleRpc ( ISender caller, string method, IList args, object rs ) : void

This provides faster translation for Rpc methods as well as allows for Asynchronous Rpc calls which are required for Puts and Creates.

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

Called by a Dht client to store data here, this supports both Puts and Creates by using the unique parameter.

Puts will store the value no matter what, Creates will only store the value if they are the first ones to store data on that key. This is the first part of a Put operation. This calls PutHandler on itself and the neighbor nearest to the key, which actually places the data into the store. The result is returned to the client upon completion of the call to the neighbor, if that fails the data is removed locally and an exception is sent to the client indicating failure.

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

Attempts to store the key:value pair into this server.

First the dht deletes any expired entries stored at the key, second it retrieves the entries from the data store. If it is empty it creates a new entry and returns. Otherwise, it looks for the value in the list and updates the lease time. If there is no entry for that key:value pair it either adds it in the case of a put or throws an exception if it is a create.

TableServer ( Node node ) : System

Creates a new TableServer object and registers it to the "dht" handler in the node's RpcManager.

Protected Methods

Method Description
ConnectionHandler ( object o, EventArgs eargs ) : void

This is called whenever there is a disconnect or a connect, the idea is to determine if there is a new left or right node, if there is and here is a pre-existing transfer, we must interupt it, and start a new transfer.

The possible scenarios where this would be active: - no change on left - new left node with no previous node (from disc or new node) - left disconnect and new left ready - left disconnect and no one ready - no change on right - new right node with no previous node (from disc or new node) - right disconnect and new right ready - right disconnect and no one ready

DepartureHandler ( ) : void

Called when Node.Disconnect is triggered stopping transfer states and preventing any more transfers.

StateChangeHandler ( Node n, Node state ) : void

If we are or were connected in the right place, we accept DHT messages otherwise we ignore them.

Method Details

ConnectionHandler() protected method

This is called whenever there is a disconnect or a connect, the idea is to determine if there is a new left or right node, if there is and here is a pre-existing transfer, we must interupt it, and start a new transfer.
The possible scenarios where this would be active: - no change on left - new left node with no previous node (from disc or new node) - left disconnect and new left ready - left disconnect and no one ready - no change on right - new right node with no previous node (from disc or new node) - right disconnect and new right ready - right disconnect and no one ready
protected ConnectionHandler ( object o, EventArgs eargs ) : void
o object Unimportant
eargs System.EventArgs Contains the ConnectionEventArgs, which lets us know if this was a Structured Connection change and if it is, we should check the state of the system to see if we have a new left or right neighbor.
return void

DepartureHandler() protected method

Called when Node.Disconnect is triggered stopping transfer states and preventing any more transfers.
protected DepartureHandler ( ) : void
return void

Get() public method

Retrieves data from the Dht.
First old entries for the key are deleted from the dht, second a look up is performed, and finally using the token a range of data is selectively returned.
public Get ( MemBlock key, byte token ) : IList
key MemBlock The index used to look up. Contains the data necessary to do follow up look ups if all the data stored in a key is to big for MAX_BYTES.
token byte
return IList

HandleRpc() public method

This provides faster translation for Rpc methods as well as allows for Asynchronous Rpc calls which are required for Puts and Creates.
Thrown when there the method is not Put, PutHandler, Get, Dump, or Count
public HandleRpc ( ISender caller, string method, IList args, object rs ) : void
caller ISender The ISender who made the request.
method string The method requested.
args IList A list of arguments to pass to the method.
rs object The return state sent back to the RpcManager so that it knows who to return the result to.
return void

Put() public method

Called by a Dht client to store data here, this supports both Puts and Creates by using the unique parameter.
Puts will store the value no matter what, Creates will only store the value if they are the first ones to store data on that key. This is the first part of a Put operation. This calls PutHandler on itself and the neighbor nearest to the key, which actually places the data into the store. The result is returned to the client upon completion of the call to the neighbor, if that fails the data is removed locally and an exception is sent to the client indicating failure.
Data is too large, unresolved remote issues, or the create is no successful
public Put ( MemBlock key, MemBlock value, int ttl, bool unique, object rs ) : bool
key MemBlock The index to store the data at.
value MemBlock Data to store at the key.
ttl int Dht lease time in seconds
unique bool True if this should perform a create, false otherwise.
rs object The return state sent back to the RpcManager so that it knows who to return the result to.
return bool

PutHandler() public method

Attempts to store the key:value pair into this server.
First the dht deletes any expired entries stored at the key, second it retrieves the entries from the data store. If it is empty it creates a new entry and returns. Otherwise, it looks for the value in the list and updates the lease time. If there is no entry for that key:value pair it either adds it in the case of a put or throws an exception if it is a create.
Data is too large, unresolved remote issues, or the create is no successful
public PutHandler ( MemBlock key, MemBlock value, int ttl, bool unique ) : bool
key MemBlock The index to store the data at.
value MemBlock Data to store at the key.
ttl int Dht lease time in seconds
unique bool True if this should perform a create, false otherwise.
return bool

StateChangeHandler() protected method

If we are or were connected in the right place, we accept DHT messages otherwise we ignore them.
protected StateChangeHandler ( Node n, Node state ) : void
n Brunet.Node The node for this event.
state Brunet.Node The new state.
return void

TableServer() public method

Creates a new TableServer object and registers it to the "dht" handler in the node's RpcManager.
public TableServer ( Node node ) : System
node Brunet.Node The node the dht is to serve from.
return System

Property Details

_data protected_oe property

The data store for this dht server
protected TableServerData,Brunet.Services.Dht _data
return TableServerData

_left_addr protected_oe property

Our left neighbors address.
protected Address,Brunet _left_addr
return Brunet.Address

_left_transfer_state protected_oe property

The current transfer state to our left.
protected TransferState _left_transfer_state
return TransferState

_node protected_oe property

The node the dht is serving from.
protected Node,Brunet _node
return Brunet.Node

_online protected_oe property

Do not allow dht operations until StructuredConnectionOverlord is connected.
protected bool _online
return bool

_right_addr protected_oe property

Our right neighbors address.
protected Address,Brunet _right_addr
return Brunet.Address

_right_transfer_state protected_oe property

The current transfer state to our right.
protected TransferState _right_transfer_state
return TransferState

_rpc protected_oe property

The RpcManager the dht is serving from.
protected RpcManager _rpc
return RpcManager

_sync protected_oe property

Used to lock the TableServerData.
protected Object _sync
return Object

_transfer_sync protected_oe property

Used to lock connection and transfer state.
protected Object _transfer_sync
return Object