Debian Codegraph @

src/dragon/main.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013 William Pitcock <[email protected]>.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
19 */
20
21 #include "atheme.h"
22 #include "libathemecore.h"
23 #include "uplink.h"
24 #include "pmodule.h"
25 #include "conf.h"
26
27 static struct timeval burstbegin;
28 static bool bursting = false;
29
30 void bootstrap(void)
31 {
32 if (me.name == NULL)
33 me.name = sstrdup("services.dereferenced.org");
34
35 if (me.numeric == NULL)
36 me.numeric = sstrdup("00A");
37
38 if (me.desc == NULL)
39 me.desc = sstrdup("dragon ircd linking performance benchmark");
40
41 servtree_update(NULL);
42
43 slog(LG_INFO, "bootstrap: done, servtree root @%p", me.me);
44 }
45
46 bool conf_check(void)
47 {
48 return true;
49 }
50
51 void build_world(void)
52 {
53 int i;
54 char userbuf[BUFSIZE];
55
56 for (i = 100000; i > 0; i--)
57 {
58 snprintf(userbuf, sizeof userbuf, "User%d", i);
59 user_add(userbuf, "user", "localhost", NULL, NULL, ircd->uses_uid ? uid_get() : NULL, "User", me.me, CURRTIME);
60 }
61 }
62
63 void burst_world(void)
64 {
65 mowgli_node_t *n;
66
67 slog(LG_INFO, "handshake complete, starting burst");
68
69 s_time(&burstbegin);
70
71 MOWGLI_ITER_FOREACH(n, me.me->userlist.head)
72 introduce_nick(n->data);
73
74 ping_sts();
75 bursting = true;
76 }
77
78 void phase_buildworld(void)
79 {
80 struct timeval ts, te;
81
82 slog(LG_INFO, "building world, please wait.");
83
84 s_time(&ts);
85 build_world();
86 e_time(ts, &te);
87
88 slog(LG_INFO, "world created in %d msec", tv2ms(&te));
89 }
90
91 static void m_pong(sourceinfo_t *si, int parc, char *parv[])
92 {
93 struct timeval te;
94
95 if (!bursting)
96 {
97 burst_world();
98 return;
99 }
100
101 e_time(burstbegin, &te);
102
103 slog(LG_INFO, "burst took %d msec", tv2ms(&te));
104
105 runflags |= RF_SHUTDOWN;
106 }
107
108 void hijack_pong_handler(void)
109 {
110 pcommand_delete("PONG");
111 pcommand_add("PONG", m_pong, 1, MSRC_SERVER);
112 }
113
114 int main(int argc, char *argv[])
115 {
116 atheme_bootstrap();
117 atheme_init(argv[0], LOGDIR "/dbverify.log");
118 atheme_setup();
119 module_t *m;
120 unsigned int errcnt;
121 char *config_file = argv[1] != NULL ? argv[1] : "./dragon.conf";
122
123 runflags = RF_LIVE;
124 datadir = DATADIR;
125 strict_mode = false;
126 cold_start = true;
127
128 slog(LG_INFO, "dragon: an ircd linking performance benchmark");
129 slog(LG_INFO, "atheme.org, 2013");
130
131 conf_parse(config_file);
132 bootstrap();
133
134 slog(LG_INFO, "link implementation: %s @%p", ircd->ircdname, ircd);
135
136 hijack_pong_handler();
137
138 mowgli_eventloop_synchronize(base_eventloop);
139 CURRTIME = mowgli_eventloop_get_time(base_eventloop);
140
141 phase_buildworld();
142 uplink_connect();
143
144 slog(LG_INFO, "uplink: %s @%p", curr_uplink->name, curr_uplink);
145
146 io_loop();
147
148 return EXIT_SUCCESS;
149 }