diff options
Diffstat (limited to 'src/dht/dht_api.c')
-rw-r--r-- | src/dht/dht_api.c | 95 |
1 files changed, 85 insertions, 10 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 8aa7320f5..be699e65e 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -93,6 +93,28 @@ struct PendingMessage | |||
93 | 93 | ||
94 | }; | 94 | }; |
95 | 95 | ||
96 | #if ENABLE_MALICIOUS | ||
97 | /** | ||
98 | * Handle to act malicious message | ||
99 | */ | ||
100 | struct GNUNET_DHT_ActMaliciousHandle | ||
101 | { | ||
102 | /** | ||
103 | * Continuation to call when done. | ||
104 | */ | ||
105 | GNUNET_DHT_ActMaliciousContinuation cont; | ||
106 | |||
107 | /** | ||
108 | * Main handle to this DHT api | ||
109 | */ | ||
110 | struct GNUNET_DHT_Handle *dht_handle; | ||
111 | |||
112 | /** | ||
113 | * Closure for 'cont'. | ||
114 | */ | ||
115 | void *cont_cls; | ||
116 | }; | ||
117 | #endif | ||
96 | 118 | ||
97 | /** | 119 | /** |
98 | * Handle to a PUT request. | 120 | * Handle to a PUT request. |
@@ -142,8 +164,6 @@ struct GNUNET_DHT_PutHandle | |||
142 | 164 | ||
143 | }; | 165 | }; |
144 | 166 | ||
145 | |||
146 | |||
147 | /** | 167 | /** |
148 | * Handle to a GET request | 168 | * Handle to a GET request |
149 | */ | 169 | */ |
@@ -342,6 +362,13 @@ struct GNUNET_DHT_Handle | |||
342 | * Did we start our receive loop yet? | 362 | * Did we start our receive loop yet? |
343 | */ | 363 | */ |
344 | int in_receive; | 364 | int in_receive; |
365 | |||
366 | #if ENABLE_MALICIOUS | ||
367 | /** | ||
368 | * Handle of act malicious request. | ||
369 | */ | ||
370 | struct GNUNET_DHT_ActMaliciousHandle *mh; | ||
371 | #endif | ||
345 | }; | 372 | }; |
346 | 373 | ||
347 | 374 | ||
@@ -857,6 +884,35 @@ process_monitor_put_message (struct GNUNET_DHT_Handle *handle, | |||
857 | } | 884 | } |
858 | 885 | ||
859 | 886 | ||
887 | #if ENABLE_MALICIOUS | ||
888 | /** | ||
889 | * Process a act malicious confirmation from service. | ||
890 | * @param handle The DHT handle. | ||
891 | * @param msg confirmation message from the service. | ||
892 | * @return #GNUNET_OK if everything went fine, | ||
893 | * #GNUNET_SYSERR if the message is malformed. | ||
894 | */ | ||
895 | static int | ||
896 | process_act_malicious_confirmation_message (struct GNUNET_DHT_Handle *handle, | ||
897 | const struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *msg) | ||
898 | { | ||
899 | struct GNUNET_DHT_ActMaliciousHandle *mh; | ||
900 | GNUNET_DHT_PutContinuation cont; | ||
901 | void *cont_cls; | ||
902 | |||
903 | mh = handle->mh; | ||
904 | if (NULL == mh) | ||
905 | return GNUNET_OK; | ||
906 | cont = mh->cont; | ||
907 | cont_cls = mh->cont_cls; | ||
908 | if (NULL != cont) | ||
909 | cont (cont_cls, GNUNET_OK); | ||
910 | |||
911 | return GNUNET_OK; | ||
912 | } | ||
913 | #endif | ||
914 | |||
915 | |||
860 | /** | 916 | /** |
861 | * Process a put confirmation message from the service. | 917 | * Process a put confirmation message from the service. |
862 | * | 918 | * |
@@ -972,6 +1028,17 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
972 | ret = process_put_confirmation_message (handle, | 1028 | ret = process_put_confirmation_message (handle, |
973 | (const struct GNUNET_DHT_ClientPutConfirmationMessage*) msg); | 1029 | (const struct GNUNET_DHT_ClientPutConfirmationMessage*) msg); |
974 | break; | 1030 | break; |
1031 | #if ENABLE_MALICIOUS | ||
1032 | case GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK: | ||
1033 | if(msize != sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage)) | ||
1034 | { | ||
1035 | GNUNET_break (0); | ||
1036 | break; | ||
1037 | } | ||
1038 | ret = process_act_malicious_confirmation_message (handle, | ||
1039 | (const struct GNUNET_DHT_ClientActMaliciousConfirmationMessage*) msg); | ||
1040 | break; | ||
1041 | #endif | ||
975 | default: | 1042 | default: |
976 | GNUNET_break(0); | 1043 | GNUNET_break(0); |
977 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1044 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -1151,7 +1218,6 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, | |||
1151 | struct PendingMessage *pending; | 1218 | struct PendingMessage *pending; |
1152 | struct GNUNET_DHT_PutHandle *ph; | 1219 | struct GNUNET_DHT_PutHandle *ph; |
1153 | 1220 | ||
1154 | |||
1155 | msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size; | 1221 | msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size; |
1156 | if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 1222 | if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
1157 | (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) | 1223 | (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) |
@@ -1499,16 +1565,21 @@ GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle) | |||
1499 | 1565 | ||
1500 | #if ENABLE_MALICIOUS | 1566 | #if ENABLE_MALICIOUS |
1501 | /** | 1567 | /** |
1502 | * Turn the DHT service to act malicious depending on @a flag | 1568 | * Turn the DHT service to act malicious. |
1503 | * | 1569 | * |
1504 | * @param handle the DHT handle | 1570 | * @param handle the DHT handle |
1505 | * @param action 1 to make the service malicious; 0 to make it benign | 1571 | * @param action 1 to make the service malicious; 0 to make it benign |
1506 | FIXME: perhaps make this an enum of known malicious behaviors? | 1572 | * @param cont continuation to call when done (transmitting request to service) |
1573 | * @param cont_cls closure for @a cont | ||
1507 | */ | 1574 | */ |
1508 | void | 1575 | struct GNUNET_DHT_ActMaliciousHandle * |
1509 | GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action) | 1576 | GNUNET_DHT_act_malicious (struct GNUNET_DHT_Handle *handle, |
1577 | unsigned int action, | ||
1578 | GNUNET_DHT_PutContinuation cont, | ||
1579 | void *cont_cls) | ||
1510 | { | 1580 | { |
1511 | struct GNUNET_DHT_ActMaliciousMessage *amm; | 1581 | struct GNUNET_DHT_ActMaliciousMessage *amm; |
1582 | struct GNUNET_DHT_ActMaliciousHandle *mh; | ||
1512 | struct PendingMessage *pending; | 1583 | struct PendingMessage *pending; |
1513 | size_t msize; | 1584 | size_t msize; |
1514 | 1585 | ||
@@ -1516,9 +1587,12 @@ GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action) | |||
1516 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1587 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1517 | { | 1588 | { |
1518 | GNUNET_break(0); | 1589 | GNUNET_break(0); |
1519 | return; | 1590 | return NULL; |
1520 | } | 1591 | } |
1521 | 1592 | mh = GNUNET_new (struct GNUNET_DHT_ActMaliciousHandle); | |
1593 | mh->dht_handle = handle; | ||
1594 | mh->cont = cont; | ||
1595 | mh->cont_cls = cont_cls; | ||
1522 | pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | 1596 | pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); |
1523 | amm = (struct GNUNET_DHT_ActMaliciousMessage *)&pending[1]; | 1597 | amm = (struct GNUNET_DHT_ActMaliciousMessage *)&pending[1]; |
1524 | pending->msg = &amm->header; | 1598 | pending->msg = &amm->header; |
@@ -1527,11 +1601,12 @@ GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action) | |||
1527 | amm->header.size = htons (msize); | 1601 | amm->header.size = htons (msize); |
1528 | amm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS); | 1602 | amm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS); |
1529 | amm->action = action; | 1603 | amm->action = action; |
1530 | 1604 | handle->mh = mh; | |
1531 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, | 1605 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, |
1532 | pending); | 1606 | pending); |
1533 | pending->in_pending_queue = GNUNET_YES; | 1607 | pending->in_pending_queue = GNUNET_YES; |
1534 | process_pending_messages (handle); | 1608 | process_pending_messages (handle); |
1609 | return mh; | ||
1535 | } | 1610 | } |
1536 | #endif | 1611 | #endif |
1537 | 1612 | ||