GNUnet  0.11.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 
38 {
43 
48 
54 
58  void *cb_cls;
59 };
60 
61 
67 static void
69 
70 
77 static void
78 handle_query (void *cls,
79  const struct BlacklistMessage *bm)
80 {
81  struct GNUNET_TRANSPORT_Blacklist *br = cls;
82  struct GNUNET_MQ_Envelope *env;
83  struct BlacklistMessage *res;
84 
85  GNUNET_break (0 == ntohl (bm->is_allowed));
86  env = GNUNET_MQ_msg (res,
88  res->is_allowed = htonl (br->cb (br->cb_cls,
89  &bm->peer));
90  res->peer = bm->peer;
91  GNUNET_MQ_send (br->mq,
92  env);
93 }
94 
95 
104 static void
105 mq_error_handler (void *cls,
106  enum GNUNET_MQ_Error error)
107 {
108  struct GNUNET_TRANSPORT_Blacklist *br = cls;
109 
110  reconnect (br);
111 }
112 
113 
119 static void
121 {
122  struct GNUNET_MQ_MessageHandler handlers[] = {
125  struct BlacklistMessage,
126  br),
128  };
129  struct GNUNET_MQ_Envelope *env;
130  struct GNUNET_MessageHeader *req;
131 
132  if (NULL != br->mq)
133  GNUNET_MQ_destroy (br->mq);
134  br->mq = GNUNET_CLIENT_connect (br->cfg,
135  "transport",
136  handlers,
138  br);
139  if (NULL == br->mq)
140  return;
141  env = GNUNET_MQ_msg (req,
143  GNUNET_MQ_send (br->mq,
144  env);
145 }
146 
147 
165  void *cb_cls)
166 {
167  struct GNUNET_TRANSPORT_Blacklist *br;
168 
170  br->cfg = cfg;
171  br->cb = cb;
172  br->cb_cls = cb_cls;
173  reconnect (br);
174  if (NULL == br->mq)
175  {
176  GNUNET_free (br);
177  return NULL;
178  }
179  return br;
180 }
181 
182 
189 void
191 {
192  GNUNET_MQ_destroy (br->mq);
193  GNUNET_free (br);
194 }
195 
196 
197 /* 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:602
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:1057
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:597
#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:585
#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:85
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:85
#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:824
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:353
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.