GNUnet  0.11.x
gnunet-service-cadet_hello.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2014, 2017 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  */
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 
32 #include "cadet_protocol.h"
33 #include "gnunet-service-cadet.h"
37 
38 #define LOG(level, ...) GNUNET_log_from (level, "cadet-hll", __VA_ARGS__)
39 
43 static struct GNUNET_HELLO_Message *mine;
44 
49 
54 
55 
64 static void
65 got_hello (void *cls,
66  const struct GNUNET_PeerIdentity *id,
67  const struct GNUNET_HELLO_Message *hello,
68  const char *err_msg)
69 {
70  struct CadetPeer *peer;
71 
72  if ((NULL == id) ||
73  (NULL == hello))
74  return;
75  if (0 == GNUNET_memcmp (id,
76  &my_full_id))
77  {
78  GNUNET_free_non_null (mine);
79  mine = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (&hello->header);
81  return;
82  }
83 
85  "Hello for %s (%d bytes), expires on %s\n",
86  GNUNET_i2s (id),
87  GNUNET_HELLO_size (hello),
90  peer = GCP_get (id,
91  GNUNET_YES);
92  GCP_set_hello (peer,
93  hello);
94 }
95 
96 
102 void
104 {
105  GNUNET_assert (NULL == nc);
106  peerinfo = GNUNET_PEERINFO_connect (c);
107  nc = GNUNET_PEERINFO_notify (c,
108  GNUNET_NO,
109  &got_hello,
110  NULL);
111 }
112 
113 
117 void
119 {
120  if (NULL != nc)
121  {
123  nc = NULL;
124  }
125  if (NULL != peerinfo)
126  {
127  GNUNET_PEERINFO_disconnect (peerinfo);
128  peerinfo = NULL;
129  }
130  if (NULL != mine)
131  {
132  GNUNET_free (mine);
133  mine = NULL;
134  }
135 }
136 
137 
143 const struct GNUNET_HELLO_Message *
145 {
146  return mine;
147 }
148 
149 
150 /* end of gnunet-service-cadet-new_hello.c */
Peer description.
Handle to the peerinfo service.
Definition: peerinfo_api.c:84
A HELLO message is used to exchange information about transports with other peers.
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:130
Context for the info handler.
static void got_hello(void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
Process each hello message received from peerinfo.
static struct GNUNET_HELLO_Message * mine
Hello message of local peer.
void GCP_set_hello(struct CadetPeer *cp, const struct GNUNET_HELLO_Message *hello)
We got a HELLO for a peer, remember it, and possibly trigger adequate actions (like trying to connect...
struct GNUNET_PeerIdentity my_full_id
Local peer own ID.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void GCH_shutdown()
Shut down the hello subsystem.
struct GNUNET_PEERINFO_NotifyContext * GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, int include_friend_only, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method whenever our known information about peers changes.
void GCD_hello_update()
Function called by the HELLO subsystem whenever OUR hello changes.
Information we track per peer.
const struct GNUNET_HELLO_Message * GCH_get_mine(void)
Get own hello message.
cadet service; dealing with hello messages
#define LOG(level,...)
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
P2P messages used by CADET.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
configuration data
Definition: configuration.c:85
struct CadetPeer * GCP_get(const struct GNUNET_PeerIdentity *peer_id, int create)
Retrieve the CadetPeer stucture associated with the peer.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:652
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:156
#define GNUNET_YES
Definition: gnunet_common.h:77
cadet service; dealing with DHT requests and results
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_last_expiration(const struct GNUNET_HELLO_Message *msg)
When does the last address in the given HELLO expire?
Definition: hello.c:892
void GCH_init(const struct GNUNET_CONFIGURATION_Handle *c)
Initialize the hello subsystem.
static struct GNUNET_PEERINFO_Handle * peerinfo
Handle to peerinfo service.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
Information we track per peer.