aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_room.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger_room.c')
-rw-r--r--src/messenger/gnunet-service-messenger_room.c142
1 files changed, 96 insertions, 46 deletions
diff --git a/src/messenger/gnunet-service-messenger_room.c b/src/messenger/gnunet-service-messenger_room.c
index 73e94908f..920abb10e 100644
--- a/src/messenger/gnunet-service-messenger_room.c
+++ b/src/messenger/gnunet-service-messenger_room.c
@@ -43,7 +43,8 @@ static void
43idle_request_room_messages (void *cls); 43idle_request_room_messages (void *cls);
44 44
45struct GNUNET_MESSENGER_SrvRoom* 45struct GNUNET_MESSENGER_SrvRoom*
46create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) 46create_room (struct GNUNET_MESSENGER_SrvHandle *handle,
47 const struct GNUNET_HashCode *key)
47{ 48{
48 GNUNET_assert((handle) && (key)); 49 GNUNET_assert((handle) && (key));
49 50
@@ -78,7 +79,9 @@ create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_Hash
78} 79}
79 80
80static int 81static int
81iterate_destroy_tunnels (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 82iterate_destroy_tunnels (void *cls,
83 const struct GNUNET_PeerIdentity *key,
84 void *value)
82{ 85{
83 struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; 86 struct GNUNET_MESSENGER_SrvTunnel *tunnel = value;
84 destroy_tunnel (tunnel); 87 destroy_tunnel (tunnel);
@@ -150,7 +153,8 @@ get_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room)
150} 153}
151 154
152static int 155static int
153send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, 156send_room_info (struct GNUNET_MESSENGER_SrvRoom *room,
157 struct GNUNET_MESSENGER_SrvHandle *handle,
154 struct GNUNET_MESSENGER_SrvTunnel *tunnel) 158 struct GNUNET_MESSENGER_SrvTunnel *tunnel)
155{ 159{
156 if ((!handle) || (!is_tunnel_connected (tunnel))) 160 if ((!handle) || (!is_tunnel_connected (tunnel)))
@@ -160,7 +164,9 @@ send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_S
160} 164}
161 165
162static void* 166static void*
163callback_room_connect (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source) 167callback_room_connect (void *cls,
168 struct GNUNET_CADET_Channel *channel,
169 const struct GNUNET_PeerIdentity *source)
164{ 170{
165 struct GNUNET_MESSENGER_SrvRoom *room = cls; 171 struct GNUNET_MESSENGER_SrvRoom *room = cls;
166 172
@@ -197,7 +203,8 @@ callback_room_connect (void *cls, struct GNUNET_CADET_Channel *channel, const st
197} 203}
198 204
199static int 205static int
200join_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, 206join_room (struct GNUNET_MESSENGER_SrvRoom *room,
207 struct GNUNET_MESSENGER_SrvHandle *handle,
201 struct GNUNET_MESSENGER_Member *member) 208 struct GNUNET_MESSENGER_Member *member)
202{ 209{
203 GNUNET_assert((room) && (handle) && (member)); 210 GNUNET_assert((room) && (handle) && (member));
@@ -228,8 +235,10 @@ struct GNUNET_MESSENGER_MemberNotify
228}; 235};
229 236
230static void 237static void
231notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify, struct GNUNET_MESSENGER_MemberSession *session, 238notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify,
232 struct GNUNET_CONTAINER_MultiHashMap *map, int check_permission) 239 struct GNUNET_MESSENGER_MemberSession *session,
240 struct GNUNET_CONTAINER_MultiHashMap *map,
241 int check_permission)
233{ 242{
234 if (session->prev) 243 if (session->prev)
235 notify_about_members (notify, session->prev, map, GNUNET_YES); 244 notify_about_members (notify, session->prev, map, GNUNET_YES);
@@ -258,7 +267,8 @@ notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify, struct GNUNE
258} 267}
259 268
260static int 269static int
261iterate_notify_about_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, 270iterate_notify_about_members (void *cls,
271 const struct GNUNET_IDENTITY_PublicKey *public_key,
262 struct GNUNET_MESSENGER_MemberSession *session) 272 struct GNUNET_MESSENGER_MemberSession *session)
263{ 273{
264 struct GNUNET_MESSENGER_MemberNotify *notify = cls; 274 struct GNUNET_MESSENGER_MemberNotify *notify = cls;
@@ -275,7 +285,8 @@ iterate_notify_about_members (void *cls, const struct GNUNET_IDENTITY_PublicKey
275} 285}
276 286
277static int 287static int
278join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) 288join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room,
289 struct GNUNET_MESSENGER_SrvHandle *handle)
279{ 290{
280 const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, get_room_key(room)); 291 const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, get_room_key(room));
281 292
@@ -306,16 +317,20 @@ join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE
306} 317}
307 318
308extern int 319extern int
309check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header); 320check_tunnel_message (void *cls,
321 const struct GNUNET_MessageHeader *header);
310 322
311extern void 323extern void
312handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header); 324handle_tunnel_message (void *cls,
325 const struct GNUNET_MessageHeader *header);
313 326
314extern void 327extern void
315callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel); 328callback_tunnel_disconnect (void *cls,
329 const struct GNUNET_CADET_Channel *channel);
316 330
317int 331int
318open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) 332open_room (struct GNUNET_MESSENGER_SrvRoom *room,
333 struct GNUNET_MESSENGER_SrvHandle *handle)
319{ 334{
320 GNUNET_assert((room) && (handle)); 335 GNUNET_assert((room) && (handle));
321 336
@@ -366,7 +381,8 @@ exit_open_room:
366} 381}
367 382
368int 383int
369enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, 384enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room,
385 struct GNUNET_MESSENGER_SrvHandle *handle,
370 const struct GNUNET_PeerIdentity *door) 386 const struct GNUNET_PeerIdentity *door)
371{ 387{
372 GNUNET_assert((room) && (handle) && (door)); 388 GNUNET_assert((room) && (handle) && (door));
@@ -404,8 +420,11 @@ enter_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Sr
404} 420}
405 421
406struct GNUNET_MQ_Envelope* 422struct GNUNET_MQ_Envelope*
407pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, 423pack_room_message (const struct GNUNET_MESSENGER_SrvRoom *room,
408 struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode) 424 const struct GNUNET_MESSENGER_SrvHandle *handle,
425 struct GNUNET_MESSENGER_Message *message,
426 struct GNUNET_HashCode *hash,
427 int mode)
409{ 428{
410 GNUNET_assert((room) && (handle) && (message) && (hash)); 429 GNUNET_assert((room) && (handle) && (message) && (hash));
411 430
@@ -432,7 +451,9 @@ struct GNUNET_MESSENGER_ClosureSendRoom
432}; 451};
433 452
434static int 453static int
435iterate_send_room_message (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 454iterate_send_room_message (void *cls,
455 const struct GNUNET_PeerIdentity *key,
456 void *value)
436{ 457{
437 struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; 458 struct GNUNET_MESSENGER_SrvTunnel *tunnel = value;
438 459
@@ -466,14 +487,18 @@ iterate_send_room_message (void *cls, const struct GNUNET_PeerIdentity *key, voi
466 487
467int 488int
468update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, 489update_room_message (struct GNUNET_MESSENGER_SrvRoom *room,
469 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); 490 struct GNUNET_MESSENGER_Message *message,
491 const struct GNUNET_HashCode *hash);
470 492
471void 493void
472callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, 494callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room,
473 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); 495 struct GNUNET_MESSENGER_SrvHandle *handle,
496 const struct GNUNET_MESSENGER_Message *message,
497 const struct GNUNET_HashCode *hash);
474 498
475int 499int
476send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, 500send_room_message (struct GNUNET_MESSENGER_SrvRoom *room,
501 struct GNUNET_MESSENGER_SrvHandle *handle,
477 struct GNUNET_MESSENGER_Message *message) 502 struct GNUNET_MESSENGER_Message *message)
478{ 503{
479 GNUNET_assert((room) && (handle)); 504 GNUNET_assert((room) && (handle));
@@ -530,8 +555,10 @@ send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE
530} 555}
531 556
532void 557void
533forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, 558forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room,
534 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 559 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
560 struct GNUNET_MESSENGER_Message *message,
561 const struct GNUNET_HashCode *hash)
535{ 562{
536 GNUNET_assert((room) && (tunnel)); 563 GNUNET_assert((room) && (tunnel));
537 564
@@ -554,7 +581,8 @@ forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSE
554} 581}
555 582
556void 583void
557check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel) 584check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room,
585 struct GNUNET_MESSENGER_SrvTunnel *tunnel)
558{ 586{
559 if (!room->peer_message) 587 if (!room->peer_message)
560 return; 588 return;
@@ -592,7 +620,8 @@ resend_peer_message:
592} 620}
593 621
594void 622void
595merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) 623merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room,
624 struct GNUNET_MESSENGER_SrvHandle *handle)
596{ 625{
597 GNUNET_assert(room); 626 GNUNET_assert(room);
598 627
@@ -612,7 +641,8 @@ merge_next:
612} 641}
613 642
614void 643void
615callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash) 644callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room,
645 const struct GNUNET_HashCode *hash)
616{ 646{
617 if (GNUNET_OK != delete_store_message (get_room_message_store(room), hash)) 647 if (GNUNET_OK != delete_store_message (get_room_message_store(room), hash))
618 { 648 {
@@ -622,7 +652,8 @@ callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUN
622} 652}
623 653
624void 654void
625callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash) 655callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room,
656 const struct GNUNET_HashCode *hash)
626{ 657{
627 if (!room->host) 658 if (!room->host)
628 return; 659 return;
@@ -631,8 +662,10 @@ callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_
631} 662}
632 663
633int 664int
634delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, 665delete_room_message (struct GNUNET_MESSENGER_SrvRoom *room,
635 const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay) 666 struct GNUNET_MESSENGER_MemberSession *session,
667 const struct GNUNET_HashCode *hash,
668 const struct GNUNET_TIME_Relative delay)
636{ 669{
637 GNUNET_assert((room) && (session) && (hash)); 670 GNUNET_assert((room) && (session) && (hash));
638 671
@@ -687,7 +720,8 @@ get_room_key (const struct GNUNET_MESSENGER_SrvRoom *room)
687} 720}
688 721
689const struct GNUNET_MESSENGER_SrvTunnel* 722const struct GNUNET_MESSENGER_SrvTunnel*
690get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer) 723get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room,
724 const struct GNUNET_PeerIdentity *peer)
691{ 725{
692 GNUNET_assert((room) && (peer)); 726 GNUNET_assert((room) && (peer));
693 727
@@ -695,9 +729,11 @@ get_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNE
695} 729}
696 730
697static int 731static int
698request_room_message_step (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, 732request_room_message_step (struct GNUNET_MESSENGER_SrvRoom *room,
733 const struct GNUNET_HashCode *hash,
699 const struct GNUNET_MESSENGER_MemberSession *session, 734 const struct GNUNET_MESSENGER_MemberSession *session,
700 GNUNET_MESSENGER_MessageRequestCallback callback, void* cls) 735 GNUNET_MESSENGER_MessageRequestCallback callback,
736 void* cls)
701{ 737{
702 struct GNUNET_MESSENGER_MessageStore *message_store = get_room_message_store(room); 738 struct GNUNET_MESSENGER_MessageStore *message_store = get_room_message_store(room);
703 739
@@ -732,9 +768,11 @@ forward:
732} 768}
733 769
734int 770int
735request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, 771request_room_message (struct GNUNET_MESSENGER_SrvRoom *room,
772 const struct GNUNET_HashCode *hash,
736 const struct GNUNET_MESSENGER_MemberSession *session, 773 const struct GNUNET_MESSENGER_MemberSession *session,
737 GNUNET_MESSENGER_MessageRequestCallback callback, void* cls) 774 GNUNET_MESSENGER_MessageRequestCallback callback,
775 void* cls)
738{ 776{
739 GNUNET_assert((room) && (hash)); 777 GNUNET_assert((room) && (hash));
740 778
@@ -747,7 +785,8 @@ request_room_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET
747} 785}
748 786
749void 787void
750callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls) 788callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room,
789 void *cls)
751{ 790{
752 struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; 791 struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
753 792
@@ -766,8 +805,10 @@ callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls)
766} 805}
767 806
768int 807int
769callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, 808callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room,
770 struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash) 809 void *cls,
810 struct GNUNET_MESSENGER_Message *message,
811 struct GNUNET_HashCode *hash)
771{ 812{
772 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind) 813 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind)
773 { 814 {
@@ -826,8 +867,10 @@ idle_request_room_messages (void *cls)
826} 867}
827 868
828void 869void
829solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_IDENTITY_PublicKey *public_key, 870solve_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room,
830 const struct GNUNET_ShortHashCode *member_id, struct GNUNET_TIME_Absolute timestamp) 871 const struct GNUNET_IDENTITY_PublicKey *public_key,
872 const struct GNUNET_ShortHashCode *member_id,
873 struct GNUNET_TIME_Absolute timestamp)
831{ 874{
832 GNUNET_assert ((room) && (public_key) && (member_id)); 875 GNUNET_assert ((room) && (public_key) && (member_id));
833 876
@@ -945,7 +988,8 @@ finish_handling:
945 988
946int 989int
947update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, 990update_room_message (struct GNUNET_MESSENGER_SrvRoom *room,
948 struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 991 struct GNUNET_MESSENGER_Message *message,
992 const struct GNUNET_HashCode *hash)
949{ 993{
950 GNUNET_assert((room) && (message) && (hash)); 994 GNUNET_assert((room) && (message) && (hash));
951 995
@@ -1008,7 +1052,8 @@ struct GNUNET_MESSENGER_MemberUpdate
1008}; 1052};
1009 1053
1010static int 1054static int
1011iterate_update_member_sessions (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, 1055iterate_update_member_sessions (void *cls,
1056 const struct GNUNET_IDENTITY_PublicKey *public_key,
1012 struct GNUNET_MESSENGER_MemberSession *session) 1057 struct GNUNET_MESSENGER_MemberSession *session)
1013{ 1058{
1014 struct GNUNET_MESSENGER_MemberUpdate *update = cls; 1059 struct GNUNET_MESSENGER_MemberUpdate *update = cls;
@@ -1030,11 +1075,14 @@ iterate_update_member_sessions (void *cls, const struct GNUNET_IDENTITY_PublicKe
1030} 1075}
1031 1076
1032static void 1077static void
1033remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session); 1078remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room,
1079 struct GNUNET_MESSENGER_MemberSession *session);
1034 1080
1035void 1081void
1036callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, 1082callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room,
1037 const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) 1083 struct GNUNET_MESSENGER_SrvHandle *handle,
1084 const struct GNUNET_MESSENGER_Message *message,
1085 const struct GNUNET_HashCode *hash)
1038{ 1086{
1039 struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room); 1087 struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
1040 struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message); 1088 struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
@@ -1113,7 +1161,8 @@ callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUN
1113} 1161}
1114 1162
1115static void 1163static void
1116get_room_data_subdir (struct GNUNET_MESSENGER_SrvRoom *room, char **dir) 1164get_room_data_subdir (struct GNUNET_MESSENGER_SrvRoom *room,
1165 char **dir)
1117{ 1166{
1118 GNUNET_assert((room) && (dir)); 1167 GNUNET_assert((room) && (dir));
1119 1168
@@ -1178,7 +1227,8 @@ save_room (struct GNUNET_MESSENGER_SrvRoom *room)
1178} 1227}
1179 1228
1180static void 1229static void
1181remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session) 1230remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room,
1231 struct GNUNET_MESSENGER_MemberSession *session)
1182{ 1232{
1183 GNUNET_assert ((room) && (session)); 1233 GNUNET_assert ((room) && (session));
1184 1234