GNUnet 0.21.2
gnunet-service-messenger_subscription.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 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,
36 struct GNUNET_TIME_Absolute timestamp,
38{
39 GNUNET_assert ((room) && (member) && (discourse));
40
41 struct GNUNET_MESSENGER_Subscription *subscribtion;
42 subscribtion = GNUNET_new (struct GNUNET_MESSENGER_Subscription);
43
44 if (! subscribtion)
45 return NULL;
46
47 subscribtion->room = room;
48 subscribtion->member = member;
49 subscribtion->task = NULL;
50
51 memcpy (&(subscribtion->discourse), discourse, sizeof (struct GNUNET_ShortHashCode));
52
53 subscribtion->start = timestamp;
54 subscribtion->end = GNUNET_TIME_absolute_add (timestamp, duration);
55
56 return subscribtion;
57}
58
59void
61{
62 GNUNET_assert (subscribtion);
63
64 if (subscribtion->task)
65 GNUNET_SCHEDULER_cancel (subscribtion->task);
66
67 GNUNET_free (subscribtion);
68}
69
70const struct GNUNET_ShortHashCode*
72{
73 GNUNET_assert (subscribtion);
74
75 return &(subscribtion->discourse);
76}
77
80 struct GNUNET_TIME_Absolute timestamp)
81{
82 GNUNET_assert (subscribtion);
83
84 if ((GNUNET_TIME_absolute_cmp (timestamp, <, subscribtion->start)) ||
85 (GNUNET_TIME_absolute_cmp (timestamp, >, subscribtion->end)))
86 return GNUNET_NO;
87 else
88 return GNUNET_YES;
89}
90
91void
93 struct GNUNET_TIME_Absolute timestamp,
95{
96 GNUNET_assert (subscribtion);
97
99
100 if (GNUNET_TIME_absolute_cmp (end, <, subscribtion->start))
101 return;
102
103 if (GNUNET_TIME_absolute_cmp (timestamp, <, subscribtion->start))
104 subscribtion->start = timestamp;
105
106 subscribtion->end = end;
107}
108
109static void
111{
112 GNUNET_assert (cls);
113
114 struct GNUNET_MESSENGER_Subscription *subscribtion = cls;
115 struct GNUNET_MESSENGER_Member *member = subscribtion->member;
116
117 subscribtion->task = NULL;
118
119 if (! member)
120 return;
121
122 struct GNUNET_MESSENGER_SrvRoom *room = subscribtion->room;
123 struct GNUNET_ShortHashCode discourse;
124
125 memcpy (&discourse, &(subscribtion->discourse),
126 sizeof (struct GNUNET_ShortHashCode));
127
128 remove_member_subscription (member, subscribtion);
129 destroy_subscription (subscribtion);
130
131 cleanup_srv_room_discourse_messages (room, &discourse);
132}
133
134void
136{
137 GNUNET_assert (subscribtion);
138
140
141 struct GNUNET_TIME_Relative time =
142 GNUNET_TIME_absolute_get_difference (current, subscribtion->end);
143
144 if (subscribtion->task)
145 GNUNET_SCHEDULER_cancel (subscribtion->task);
146
147 subscribtion->task =
149}
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
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...
void update_subscription(struct GNUNET_MESSENGER_Subscription *subscribtion, struct GNUNET_TIME_Absolute timestamp, struct GNUNET_TIME_Relative duration)
static void task_subscription_exit(void *cls)
enum GNUNET_GenericReturnValue has_subscription_of_timestamp(const struct GNUNET_MESSENGER_Subscription *subscribtion, struct GNUNET_TIME_Absolute timestamp)
void update_subscription_timing(struct GNUNET_MESSENGER_Subscription *subscribtion)
const struct GNUNET_ShortHashCode * get_subscription_discourse(const struct GNUNET_MESSENGER_Subscription *subscribtion)
void destroy_subscription(struct GNUNET_MESSENGER_Subscription *subscribtion)
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
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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:981
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:1278
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:450
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:421
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.