]>
jfr.im git - irc/quakenet/newserv.git/blob - patricia/patricia.c
1 #include "../core/nsmalloc.h"
2 #include "../lib/irc_string.h"
3 #include "../lib/version.h"
5 #include "../core/error.h"
6 #include "../core/hooks.h"
7 #include "../control/control.h"
9 #include <assert.h> /* assert */
15 patricia_tree_t
*iptree
;
16 sstring
*nodeextnames
[PATRICIA_MAXSLOTS
];
18 void patriciastats(int hooknum
, void *arg
);
21 iptree
= patricia_new_tree(PATRICIA_MAXBITS
);
24 registerhook(HOOK_CORE_STATSREQUEST
,&patriciastats
);
28 deregisterhook(HOOK_CORE_STATSREQUEST
,&patriciastats
);
29 patricia_destroy_tree (iptree
, NULL
);
30 nsfreeall(POOL_PATRICIA
);
33 void patriciastats(int hooknum
, void *arg
) {
36 patricia_node_t
*head
, *node
;
42 sprintf(buf
, "Patricia: %6d Active Nodes (%d bits)", iptree
->num_active_node
, iptree
->maxbits
);
43 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
48 PATRICIA_WALK_ALL(head
, node
) {
54 sprintf(buf
, "Patricia: %6d Nodes, %6d Prefix (walk all)", i
,j
);
55 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
59 PATRICIA_WALK(head
, node
) {
61 if (irc_in_addr_is_ipv4(&(node
->prefix
->sin
)))
69 sprintf(buf
, "Patricia: %6d Nodes, %6d Prefix (walk prefixes only)", i
,j
);
70 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
71 sprintf(buf
, "Patricia: %6d IP4Node, %6d IP6Node", k
, l
);
72 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
75 for (i
=0;i
<PATRICIA_MAXSLOTS
;i
++) {
76 if (nodeextnames
[i
]!=NULL
) {
80 sprintf(buf
, "Patricia: %6d ExtsUsed, %5d Max", j
,PATRICIA_MAXSLOTS
);
81 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
85 int registernodeext(const char *name
) {
88 if (findnodeext(name
)!=-1) {
89 Error("patricia",ERR_WARNING
,"Tried to register duplicate node extension %s",name
);
93 for (i
=0;i
<PATRICIA_MAXSLOTS
;i
++) {
94 if (nodeextnames
[i
]==NULL
) {
95 nodeextnames
[i
]=getsstring(name
,100);
100 Error("patricia",ERR_WARNING
,"Tried to register too many extensions: %s",name
);
104 int findnodeext(const char *name
) {
107 for (i
=0;i
<PATRICIA_MAXSLOTS
;i
++) {
108 if (nodeextnames
[i
]!=NULL
&& !ircd_strcmp(name
,nodeextnames
[i
]->content
)) {
116 void releasenodeext(int index
) {
117 patricia_node_t
*head
, *node
;
119 freesstring(nodeextnames
[index
]);
120 nodeextnames
[index
]=NULL
;
124 PATRICIA_WALK_ALL(head
, node
)
126 node
->exts
[index
]=NULL
;