diff options
Diffstat (limited to 'src/gnunet/service/dht/blocks/handlers.go')
-rw-r--r-- | src/gnunet/service/dht/blocks/handlers.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/gnunet/service/dht/blocks/handlers.go b/src/gnunet/service/dht/blocks/handlers.go new file mode 100644 index 0000000..9df3867 --- /dev/null +++ b/src/gnunet/service/dht/blocks/handlers.go | |||
@@ -0,0 +1,80 @@ | |||
1 | // This file is part of gnunet-go, a GNUnet-implementation in Golang. | ||
2 | // Copyright (C) 2019-2022 Bernd Fix >Y< | ||
3 | // | ||
4 | // gnunet-go is free software: you can redistribute it and/or modify it | ||
5 | // under the terms of the GNU Affero General Public License as published | ||
6 | // by the Free Software Foundation, either version 3 of the License, | ||
7 | // or (at your option) any later version. | ||
8 | // | ||
9 | // gnunet-go is distributed in the hope that it will be useful, but | ||
10 | // WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | // Affero General Public License for more details. | ||
13 | // | ||
14 | // You should have received a copy of the GNU Affero General Public License | ||
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | // | ||
17 | // SPDX-License-Identifier: AGPL3.0-or-later | ||
18 | |||
19 | package blocks | ||
20 | |||
21 | import ( | ||
22 | "gnunet/crypto" | ||
23 | "gnunet/enums" | ||
24 | ) | ||
25 | |||
26 | // BlockHandler interface defines methods specific to block types. | ||
27 | type BlockHandler interface { | ||
28 | |||
29 | // Parse a block instance from binary data | ||
30 | ParseBlock(buf []byte) (Block, error) | ||
31 | |||
32 | // ValidateBlockQuery is used to evaluate the request for a block as part of | ||
33 | // DHT-P2P-GET processing. Here, the block payload is unknown, but if possible | ||
34 | // the XQuery and Key SHOULD be verified. | ||
35 | ValidateBlockQuery(key *crypto.HashCode, xquery []byte) bool | ||
36 | |||
37 | // ValidateBlockKey returns true if the block key is the same as the | ||
38 | // query key used to access the block. | ||
39 | ValidateBlockKey(b Block, key *crypto.HashCode) bool | ||
40 | |||
41 | // ValidateBlockStoreRequest is used to evaluate a block payload as part of | ||
42 | // PutMessage and ResultMessage processing. | ||
43 | ValidateBlockStoreRequest(b Block) bool | ||
44 | |||
45 | // SetupResultFilter is used to setup an empty result filter. The arguments | ||
46 | // are the set of results that must be filtered at the initiator, and a | ||
47 | // MUTATOR value which MAY be used to deterministically re-randomize | ||
48 | // probabilistic data structures. | ||
49 | SetupResultFilter(filterSize int, mutator uint32) ResultFilter | ||
50 | |||
51 | // ParseResultFilter from binary data | ||
52 | ParseResultFilter(data []byte) ResultFilter | ||
53 | |||
54 | // FilterResult is used to filter results against specific queries. This | ||
55 | // function does not check the validity of the block itself or that it | ||
56 | // matches the given key, as this must have been checked earlier. Thus, | ||
57 | // locally stored blocks from previously observed ResultMessages and | ||
58 | // PutMessages use this function to perform filtering based on the request | ||
59 | // parameters of a particular GET operation. Possible values for the | ||
60 | // FilterEvaluationResult are defined above. If the main evaluation result | ||
61 | // is RF_MORE, the function also returns and updated result filter where | ||
62 | // the block is added to the set of filtered replies. An implementation is | ||
63 | // not expected to actually differentiate between the RF_DUPLICATE and | ||
64 | // RF_IRRELEVANT return values: in both cases the block is ignored for | ||
65 | // this query. | ||
66 | FilterResult(b Block, key *crypto.HashCode, rf ResultFilter, xQuery []byte) int | ||
67 | } | ||
68 | |||
69 | // BlockHandlers is a map of block query validation implementations | ||
70 | // for supported block types. | ||
71 | var BlockHandlers map[enums.BlockType]BlockHandler | ||
72 | |||
73 | // initializer function | ||
74 | func init() { | ||
75 | // create map instance | ||
76 | BlockHandlers = make(map[enums.BlockType]BlockHandler) | ||
77 | |||
78 | // add validation functions | ||
79 | BlockHandlers[enums.BLOCK_TYPE_DHT_URL_HELLO] = new(HelloBlockHandler) | ||
80 | } | ||