GNUnet  0.10.x
transport_api_blacklist.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2010-2014, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_arm_service.h"
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_protocols.h"
32 #include "transport.h"
33 
42 
47 
53 
57  void *cb_cls;
58 };
59 
60 
66 static void
68 
69 
76 static void
77 handle_query(void *cls,
78  const struct BlacklistMessage *bm)
79 {
80  struct GNUNET_TRANSPORT_Blacklist *br = cls;
81  struct GNUNET_MQ_Envelope *env;
82  struct BlacklistMessage *res;
83 
84  GNUNET_break(0 == ntohl(bm->is_allowed));
85  env = GNUNET_MQ_msg(res,
87  res->is_allowed = htonl(br->cb(br->cb_cls,
88  &bm->peer));
89  res->peer = bm->peer;
90  GNUNET_MQ_send(br->mq,
91  env);
92 }
93 
102 static void
104  enum GNUNET_MQ_Error error)
105 {
106  struct GNUNET_TRANSPORT_Blacklist *br = cls;
107 
108  reconnect(br);
109 }
110 
111 
117 static void
119 {
120  struct GNUNET_MQ_MessageHandler handlers[] = {
123  struct BlacklistMessage,
124  br),
126  };
127  struct GNUNET_MQ_Envelope *env;
128  struct GNUNET_MessageHeader *req;
129 
130  if (NULL != br->mq)
131  GNUNET_MQ_destroy(br->mq);
132  br->mq = GNUNET_CLIENT_connect(br->cfg,
133  "transport",
134  handlers,
136  br);
137  if (NULL == br->mq)
138  return;
139  env = GNUNET_MQ_msg(req,
141  GNUNET_MQ_send(br->mq,
142  env);
143 }
144 
145 
163  void *cb_cls)
164 {
165  struct GNUNET_TRANSPORT_Blacklist *br;
166 
168  br->cfg = cfg;
169  br->cb = cb;
170  br->cb_cls = cb_cls;
171  reconnect(br);
172  if (NULL == br->mq)
173  {
174  GNUNET_free(br);
175  return NULL;
176  }
177  return br;
178 }
179 
180 
187 void
189 {
190  GNUNET_MQ_destroy(br->mq);
191  GNUNET_free(br);
192 }
193 
194 
195 /* end of transport_api_blacklist.c */
int(* GNUNET_TRANSPORT_BlacklistCallback)(void *cls, const struct GNUNET_PeerIdentity *pid)
Function that decides if a connection is acceptable or not.
common internal definitions for transport service
struct GNUNET_PeerIdentity peer
Which peer is being blacklisted or queried?
Definition: transport.h:586
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:900
GNUNET_MQ_Error
Error codes for the queue.
uint32_t is_allowed
0 for the query, GNUNET_OK (allowed) or GNUNET_SYSERR (disallowed) for the response.
Definition: transport.h:581
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_TRANSPORT_blacklist_cancel(struct GNUNET_TRANSPORT_Blacklist *br)
Abort the blacklist.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Change in blacklisting (either request or notification, depending on which direction it is going)...
Definition: transport.h:570
#define GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY
Reply from blacklisting client (answer to blacklist query).
struct GNUNET_TRANSPORT_Blacklist * GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls)
Install a blacklist callback.
Message handler for a specific message type.
static int res
struct GNUNET_MQ_Handle * mq
Connection to transport service.
Handle for blacklisting requests.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
GNUNET_TRANSPORT_BlacklistCallback cb
Function to call for determining if a peer is allowed to communicate with us.
Handle to a message queue.
Definition: mq.c:84
static void handle_query(void *cls, const struct BlacklistMessage *bm)
Handle blacklist queries.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT
Register a client that wants to do blacklisting.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
configuration data
Definition: configuration.c:83
#define GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY
Query to a blacklisting client (is this peer blacklisted)?
Header for all communications.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static void reconnect(struct GNUNET_TRANSPORT_Blacklist *br)
Establish blacklist connection to transport service.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.