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 
38 {
39 
44 
49 
55 
59  void *cb_cls;
60 
61 };
62 
63 
69 static void
71 
72 
79 static void
80 handle_query (void *cls,
81  const struct BlacklistMessage *bm)
82 {
83  struct GNUNET_TRANSPORT_Blacklist *br = cls;
84  struct GNUNET_MQ_Envelope *env;
85  struct BlacklistMessage *res;
86 
87  GNUNET_break (0 == ntohl (bm->is_allowed));
88  env = GNUNET_MQ_msg (res,
90  res->is_allowed = htonl (br->cb (br->cb_cls,
91  &bm->peer));
92  res->peer = bm->peer;
93  GNUNET_MQ_send (br->mq,
94  env);
95 }
96 
105 static void
106 mq_error_handler (void *cls,
107  enum GNUNET_MQ_Error error)
108 {
109  struct GNUNET_TRANSPORT_Blacklist *br = cls;
110 
111  reconnect (br);
112 }
113 
114 
120 static void
122 {
123  struct GNUNET_MQ_MessageHandler handlers[] = {
126  struct BlacklistMessage,
127  br),
129  };
130  struct GNUNET_MQ_Envelope *env;
131  struct GNUNET_MessageHeader *req;
132 
133  if (NULL != br->mq)
134  GNUNET_MQ_destroy (br->mq);
135  br->mq = GNUNET_CLIENT_connect (br->cfg,
136  "transport",
137  handlers,
139  br);
140  if (NULL == br->mq)
141  return;
142  env = GNUNET_MQ_msg (req,
144  GNUNET_MQ_send (br->mq,
145  env);
146 }
147 
148 
166  void *cb_cls)
167 {
168  struct GNUNET_TRANSPORT_Blacklist *br;
169 
171  br->cfg = cfg;
172  br->cb = cb;
173  br->cb_cls = cb_cls;
174  reconnect (br);
175  if (NULL == br->mq)
176  {
177  GNUNET_free (br);
178  return NULL;
179  }
180  return br;
181 }
182 
183 
190 void
192 {
193  GNUNET_MQ_destroy (br->mq);
194  GNUNET_free (br);
195 }
196 
197 
198 /* 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:618
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:901
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:613
#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:600
#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.