diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-10-04 15:08:12 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-10-04 15:08:12 +0000 |
commit | 32c6b50f5c00042069e563ca238080ac4b6f309e (patch) | |
tree | e2dc4226df6446fce55e8e5babcab51ffc0fa310 /src/mesh/gnunet-service-mesh-enc.c | |
parent | ed9c614f78b9a53d1c0a928a47e6f07f8470adfa (diff) | |
download | gnunet-32c6b50f5c00042069e563ca238080ac4b6f309e.tar.gz gnunet-32c6b50f5c00042069e563ca238080ac4b6f309e.zip |
- sync
Diffstat (limited to 'src/mesh/gnunet-service-mesh-enc.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 260 |
1 files changed, 3 insertions, 257 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index 4fef1905e..18b6460b7 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -496,31 +496,6 @@ GNUNET_MESH_DEBUG_TS2S (enum MeshTunnelState s) | |||
496 | } | 496 | } |
497 | 497 | ||
498 | 498 | ||
499 | /** | ||
500 | * Get string description for tunnel state. | ||
501 | * | ||
502 | * @param s Tunnel state. | ||
503 | * | ||
504 | * @return String representation. | ||
505 | */ | ||
506 | static const char * | ||
507 | GNUNET_MESH_DEBUG_CS2S (enum MeshTunnelState s) | ||
508 | { | ||
509 | switch (s) | ||
510 | { | ||
511 | case MESH_CONNECTION_NEW: | ||
512 | return "MESH_CONNECTION_NEW"; | ||
513 | case MESH_CONNECTION_SENT: | ||
514 | return "MESH_CONNECTION_SENT"; | ||
515 | case MESH_CONNECTION_ACK: | ||
516 | return "MESH_CONNECTION_ACK"; | ||
517 | case MESH_CONNECTION_READY: | ||
518 | return "MESH_CONNECTION_READY"; | ||
519 | default: | ||
520 | return "MESH_CONNECTION_STATE_ERROR"; | ||
521 | } | ||
522 | } | ||
523 | |||
524 | 499 | ||
525 | 500 | ||
526 | /******************************************************************************/ | 501 | /******************************************************************************/ |
@@ -913,91 +888,6 @@ send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf) | |||
913 | return sizeof (struct GNUNET_MESH_ConnectionACK); | 888 | return sizeof (struct GNUNET_MESH_ConnectionACK); |
914 | } | 889 | } |
915 | 890 | ||
916 | /** | ||
917 | * Build a PeerPath from the paths returned from the DHT, reversing the paths | ||
918 | * to obtain a local peer -> destination path and interning the peer ids. | ||
919 | * | ||
920 | * @return Newly allocated and created path | ||
921 | */ | ||
922 | static struct MeshPeerPath * | ||
923 | path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | ||
924 | unsigned int get_path_length, | ||
925 | const struct GNUNET_PeerIdentity *put_path, | ||
926 | unsigned int put_path_length) | ||
927 | { | ||
928 | struct MeshPeerPath *p; | ||
929 | GNUNET_PEER_Id id; | ||
930 | int i; | ||
931 | |||
932 | p = path_new (1); | ||
933 | p->peers[0] = myid; | ||
934 | GNUNET_PEER_change_rc (myid, 1); | ||
935 | i = get_path_length; | ||
936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " GET has %d hops.\n", i); | ||
937 | for (i--; i >= 0; i--) | ||
938 | { | ||
939 | id = GNUNET_PEER_intern (&get_path[i]); | ||
940 | if (p->length > 0 && id == p->peers[p->length - 1]) | ||
941 | { | ||
942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Optimizing 1 hop out.\n"); | ||
943 | GNUNET_PEER_change_rc (id, -1); | ||
944 | } | ||
945 | else | ||
946 | { | ||
947 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Adding from GET: %s.\n", | ||
948 | GNUNET_i2s (&get_path[i])); | ||
949 | p->length++; | ||
950 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
951 | p->peers[p->length - 1] = id; | ||
952 | } | ||
953 | } | ||
954 | i = put_path_length; | ||
955 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " PUT has %d hops.\n", i); | ||
956 | for (i--; i >= 0; i--) | ||
957 | { | ||
958 | id = GNUNET_PEER_intern (&put_path[i]); | ||
959 | if (id == myid) | ||
960 | { | ||
961 | /* PUT path went through us, so discard the path up until now and start | ||
962 | * from here to get a much shorter (and loop-free) path. | ||
963 | */ | ||
964 | path_destroy (p); | ||
965 | p = path_new (0); | ||
966 | } | ||
967 | if (p->length > 0 && id == p->peers[p->length - 1]) | ||
968 | { | ||
969 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Optimizing 1 hop out.\n"); | ||
970 | GNUNET_PEER_change_rc (id, -1); | ||
971 | } | ||
972 | else | ||
973 | { | ||
974 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Adding from PUT: %s.\n", | ||
975 | GNUNET_i2s (&put_path[i])); | ||
976 | p->length++; | ||
977 | p->peers = GNUNET_realloc (p->peers, sizeof (GNUNET_PEER_Id) * p->length); | ||
978 | p->peers[p->length - 1] = id; | ||
979 | } | ||
980 | } | ||
981 | #if MESH_DEBUG | ||
982 | if (get_path_length > 0) | ||
983 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (first of GET: %s)\n", | ||
984 | GNUNET_i2s (&get_path[0])); | ||
985 | if (put_path_length > 0) | ||
986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (first of PUT: %s)\n", | ||
987 | GNUNET_i2s (&put_path[0])); | ||
988 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " In total: %d hops\n", | ||
989 | p->length); | ||
990 | for (i = 0; i < p->length; i++) | ||
991 | { | ||
992 | struct GNUNET_PeerIdentity peer_id; | ||
993 | |||
994 | GNUNET_PEER_resolve (p->peers[i], &peer_id); | ||
995 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n", p->peers[i], | ||
996 | GNUNET_i2s (&peer_id)); | ||
997 | } | ||
998 | #endif | ||
999 | return p; | ||
1000 | } | ||
1001 | 891 | ||
1002 | 892 | ||
1003 | /** | 893 | /** |
@@ -1907,39 +1797,15 @@ handle_decrypted (struct MeshTunnel2 *t, | |||
1907 | * Called on each result obtained for the DHT search. | 1797 | * Called on each result obtained for the DHT search. |
1908 | * | 1798 | * |
1909 | * @param cls closure | 1799 | * @param cls closure |
1910 | * @param exp when will this value expire | 1800 | * @param path |
1911 | * @param key key of the result | ||
1912 | * @param get_path path of the get request | ||
1913 | * @param get_path_length lenght of get_path | ||
1914 | * @param put_path path of the put request | ||
1915 | * @param put_path_length length of the put_path | ||
1916 | * @param type type of the result | ||
1917 | * @param size number of bytes in data | ||
1918 | * @param data pointer to the result data | ||
1919 | */ | 1801 | */ |
1920 | static void | 1802 | static void |
1921 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | 1803 | search_handler (void *cls, struct MeshPeerPath *path) |
1922 | const struct GNUNET_HashCode * key, | ||
1923 | const struct GNUNET_PeerIdentity *get_path, | ||
1924 | unsigned int get_path_length, | ||
1925 | const struct GNUNET_PeerIdentity *put_path, | ||
1926 | unsigned int put_path_length, enum GNUNET_BLOCK_Type type, | ||
1927 | size_t size, const void *data) | ||
1928 | { | 1804 | { |
1929 | struct MeshPeer *peer = cls; | ||
1930 | struct MeshPeerPath *p; | ||
1931 | struct MeshConnection *c; | 1805 | struct MeshConnection *c; |
1932 | struct GNUNET_PeerIdentity pi; | ||
1933 | unsigned int connection_count; | 1806 | unsigned int connection_count; |
1934 | 1807 | ||
1935 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got results from DHT!\n"); | 1808 | path_add_to_peers (path, GNUNET_NO); |
1936 | GNUNET_PEER_resolve (peer->id, &pi); | ||
1937 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n", GNUNET_i2s (&pi)); | ||
1938 | |||
1939 | p = path_build_from_dht (get_path, get_path_length, | ||
1940 | put_path, put_path_length); | ||
1941 | path_add_to_peers (p, GNUNET_NO); | ||
1942 | path_destroy (p); | ||
1943 | 1809 | ||
1944 | /* Count connections */ | 1810 | /* Count connections */ |
1945 | connection_count = GMC_count (peer->tunnel->connection_head); | 1811 | connection_count = GMC_count (peer->tunnel->connection_head); |
@@ -1957,126 +1823,6 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
1957 | } | 1823 | } |
1958 | 1824 | ||
1959 | 1825 | ||
1960 | |||
1961 | /** | ||
1962 | * Method called whenever a given peer connects. | ||
1963 | * | ||
1964 | * @param cls closure | ||
1965 | * @param peer peer identity this notification is about | ||
1966 | */ | ||
1967 | static void | ||
1968 | core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
1969 | { | ||
1970 | struct MeshPeer *pi; | ||
1971 | struct MeshPeerPath *path; | ||
1972 | |||
1973 | DEBUG_CONN ("Peer connected\n"); | ||
1974 | DEBUG_CONN (" %s\n", GNUNET_i2s (&my_full_id)); | ||
1975 | pi = peer_get (peer); | ||
1976 | if (myid == pi->id) | ||
1977 | { | ||
1978 | DEBUG_CONN (" (self)\n"); | ||
1979 | path = path_new (1); | ||
1980 | } | ||
1981 | else | ||
1982 | { | ||
1983 | DEBUG_CONN (" %s\n", GNUNET_i2s (peer)); | ||
1984 | path = path_new (2); | ||
1985 | path->peers[1] = pi->id; | ||
1986 | GNUNET_PEER_change_rc (pi->id, 1); | ||
1987 | GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO); | ||
1988 | } | ||
1989 | path->peers[0] = myid; | ||
1990 | GNUNET_PEER_change_rc (myid, 1); | ||
1991 | peer_add_path (pi, path, GNUNET_YES); | ||
1992 | |||
1993 | pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); | ||
1994 | return; | ||
1995 | } | ||
1996 | |||
1997 | |||
1998 | /** | ||
1999 | * Method called whenever a peer disconnects. | ||
2000 | * | ||
2001 | * @param cls closure | ||
2002 | * @param peer peer identity this notification is about | ||
2003 | */ | ||
2004 | static void | ||
2005 | core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
2006 | { | ||
2007 | struct MeshPeer *pi; | ||
2008 | |||
2009 | DEBUG_CONN ("Peer disconnected\n"); | ||
2010 | pi = GNUNET_CONTAINER_multipeermap_get (peers, peer); | ||
2011 | if (NULL == pi) | ||
2012 | { | ||
2013 | GNUNET_break (0); | ||
2014 | return; | ||
2015 | } | ||
2016 | |||
2017 | GNUNET_CONTAINER_multihashmap_iterate (pi->connections, | ||
2018 | GMC_notify_broken, | ||
2019 | pi); | ||
2020 | GNUNET_CONTAINER_multihashmap_destroy (pi->connections); | ||
2021 | pi->connections = NULL; | ||
2022 | if (NULL != pi->core_transmit) | ||
2023 | { | ||
2024 | GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit); | ||
2025 | pi->core_transmit = NULL; | ||
2026 | } | ||
2027 | if (myid == pi->id) | ||
2028 | { | ||
2029 | DEBUG_CONN (" (self)\n"); | ||
2030 | } | ||
2031 | GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO); | ||
2032 | |||
2033 | return; | ||
2034 | } | ||
2035 | |||
2036 | |||
2037 | |||
2038 | /** | ||
2039 | * To be called on core init/fail. | ||
2040 | * | ||
2041 | * @param cls Closure (config) | ||
2042 | * @param identity the public identity of this peer | ||
2043 | */ | ||
2044 | static void | ||
2045 | core_init (void *cls, | ||
2046 | const struct GNUNET_PeerIdentity *identity) | ||
2047 | { | ||
2048 | const struct GNUNET_CONFIGURATION_Handle *c = cls; | ||
2049 | static int i = 0; | ||
2050 | |||
2051 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n"); | ||
2052 | if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id))) | ||
2053 | { | ||
2054 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n")); | ||
2055 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2056 | " core id %s\n", | ||
2057 | GNUNET_i2s (identity)); | ||
2058 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2059 | " my id %s\n", | ||
2060 | GNUNET_i2s (&my_full_id)); | ||
2061 | GNUNET_CORE_disconnect (core_handle); | ||
2062 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | ||
2063 | NULL, /* Closure passed to MESH functions */ | ||
2064 | &core_init, /* Call core_init once connected */ | ||
2065 | &core_connect, /* Handle connects */ | ||
2066 | &core_disconnect, /* remove peers on disconnects */ | ||
2067 | NULL, /* Don't notify about all incoming messages */ | ||
2068 | GNUNET_NO, /* For header only in notification */ | ||
2069 | NULL, /* Don't notify about all outbound messages */ | ||
2070 | GNUNET_NO, /* For header-only out notification */ | ||
2071 | core_handlers); /* Register these handlers */ | ||
2072 | if (10 < i++) | ||
2073 | GNUNET_abort(); | ||
2074 | } | ||
2075 | server_init (); | ||
2076 | return; | ||
2077 | } | ||
2078 | |||
2079 | |||
2080 | /******************************************************************************/ | 1826 | /******************************************************************************/ |
2081 | /************************ MAIN FUNCTIONS ****************************/ | 1827 | /************************ MAIN FUNCTIONS ****************************/ |
2082 | /******************************************************************************/ | 1828 | /******************************************************************************/ |