Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / gdplogd / logd_adv.c @ master

History | View | Annotate | Download (4.8 KB)

1
/* vim: set ai sw=4 sts=4 ts=4 : */
2

    
3
/*
4
**  Log Advertisements
5
**
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
**        Copyright (c) 2015-2019, Regents of the University of California.
11
**        All rights reserved.
12
**
13
**        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
**
19
**        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
**
24
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
25
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
**        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
**        ----- END LICENSE BLOCK -----
31
*/
32

    
33

    
34
#include "logd.h"
35

    
36
#include <gdp/gdp.h>
37
#include <gdp/gdp_chan.h>
38
#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
typedef struct gdp_advert_x        gdp_advert_x_t;
48

    
49
struct gdp_advert_x
50
{
51
        gdp_chan_t                                *chan;
52
        gdp_adcert_t                        *adcert;
53
        gdp_chan_advert_cr_t        *challenge_cb;
54
};
55

    
56

    
57
static long                AdvertDelay;        // time between adverts (in microseconds)
58

    
59
void
60
logd_advertise_init(void)
61
{
62
        AdvertDelay = ep_adm_getlongparam("swarm.gdplogd.advertise.delay", 0);
63
}
64

    
65

    
66
/*
67
**  Advertise a new GCL
68
*/
69

    
70
void
71
logd_advertise_one(gdp_chan_t *chan, gdp_name_t gname, int cmd)
72
{
73
        EP_STAT estat;
74
        gdp_adcert_t *adcert = NULL;                                        //XXX XXX
75
        gdp_chan_advert_cr_t *challenge_cb = NULL;                //XXX XXX
76
        gdp_advert_x_t advert;
77

    
78
        memset(&advert, 0, sizeof advert);
79
        advert.chan = chan;
80

    
81
        if (cmd == GDP_CMD_ADVERTISE)
82
                estat = _gdp_chan_advertise(chan, gname, adcert, challenge_cb, &advert);
83
        else
84
                estat = _gdp_chan_withdraw(chan, gname, &advert);
85

    
86
        if (ep_dbg_test(Dbg, 11))
87
        {
88
                char ebuf[100];
89
                gdp_pname_t pname;
90

    
91
                ep_dbg_printf("logd_advertise_one(%s) => %s\n",
92
                                gdp_printable_name(gname, pname),
93
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
94
        }
95
}
96

    
97

    
98
/*
99
**  Advertise all known GCLs
100
*/
101

    
102
static EP_STAT
103
advertise_one(gdp_name_t gname, void *ax_)
104
{
105
        gdp_advert_x_t *ax = (gdp_advert_x_t *) ax_;
106
        EP_STAT estat;
107

    
108
        estat = _gdp_chan_advertise(ax->chan, gname, ax->adcert,
109
                                                        ax->challenge_cb, ax);
110
        if (EP_STAT_ISOK(estat))
111
                estat = _gdp_chan_flush(ax->chan);
112
        if (AdvertDelay > 0)
113
                ep_time_nanosleep(AdvertDelay MICROSECONDS);
114

    
115
        if (ep_dbg_test(Dbg, 54))
116
        {
117
                gdp_pname_t pname;
118
                char ebuf[100];
119

    
120
                ep_dbg_printf("\tAdvertise %s => %s\n",
121
                                gdp_printable_name(gname, pname),
122
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
123
        }
124
        return estat;
125
}
126

    
127
static EP_STAT
128
withdraw_one(gdp_name_t gname, void *ax_)
129
{
130
        gdp_advert_x_t *ax = (gdp_advert_x_t *) ax_;
131
        EP_STAT estat;
132

    
133
        if (!EP_ASSERT(ax != NULL))
134
                return EP_STAT_ASSERT_ABORT;
135

    
136
        estat = _gdp_chan_withdraw(ax->chan, gname, ax);
137
        if (EP_STAT_ISOK(estat))
138
                estat = _gdp_chan_flush(ax->chan);
139
        if (AdvertDelay > 0)
140
                ep_time_nanosleep(AdvertDelay MICROSECONDS);
141

    
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
}
153

    
154

    
155
EP_STAT
156
logd_advertise_all(gdp_chan_t *chan, int cmd, void *adata_unused)
157
{
158
        EP_STAT estat, tstat;
159
        gdp_adcert_t *adcert = NULL;                                        //XXX XXX
160
        gdp_chan_advert_cr_t *challenge_cb = NULL;                //XXX XXX
161
        gdp_advert_x_t advert;
162

    
163
        memset(&advert, 0, sizeof advert);
164
        advert.chan = chan;
165

    
166
        if (cmd == GDP_CMD_ADVERTISE)
167
        {
168
                ep_dbg_cprintf(Dbg, 24, "logd_advertise_all(ADVERTISE)\n");
169

    
170
                // advertise me ...
171
                estat = _gdp_chan_advertise(chan, _GdpMyRoutingName, adcert,
172
                                                                        challenge_cb, &advert);
173

    
174
                // ... and all of my logs
175
                tstat = GdpSqliteImpl.foreach(advertise_one, &advert);
176
        }
177
        else
178
        {
179
                ep_dbg_cprintf(Dbg, 24, "logd_advertise_all(WITHDRAW)\n");
180

    
181
                // withdraw log advertisements ...
182
                estat = GdpSqliteImpl.foreach(withdraw_one, &advert);
183

    
184
                // ... and finally myself
185
                tstat = _gdp_chan_withdraw(chan, _GdpMyRoutingName, &advert);
186
        }
187

    
188
        if (EP_STAT_SEVERITY(tstat) > EP_STAT_SEVERITY(estat))
189
                estat = tstat;
190
        tstat = _gdp_chan_advert_flush(chan);
191
        if (EP_STAT_SEVERITY(tstat) > EP_STAT_SEVERITY(estat))
192
                estat = tstat;
193

    
194
        if (ep_dbg_test(Dbg, 21))
195
        {
196
                char ebuf[100];
197

    
198
                ep_dbg_printf("logd_advertise_all => %s\n",
199
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
200
        }
201
        return estat;
202
}