aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-14 20:47:31 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-14 20:47:31 +0000
commit4b5e3086a0813daa6709ee7c0087ece6222bb022 (patch)
tree8ad7d9ad685542ba96f897a992f8c1fa15e0a2e0 /src
parent7abd5a10ab1121bade799ac3a9b4c770badbd1db (diff)
downloadgnunet-4b5e3086a0813daa6709ee7c0087ece6222bb022.tar.gz
gnunet-4b5e3086a0813daa6709ee7c0087ece6222bb022.zip
process keepalive, simplify PONGs
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_signatures.h2
-rw-r--r--src/transport/gnunet-service-transport-new.c3
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c31
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h10
-rw-r--r--src/transport/gnunet-service-transport_validation.c30
-rw-r--r--src/transport/plugin_transport_udp.c3
6 files changed, 53 insertions, 26 deletions
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 9b6a3d6b6..c54df3e85 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -49,7 +49,7 @@ extern "C"
49 49
50/** 50/**
51 * Signature for confirming that this peer connected to another peer 51 * Signature for confirming that this peer connected to another peer
52 * using a particular address. 52 * using a particular address (LEGACY)
53 */ 53 */
54#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING 2 54#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING 2
55 55
diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c
index 6bc3c2541..3cc1191fd 100644
--- a/src/transport/gnunet-service-transport-new.c
+++ b/src/transport/gnunet-service-transport-new.c
@@ -226,6 +226,9 @@ plugin_env_receive_callback (void *cls,
226 a fake disconnect message... */ 226 a fake disconnect message... */
227 GST_neighbours_force_disconnect (peer); 227 GST_neighbours_force_disconnect (peer);
228 break; 228 break;
229 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
230 GST_neighbours_keepalive (peer);
231 break;
229 default: 232 default:
230 /* should be payload */ 233 /* should be payload */
231 do_forward = GNUNET_SYSERR; 234 do_forward = GNUNET_SYSERR;
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 211595b51..604112560 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -815,10 +815,6 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
815 n->quota_violation_count--; 815 n->quota_violation_count--;
816 } 816 }
817 } 817 }
818 GNUNET_SCHEDULER_cancel (n->timeout_task);
819 n->timeout_task =
820 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
821 &neighbour_timeout_task, n);
822 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) 818 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
823 { 819 {
824 GNUNET_STATISTICS_update (GST_stats, 820 GNUNET_STATISTICS_update (GST_stats,
@@ -849,6 +845,33 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
849 845
850 846
851/** 847/**
848 * Keep the connection to the given neighbour alive longer,
849 * we received a KEEPALIVE (or equivalent).
850 *
851 * @param neighbour neighbour to keep alive
852 */
853void
854GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
855{
856 struct NeighbourMapEntry *n;
857
858 n = lookup_neighbour (neighbour);
859 if (NULL == n)
860 {
861 GNUNET_STATISTICS_update (GST_stats,
862 gettext_noop ("# KEEPALIVE messages discarded (not connected)"),
863 1,
864 GNUNET_NO);
865 return;
866 }
867 GNUNET_SCHEDULER_cancel (n->timeout_task);
868 n->timeout_task =
869 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
870 &neighbour_timeout_task, n);
871}
872
873
874/**
852 * Change the incoming quota for the given peer. 875 * Change the incoming quota for the given peer.
853 * 876 *
854 * @param neighbour identity of peer to change qutoa for 877 * @param neighbour identity of peer to change qutoa for
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 14f223811..a99cd1e96 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -122,6 +122,16 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
122 122
123 123
124/** 124/**
125 * Keep the connection to the given neighbour alive longer,
126 * we received a KEEPALIVE (or equivalent).
127 *
128 * @param neighbour neighbour to keep alive
129 */
130void
131GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
132
133
134/**
125 * Change the incoming quota for the given peer. 135 * Change the incoming quota for the given peer.
126 * 136 *
127 * @param neighbour identity of peer to change qutoa for 137 * @param neighbour identity of peer to change qutoa for
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index e07ff7546..86c51c729 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -132,11 +132,8 @@ struct TransportPongMessage
132 struct GNUNET_CRYPTO_RsaSignature signature; 132 struct GNUNET_CRYPTO_RsaSignature signature;
133 133
134 /** 134 /**
135 * What are we signing and why? Two possible reason codes can be here:
136 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a 135 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a
137 * plausible address for this peer (pid is set to identity of signer); or 136 * plausible address for the signing peer.
138 * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING to confirm that this is
139 * an address we used to connect to the peer with the given pid.
140 */ 137 */
141 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; 138 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
142 139
@@ -146,13 +143,6 @@ struct TransportPongMessage
146 struct GNUNET_TIME_AbsoluteNBO expiration; 143 struct GNUNET_TIME_AbsoluteNBO expiration;
147 144
148 /** 145 /**
149 * Either the identity of the peer Who signed this message, or the
150 * identity of the peer that we're connected to using the given
151 * address (depending on purpose.type).
152 */
153 struct GNUNET_PeerIdentity pid;
154
155 /**
156 * Size of address appended to this message (part of what is 146 * Size of address appended to this message (part of what is
157 * being signed, hence not redundant). 147 * being signed, hence not redundant).
158 */ 148 */
@@ -683,11 +673,10 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
683 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 673 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
684 sizeof (uint32_t) + 674 sizeof (uint32_t) +
685 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 675 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
686 sizeof (struct GNUNET_PeerIdentity) + alen + slen); 676 alen + slen);
687 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); 677 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
688 pong->challenge = ping->challenge; 678 pong->challenge = ping->challenge;
689 pong->addrlen = htonl(alen + slen); 679 pong->addrlen = htonl(alen + slen);
690 pong->pid = GST_my_identity;
691 memcpy (&pong[1], addr, slen); 680 memcpy (&pong[1], addr, slen);
692 memcpy (&((char*)&pong[1])[slen], addrend, alen); 681 memcpy (&((char*)&pong[1])[slen], addrend, alen);
693 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) 682 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4)
@@ -993,13 +982,6 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
993 1, 982 1,
994 GNUNET_NO); 983 GNUNET_NO);
995 pong = (const struct TransportPongMessage *) hdr; 984 pong = (const struct TransportPongMessage *) hdr;
996 if (0 != memcmp (&pong->pid,
997 sender,
998 sizeof (struct GNUNET_PeerIdentity)))
999 {
1000 GNUNET_break_op (0);
1001 return;
1002 }
1003 addr = (const char*) &pong[1]; 985 addr = (const char*) &pong[1];
1004 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); 986 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
1005 addrend = memchr (addr, '\0', alen); 987 addrend = memchr (addr, '\0', alen);
@@ -1025,6 +1007,14 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1025 return; 1007 return;
1026 } 1008 }
1027 /* now check that PONG is well-formed */ 1009 /* now check that PONG is well-formed */
1010 if (0 != memcmp (&ve->pid,
1011 sender,
1012 sizeof (struct GNUNET_PeerIdentity)))
1013 {
1014 GNUNET_break_op (0);
1015 return;
1016 }
1017
1028 if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0) 1018 if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
1029 { 1019 {
1030 GNUNET_STATISTICS_update (GST_stats, 1020 GNUNET_STATISTICS_update (GST_stats,
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index e58d4312e..7d8c1520f 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -129,7 +129,8 @@ struct Plugin;
129 129
130 130
131/** 131/**
132 * Session with another peer. 132 * Session with another peer. FIXME: why not make this into
133 * a regular 'struct Session' and pass it around!?
133 */ 134 */
134struct PeerSession 135struct PeerSession
135{ 136{