/
main.c
executable file
·63 lines (51 loc) · 1.66 KB
/
main.c
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
#include <string.h>
#include <stdio.h>
#define MAX_LINE 1024
#include "conhash/conhash.h"
int main(int argc, char* argv[])
{
struct conhash_s* conhashp = conhash_init(NULL);
int index = 0;
for(index=0; index<6; index++)
{
struct node_s* nodep = (struct node_s*)malloc(sizeof(struct node_s));
memset(nodep, 0, sizeof(struct node_s));
nodep->index = 0;
nodep->replicas = 500;
nodep->flag = NODE_FLAG_INIT;
snprintf(nodep->iden, 64, "10.1.15.1%d", index);
nodep->iden[63] = '\0';
conhash_add_node(conhashp, nodep);
}
#if 0
char* uri = "/videos/v/20110926/205763500/205763500/1/f3a89defde4e580e4058149e9059d1d4.ts";
int len = strlen(uri);
struct node_s* findp = conhash_lookup(conhashp, uri, len);
fprintf(stdout, "find [%d][%s] by %s\n", findp->index, findp->iden, uri);
uri = "/videos/v/20110926/205763500/205763500/2/c59965f441f474c6b0dfbe36232bd614.ts";
len = strlen(uri);
findp = conhash_lookup(conhashp, uri, len);
fprintf(stdout, "find [%d][%s] by %s\n", findp->index, findp->iden, uri);
uri = "abcdefsdfgdsaklj";
len = strlen(uri);
findp = conhash_lookup(conhashp, uri, len);
fprintf(stdout, "find [%d][%s] by %s\n", findp->index, findp->iden, uri);
#endif
char buf[MAX_LINE];
FILE *fp;
int len;
if((fp = fopen("./ts.list","r")) == NULL)
{
perror("fail to read");
exit (1) ;
}
while(fgets(buf,MAX_LINE,fp) != NULL)
{
len = strlen(buf);
buf[len-1] = '\0';
struct node_s* findp = conhash_lookup(conhashp, buf, len-1);
fprintf(stdout, "%s,%s\n", buf, findp->iden);
}
fclose(fp);
return 0;
}