#include "gnunet-service-messenger_tunnel.h"
#include "gnunet-service-messenger_handle.h"
#include "gnunet-service-messenger_message_kind.h"
#include "gnunet-service-messenger_message_recv.h"
#include "gnunet-service-messenger_message_store.h"
#include "gnunet-service-messenger_operation_store.h"
#include "gnunet-service-messenger_operation.h"
#include "gnunet-service-messenger_room.h"
#include "messenger_api_util.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_MESSENGER_MessageSent |
Functions | |
struct GNUNET_MESSENGER_SrvTunnel * | create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door) |
Creates and allocates a tunnel of a room to a specific peer identity (called door). More... | |
void | destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
Destroys a tunnel and frees its memory fully. More... | |
void | bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel) |
Binds a CADET channel to a tunnel and replaces its channel the tunnel is currently bound to if necessary. More... | |
void | callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel) |
Callback for a CADET channel disconnecting to manage this event as a proper tunnel provided as its closure. More... | |
static enum GNUNET_GenericReturnValue | verify_tunnel_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash) |
enum GNUNET_GenericReturnValue | check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) |
Callback for message verification via header in a tunnel that is provided as a closure from a CADET channel. More... | |
enum GNUNET_GenericReturnValue | update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) |
void | callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) |
static void | update_tunnel_last_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_HashCode *hash) |
void | handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) |
Callback for message handling via header in a tunnel that is provided as a closure from a CADET channel. More... | |
enum GNUNET_GenericReturnValue | connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
Tries to connect a tunnel by creating a new CADET channel and binding it. More... | |
void | disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
Disconnects and unbinds a channel from a tunnel. More... | |
enum GNUNET_GenericReturnValue | is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
Returns the status of a currently bound channel of a tunnel. More... | |
static void | callback_tunnel_sent (void *cls) |
void | send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash) |
Sends an envelope containing a message with a given hash through a tunnel. More... | |
enum GNUNET_GenericReturnValue | 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. More... | |
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. More... | |
const struct GNUNET_HashCode * | get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
Returns the hash of the latest peer message published through a given tunnel and matching the tunnels peer identity. More... | |
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. More... | |
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 if it was compatible during updating. More... | |
enum GNUNET_GenericReturnValue | 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 peer of the service. More... | |
struct GNUNET_MESSENGER_SrvTunnel * create_tunnel | ( | struct GNUNET_MESSENGER_SrvRoom * | room, |
const struct GNUNET_PeerIdentity * | door | ||
) |
Creates and allocates a tunnel of a room to a specific peer identity (called door).
[in,out] | room | Room |
[in] | door | Peer identity |
Definition at line 39 of file gnunet-service-messenger_tunnel.c.
References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_assert, GNUNET_new, GNUNET_PEER_intern(), init_message_state(), GNUNET_MESSENGER_SrvTunnel::messenger_version, GNUNET_MESSENGER_SrvTunnel::peer, GNUNET_MESSENGER_SrvTunnel::peer_message, GNUNET_MESSENGER_SrvTunnel::room, and GNUNET_MESSENGER_SrvTunnel::state.
Referenced by callback_room_connect(), and enter_srv_room_at().
void destroy_tunnel | ( | struct GNUNET_MESSENGER_SrvTunnel * | tunnel | ) |
Destroys a tunnel and frees its memory fully.
[in,out] | tunnel |
Definition at line 64 of file gnunet-service-messenger_tunnel.c.
References GNUNET_MESSENGER_SrvTunnel::channel, clear_message_state(), GNUNET_assert, GNUNET_CADET_channel_destroy(), GNUNET_free, GNUNET_PEER_change_rc(), GNUNET_MESSENGER_SrvTunnel::peer, GNUNET_MESSENGER_SrvTunnel::peer_message, and GNUNET_MESSENGER_SrvTunnel::state.
void bind_tunnel | ( | struct GNUNET_MESSENGER_SrvTunnel * | tunnel, |
struct GNUNET_CADET_Channel * | channel | ||
) |
Binds a CADET channel to a tunnel and replaces its channel the tunnel is currently bound to if necessary.
[in,out] | tunnel | Tunnel |
[in,out] | channel | CADET channel |
Definition at line 83 of file gnunet-service-messenger_tunnel.c.
References GNUNET_MESSENGER_SrvTunnel::channel, delayed_disconnect_channel(), and GNUNET_assert.
Referenced by callback_room_connect().
void callback_tunnel_disconnect | ( | void * | cls, |
const struct GNUNET_CADET_Channel * | channel | ||
) |
Callback for a CADET channel disconnecting to manage this event as a proper tunnel provided as its closure.
[in,out] | cls | Closure |
[in] | channel | CADET channel |
Definition at line 96 of file gnunet-service-messenger_tunnel.c.
References GNUNET_MESSENGER_Service::auto_connecting, GNUNET_MESSENGER_SrvRoom::basement, GNUNET_MESSENGER_SrvTunnel::channel, contains_list_tunnels(), create_message_miss(), enter_srv_room_at(), find_list_tunnels_alternate(), get_srv_room_key(), get_tunnel_peer_identity(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_PEER_resolve(), GNUNET_STATISTICS_update(), GNUNET_YES, GNUNET_MESSENGER_SrvRoom::host, identity, GNUNET_MESSENGER_ListTunnel::peer, GNUNET_MESSENGER_SrvTunnel::room, send_srv_room_message(), GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_Service::statistics, and GNUNET_MESSENGER_SrvRoom::tunnels.
Referenced by connect_tunnel(), and open_srv_room().
|
static |
Definition at line 165 of file gnunet-service-messenger_tunnel.c.
References get_srv_room_message_store(), get_store_message(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_name_of_kind(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_get_zero_(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::timestamp, and timestamp().
Referenced by check_tunnel_message().
enum GNUNET_GenericReturnValue check_tunnel_message | ( | void * | cls, |
const struct GNUNET_MessageHeader * | header | ||
) |
Callback for message verification via header in a tunnel that is provided as a closure from a CADET channel.
[in,out] | cls | Closure |
[in] | header | Message header |
Definition at line 216 of file gnunet-service-messenger_tunnel.c.
References decode_message(), get_message_kind_size(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_SYSERR, GNUNET_YES, hash_message(), GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MessageHeader::size, and verify_tunnel_message().
enum GNUNET_GenericReturnValue update_room_message | ( | struct GNUNET_MESSENGER_SrvRoom * | room, |
struct GNUNET_MESSENGER_Message * | message, | ||
const struct GNUNET_HashCode * | hash | ||
) |
Definition at line 1156 of file gnunet-service-messenger_room.c.
References GNUNET_MESSENGER_Message::body, cancel_store_operation(), contains_store_message(), destroy_message(), get_srv_room_key(), get_srv_room_message_store(), get_srv_room_operation_store(), get_store_operation_type(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_OP_MERGE, GNUNET_MESSENGER_OP_REQUEST, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageMerge::previous, put_store_message(), GNUNET_MESSENGER_SrvRoom::state, and update_message_state().
Referenced by handle_tunnel_message(), and send_srv_room_message().
void callback_room_handle_message | ( | struct GNUNET_MESSENGER_SrvRoom * | room, |
const struct GNUNET_MESSENGER_Message * | message, | ||
const struct GNUNET_HashCode * | hash | ||
) |
Definition at line 1324 of file gnunet-service-messenger_room.c.
References add_to_list_messages(), get_member_session_of(), get_srv_room_member_store(), get_srv_room_peer_store(), get_store_member_of(), get_store_peer_of(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_SUBSCRIBE, GNUNET_NO, GNUNET_YES, handle_message_connection(), handle_message_delete(), handle_message_id(), handle_message_join(), handle_message_key(), handle_message_leave(), handle_message_miss(), handle_message_peer(), handle_message_subscribe(), handle_room_messages(), GNUNET_MESSENGER_SrvRoom::handling, GNUNET_MESSENGER_MemberUpdate::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_MemberUpdate::head, GNUNET_MESSENGER_Message::header, is_peer_message(), iterate_store_members(), iterate_update_member_sessions(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_SenderSession::member, GNUNET_MESSENGER_MemberUpdate::message, GNUNET_MESSENGER_SenderSession::peer, remove_room_member_session(), GNUNET_MESSENGER_MemberSessionCompletion::session, and GNUNET_MESSENGER_MemberUpdate::tail.
Referenced by handle_tunnel_message(), and send_srv_room_message().
|
static |
Definition at line 273 of file gnunet-service-messenger_tunnel.c.
References get_srv_room_message_store(), get_srv_room_operation_store(), get_store_message(), get_store_operation_type(), GNUNET_assert, GNUNET_MESSENGER_OP_REQUEST, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvTunnel::state, and update_message_state().
Referenced by callback_tunnel_sent(), and handle_tunnel_message().
void handle_tunnel_message | ( | void * | cls, |
const struct GNUNET_MessageHeader * | header | ||
) |
Callback for message handling via header in a tunnel that is provided as a closure from a CADET channel.
[in,out] | cls | Closure |
[in] | header | Message header |
Definition at line 303 of file gnunet-service-messenger_tunnel.c.
References callback_room_handle_message(), GNUNET_MESSENGER_SrvTunnel::channel, cleanup_message(), copy_message(), decode_message(), forward_srv_room_message(), GNUNET_assert, GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_name_of_kind(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, recv_message_info(), recv_message_miss(), recv_message_peer(), recv_message_request(), GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvRoom::service, GNUNET_MessageHeader::size, GNUNET_MESSENGER_Service::statistics, update_room_message(), and update_tunnel_last_message().
enum GNUNET_GenericReturnValue connect_tunnel | ( | struct GNUNET_MESSENGER_SrvTunnel * | tunnel | ) |
Tries to connect a tunnel by creating a new CADET channel and binding it.
The function returns GNUNET_YES on success, otherwise GNUNET_NO.
[in,out] | tunnel | Tunnel |
Definition at line 390 of file gnunet-service-messenger_tunnel.c.
References cadet, callback_tunnel_disconnect(), GNUNET_MESSENGER_SrvTunnel::channel, convert_messenger_key_to_port(), get_srv_room_cadet(), get_srv_room_key(), GNUNET_assert, GNUNET_CADET_channel_create(), GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_PEER_resolve2(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, handlers, key, GNUNET_MESSENGER_SrvTunnel::peer, port, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvRoom::service, and GNUNET_MESSENGER_Service::statistics.
Referenced by enter_srv_room_at(), and rebuild_srv_room_basement_structure().
void disconnect_tunnel | ( | struct GNUNET_MESSENGER_SrvTunnel * | tunnel | ) |
Disconnects and unbinds a channel from a tunnel.
The actual disconnection will be asynchronous.
[in,out] | tunnel | Tunnel |
Definition at line 436 of file gnunet-service-messenger_tunnel.c.
References GNUNET_MESSENGER_SrvTunnel::channel, delayed_disconnect_channel(), and GNUNET_assert.
Referenced by callback_room_connect(), rebuild_srv_room_basement_structure(), and recv_message_info().
enum GNUNET_GenericReturnValue is_tunnel_connected | ( | const struct GNUNET_MESSENGER_SrvTunnel * | tunnel | ) |
Returns the status of a currently bound channel of a tunnel.
[in] | tunnel | Tunnel |
Definition at line 450 of file gnunet-service-messenger_tunnel.c.
References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_assert, GNUNET_NO, and GNUNET_YES.
Referenced by iterate_send_room_message(), and send_room_info().
|
static |
Definition at line 465 of file gnunet-service-messenger_tunnel.c.
References GNUNET_assert, GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_MESSENGER_MessageSent::hash, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_Service::statistics, GNUNET_MESSENGER_MessageSent::tunnel, and update_tunnel_last_message().
Referenced by send_tunnel_envelope().
void send_tunnel_envelope | ( | struct GNUNET_MESSENGER_SrvTunnel * | tunnel, |
struct GNUNET_MQ_Envelope * | env, | ||
const struct GNUNET_HashCode * | hash | ||
) |
Sends an envelope containing a message with a given hash through a tunnel.
[in,out] | tunnel | Tunnel |
[in,out] | env | Envelope |
[in] | hash | Hash of message |
Definition at line 488 of file gnunet-service-messenger_tunnel.c.
References callback_tunnel_sent(), GNUNET_MESSENGER_SrvTunnel::channel, env, GNUNET_assert, GNUNET_CADET_get_mq(), GNUNET_memcpy, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_new, GNUNET_MESSENGER_MessageSent::hash, mq, and GNUNET_MESSENGER_MessageSent::tunnel.
Referenced by forward_tunnel_message(), iterate_send_room_message(), and send_tunnel_message().
enum GNUNET_GenericReturnValue 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.
The used handle will sign the message and the hash will be calculated and stored.
[in,out] | tunnel | Tunnel |
[in,out] | handle | Handle |
[in,out] | message | Message |
Definition at line 510 of file gnunet-service-messenger_tunnel.c.
References destroy_message(), env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_NO, GNUNET_YES, handle, pack_srv_room_message(), GNUNET_MESSENGER_SrvTunnel::room, and send_tunnel_envelope().
Referenced by recv_message_info(), and send_room_info().
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.
[in,out] | tunnel | Tunnel |
[in] | message | Message |
[in] | hash | Hash of message |
Definition at line 541 of file gnunet-service-messenger_tunnel.c.
References copy_message(), destroy_message(), env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, pack_message(), and send_tunnel_envelope().
Referenced by callback_found_message(), check_srv_room_peer_status(), forward_about_members(), and recv_message_info().
const struct GNUNET_HashCode * get_tunnel_peer_message | ( | const struct GNUNET_MESSENGER_SrvTunnel * | tunnel | ) |
Returns the hash of the latest peer message published through a given tunnel and matching the tunnels peer identity.
If no peer message has been linked to the tunnel yet, NULL gets returned.
[in] | tunnel | Tunnel |
Definition at line 567 of file gnunet-service-messenger_tunnel.c.
References GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::peer_message.
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.
[in] | tunnel | Tunnel |
[out] | peer | Peer identity |
Definition at line 576 of file gnunet-service-messenger_tunnel.c.
References GNUNET_assert, GNUNET_PEER_resolve(), and GNUNET_MESSENGER_SrvTunnel::peer.
Referenced by callback_tunnel_disconnect(), and recv_message_info().
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 if it was compatible during updating.
[in] | tunnel | Tunnel |
Definition at line 586 of file gnunet-service-messenger_tunnel.c.
References GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::messenger_version.
Referenced by iterate_send_room_message(), and recv_message_info().
enum GNUNET_GenericReturnValue 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 peer of the service.
Depending on success it returns GNUNET_OK or GNUNET_SYSERR on failure.
[in,out] | tunnel | Tunnel |
[in] | version | Version of messenger |
Definition at line 595 of file gnunet-service-messenger_tunnel.c.
References GNUNET_assert, GNUNET_MESSENGER_VERSION, GNUNET_OK, GNUNET_SYSERR, and GNUNET_MESSENGER_SrvTunnel::messenger_version.
Referenced by recv_message_info().