diff options
Diffstat (limited to 'src/gnunet/service/zonemaster/module.go')
-rw-r--r-- | src/gnunet/service/zonemaster/module.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/gnunet/service/zonemaster/module.go b/src/gnunet/service/zonemaster/module.go new file mode 100644 index 0000000..8f7b000 --- /dev/null +++ b/src/gnunet/service/zonemaster/module.go | |||
@@ -0,0 +1,84 @@ | |||
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 zonemaster | ||
20 | |||
21 | import ( | ||
22 | "context" | ||
23 | |||
24 | "gnunet/core" | ||
25 | "gnunet/enums" | ||
26 | "gnunet/service" | ||
27 | "gnunet/service/dht/blocks" | ||
28 | ) | ||
29 | |||
30 | //====================================================================== | ||
31 | // "GNUnet Zonemaster" implementation | ||
32 | //====================================================================== | ||
33 | |||
34 | // Module handles namestore and identity requests. | ||
35 | type Module struct { | ||
36 | service.ModuleImpl | ||
37 | |||
38 | // Use function references for calls to methods in other modules: | ||
39 | StoreLocal func(ctx context.Context, query *blocks.GNSQuery, block *blocks.GNSBlock) error | ||
40 | StoreRemote func(ctx context.Context, query blocks.Query, block blocks.Block) error | ||
41 | } | ||
42 | |||
43 | // NewModule instantiates a new GNS module. | ||
44 | func NewModule(ctx context.Context, c *core.Core) (m *Module) { | ||
45 | m = &Module{ | ||
46 | ModuleImpl: *service.NewModuleImpl(), | ||
47 | } | ||
48 | if c != nil { | ||
49 | // register as listener for core events | ||
50 | listener := m.ModuleImpl.Run(ctx, m.event, m.Filter(), 0, nil) | ||
51 | c.Register("zonemaster", listener) | ||
52 | } | ||
53 | return | ||
54 | } | ||
55 | |||
56 | //---------------------------------------------------------------------- | ||
57 | |||
58 | // Filter returns the event filter for the service | ||
59 | func (m *Module) Filter() *core.EventFilter { | ||
60 | f := core.NewEventFilter() | ||
61 | f.AddMsgType(enums.MSG_NAMESTORE_ZONE_ITERATION_START) | ||
62 | return f | ||
63 | } | ||
64 | |||
65 | // Event handler | ||
66 | func (m *Module) event(ctx context.Context, ev *core.Event) { | ||
67 | |||
68 | } | ||
69 | |||
70 | //---------------------------------------------------------------------- | ||
71 | |||
72 | // Export functions | ||
73 | func (m *Module) Export(fcn map[string]any) { | ||
74 | // add exported functions from module | ||
75 | } | ||
76 | |||
77 | // Import functions | ||
78 | func (m *Module) Import(fcn map[string]any) { | ||
79 | // resolve imports from other modules | ||
80 | m.StoreLocal, _ = fcn["namecache:put"].(func(ctx context.Context, query *blocks.GNSQuery, block *blocks.GNSBlock) error) | ||
81 | m.StoreRemote, _ = fcn["dht:put"].(func(ctx context.Context, query blocks.Query, block blocks.Block) error) | ||
82 | } | ||
83 | |||
84 | //---------------------------------------------------------------------- | ||