Distributed File System 1
Distributed file system in C
Loading...
Searching...
No Matches
dnode.h File Reference
#include "lib.h"
#include "list.h"
#include "uuid.h"
#include "enchufe.h"

Go to the source code of this file.

Classes

struct  DNode
 Saves the connection data. More...
struct  DNodeInfo
 This carries all the necessary information that a chunk should have. More...

Macros

#define DNODE_TABLE   "data/dnode.bin"

Functions

 DefList (DNode) DefList(DNodeInfo) Buffer DNode_serialize(DNode dnode)
 Serialize a DNode into a Buffer.
DNode DNode_deserialize (Buffer buf)
 Deserialize a Buffer into a DNode.
Buffer ListDNode_serialize (ListDNode list)
 Serialize a List of DNode's into a Buffer.
ListDNode ListDNode_deserialize (Buffer buf)
 Deserialize a Buffer into a List of DNode's.
Buffer DNodeInfo_serialize (DNodeInfo dinfo)
 Serialize a DNodeInfo to a buffer.
DNodeInfo DNodeInfo_deserialize (Buffer buf)
 Deserialize a Buffer into a List of DNodeInfo's.
Buffer ListDNodeInfo_serialize (ListDNodeInfo list)
 Serialize a ListDNodeInfo to a buffer.
ListDNodeInfo ListDNodeInfo_deserialize (Buffer buf)
 Deserialize a Buffer into a List of DNodeInfo's.
void insert_into_dnode (IPv4 address, Port port)
 INSERT into the DNode table.
ListDNode select_from_dnode (UUID *nid, IPv4 *address, Port *port)
 SELECT from the DNode table.
ListDNode DNode_get_db (void)
 Get the DNode table from the database.
void DNode_set_db (ListDNode dnodes)
 Write the database with the List of DNode's.
void print_dnode (DNode dnode)
 Print a DNode's data as a tuple.
ListDNodeInfo insert (ListDNodeInfo l, DNodeInfo a)
 Insert a DNodeInfo into a ListDNodeInfo in a sorted fashion.
ListDNodeInfo sort (ListDNodeInfo l)
 Sort a ListDNodeInfo depending on the sequence numbers of its entries.

Macro Definition Documentation

◆ DNODE_TABLE

#define DNODE_TABLE   "data/dnode.bin"

Function Documentation

◆ DefList()

DefList ( DNode )

Serialize a DNode into a Buffer.

Caller must free memory in Buffer.buf.

Parameters
dnodethe DNode you want to serialize
Returns
the Buffer that the DNode represents

◆ DNode_deserialize()

DNode DNode_deserialize ( Buffer buf)

Deserialize a Buffer into a DNode.

Caller must free memory in DNode.address.

Parameters
bufferThe Buffer you want to deserialize
Returns
The DNode that the Buffer represents

◆ DNode_get_db()

ListDNode DNode_get_db ( void )

Get the DNode table from the database.

Returns
a List of DNode's

◆ DNode_set_db()

void DNode_set_db ( ListDNode dnodes)

Write the database with the List of DNode's.

◆ DNodeInfo_deserialize()

DNodeInfo DNodeInfo_deserialize ( Buffer buf)

Deserialize a Buffer into a List of DNodeInfo's.

Caller must free memory in DNodeInfo.address.

Parameters
bufferThe Buffer you want to deserialize
Returns
The List of DNodeInfo's that the Buffer represents

◆ DNodeInfo_serialize()

Buffer DNodeInfo_serialize ( DNodeInfo dinfo)

Serialize a DNodeInfo to a buffer.

Parameters
dinfothe DNodeInfo you want to serialize
Returns
the Buffer thet tha DNodeInfo represents

◆ insert()

ListDNodeInfo insert ( ListDNodeInfo l,
DNodeInfo a )

Insert a DNodeInfo into a ListDNodeInfo in a sorted fashion.

This is really just a helper function for sort(ListDNodeInfo l). Here is a Haskell implementation of it:

insert :: [Int] -> Int -> [Int]
insert [] a = [a]
insert (x:xs) a = if x > a then a:x:xs else x:insert xs a
Parameters
lthe ListDNodeInfo that you want to insert into
athe DNodeInfo that you want to insert
Returns
a ListDNodeInfo with a placed depending on its sequence number

◆ insert_into_dnode()

void insert_into_dnode ( IPv4 address,
Port port )

INSERT into the DNode table.

Parameters
addressthe URI address
portthe port of the connection

◆ ListDNode_deserialize()

ListDNode ListDNode_deserialize ( Buffer buf)

Deserialize a Buffer into a List of DNode's.

Caller must free memory in DNode.address.

Parameters
bufferThe Buffer you want to deserialize
Returns
The List of DNode's that the Buffer represents

◆ ListDNode_serialize()

Buffer ListDNode_serialize ( ListDNode list)

Serialize a List of DNode's into a Buffer.

Caller must free memory in Buffer.buf.

Parameters
listthe List of DNode's that you want to serialize
Returns
the Buffer that the ListDNode represents

◆ ListDNodeInfo_deserialize()

ListDNodeInfo ListDNodeInfo_deserialize ( Buffer buf)

Deserialize a Buffer into a List of DNodeInfo's.

Caller must free memory in DNodeInfo.address.

Parameters
bufferThe Buffer you want to deserialize
Returns
The List of DNodeInfo's that the Buffer represents

◆ ListDNodeInfo_serialize()

Buffer ListDNodeInfo_serialize ( ListDNodeInfo list)

Serialize a ListDNodeInfo to a buffer.

Parameters
dinfothe ListDNodeInfo you want to serialize
Returns
the Buffer thet tha ListDNodeInfo represents

◆ print_dnode()

void print_dnode ( DNode dnode)

Print a DNode's data as a tuple.

Parameters
dnodethe DNode to be printed

◆ select_from_dnode()

ListDNode select_from_dnode ( UUID * nid,
IPv4 * address,
Port * port )

SELECT from the DNode table.

Parameters
nidthe DNode's ID or NULL
addressthe host's address or PULL
portthe host's Port or NULL
Returns
a ListDNode of the possible matches

◆ sort()

ListDNodeInfo sort ( ListDNodeInfo l)

Sort a ListDNodeInfo depending on the sequence numbers of its entries.

sort :: [Int] -> [Int]
sort = foldl insert []
Parameters
lthe ListDNodeInfo you want to sort
Returns
a sorted version of l