GNUnet  0.11.x
gnunet-service-messenger_message_recv.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020--2021 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 
29 
30 static int
31 iterate_forward_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key,
32  struct GNUNET_MESSENGER_MemberSession *session)
33 {
34  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
35  struct GNUNET_MESSENGER_SrvRoom *room = tunnel->room;
36 
37  struct GNUNET_MESSENGER_ListMessage *element;
38 
39  for (element = session->messages.head; element; element = element->next)
40  forward_tunnel_message(tunnel, get_room_message(room, NULL, &(element->hash), GNUNET_NO), &(element->hash));
41 
42  return GNUNET_YES;
43 }
44 
45 int
47  const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
48 {
49  const uint32_t version = get_tunnel_messenger_version(tunnel);
50 
52  {
53  disconnect_tunnel(tunnel);
54  return GNUNET_NO;
55  }
56 
57  if (version == get_tunnel_messenger_version(tunnel))
58  return GNUNET_NO;
59 
60  if (room->host)
61  {
62  const struct GNUNET_MESSENGER_Ego *ego = get_handle_ego(room->host);
63 
64  send_tunnel_message (tunnel, room->host, create_message_info(ego));
65  }
66 
67  struct GNUNET_PeerIdentity peer;
68  get_tunnel_peer_identity(tunnel, &peer);
69 
70  if (GNUNET_YES != contains_list_tunnels(&(room->basement), &peer))
71  {
72  struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
73 
74  iterate_store_members(member_store, iterate_forward_members, tunnel);
75  }
76 
77  check_room_peer_status(room, tunnel);
78 
79  return GNUNET_NO;
80 }
81 
82 int
84  const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
85 {
86  struct GNUNET_PeerIdentity peer;
87  GNUNET_PEER_resolve (tunnel->peer, &peer);
88 
89  if (0 == GNUNET_memcmp(&peer, &(message->body.peer.peer)))
90  {
91  if (!tunnel->peer_message)
92  tunnel->peer_message = GNUNET_new(struct GNUNET_HashCode);
93 
94  GNUNET_memcpy(tunnel->peer_message, &hash, sizeof(hash));
95  }
96 
97  return GNUNET_YES;
98 }
99 
100 int
102  const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
103 {
105  room, NULL, &(message->body.request.hash), GNUNET_NO
106  );
107 
108  if (!msg)
109  {
110  struct GNUNET_MESSENGER_OperationStore *operation_store = get_room_operation_store(room);
111 
113  operation_store,
114  &(message->body.request.hash),
117  );
118 
119  return GNUNET_YES;
120  }
121 
122  struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
123  struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
124 
125  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Callback for message (%s)\n", GNUNET_h2s (hash));
126 
127  if (!member)
128  return GNUNET_NO;
129 
130  struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, hash);
131 
132  if ((!session) || (GNUNET_YES != check_member_session_history(session, hash, GNUNET_NO)))
133  return GNUNET_NO;
134 
135  forward_tunnel_message (tunnel, msg, &(message->body.request.hash));
136 
137  return GNUNET_NO;
138 }
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
int contains_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Tests linearly if the list of tunnels peer identities contains a specific peer identity and returns G...
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MESSENGER_ListMessage * head
void check_room_peer_status(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Checks the current state of opening a given room from this peer and re-publishes it if necessary to a...
GNUnet MESSENGER service.
int iterate_store_members(struct GNUNET_MESSENGER_MemberStore *store, GNUNET_MESSENGER_MemberIteratorCallback it, void *cls)
Iterate through all member sessions currently connected to the members of the given member store and ...
struct GNUNET_HashCode hash
The hash of the requested message.
uint32_t messenger_version
The version of GNUnet Messenger API.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:225
int recv_message_info(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received info message to change the current member id to the one generated by the host conn...
struct GNUNET_MESSENGER_MemberStore * get_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
uint32_t get_tunnel_messenger_version(const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Returns the current messenger version the peer connected via a given tunnel has reported to be using ...
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_OperationStore * get_room_operation_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used operation store of a given room.
void get_tunnel_peer_identity(const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer)
Writes the peer identity of the peer connected via tunnel to this peer into the peer parameter...
struct GNUNET_MESSENGER_Message * create_message_info(const struct GNUNET_MESSENGER_Ego *ego)
Creates and allocates a new info message containing the hosts EGO public key and a newly generated un...
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_SrvRoom * room
A 512-bit hashcode.
int check_member_session_history(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, int ownership)
Checks the history of a session for a specific message which is identified by its hash and if the own...
int recv_message_request(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received request message by checking for the requested message and forwarding it back if th...
#define GNUNET_MESSENGER_REQUEST_DELAY
struct GNUNET_MESSENGER_SrvHandle * host
static int iterate_forward_members(void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)
GNUnet MESSENGER service.
struct GNUNET_MESSENGER_MessageInfo info
struct GNUNET_MESSENGER_ListMessages messages
struct GNUNET_MESSENGER_MessagePeer peer
int use_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_OperationType type, struct GNUNET_TIME_Relative delay)
Tries to use an operation under a given hash in a specific operation store.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
struct GNUNET_MESSENGER_Member * get_store_member_of(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message)
Returns the member of a store using a sender id of a given message.
int recv_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received peer message to link it to its origin tunnel if the peer identity matches...
void forward_tunnel_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Forwards a given message with a known hash through a tunnel.
The identity of the host (wraps the signing key of the peer).
An identity key as per LSD0001.
int update_tunnel_messenger_version(struct GNUNET_MESSENGER_SrvTunnel *tunnel, uint32_t version)
Updates the messenger version of the tunnel to a given version if it is compatible to the running pee...
struct GNUNET_MESSENGER_ListTunnels basement
#define GNUNET_log(kind,...)
int send_tunnel_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message by packing it automatically into an envelope and passing it through the tunnel...
void disconnect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Disconnects and unbinds a channel from a tunnel.
struct GNUNET_MESSENGER_MemberSession * get_member_session_of(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Returns the member session of a member using a public key which can verify the signature of a given m...
const struct GNUNET_MESSENGER_Ego * get_handle_ego(const struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the EGO used by a given handle.