GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-service-messenger_subscription.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024--2025 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 */
26#include "platform.h"
28
31
35 const struct GNUNET_ShortHashCode *discourse,
38{
39 struct GNUNET_MESSENGER_Subscription *subscription;
40
41 GNUNET_assert ((room) && (member) && (discourse));
42
43 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new subscription: %s [%s]\n",
44 GNUNET_h2s (&(room->key)),
46
47 subscription = GNUNET_new (struct GNUNET_MESSENGER_Subscription);
48
49 if (! subscription)
50 return NULL;
51
52 subscription->room = room;
53 subscription->member = member;
54 subscription->task = NULL;
55
56 memcpy (
57 &(subscription->discourse),
59 sizeof (struct GNUNET_ShortHashCode));
60
61 subscription->start = timestamp;
63
64 return subscription;
65}
66
67
68void
70{
71 GNUNET_assert (subscription);
72
73 if (subscription->task)
74 GNUNET_SCHEDULER_cancel (subscription->task);
75
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free subscription: %s [%s]\n",
77 GNUNET_h2s (&(subscription->room->key)),
78 GNUNET_sh2s (&(subscription->discourse)));
79
80 GNUNET_free (subscription);
81}
82
83
84const struct GNUNET_ShortHashCode*
86 subscription)
87{
88 GNUNET_assert (subscription);
89
90 return &(subscription->discourse);
91}
92
93
96 subscription,
98{
99 GNUNET_assert (subscription);
100
101 if ((GNUNET_TIME_absolute_cmp (timestamp, <, subscription->start)) ||
102 (GNUNET_TIME_absolute_cmp (timestamp, >, subscription->end)))
103 return GNUNET_NO;
104 else
105 return GNUNET_YES;
106}
107
108
109void
113{
115
116 GNUNET_assert (subscription);
117
119
120 if (GNUNET_TIME_absolute_cmp (end, <, subscription->start))
121 return;
122
123 if (GNUNET_TIME_absolute_cmp (timestamp, <, subscription->start))
124 subscription->start = timestamp;
125
126 subscription->end = end;
127}
128
129
130static void
132{
133 struct GNUNET_MESSENGER_Subscription *subscription;
134 struct GNUNET_MESSENGER_Member *member;
135 struct GNUNET_MESSENGER_SrvRoom *room;
136 struct GNUNET_ShortHashCode discourse;
137
138 GNUNET_assert (cls);
139
140 subscription = cls;
141 member = subscription->member;
142
143 subscription->task = NULL;
144
145 if (! member)
146 return;
147
148 room = subscription->room;
149
150 memcpy (&discourse, &(subscription->discourse),
151 sizeof (struct GNUNET_ShortHashCode));
152
153 remove_member_subscription (member, subscription);
154 destroy_subscription (subscription);
155
156 cleanup_srv_room_discourse_messages (room, &discourse);
157}
158
159
160void
162{
163 struct GNUNET_TIME_Absolute current;
164 struct GNUNET_TIME_Relative time;
165
166 GNUNET_assert (subscription);
167
168 current = GNUNET_TIME_absolute_get ();
169 time = GNUNET_TIME_absolute_get_difference (current, subscription->end);
170
171 if (subscription->task)
172 GNUNET_SCHEDULER_cancel (subscription->task);
173
174 subscription->task = GNUNET_SCHEDULER_add_delayed (
175 time, task_subscription_exit, subscription);
176}
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
static uint64_t timestamp(void)
Get current timestamp.
void remove_member_subscription(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_Subscription *subscription)
Removes a given subscription from a member.
void cleanup_srv_room_discourse_messages(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *discourse)
Cleanup discourse messages outside of current subscriptions from a specific discourse of all the memb...
static void task_subscription_exit(void *cls)
const struct GNUNET_ShortHashCode * get_subscription_discourse(const struct GNUNET_MESSENGER_Subscription *subscription)
void update_subscription_timing(struct GNUNET_MESSENGER_Subscription *subscription)
void destroy_subscription(struct GNUNET_MESSENGER_Subscription *subscription)
enum GNUNET_GenericReturnValue has_subscription_of_timestamp(const struct GNUNET_MESSENGER_Subscription *subscription, struct GNUNET_TIME_Absolute timestamp)
void update_subscription(struct GNUNET_MESSENGER_Subscription *subscription, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Relative duration)
struct GNUNET_MESSENGER_Subscription * create_subscription(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Member *member, const struct GNUNET_ShortHashCode *discourse, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Relative duration)
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition gnunet-vpn.c:90
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1277
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
#define GNUNET_TIME_absolute_cmp(t1, op, t2)
Compare two absolute times.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition time.c:452
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition time.c:423
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.