diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_peer.c | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index 8258881d0..55800b88c 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c | |||
@@ -31,6 +31,7 @@ | |||
31 | * to take a break if we have some connections and have searched a lot (?)) | 31 | * to take a break if we have some connections and have searched a lot (?)) |
32 | */ | 32 | */ |
33 | #include "platform.h" | 33 | #include "platform.h" |
34 | #include "gnunet_time_lib.h" | ||
34 | #include "gnunet_util_lib.h" | 35 | #include "gnunet_util_lib.h" |
35 | #include "gnunet_hello_lib.h" | 36 | #include "gnunet_hello_lib.h" |
36 | #include "gnunet_signatures.h" | 37 | #include "gnunet_signatures.h" |
@@ -38,10 +39,10 @@ | |||
38 | #include "gnunet_ats_service.h" | 39 | #include "gnunet_ats_service.h" |
39 | #include "gnunet_core_service.h" | 40 | #include "gnunet_core_service.h" |
40 | #include "gnunet_statistics_service.h" | 41 | #include "gnunet_statistics_service.h" |
41 | #include "cadet_protocol.h" | 42 | #include "gnunet-service-cadet_peer.h" |
43 | #include "gnunet-service-cadet.h" | ||
42 | #include "gnunet-service-cadet_connection.h" | 44 | #include "gnunet-service-cadet_connection.h" |
43 | #include "gnunet-service-cadet_dht.h" | 45 | #include "gnunet-service-cadet_dht.h" |
44 | #include "gnunet-service-cadet_peer.h" | ||
45 | #include "gnunet-service-cadet_paths.h" | 46 | #include "gnunet-service-cadet_paths.h" |
46 | #include "gnunet-service-cadet_tunnels.h" | 47 | #include "gnunet-service-cadet_tunnels.h" |
47 | 48 | ||
@@ -66,7 +67,6 @@ | |||
66 | */ | 67 | */ |
67 | #define MAX_OOO_QUEUE_SIZE 100 | 68 | #define MAX_OOO_QUEUE_SIZE 100 |
68 | 69 | ||
69 | |||
70 | /** | 70 | /** |
71 | * Data structure used to track whom we have to notify about changes | 71 | * Data structure used to track whom we have to notify about changes |
72 | * to our message queue. | 72 | * to our message queue. |
@@ -118,7 +118,7 @@ struct CadetPeer | |||
118 | /** | 118 | /** |
119 | * Last time we heard from this peer (currently not used!) | 119 | * Last time we heard from this peer (currently not used!) |
120 | */ | 120 | */ |
121 | struct GNUNET_TIME_Absolute last_contactXXX; | 121 | struct GNUNET_TIME_Absolute last_connection_create; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Array of DLLs of paths traversing the peer, organized by the | 124 | * Array of DLLs of paths traversing the peer, organized by the |
@@ -1552,5 +1552,56 @@ GCP_send_ooo (struct CadetPeer *cp, | |||
1552 | env); | 1552 | env); |
1553 | } | 1553 | } |
1554 | 1554 | ||
1555 | /** | ||
1556 | * Checking if a monotime value is newer than the last monotime value received from a peer. If the time value is newer it will be stored at the peer. | ||
1557 | * | ||
1558 | * @param peer The peer we received a new time value from. | ||
1559 | * @param monotime Time value we check against the last time value we received from a peer. | ||
1560 | * @return GNUNET_YES if monotime is newer than the last received time value, GNUNET_NO if monotime is not newer. | ||
1561 | */ | ||
1562 | int | ||
1563 | GCP_check_and_update_monotime (struct CadetPeer *peer, | ||
1564 | struct GNUNET_TIME_AbsoluteNBO monotime) | ||
1565 | { | ||
1566 | |||
1567 | struct GNUNET_TIME_Absolute mt = GNUNET_TIME_absolute_ntoh (monotime); | ||
1568 | |||
1569 | if (mt.abs_value_us > *(&peer->last_connection_create.abs_value_us)) | ||
1570 | { | ||
1571 | peer->last_connection_create = mt; | ||
1572 | return GNUNET_YES; | ||
1573 | } | ||
1574 | return GNUNET_NO; | ||
1575 | } | ||
1576 | |||
1577 | /** | ||
1578 | * Checking the signature for a monotime of a GNUNET_CADET_ConnectionCreateMessage. | ||
1579 | * | ||
1580 | * @param peer The peer that signed the monotime value. | ||
1581 | * @param msg The GNUNET_CADET_ConnectionCreateMessage with the monotime value. | ||
1582 | * @return GNUNET_OK if the signature is good, GNUNET_SYSERR if not. | ||
1583 | */ | ||
1584 | int | ||
1585 | GCP_check_monotime_sig (struct CadetPeer *peer, | ||
1586 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | ||
1587 | { | ||
1588 | struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl ( | ||
1589 | GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR), | ||
1590 | .purpose.size = htonl (sizeof(cp)), | ||
1591 | .monotonic_time = msg->monotime}; | ||
1592 | |||
1593 | if (GNUNET_OK != | ||
1594 | GNUNET_CRYPTO_eddsa_verify ( | ||
1595 | GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR, | ||
1596 | &cp, | ||
1597 | &msg->monotime_sig, | ||
1598 | &peer->pid.public_key)) | ||
1599 | { | ||
1600 | GNUNET_break_op (0); | ||
1601 | return GNUNET_SYSERR; | ||
1602 | } | ||
1603 | return GNUNET_OK; | ||
1604 | } | ||
1605 | |||
1555 | 1606 | ||
1556 | /* end of gnunet-service-cadet-new_peer.c */ | 1607 | /* end of gnunet-service-cadet-new_peer.c */ |