diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-07 13:15:42 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-07 13:15:42 +0000 |
commit | d362ce610be73a50342ea0b5245622e048f56d2e (patch) | |
tree | 45454106b2f41bd4fe987869b5f62f00ebe1ed64 /src/mesh | |
parent | 98cb7168209d708a8e19006fbdce388a69afed1a (diff) | |
download | gnunet-d362ce610be73a50342ea0b5245622e048f56d2e.tar.gz gnunet-d362ce610be73a50342ea0b5245622e048f56d2e.zip |
Refactored sending a CREATE PATH message
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 86 |
1 files changed, 52 insertions, 34 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 612cade81..0dd729ec6 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -716,6 +716,20 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id) | |||
716 | 716 | ||
717 | 717 | ||
718 | /** | 718 | /** |
719 | * Function called to notify a client about the socket | ||
720 | * being ready to queue more data. "buf" will be | ||
721 | * NULL and "size" zero if the socket was closed for | ||
722 | * writing in the meantime. | ||
723 | * | ||
724 | * @param cls closure | ||
725 | * @param size number of bytes available in buf | ||
726 | * @param buf where the callee should write the message | ||
727 | * @return number of bytes written to buf | ||
728 | */ | ||
729 | static size_t | ||
730 | send_core_create_path (void *cls, size_t size, void *buf); | ||
731 | |||
732 | /** | ||
719 | * Cancel a core transmission that was already requested and free all resources | 733 | * Cancel a core transmission that was already requested and free all resources |
720 | * associated to the request. | 734 | * associated to the request. |
721 | * | 735 | * |
@@ -826,18 +840,44 @@ peer_info_get_short (const GNUNET_PEER_Id peer) | |||
826 | 840 | ||
827 | 841 | ||
828 | /** | 842 | /** |
829 | * Function called to notify a client about the socket | 843 | * Sends a CREATE PATH message for a path to a peer, properly registrating |
830 | * being ready to queue more data. "buf" will be | 844 | * all used resources. |
831 | * NULL and "size" zero if the socket was closed for | 845 | * |
832 | * writing in the meantime. | 846 | * @param peer PeerInfo of the final peer for whom this path is being created. |
833 | * | 847 | * @param p Path itself. |
834 | * @param cls closure | 848 | * @param t Tunnel for which the path is created. |
835 | * @param size number of bytes available in buf | ||
836 | * @param buf where the callee should write the message | ||
837 | * @return number of bytes written to buf | ||
838 | */ | 849 | */ |
839 | static size_t | 850 | static void |
840 | send_core_create_path (void *cls, size_t size, void *buf); | 851 | send_create_path (struct MeshPeerInfo *peer, |
852 | struct MeshPeerPath *p, | ||
853 | struct MeshTunnel *t) | ||
854 | { | ||
855 | struct GNUNET_PeerIdentity *id; | ||
856 | struct MeshPathInfo *path_info; | ||
857 | struct MeshPeerInfo *neighbor; | ||
858 | |||
859 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); | ||
860 | path_info->path = p; | ||
861 | path_info->peer = peer; | ||
862 | path_info->t = t; | ||
863 | id = path_get_first_hop(t->tree, peer->id); | ||
864 | neighbor = peer_info_get(id); | ||
865 | path_info->pos = peer_info_transmit_position(neighbor); | ||
866 | neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; | ||
867 | neighbor->infos[path_info->pos] = path_info; | ||
868 | neighbor->core_transmit[path_info->pos] = | ||
869 | GNUNET_CORE_notify_transmit_ready ( | ||
870 | core_handle, /* handle */ | ||
871 | 0, /* cork */ | ||
872 | 0, /* priority */ | ||
873 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | ||
874 | id, /* target */ | ||
875 | sizeof (struct GNUNET_MESH_ManipulatePath) | ||
876 | + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ | ||
877 | &send_core_create_path, /* callback */ | ||
878 | path_info); /* cls */ | ||
879 | |||
880 | } | ||
841 | 881 | ||
842 | 882 | ||
843 | /** | 883 | /** |
@@ -854,35 +894,13 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) | |||
854 | { | 894 | { |
855 | struct MeshPeerPath *p; | 895 | struct MeshPeerPath *p; |
856 | struct MeshPathInfo *path_info; | 896 | struct MeshPathInfo *path_info; |
857 | struct MeshPeerInfo *neighbor; | ||
858 | 897 | ||
859 | if (NULL != peer->path_head) | 898 | if (NULL != peer->path_head) |
860 | { | 899 | { |
861 | p = tree_get_path_to_peer(t->tree, peer->id); | 900 | p = tree_get_path_to_peer(t->tree, peer->id); |
862 | if (p->length > 1) | 901 | if (p->length > 1) |
863 | { | 902 | { |
864 | struct GNUNET_PeerIdentity *id; | 903 | send_create_path(peer, p, t); |
865 | |||
866 | path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); | ||
867 | path_info->path = p; | ||
868 | path_info->peer = peer; | ||
869 | path_info->t = t; | ||
870 | id = path_get_first_hop(t->tree, peer->id); | ||
871 | neighbor = peer_info_get(id); | ||
872 | path_info->pos = peer_info_transmit_position(neighbor); | ||
873 | neighbor->types[path_info->pos] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE; | ||
874 | neighbor->infos[path_info->pos] = path_info; | ||
875 | neighbor->core_transmit[path_info->pos] = | ||
876 | GNUNET_CORE_notify_transmit_ready ( | ||
877 | core_handle, /* handle */ | ||
878 | 0, /* cork */ | ||
879 | 0, /* priority */ | ||
880 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | ||
881 | id, /* target */ | ||
882 | sizeof (struct GNUNET_MESH_ManipulatePath) | ||
883 | + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ | ||
884 | &send_core_create_path, /* callback */ | ||
885 | path_info); /* cls */ | ||
886 | } | 904 | } |
887 | else | 905 | else |
888 | { | 906 | { |