Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / gdplogd / logd_adv.c @ master

History | View | Annotate | Download (4.8 KB)

1 d260b754 Eric Allman
/* vim: set ai sw=4 sts=4 ts=4 : */
2
3
/*
4
**  Log Advertisements
5 055d3009 Eric Allman
**
6
**        ----- BEGIN LICENSE BLOCK -----
7
**        GDPLOGD: Log Daemon for the Global Data Plane
8
**        From the Ubiquitous Swarm Lab, 490 Cory Hall, U.C. Berkeley.
9
**
10 c87dd166 Eric Allman
**        Copyright (c) 2015-2019, Regents of the University of California.
11 6bd5476b Eric Allman
**        All rights reserved.
12 055d3009 Eric Allman
**
13 6bd5476b Eric Allman
**        Permission is hereby granted, without written agreement and without
14
**        license or royalty fees, to use, copy, modify, and distribute this
15
**        software and its documentation for any purpose, provided that the above
16
**        copyright notice and the following two paragraphs appear in all copies
17
**        of this software.
18 055d3009 Eric Allman
**
19 6bd5476b Eric Allman
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
20
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
21
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
22
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 055d3009 Eric Allman
**
24 6bd5476b Eric Allman
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
25 055d3009 Eric Allman
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 6bd5476b Eric Allman
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
27
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
28
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
29
**        OR MODIFICATIONS.
30 055d3009 Eric Allman
**        ----- END LICENSE BLOCK -----
31 d260b754 Eric Allman
*/
32
33
34
#include "logd.h"
35
36
#include <gdp/gdp.h>
37 f2bf61a4 Eric Allman
#include <gdp/gdp_chan.h>
38 d260b754 Eric Allman
#include <gdp/gdp_priv.h>
39
40
#include <ep/ep_dbg.h>
41
42
43
static EP_DBG        Dbg = EP_DBG_INIT("gdplogd.advertise",
44
                                                        "GDP GCL Advertisements");
45
46
47 218aa128 Eric Allman
typedef struct gdp_advert_x        gdp_advert_x_t;
48
49
struct gdp_advert_x
50 f2bf61a4 Eric Allman
{
51 218aa128 Eric Allman
        gdp_chan_t                                *chan;
52
        gdp_adcert_t                        *adcert;
53 f2bf61a4 Eric Allman
        gdp_chan_advert_cr_t        *challenge_cb;
54 218aa128 Eric Allman
};
55 f2bf61a4 Eric Allman
56
57 5c2abdd9 Eric Allman
static long                AdvertDelay;        // time between adverts (in microseconds)
58
59
void
60
logd_advertise_init(void)
61
{
62 b38a3bc2 Eric Allman
        AdvertDelay = ep_adm_getlongparam("swarm.gdplogd.advertise.delay", 0);
63 5c2abdd9 Eric Allman
}
64
65 f2bf61a4 Eric Allman
66 d260b754 Eric Allman
/*
67 f2bf61a4 Eric Allman
**  Advertise a new GCL
68 d260b754 Eric Allman
*/
69
70 f2bf61a4 Eric Allman
void
71
logd_advertise_one(gdp_chan_t *chan, gdp_name_t gname, int cmd)
72 d260b754 Eric Allman
{
73 f2bf61a4 Eric Allman
        EP_STAT estat;
74
        gdp_adcert_t *adcert = NULL;                                        //XXX XXX
75
        gdp_chan_advert_cr_t *challenge_cb = NULL;                //XXX XXX
76 218aa128 Eric Allman
        gdp_advert_x_t advert;
77
78
        memset(&advert, 0, sizeof advert);
79
        advert.chan = chan;
80 d260b754 Eric Allman
81 f2bf61a4 Eric Allman
        if (cmd == GDP_CMD_ADVERTISE)
82 218aa128 Eric Allman
                estat = _gdp_chan_advertise(chan, gname, adcert, challenge_cb, &advert);
83 f2bf61a4 Eric Allman
        else
84 218aa128 Eric Allman
                estat = _gdp_chan_withdraw(chan, gname, &advert);
85 f2bf61a4 Eric Allman
86
        if (ep_dbg_test(Dbg, 11))
87 d260b754 Eric Allman
        {
88 f2bf61a4 Eric Allman
                char ebuf[100];
89 d260b754 Eric Allman
                gdp_pname_t pname;
90
91 f2bf61a4 Eric Allman
                ep_dbg_printf("logd_advertise_one(%s) => %s\n",
92
                                gdp_printable_name(gname, pname),
93
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
94 d260b754 Eric Allman
        }
95
}
96
97
98 f2bf61a4 Eric Allman
/*
99
**  Advertise all known GCLs
100
*/
101
102 d260b754 Eric Allman
static EP_STAT
103 218aa128 Eric Allman
advertise_one(gdp_name_t gname, void *ax_)
104 d260b754 Eric Allman
{
105 fc0cbc23 Eric Allman
        gdp_advert_x_t *ax = (gdp_advert_x_t *) ax_;
106 f2bf61a4 Eric Allman
        EP_STAT estat;
107 d260b754 Eric Allman
108 f2bf61a4 Eric Allman
        estat = _gdp_chan_advertise(ax->chan, gname, ax->adcert,
109
                                                        ax->challenge_cb, ax);
110 a1e5eca3 Eric Allman
        if (EP_STAT_ISOK(estat))
111
                estat = _gdp_chan_flush(ax->chan);
112 5c2abdd9 Eric Allman
        if (AdvertDelay > 0)
113
                ep_time_nanosleep(AdvertDelay MICROSECONDS);
114 d260b754 Eric Allman
115 f2bf61a4 Eric Allman
        if (ep_dbg_test(Dbg, 54))
116 d260b754 Eric Allman
        {
117 f2bf61a4 Eric Allman
                gdp_pname_t pname;
118 d260b754 Eric Allman
                char ebuf[100];
119
120 f2bf61a4 Eric Allman
                ep_dbg_printf("\tAdvertise %s => %s\n",
121
                                gdp_printable_name(gname, pname),
122 d260b754 Eric Allman
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
123
        }
124 08709feb Eric Allman
        return estat;
125 d260b754 Eric Allman
}
126
127
static EP_STAT
128 218aa128 Eric Allman
withdraw_one(gdp_name_t gname, void *ax_)
129 d260b754 Eric Allman
{
130 fc0cbc23 Eric Allman
        gdp_advert_x_t *ax = (gdp_advert_x_t *) ax_;
131 f2bf61a4 Eric Allman
        EP_STAT estat;
132
133 218aa128 Eric Allman
        if (!EP_ASSERT(ax != NULL))
134
                return EP_STAT_ASSERT_ABORT;
135
136 f2bf61a4 Eric Allman
        estat = _gdp_chan_withdraw(ax->chan, gname, ax);
137 a1e5eca3 Eric Allman
        if (EP_STAT_ISOK(estat))
138
                estat = _gdp_chan_flush(ax->chan);
139 5c2abdd9 Eric Allman
        if (AdvertDelay > 0)
140
                ep_time_nanosleep(AdvertDelay MICROSECONDS);
141 f2bf61a4 Eric Allman
142
        if (ep_dbg_test(Dbg, 54))
143
        {
144
                gdp_pname_t pname;
145
                char ebuf[100];
146
147
                ep_dbg_printf("\tWithdraw %s => %s\n",
148
                                gdp_printable_name(gname, pname),
149
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
150
        }
151
        return estat;
152 d260b754 Eric Allman
}
153
154 f2bf61a4 Eric Allman
155
EP_STAT
156 218aa128 Eric Allman
logd_advertise_all(gdp_chan_t *chan, int cmd, void *adata_unused)
157 d260b754 Eric Allman
{
158 bd472f67 Eric Allman
        EP_STAT estat, tstat;
159 f2bf61a4 Eric Allman
        gdp_adcert_t *adcert = NULL;                                        //XXX XXX
160
        gdp_chan_advert_cr_t *challenge_cb = NULL;                //XXX XXX
161 218aa128 Eric Allman
        gdp_advert_x_t advert;
162
163
        memset(&advert, 0, sizeof advert);
164
        advert.chan = chan;
165 f2bf61a4 Eric Allman
166
        if (cmd == GDP_CMD_ADVERTISE)
167
        {
168 9c42eb2e Eric Allman
                ep_dbg_cprintf(Dbg, 24, "logd_advertise_all(ADVERTISE)\n");
169
170 218aa128 Eric Allman
                // advertise me ...
171 f2bf61a4 Eric Allman
                estat = _gdp_chan_advertise(chan, _GdpMyRoutingName, adcert,
172 218aa128 Eric Allman
                                                                        challenge_cb, &advert);
173 f2bf61a4 Eric Allman
174 218aa128 Eric Allman
                // ... and all of my logs
175 bd472f67 Eric Allman
                tstat = GdpSqliteImpl.foreach(advertise_one, &advert);
176 f2bf61a4 Eric Allman
        }
177
        else
178
        {
179 9c42eb2e Eric Allman
                ep_dbg_cprintf(Dbg, 24, "logd_advertise_all(WITHDRAW)\n");
180
181 218aa128 Eric Allman
                // withdraw log advertisements ...
182 92243bf4 Eric Allman
                estat = GdpSqliteImpl.foreach(withdraw_one, &advert);
183 218aa128 Eric Allman
184
                // ... and finally myself
185 bd472f67 Eric Allman
                tstat = _gdp_chan_withdraw(chan, _GdpMyRoutingName, &advert);
186 f2bf61a4 Eric Allman
        }
187
188 bd472f67 Eric Allman
        if (EP_STAT_SEVERITY(tstat) > EP_STAT_SEVERITY(estat))
189
                estat = tstat;
190 47bf70a0 Eric Allman
        tstat = _gdp_chan_advert_flush(chan);
191 bd472f67 Eric Allman
        if (EP_STAT_SEVERITY(tstat) > EP_STAT_SEVERITY(estat))
192
                estat = tstat;
193
194 f2bf61a4 Eric Allman
        if (ep_dbg_test(Dbg, 21))
195 d260b754 Eric Allman
        {
196
                char ebuf[100];
197
198 f2bf61a4 Eric Allman
                ep_dbg_printf("logd_advertise_all => %s\n",
199 d260b754 Eric Allman
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
200
        }
201 f2bf61a4 Eric Allman
        return estat;
202 d260b754 Eric Allman
}