GNUnet 0.29.1-6-gb66d952d5
 
Loading...
Searching...
No Matches
gnunet-service-messenger_subscription.c File Reference
Include dependency graph for gnunet-service-messenger_subscription.c:

Go to the source code of this file.

Functions

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)
 
void destroy_subscription (struct GNUNET_MESSENGER_Subscription *subscription)
 
const struct GNUNET_ShortHashCode * get_subscription_discourse (const 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)
 
static void task_subscription_exit (void *cls)
 
void update_subscription_timing (struct GNUNET_MESSENGER_Subscription *subscription)
 

Function Documentation

◆ create_subscription()

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 
)

Definition at line 32 of file gnunet-service-messenger_subscription.c.

37{
38 struct GNUNET_MESSENGER_Subscription *subscription;
39
40 GNUNET_assert ((room) && (member) && (discourse));
41
42 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new subscription: %s [%s]\n",
43 GNUNET_h2s (&(room->key)),
45
46 subscription = GNUNET_new (struct GNUNET_MESSENGER_Subscription);
47
48 if (! subscription)
49 return NULL;
50
51 subscription->room = room;
52 subscription->member = member;
53 subscription->task = NULL;
54
55 memcpy (
56 &(subscription->discourse),
58 sizeof (struct GNUNET_ShortHashCode));
59
60 subscription->start = timestamp;
62
63 return subscription;
64}
static uint64_t timestamp(void)
Get current timestamp.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition gnunet-vpn.c:90
#define GNUNET_log(kind,...)
#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.
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
A 256-bit hashcode.

References GNUNET_MESSENGER_Subscription::discourse, duration, GNUNET_MESSENGER_Subscription::end, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_new, GNUNET_sh2s(), GNUNET_TIME_absolute_add(), GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_Subscription::member, GNUNET_MESSENGER_Subscription::room, GNUNET_MESSENGER_Subscription::start, GNUNET_MESSENGER_Subscription::task, and timestamp().

Referenced by handle_message_subscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_subscription()

void destroy_subscription ( struct GNUNET_MESSENGER_Subscription *  subscription)

Definition at line 68 of file gnunet-service-messenger_subscription.c.

69{
70 GNUNET_assert (subscription);
71
72 if (subscription->task)
73 GNUNET_SCHEDULER_cancel (subscription->task);
74
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free subscription: %s [%s]\n",
76 GNUNET_h2s (&(subscription->room->key)),
77 GNUNET_sh2s (&(subscription->discourse)));
78
79 GNUNET_free (subscription);
80}
#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:986

References GNUNET_MESSENGER_Subscription::discourse, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_sh2s(), GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_Subscription::room, and GNUNET_MESSENGER_Subscription::task.

Referenced by iterate_destroy_subscription(), and task_subscription_exit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_subscription_discourse()

const struct GNUNET_ShortHashCode * get_subscription_discourse ( const struct GNUNET_MESSENGER_Subscription *  subscription)

Definition at line 84 of file gnunet-service-messenger_subscription.c.

86{
87 GNUNET_assert (subscription);
88
89 return &(subscription->discourse);
90}

References GNUNET_MESSENGER_Subscription::discourse, and GNUNET_assert.

Referenced by add_member_subscription(), and remove_member_subscription().

Here is the caller graph for this function:

◆ has_subscription_of_timestamp()

enum GNUNET_GenericReturnValue has_subscription_of_timestamp ( const struct GNUNET_MESSENGER_Subscription *  subscription,
struct GNUNET_TIME_Absolute  timestamp 
)

Definition at line 94 of file gnunet-service-messenger_subscription.c.

97{
98 GNUNET_assert (subscription);
99
100 if ((GNUNET_TIME_absolute_cmp (timestamp, <, subscription->start)) ||
101 (GNUNET_TIME_absolute_cmp (timestamp, >, subscription->end)))
102 return GNUNET_NO;
103 else
104 return GNUNET_YES;
105}
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_TIME_absolute_cmp(t1, op, t2)
Compare two absolute times.

References GNUNET_MESSENGER_Subscription::end, GNUNET_assert, GNUNET_NO, GNUNET_TIME_absolute_cmp, GNUNET_YES, GNUNET_MESSENGER_Subscription::start, and timestamp().

Referenced by notify_srv_handle_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_subscription()

void update_subscription ( struct GNUNET_MESSENGER_Subscription *  subscription,
struct GNUNET_TIME_Absolute  timestamp,
struct GNUNET_TIME_Relative  duration 
)

Definition at line 109 of file gnunet-service-messenger_subscription.c.

112{
114
115 GNUNET_assert (subscription);
116
118
119 if (GNUNET_TIME_absolute_cmp (end, <, subscription->start))
120 return;
121
122 if (GNUNET_TIME_absolute_cmp (timestamp, <, subscription->start))
123 subscription->start = timestamp;
124
125 subscription->end = end;
126}
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
Time for absolute times used by GNUnet, in microseconds.

References duration, end, GNUNET_MESSENGER_Subscription::end, GNUNET_assert, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_cmp, GNUNET_MESSENGER_Subscription::start, and timestamp().

Referenced by handle_message_subscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ task_subscription_exit()

static void task_subscription_exit ( void *  cls)
static

Definition at line 130 of file gnunet-service-messenger_subscription.c.

131{
132 struct GNUNET_MESSENGER_Subscription *subscription;
133 struct GNUNET_MESSENGER_Member *member;
134 struct GNUNET_MESSENGER_SrvRoom *room;
135 struct GNUNET_ShortHashCode discourse;
136
137 GNUNET_assert (cls);
138
139 subscription = cls;
140 member = subscription->member;
141
142 subscription->task = NULL;
143
144 if (! member)
145 return;
146
147 room = subscription->room;
148
149 memcpy (&discourse, &(subscription->discourse),
150 sizeof (struct GNUNET_ShortHashCode));
151
152 remove_member_subscription (member, subscription);
153 destroy_subscription (subscription);
154
155 cleanup_srv_room_discourse_messages (room, &discourse);
156}
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 destroy_subscription(struct GNUNET_MESSENGER_Subscription *subscription)

References cleanup_srv_room_discourse_messages(), destroy_subscription(), GNUNET_MESSENGER_Subscription::discourse, GNUNET_assert, GNUNET_MESSENGER_Subscription::member, remove_member_subscription(), GNUNET_MESSENGER_Subscription::room, and GNUNET_MESSENGER_Subscription::task.

Referenced by update_subscription_timing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_subscription_timing()

void update_subscription_timing ( struct GNUNET_MESSENGER_Subscription *  subscription)

Definition at line 160 of file gnunet-service-messenger_subscription.c.

161{
162 struct GNUNET_TIME_Absolute current;
163 struct GNUNET_TIME_Relative time;
164
165 GNUNET_assert (subscription);
166
167 current = GNUNET_TIME_absolute_get ();
168 time = GNUNET_TIME_absolute_get_difference (current, subscription->end);
169
170 if (subscription->task)
171 GNUNET_SCHEDULER_cancel (subscription->task);
172
173 subscription->task = GNUNET_SCHEDULER_add_delayed (
174 time, task_subscription_exit, subscription);
175}
static void task_subscription_exit(void *cls)
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:1283
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
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
Time for relative time used by GNUnet, in microseconds.

References GNUNET_MESSENGER_Subscription::end, GNUNET_assert, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_difference(), GNUNET_MESSENGER_Subscription::task, and task_subscription_exit().

Referenced by handle_message_subscribe().

Here is the call graph for this function:
Here is the caller graph for this function: