forked from mengning/nezha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.h
76 lines (63 loc) · 2.33 KB
/
nodes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/********************************************************************/
/* Copyright (C) SSE-USTC, 2012-2013 */
/* */
/* FILE NAME : nodes.h */
/* PRINCIPAL AUTHOR : Mengning */
/* SUBSYSTEM NAME : cloud */
/* MODULE NAME : nodes */
/* LANGUAGE : C */
/* TARGET ENVIRONMENT : Linux */
/* DATE OF FIRST RELEASE : 2013/1/4 */
/* DESCRIPTION : server nodes admin module */
/********************************************************************/
/*
* Revision log:
*
* Created by Mengning,2013/1/4
* Consistent-Hash support ,by Mengning,2013/1/9
*
*/
#ifndef _NODES_H_
#define _NODES_H_
#include "protocol.h"
#define MAX_NODE_NUM 3
#define PORT 5001
#define IP_ADDR "127.0.0.1"
#define ADDR_STR_LEN 128
typedef struct Node
{
struct Node * pNext;
int hash;
char addr[ADDR_STR_LEN];
int port;
int fd;
}tNode;
typedef struct Cluster
{
int SumOfNodes;
tNode * nodes[MAX_NODE_NUM+1]; /* array of node info */
tNode * pHead;
tNode * pTail;
}tCluster;
/*
* Basic Operation
*/
/* Init cloud nodes info */
tCluster * InitCluster();
/* Destroy Cluster */
int DestroyCluster(tCluster * cluster);
/* Get cloud nodes info */
tNode * GetNode(tCluster * cluster,int hash);
/* Add cloud nodes info */
int AddNode(tCluster * cluster,char * addr,int port);
/* Register cloud nodes info */
int RemoveNode(tCluster * cluster,int hash,char * addr,int port,int fd);
/* Register And Load cloud nodes info */
tCluster * RegisterAndLoadClusterNodes(char * addr,int port);
/* add recved buf(nodes info) to cluster */
int AddClusterNodes(tCluster * cluster,char ppData[MAX_DATA_NUM][MAX_DATA_LEN],int DataNum);
/* Cluseter(Nodes info) to ppData array */
int ClusterNodesInfo(tCluster * cluster,char ppData[MAX_DATA_NUM][MAX_DATA_LEN],int *NodeNum);
int ConnectDataNode(tCluster* cluster,char * addr,int port,char * filename);
int DisconnectDataNode(tCluster* cluster);
#endif /* _NODES_H_ */