aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernd Fix <brf@hoi-polloi.org>2022-06-10 09:48:44 +0200
committerBernd Fix <brf@hoi-polloi.org>2022-06-10 09:48:44 +0200
commit22787606b45af3c36aebc4eb48c353f61aef9349 (patch)
tree2b7dfa716fdd90f8462b54d810bacfd4cd428d59 /src
parent7a6ae8f61ee7efde161db98462259ea9bbb23386 (diff)
downloadgnunet-go-22787606b45af3c36aebc4eb48c353f61aef9349.tar.gz
gnunet-go-22787606b45af3c36aebc4eb48c353f61aef9349.zip
RC1 for milestone 1 (NI Assure).v0.1.25
Diffstat (limited to 'src')
-rwxr-xr-xsrc/gnunet/build.sh1
-rw-r--r--src/gnunet/cmd/gnunet-service-dht-go/main.go20
-rw-r--r--src/gnunet/cmd/gnunet-service-gns-go/main.go27
-rw-r--r--src/gnunet/cmd/gnunet-service-revocation-go/main.go27
-rw-r--r--src/gnunet/cmd/revoke-zonekey/main.go2
-rw-r--r--src/gnunet/config/config.go2
-rw-r--r--src/gnunet/config/config_test.go2
-rw-r--r--src/gnunet/config/gnunet-config.json2
-rw-r--r--src/gnunet/core/core.go164
-rw-r--r--src/gnunet/core/core_test.go78
-rw-r--r--src/gnunet/core/event.go9
-rw-r--r--src/gnunet/core/hello_test.go107
-rw-r--r--src/gnunet/core/peer_test.go2
-rw-r--r--src/gnunet/crypto/gns.go2
-rw-r--r--src/gnunet/crypto/gns_test.go2
-rw-r--r--src/gnunet/crypto/hash.go2
-rw-r--r--src/gnunet/crypto/key_exchange.go2
-rw-r--r--src/gnunet/crypto/key_exchange_test.go2
-rw-r--r--src/gnunet/crypto/keys_test.go5
-rw-r--r--src/gnunet/crypto/signature.go2
-rw-r--r--src/gnunet/enums/blocktype_string.go54
-rw-r--r--src/gnunet/enums/dht.go26
-rw-r--r--src/gnunet/enums/dht_block_type.go27
-rw-r--r--src/gnunet/enums/generate.go134
-rw-r--r--src/gnunet/enums/gns.go291
-rw-r--r--src/gnunet/enums/gns_type.go72
-rw-r--r--src/gnunet/enums/gnstype_string.go145
-rw-r--r--src/gnunet/enums/gnunet-dht.rec102
-rw-r--r--src/gnunet/enums/gnunet-dht.tpl12
-rw-r--r--src/gnunet/enums/gnunet-gns.rec132
-rw-r--r--src/gnunet/enums/gnunet-gns.tpl51
-rw-r--r--src/gnunet/enums/gnunet-signature.rec183
-rw-r--r--src/gnunet/enums/gnunet-signature.tpl11
-rw-r--r--src/gnunet/enums/signature.go37
-rw-r--r--src/gnunet/enums/signature_purpose.go42
-rw-r--r--src/gnunet/enums/sigpurpose_string.go75
-rw-r--r--src/gnunet/message/const.go2
-rw-r--r--src/gnunet/message/factory.go4
-rw-r--r--src/gnunet/message/message.go2
-rw-r--r--src/gnunet/message/msg_core.go6
-rw-r--r--src/gnunet/message/msg_dht.go2
-rw-r--r--src/gnunet/message/msg_gns.go4
-rw-r--r--src/gnunet/message/msg_hello.go163
-rw-r--r--src/gnunet/message/msg_hello_dht.go146
-rw-r--r--src/gnunet/message/msg_namecache.go2
-rw-r--r--src/gnunet/message/msg_revocation.go2
-rw-r--r--src/gnunet/message/msg_transport.go2
-rw-r--r--src/gnunet/message/types.go6
-rw-r--r--src/gnunet/service/client.go2
-rw-r--r--src/gnunet/service/dht/blocks/hello.go107
-rw-r--r--src/gnunet/service/dht/module.go49
-rw-r--r--src/gnunet/service/dht/rpc.go (renamed from src/gnunet/service/dht/blocks/hello_test.go)40
-rw-r--r--src/gnunet/service/dht/service.go17
-rw-r--r--src/gnunet/service/gns/block_handler.go54
-rw-r--r--src/gnunet/service/gns/box.go2
-rw-r--r--src/gnunet/service/gns/dns.go12
-rw-r--r--src/gnunet/service/gns/module.go17
-rw-r--r--src/gnunet/service/gns/rpc.go27
-rw-r--r--src/gnunet/service/gns/service.go39
-rw-r--r--src/gnunet/service/module.go20
-rw-r--r--src/gnunet/service/namecache/module.go2
-rw-r--r--src/gnunet/service/revocation/module.go2
-rw-r--r--src/gnunet/service/revocation/pow.go6
-rw-r--r--src/gnunet/service/revocation/pow_test.go2
-rw-r--r--src/gnunet/service/revocation/rpc.go27
-rw-r--r--src/gnunet/service/revocation/service.go18
-rw-r--r--src/gnunet/service/rpc.go (renamed from src/gnunet/rpc/server.go)38
-rw-r--r--src/gnunet/service/service.go29
-rw-r--r--src/gnunet/service/store.go2
-rw-r--r--src/gnunet/test/gnunet-dhtu/main.go218
-rw-r--r--src/gnunet/transport/endpoint.go8
-rw-r--r--src/gnunet/transport/responder.go52
-rw-r--r--src/gnunet/transport/transport.go41
-rw-r--r--src/gnunet/util/address.go2
-rw-r--r--src/gnunet/util/array.go14
-rw-r--r--src/gnunet/util/base32.go2
-rw-r--r--src/gnunet/util/base32_test.go2
-rw-r--r--src/gnunet/util/database.go2
-rw-r--r--src/gnunet/util/format.go2
-rw-r--r--src/gnunet/util/fs.go2
-rw-r--r--src/gnunet/util/id.go2
-rw-r--r--src/gnunet/util/misc.go2
-rw-r--r--src/gnunet/util/peer_id.go10
-rw-r--r--src/gnunet/util/rnd.go2
-rw-r--r--src/gnunet/util/time.go4
85 files changed, 2338 insertions, 734 deletions
diff --git a/src/gnunet/build.sh b/src/gnunet/build.sh
index 5ec677f..39ecbaf 100755
--- a/src/gnunet/build.sh
+++ b/src/gnunet/build.sh
@@ -1,3 +1,4 @@
1#!/bin/bash 1#!/bin/bash
2 2
3go generate ./...
3go install -v -gcflags "-N -l" ./... 4go install -v -gcflags "-N -l" ./...
diff --git a/src/gnunet/cmd/gnunet-service-dht-go/main.go b/src/gnunet/cmd/gnunet-service-dht-go/main.go
index 3b525fd..f9e24bc 100644
--- a/src/gnunet/cmd/gnunet-service-dht-go/main.go
+++ b/src/gnunet/cmd/gnunet-service-dht-go/main.go
@@ -21,6 +21,7 @@ package main
21import ( 21import (
22 "context" 22 "context"
23 "flag" 23 "flag"
24 "net/rpc"
24 "os" 25 "os"
25 "os/signal" 26 "os/signal"
26 "strings" 27 "strings"
@@ -29,7 +30,6 @@ import (
29 30
30 "gnunet/config" 31 "gnunet/config"
31 "gnunet/core" 32 "gnunet/core"
32 "gnunet/rpc"
33 "gnunet/service" 33 "gnunet/service"
34 "gnunet/service/dht" 34 "gnunet/service/dht"
35 35
@@ -91,14 +91,18 @@ func main() {
91 defer c.Shutdown() 91 defer c.Shutdown()
92 92
93 // start a new DHT service 93 // start a new DHT service
94 dht := dht.NewService(ctx, c) 94 var dhtSrv service.Service
95 srv := service.NewSocketHandler("dht", dht) 95 if dhtSrv, err = dht.NewService(ctx, c); err != nil {
96 logger.Printf(logger.ERROR, "[dht] failed to create DHT service: %s\n", err.Error())
97 return
98 }
99 srv := service.NewSocketHandler("dht", dhtSrv)
96 if err = srv.Start(ctx, socket, params); err != nil { 100 if err = srv.Start(ctx, socket, params); err != nil {
97 logger.Printf(logger.ERROR, "[dht] Failed to start DHT service: '%s'", err.Error()) 101 logger.Printf(logger.ERROR, "[dht] Failed to start DHT service: '%s'", err.Error())
98 return 102 return
99 } 103 }
100 104
101 // start JSON-RPC server on request 105 // handle command-line arguments for RPC
102 if len(rpcEndp) > 0 { 106 if len(rpcEndp) > 0 {
103 parts := strings.Split(rpcEndp, ":") 107 parts := strings.Split(rpcEndp, ":")
104 if parts[0] != "tcp" { 108 if parts[0] != "tcp" {
@@ -106,11 +110,15 @@ func main() {
106 return 110 return
107 } 111 }
108 config.Cfg.RPC.Endpoint = parts[1] 112 config.Cfg.RPC.Endpoint = parts[1]
109 if err = rpc.Start(ctx); err != nil { 113 }
114 // start JSON-RPC server on request
115 if ep := config.Cfg.RPC.Endpoint; len(ep) > 0 {
116 var rpc *rpc.Server
117 if rpc, err = service.StartRPC(ctx, ep); err != nil {
110 logger.Printf(logger.ERROR, "[dht] RPC failed to start: %s", err.Error()) 118 logger.Printf(logger.ERROR, "[dht] RPC failed to start: %s", err.Error())
111 return 119 return
112 } 120 }
113 rpc.Register(dht) 121 dhtSrv.InitRPC(rpc)
114 } 122 }
115 123
116 // handle OS signals 124 // handle OS signals
diff --git a/src/gnunet/cmd/gnunet-service-gns-go/main.go b/src/gnunet/cmd/gnunet-service-gns-go/main.go
index 6eb027b..72f7de6 100644
--- a/src/gnunet/cmd/gnunet-service-gns-go/main.go
+++ b/src/gnunet/cmd/gnunet-service-gns-go/main.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -21,6 +21,7 @@ package main
21import ( 21import (
22 "context" 22 "context"
23 "flag" 23 "flag"
24 "net/rpc"
24 "os" 25 "os"
25 "os/signal" 26 "os/signal"
26 "strings" 27 "strings"
@@ -28,7 +29,7 @@ import (
28 "time" 29 "time"
29 30
30 "gnunet/config" 31 "gnunet/config"
31 "gnunet/rpc" 32 "gnunet/core"
32 "gnunet/service" 33 "gnunet/service"
33 "gnunet/service/gns" 34 "gnunet/service/gns"
34 35
@@ -80,16 +81,24 @@ func main() {
80 params = config.Cfg.GNS.Service.Params 81 params = config.Cfg.GNS.Service.Params
81 } 82 }
82 83
83 // start a new GNS service 84 // instantiate core service
84 ctx, cancel := context.WithCancel(context.Background()) 85 ctx, cancel := context.WithCancel(context.Background())
85 gns := gns.NewService() 86 var c *core.Core
87 if c, err = core.NewCore(ctx, config.Cfg.Local); err != nil {
88 logger.Printf(logger.ERROR, "[gns] core failed: %s\n", err.Error())
89 return
90 }
91 defer c.Shutdown()
92
93 // start a new GNS service
94 gns := gns.NewService(ctx, c)
86 srv := service.NewSocketHandler("gns", gns) 95 srv := service.NewSocketHandler("gns", gns)
87 if err = srv.Start(ctx, socket, params); err != nil { 96 if err = srv.Start(ctx, socket, params); err != nil {
88 logger.Printf(logger.ERROR, "[gns] Error: '%s'", err.Error()) 97 logger.Printf(logger.ERROR, "[gns] Error: '%s'", err.Error())
89 return 98 return
90 } 99 }
91 100
92 // start JSON-RPC server on request 101 // handle command-line arguments for RPC
93 if len(rpcEndp) > 0 { 102 if len(rpcEndp) > 0 {
94 parts := strings.Split(rpcEndp, ":") 103 parts := strings.Split(rpcEndp, ":")
95 if parts[0] != "tcp" { 104 if parts[0] != "tcp" {
@@ -97,11 +106,15 @@ func main() {
97 return 106 return
98 } 107 }
99 config.Cfg.RPC.Endpoint = parts[1] 108 config.Cfg.RPC.Endpoint = parts[1]
100 if err = rpc.Start(ctx); err != nil { 109 }
110 // start JSON-RPC server on request
111 if ep := config.Cfg.RPC.Endpoint; len(ep) > 0 {
112 var rpc *rpc.Server
113 if rpc, err = service.StartRPC(ctx, ep); err != nil {
101 logger.Printf(logger.ERROR, "[gns] RPC failed to start: %s", err.Error()) 114 logger.Printf(logger.ERROR, "[gns] RPC failed to start: %s", err.Error())
102 return 115 return
103 } 116 }
104 rpc.Register(gns) 117 gns.InitRPC(rpc)
105 } 118 }
106 119
107 // handle OS signals 120 // handle OS signals
diff --git a/src/gnunet/cmd/gnunet-service-revocation-go/main.go b/src/gnunet/cmd/gnunet-service-revocation-go/main.go
index e21732c..564f430 100644
--- a/src/gnunet/cmd/gnunet-service-revocation-go/main.go
+++ b/src/gnunet/cmd/gnunet-service-revocation-go/main.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -21,6 +21,7 @@ package main
21import ( 21import (
22 "context" 22 "context"
23 "flag" 23 "flag"
24 "net/rpc"
24 "os" 25 "os"
25 "os/signal" 26 "os/signal"
26 "strings" 27 "strings"
@@ -28,7 +29,7 @@ import (
28 "time" 29 "time"
29 30
30 "gnunet/config" 31 "gnunet/config"
31 "gnunet/rpc" 32 "gnunet/core"
32 "gnunet/service" 33 "gnunet/service"
33 "gnunet/service/revocation" 34 "gnunet/service/revocation"
34 35
@@ -80,16 +81,24 @@ func main() {
80 params = config.Cfg.GNS.Service.Params 81 params = config.Cfg.GNS.Service.Params
81 } 82 }
82 83
83 // start a new REVOCATION service 84 // instantiate core service
84 ctx, cancel := context.WithCancel(context.Background()) 85 ctx, cancel := context.WithCancel(context.Background())
85 rvc := revocation.NewService() 86 var c *core.Core
87 if c, err = core.NewCore(ctx, config.Cfg.Local); err != nil {
88 logger.Printf(logger.ERROR, "[gns] core failed: %s\n", err.Error())
89 return
90 }
91 defer c.Shutdown()
92
93 // start a new REVOCATION service
94 rvc := revocation.NewService(ctx, c)
86 srv := service.NewSocketHandler("revocation", rvc) 95 srv := service.NewSocketHandler("revocation", rvc)
87 if err = srv.Start(ctx, socket, params); err != nil { 96 if err = srv.Start(ctx, socket, params); err != nil {
88 logger.Printf(logger.ERROR, "[revocation] Error: '%s'\n", err.Error()) 97 logger.Printf(logger.ERROR, "[revocation] Error: '%s'\n", err.Error())
89 return 98 return
90 } 99 }
91 100
92 // start JSON-RPC server on request 101 // handle command-line arguments for RPC
93 if len(rpcEndp) > 0 { 102 if len(rpcEndp) > 0 {
94 parts := strings.Split(rpcEndp, ":") 103 parts := strings.Split(rpcEndp, ":")
95 if parts[0] != "tcp" { 104 if parts[0] != "tcp" {
@@ -97,11 +106,15 @@ func main() {
97 return 106 return
98 } 107 }
99 config.Cfg.RPC.Endpoint = parts[1] 108 config.Cfg.RPC.Endpoint = parts[1]
100 if err = rpc.Start(ctx); err != nil { 109 }
110 // start JSON-RPC server on request
111 if ep := config.Cfg.RPC.Endpoint; len(ep) > 0 {
112 var rpc *rpc.Server
113 if rpc, err = service.StartRPC(ctx, ep); err != nil {
101 logger.Printf(logger.ERROR, "[revocation] RPC failed to start: %s", err.Error()) 114 logger.Printf(logger.ERROR, "[revocation] RPC failed to start: %s", err.Error())
102 return 115 return
103 } 116 }
104 rpc.Register(rvc) 117 rvc.InitRPC(rpc)
105 } 118 }
106 119
107 // handle OS signals 120 // handle OS signals
diff --git a/src/gnunet/cmd/revoke-zonekey/main.go b/src/gnunet/cmd/revoke-zonekey/main.go
index aab9602..0713582 100644
--- a/src/gnunet/cmd/revoke-zonekey/main.go
+++ b/src/gnunet/cmd/revoke-zonekey/main.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/config/config.go b/src/gnunet/config/config.go
index 3687a3e..a92bdd6 100644
--- a/src/gnunet/config/config.go
+++ b/src/gnunet/config/config.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/config/config_test.go b/src/gnunet/config/config_test.go
index d40bc19..d82019e 100644
--- a/src/gnunet/config/config_test.go
+++ b/src/gnunet/config/config_test.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/config/gnunet-config.json b/src/gnunet/config/gnunet-config.json
index 82606d7..7927cda 100644
--- a/src/gnunet/config/gnunet-config.json
+++ b/src/gnunet/config/gnunet-config.json
@@ -1,7 +1,7 @@
1{ 1{
2 "bootstrap": { 2 "bootstrap": {
3 "nodes": [ 3 "nodes": [
4 "gnunet://hello/7KTBJ90340HF1Q2GB0A57E2XJER4FDHX8HP5GHEB9125VPWPD27G/BNMDFN6HJCPWSPNBSEC06MC1K8QN1Z2DHRQSRXDTFR7FTBD4JHNBJ2RJAAEZ31FWG1Q3PMN3PXGZQ3Q7NTNEKQZFA7TE2Y46FM8E20R/1653499308?r5n%2Bip%2Budp%3A127.0.0.1%3A7654" 4 "gnunet://hello/7KTBJ90340HF1Q2GB0A57E2XJER4FDHX8HP5GHEB9125VPWPD27G/BNMDFN6HJCPWSPNBSEC06MC1K8QN1Z2DHRQSRXDTFR7FTBD4JHNBJ2RJAAEZ31FWG1Q3PMN3PXGZQ3Q7NTNEKQZFA7TE2Y46FM8E20R/1653499308?r5n+ip+udp=127.0.0.1%3A7654"
5 ] 5 ]
6 }, 6 },
7 "local": { 7 "local": {
diff --git a/src/gnunet/core/core.go b/src/gnunet/core/core.go
index 7582891..ee354e3 100644
--- a/src/gnunet/core/core.go
+++ b/src/gnunet/core/core.go
@@ -29,6 +29,8 @@ import (
29 "net" 29 "net"
30 "strings" 30 "strings"
31 "time" 31 "time"
32
33 "github.com/bfix/gospel/logger"
32) 34)
33 35
34//---------------------------------------------------------------------- 36//----------------------------------------------------------------------
@@ -146,49 +148,68 @@ func NewCore(ctx context.Context, node *config.NodeConfig) (c *Core, err error)
146 } 148 }
147 } 149 }
148 // run message pump 150 // run message pump
149 go func() { 151 go c.pump(ctx)
150 // wait for incoming messages 152 return
151 for { 153}
152 select { 154
153 // get (next) message from transport 155// message pump for core
154 case tm := <-c.incoming: 156func (c *Core) pump(ctx context.Context) {
155 var ev *Event 157 // wait for incoming messages
156 158 for {
157 // inspect message for peer state events 159 select {
158 switch msg := tm.Msg.(type) { 160 // get (next) message from transport
159 case *message.HelloMsg: 161 case tm := <-c.incoming:
160 // keep peer addresses 162 var ev *Event
161 for _, addr := range msg.Addresses { 163
162 a := &util.Address{ 164 // inspect message for peer state events
163 Netw: addr.Transport, 165 switch msg := tm.Msg.(type) {
164 Address: addr.Address, 166 case *message.HelloDHTMsg:
165 Expires: addr.ExpireOn, 167 logger.Println(logger.INFO, "[core] Received HELLO message: "+msg.String())
166 } 168 // verify integrity of message
167 c.Learn(ctx, msg.PeerID, a) 169 if ok, err := msg.Verify(tm.Peer); !ok || err != nil {
168 } 170 logger.Println(logger.WARN, "[core] Received invalid DHT_P2P_HELLO message")
169 // generate EV_CONNECT event 171 break
170 ev = &Event{ 172 }
171 ID: EV_CONNECT, 173 // keep peer addresses
172 Peer: tm.Peer, 174 aList, err := msg.Addresses()
173 Msg: msg, 175 if err != nil {
174 } 176 logger.Println(logger.WARN, "[core] Failed to parse addresses from DHT_P2P_HELLO message")
175 c.dispatch(ev) 177 break
176 } 178 }
177 // generate EV_MESSAGE event 179 for _, addr := range aList {
180 c.Learn(ctx, tm.Peer, addr.Wrap())
181 }
182 // generate EV_CONNECT event
178 ev = &Event{ 183 ev = &Event{
179 ID: EV_MESSAGE, 184 ID: EV_CONNECT,
180 Peer: tm.Peer, 185 Peer: tm.Peer,
181 Msg: tm.Msg, 186 Msg: msg,
182 } 187 }
183 c.dispatch(ev) 188 c.dispatch(ev)
184
185 // wait for termination
186 case <-ctx.Done():
187 return
188 } 189 }
190 // set default responder (core) if no custom responder
191 // is defined by the receiving endpoint.
192 resp := tm.Resp
193 if resp == nil {
194 resp = &transport.TransportResponder{
195 Peer: tm.Peer,
196 SendFcn: c.Send,
197 }
198 }
199 // generate EV_MESSAGE event
200 ev = &Event{
201 ID: EV_MESSAGE,
202 Peer: tm.Peer,
203 Msg: tm.Msg,
204 Resp: tm.Resp,
205 }
206 c.dispatch(ev)
207
208 // wait for termination
209 case <-ctx.Done():
210 return
189 } 211 }
190 }() 212 }
191 return
192} 213}
193 214
194// Shutdown all core-related processes. 215// Shutdown all core-related processes.
@@ -202,32 +223,24 @@ func (c *Core) Shutdown() {
202// Send is a function that allows the local peer to send a protocol 223// Send is a function that allows the local peer to send a protocol
203// message to a remote peer. 224// message to a remote peer.
204func (c *Core) Send(ctx context.Context, peer *util.PeerID, msg message.Message) error { 225func (c *Core) Send(ctx context.Context, peer *util.PeerID, msg message.Message) error {
226 // get peer label (id or "@")
227 label := "@"
228 if peer != nil {
229 label = peer.String()
230 }
205 // TODO: select best endpoint protocol for transport; now fixed to IP+UDP 231 // TODO: select best endpoint protocol for transport; now fixed to IP+UDP
206 netw := "ip+udp" 232 netw := "ip+udp"
207 addrs := c.peers.Get(peer.String(), netw) 233 addrs := c.peers.Get(label, netw)
208 if len(addrs) == 0 { 234 if len(addrs) == 0 {
209 return ErrCoreNoEndpAddr 235 return ErrCoreNoEndpAddr
210 } 236 }
211 // TODO: select best address; curently selects first 237 // TODO: select best address; curently selects first
212 addr := addrs[0] 238 addr := addrs[0]
239 return c.send(ctx, addr, msg)
240}
213 241
214 // select best endpoint for transport 242// send message directly to address
215 var ep transport.Endpoint 243func (c *Core) send(ctx context.Context, addr *util.Address, msg message.Message) error {
216 for _, epCfg := range c.endpoints {
217 if epCfg.addr.Network() == netw {
218 if ep == nil {
219 ep = epCfg.ep
220 }
221 // TODO: compare endpoints, select better one:
222 // if ep.Better(epCfg.ep) {
223 // ep = epCfg.ep
224 // }
225 }
226 }
227 // check we have an endpoint to send on
228 if ep == nil {
229 return ErrCoreNoEndpAddr
230 }
231 // assemble transport message 244 // assemble transport message
232 tm := transport.NewTransportMessage(c.PeerID(), msg) 245 tm := transport.NewTransportMessage(c.PeerID(), msg)
233 // send on transport 246 // send on transport
@@ -236,26 +249,33 @@ func (c *Core) Send(ctx context.Context, peer *util.PeerID, msg message.Message)
236 249
237// Learn a (new) address for peer 250// Learn a (new) address for peer
238func (c *Core) Learn(ctx context.Context, peer *util.PeerID, addr *util.Address) (err error) { 251func (c *Core) Learn(ctx context.Context, peer *util.PeerID, addr *util.Address) (err error) {
252 // assemble our own HELLO message:
253 addrList := make([]*util.Address, 0)
254 for _, epRef := range c.endpoints {
255 addrList = append(addrList, epRef.addr)
256 }
257 node := c.local
258 var hello *blocks.HelloBlock
259 hello, err = node.HelloData(time.Hour, addrList)
260 if err != nil {
261 return
262 }
263 msg := message.NewHelloDHTMsg()
264 var aList []*message.HelloAddress
265 msg.NumAddr = uint16(len(hello.Addresses()))
266 for _, a := range hello.Addresses() {
267 ha := message.NewHelloAddress(a)
268 aList = append(aList, ha)
269 }
270 msg.SetAddresses(aList)
271
272 // if no peer is given, we send HELLO directly to address
273 if peer == nil {
274 return c.send(ctx, addr, msg)
275 }
276 // add peer address to address list
239 if c.peers.Add(peer.String(), addr) == 1 { 277 if c.peers.Add(peer.String(), addr) == 1 {
240 // we added a previously unknown peer: send a HELLO 278 // we added a previously unknown peer: send a HELLO
241
242 // collect endpoint addresses
243 addrList := make([]*util.Address, 0)
244 for _, epRef := range c.endpoints {
245 addrList = append(addrList, epRef.addr)
246 }
247 // new peer id: send HELLO message to newly added peer
248 node := c.local
249 var hello *blocks.HelloBlock
250 hello, err = node.HelloData(time.Hour, addrList)
251 if err != nil {
252 return
253 }
254 msg := message.NewHelloMsg(node.GetID())
255 for _, a := range hello.Addresses() {
256 ha := message.NewHelloAddress(a)
257 msg.AddAddress(ha)
258 }
259 err = c.Send(ctx, peer, msg) 279 err = c.Send(ctx, peer, msg)
260 } 280 }
261 return 281 return
diff --git a/src/gnunet/core/core_test.go b/src/gnunet/core/core_test.go
index d8a6277..3c7d25a 100644
--- a/src/gnunet/core/core_test.go
+++ b/src/gnunet/core/core_test.go
@@ -19,10 +19,13 @@
19package core 19package core
20 20
21import ( 21import (
22 "bytes"
22 "context" 23 "context"
23 "encoding/hex" 24 "encoding/hex"
24 "gnunet/config" 25 "gnunet/config"
26 "gnunet/transport"
25 "gnunet/util" 27 "gnunet/util"
28 "log"
26 "testing" 29 "testing"
27 "time" 30 "time"
28) 31)
@@ -165,6 +168,64 @@ func TestCoreUPNP(t *testing.T) {
165} 168}
166 169
167//---------------------------------------------------------------------- 170//----------------------------------------------------------------------
171// Test Go node with DHTU GNUnet nodes
172//----------------------------------------------------------------------
173
174var testDHTU = false
175
176func TestDHTU(t *testing.T) {
177 // skip test on demand
178 if !testDHTU {
179 return
180 }
181 // convert arguments
182 var (
183 rId *util.PeerID
184 rAddr *util.Address
185 err error
186 )
187 if rAddr, err = util.ParseAddress("ip+udp://172.17.0.4:10000"); err != nil {
188 t.Fatal(err)
189 }
190 // configuration data
191 var (
192 peerCfg = &config.NodeConfig{
193 Name: "p1",
194 PrivateSeed: "iYK1wSi5XtCP774eNFk1LYXqKlOPEpwKBw+2/bMkE24=",
195 Endpoints: []*config.EndpointConfig{
196 {
197 ID: "p1",
198 Network: "ip+udp",
199 Address: "172.17.0.1",
200 Port: 2086,
201 TTL: 86400,
202 },
203 },
204 }
205 )
206 // setup execution context
207 ctx, cancel := context.WithCancel(context.Background())
208 defer func() {
209 cancel()
210 time.Sleep(time.Second)
211 }()
212
213 // create and run node
214 node, err := NewTestNode(t, ctx, peerCfg)
215 if err != nil {
216 log.Fatal(err)
217 }
218 defer node.Shutdown()
219
220 // learn bootstrap address (triggers HELLO)
221 node.Learn(ctx, rId, rAddr)
222
223 // run forever
224 var ch chan struct{}
225 <-ch
226}
227
228//----------------------------------------------------------------------
168// create and run a node with given spec 229// create and run a node with given spec
169//---------------------------------------------------------------------- 230//----------------------------------------------------------------------
170 231
@@ -181,7 +242,11 @@ func (n *TestNode) Shutdown() {
181} 242}
182 243
183func (n *TestNode) Learn(ctx context.Context, peer *util.PeerID, addr *util.Address) { 244func (n *TestNode) Learn(ctx context.Context, peer *util.PeerID, addr *util.Address) {
184 n.t.Logf("[%d] Learning %s for %s", n.id, addr.StringAll(), peer.String()) 245 label := "@"
246 if peer != nil {
247 label = peer.String()
248 }
249 n.t.Logf("[%d] Learning %s for %s", n.id, addr.StringAll(), label)
185 if err := n.core.Learn(ctx, peer, addr); err != nil { 250 if err := n.core.Learn(ctx, peer, addr); err != nil {
186 n.t.Log("Learn: " + err.Error()) 251 n.t.Log("Learn: " + err.Error())
187 } 252 }
@@ -199,11 +264,6 @@ func NewTestNode(t *testing.T, ctx context.Context, cfg *config.NodeConfig) (nod
199 return 264 return
200 } 265 }
201 node.peer = node.core.Peer() 266 node.peer = node.core.Peer()
202
203 // create peer object
204 if node.peer, err = NewLocalPeer(cfg); err != nil {
205 return
206 }
207 t.Logf("[%d] Node %s starting", node.id, node.peer.GetID()) 267 t.Logf("[%d] Node %s starting", node.id, node.peer.GetID())
208 t.Logf("[%d] --> %s", node.id, hex.EncodeToString(node.peer.GetID().Key)) 268 t.Logf("[%d] --> %s", node.id, hex.EncodeToString(node.peer.GetID().Key))
209 269
@@ -240,6 +300,12 @@ func NewTestNode(t *testing.T, ctx context.Context, cfg *config.NodeConfig) (nod
240 case EV_MESSAGE: 300 case EV_MESSAGE:
241 t.Logf("[%d] <<< Msg from %s of type %d", node.id, ev.Peer, ev.Msg.Header().MsgType) 301 t.Logf("[%d] <<< Msg from %s of type %d", node.id, ev.Peer, ev.Msg.Header().MsgType)
242 t.Logf("[%d] <<< --> %s", node.id, ev.Msg.String()) 302 t.Logf("[%d] <<< --> %s", node.id, ev.Msg.String())
303 wrt := new(bytes.Buffer)
304 if err := transport.WriteMessageDirect(wrt, ev.Msg); err == nil {
305 t.Logf("[%d] <<< %s", node.id, hex.EncodeToString(wrt.Bytes()))
306 } else {
307 t.Logf("[%d] <<< Error %s", node.id, err.Error())
308 }
243 } 309 }
244 310
245 // handle termination signal 311 // handle termination signal
diff --git a/src/gnunet/core/event.go b/src/gnunet/core/event.go
index 4eab112..8d05b0d 100644
--- a/src/gnunet/core/event.go
+++ b/src/gnunet/core/event.go
@@ -20,6 +20,7 @@ package core
20 20
21import ( 21import (
22 "gnunet/message" 22 "gnunet/message"
23 "gnunet/transport"
23 "gnunet/util" 24 "gnunet/util"
24) 25)
25 26
@@ -83,9 +84,11 @@ func (f *EventFilter) CheckMsgType(mt uint16) bool {
83 84
84// Event sent to listeners 85// Event sent to listeners
85type Event struct { 86type Event struct {
86 ID int // event type 87 ID int // event type
87 Peer *util.PeerID // remote peer 88 Peer *util.PeerID // remote peer
88 Msg message.Message // GNUnet message (can be nil) 89 Msg message.Message // GNUnet message (can be nil)
90 Resp transport.Responder // reply handler (can be nil)
91 Label string // event label (can be empty)
89} 92}
90 93
91//---------------------------------------------------------------------- 94//----------------------------------------------------------------------
diff --git a/src/gnunet/core/hello_test.go b/src/gnunet/core/hello_test.go
new file mode 100644
index 0000000..4abad04
--- /dev/null
+++ b/src/gnunet/core/hello_test.go
@@ -0,0 +1,107 @@
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
19package core
20
21import (
22 "fmt"
23 "gnunet/config"
24 "gnunet/service/dht/blocks"
25 "gnunet/util"
26 "testing"
27 "time"
28)
29
30var (
31 peerCfg = &config.NodeConfig{
32 Name: "p1",
33 PrivateSeed: "iYK1wSi5XtCP774eNFk1LYXqKlOPEpwKBw+2/bMkE24=",
34 Endpoints: []*config.EndpointConfig{
35 {
36 ID: "p1",
37 Network: "ip+udp",
38 Address: "172.17.0.1",
39 Port: 2086,
40 TTL: 86400,
41 },
42 },
43 }
44
45 helloURL = []string{
46 "gnunet://hello" +
47 "/RBVQWST48N9YDVHYM7KYR1YDBZN7X4KG1SJJZHGHGX5HFHX5P010" +
48 "/Y4YEXZBBKS1HFGGHZW5QWQTX20QJ5BBEQZB8PNA85VCASRR60P741X28E8HS6P20HQED43RAQFADJTVREFQ37W1YQFN29TCC2AT4R2R" +
49 "/1654964519" +
50 "?ip+udp=127.0.0.1%3A10000" +
51 "&ip+udp=192.168.178.50%3A10000" +
52 "&ip+udp=%5B%3A%3A1%5D%3A10000" +
53 "&ip+udp=%5B2001%3A1620%3Afe9%3A0%3A7285%3Ac2ff%3Afe62%3Ab4c9%5D%3A10000" +
54 "&ip+udp=%5Bfe80%3A%3A7285%3Ac2ff%3Afe62%3Ab4c9%5D%3A10000",
55 "gnunet://hello" +
56 "/6SR91X40JHTTSKTEY04KC920MDJBVDDNJ9Y2KPVY1RJK40KC1SVG" +
57 "/7H3BX1XDYXKXDR20X1GPCYY1CT68GGH1CC9FSDBW4MZ4H5GFB3K7PMJZTEWK3NVVJ0FXBBG6QFBWFM233F5YTQZGZ8JV5MEPNBWP800" +
58 "/1654953178" +
59 "?ip+udp=127.0.0.1%3A10000" +
60 "&ip+udp=172.17.0.4%3A10000" +
61 "&ip+udp=%5B%3A%3Affff%3A172.17.0.4%5D%3A10000",
62 }
63)
64
65func TestHelloURLDirect(t *testing.T) {
66 for _, hu := range helloURL {
67 if _, err := blocks.ParseHelloURL(hu, false); err != nil {
68 t.Fatal(err)
69 }
70 }
71}
72
73func TestHelloURL(t *testing.T) {
74
75 // prepare peer and HELLO data
76 peer, err := NewLocalPeer(peerCfg)
77 if err != nil {
78 t.Fatal(err)
79 }
80 as := fmt.Sprintf("%s://%s:%d",
81 peerCfg.Endpoints[0].Network,
82 peerCfg.Endpoints[0].Address,
83 peerCfg.Endpoints[0].Port,
84 )
85 listen, err := util.ParseAddress(as)
86 if err != nil {
87 t.Fatal(err)
88 }
89 aList := []*util.Address{listen}
90 hd, err := peer.HelloData(time.Hour, aList)
91 if err != nil {
92 t.Fatal(err)
93 }
94
95 // convert to and from HELLO URL
96 url1 := hd.URL()
97 hd2, err := blocks.ParseHelloURL(url1, true)
98 if err != nil {
99 t.Fatal(err)
100 }
101 url2 := hd2.URL()
102 if url1 != url2 {
103 t.Log(">>> " + url1)
104 t.Log("<<< " + url2)
105 t.Fatal("urls don't match")
106 }
107}
diff --git a/src/gnunet/core/peer_test.go b/src/gnunet/core/peer_test.go
index 70a5c5f..f546a52 100644
--- a/src/gnunet/core/peer_test.go
+++ b/src/gnunet/core/peer_test.go
@@ -65,7 +65,7 @@ func TestPeerHello(t *testing.T) {
65 // convert to URL and back 65 // convert to URL and back
66 u := h.URL() 66 u := h.URL()
67 t.Log(u) 67 t.Log(u)
68 h2, err := blocks.ParseHelloURL(u) 68 h2, err := blocks.ParseHelloURL(u, true)
69 if err != nil { 69 if err != nil {
70 t.Fatal(err) 70 t.Fatal(err)
71 } 71 }
diff --git a/src/gnunet/crypto/gns.go b/src/gnunet/crypto/gns.go
index f4c5627..d62a047 100644
--- a/src/gnunet/crypto/gns.go
+++ b/src/gnunet/crypto/gns.go
@@ -148,7 +148,7 @@ var (
148 ZONE_EDKEY = uint32(enums.GNS_TYPE_EDKEY) 148 ZONE_EDKEY = uint32(enums.GNS_TYPE_EDKEY)
149 149
150 // register available zone types for BlockHandler 150 // register available zone types for BlockHandler
151 ZoneTypes = []int{ 151 ZoneTypes = []enums.GNSType{
152 enums.GNS_TYPE_PKEY, 152 enums.GNS_TYPE_PKEY,
153 enums.GNS_TYPE_EDKEY, 153 enums.GNS_TYPE_EDKEY,
154 } 154 }
diff --git a/src/gnunet/crypto/gns_test.go b/src/gnunet/crypto/gns_test.go
index 62a2dfd..4ef64d4 100644
--- a/src/gnunet/crypto/gns_test.go
+++ b/src/gnunet/crypto/gns_test.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/crypto/hash.go b/src/gnunet/crypto/hash.go
index 049a8ef..ed6edc7 100644
--- a/src/gnunet/crypto/hash.go
+++ b/src/gnunet/crypto/hash.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/crypto/key_exchange.go b/src/gnunet/crypto/key_exchange.go
index 5ff51ea..a16bda5 100644
--- a/src/gnunet/crypto/key_exchange.go
+++ b/src/gnunet/crypto/key_exchange.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/crypto/key_exchange_test.go b/src/gnunet/crypto/key_exchange_test.go
index a433ec3..1e4f0dc 100644
--- a/src/gnunet/crypto/key_exchange_test.go
+++ b/src/gnunet/crypto/key_exchange_test.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/crypto/keys_test.go b/src/gnunet/crypto/keys_test.go
index 8dae1f1..d8ffe96 100644
--- a/src/gnunet/crypto/keys_test.go
+++ b/src/gnunet/crypto/keys_test.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -23,9 +23,10 @@ import (
23 "encoding/hex" 23 "encoding/hex"
24 "testing" 24 "testing"
25 25
26 "gnunet/util"
27
26 "github.com/bfix/gospel/crypto/ed25519" 28 "github.com/bfix/gospel/crypto/ed25519"
27 "github.com/bfix/gospel/math" 29 "github.com/bfix/gospel/math"
28 "gnunet/util"
29) 30)
30 31
31var ( 32var (
diff --git a/src/gnunet/crypto/signature.go b/src/gnunet/crypto/signature.go
index ca4c4a3..4bc5aac 100644
--- a/src/gnunet/crypto/signature.go
+++ b/src/gnunet/crypto/signature.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/enums/blocktype_string.go b/src/gnunet/enums/blocktype_string.go
new file mode 100644
index 0000000..639501f
--- /dev/null
+++ b/src/gnunet/enums/blocktype_string.go
@@ -0,0 +1,54 @@
1// Code generated by "stringer -type=BlockType dht_block_type.go"; DO NOT EDIT.
2
3package enums
4
5import "strconv"
6
7func _() {
8 // An "invalid array index" compiler error signifies that the constant values have changed.
9 // Re-run the stringer command to generate them again.
10 var x [1]struct{}
11 _ = x[BLOCK_TYPE_ANY-0]
12 _ = x[BLOCK_TYPE_FS_DBLOCK-1]
13 _ = x[BLOCK_TYPE_FS_IBLOCK-2]
14 _ = x[BLOCK_TYPE_FS_ONDEMAND-6]
15 _ = x[BLOCK_TYPE_DHT_HELLO-7]
16 _ = x[BLOCK_TYPE_TEST-8]
17 _ = x[BLOCK_TYPE_FS_UBLOCK-9]
18 _ = x[BLOCK_TYPE_DNS-10]
19 _ = x[BLOCK_TYPE_GNS_NAMERECORD-11]
20 _ = x[BLOCK_TYPE_REVOCATION-12]
21 _ = x[BLOCK_TYPE_DHT_URL_HELLO-13]
22 _ = x[BLOCK_TYPE_REGEX-22]
23 _ = x[BLOCK_TYPE_REGEX_ACCEPT-23]
24 _ = x[BLOCK_TYPE_SET_TEST-24]
25 _ = x[BLOCK_TYPE_CONSENSUS_ELEMENT-25]
26 _ = x[BLOCK_TYPE_SETI_TEST-26]
27}
28
29const (
30 _BlockType_name_0 = "BLOCK_TYPE_ANYBLOCK_TYPE_FS_DBLOCKBLOCK_TYPE_FS_IBLOCK"
31 _BlockType_name_1 = "BLOCK_TYPE_FS_ONDEMANDBLOCK_TYPE_DHT_HELLOBLOCK_TYPE_TESTBLOCK_TYPE_FS_UBLOCKBLOCK_TYPE_DNSBLOCK_TYPE_GNS_NAMERECORDBLOCK_TYPE_REVOCATIONBLOCK_TYPE_DHT_URL_HELLO"
32 _BlockType_name_2 = "BLOCK_TYPE_REGEXBLOCK_TYPE_REGEX_ACCEPTBLOCK_TYPE_SET_TESTBLOCK_TYPE_CONSENSUS_ELEMENTBLOCK_TYPE_SETI_TEST"
33)
34
35var (
36 _BlockType_index_0 = [...]uint8{0, 14, 34, 54}
37 _BlockType_index_1 = [...]uint8{0, 22, 42, 57, 77, 91, 116, 137, 161}
38 _BlockType_index_2 = [...]uint8{0, 16, 39, 58, 86, 106}
39)
40
41func (i BlockType) String() string {
42 switch {
43 case 0 <= i && i <= 2:
44 return _BlockType_name_0[_BlockType_index_0[i]:_BlockType_index_0[i+1]]
45 case 6 <= i && i <= 13:
46 i -= 6
47 return _BlockType_name_1[_BlockType_index_1[i]:_BlockType_index_1[i+1]]
48 case 22 <= i && i <= 26:
49 i -= 22
50 return _BlockType_name_2[_BlockType_index_2[i]:_BlockType_index_2[i+1]]
51 default:
52 return "BlockType(" + strconv.FormatInt(int64(i), 10) + ")"
53 }
54}
diff --git a/src/gnunet/enums/dht.go b/src/gnunet/enums/dht.go
index 06a43d5..36c3d8a 100644
--- a/src/gnunet/enums/dht.go
+++ b/src/gnunet/enums/dht.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -19,7 +19,7 @@
19package enums 19package enums
20 20
21// DHT flags and settings 21// DHT flags and settings
22var ( 22const (
23 DHT_RO_NONE = 0 // Default. Do nothing special. 23 DHT_RO_NONE = 0 // Default. Do nothing special.
24 DHT_RO_DEMULTIPLEX_EVERYWHERE = 1 // Each peer along the way should look at 'enc' 24 DHT_RO_DEMULTIPLEX_EVERYWHERE = 1 // Each peer along the way should look at 'enc'
25 DHT_RO_RECORD_ROUTE = 2 // keep track of the route that the message took in the P2P network. 25 DHT_RO_RECORD_ROUTE = 2 // keep track of the route that the message took in the P2P network.
@@ -30,24 +30,6 @@ var (
30 DHT_GNS_REPLICATION_LEVEL = 10 30 DHT_GNS_REPLICATION_LEVEL = 10
31) 31)
32 32
33// DHT block types 33//go:generate go run generate.go gnunet-dht.rec gnunet-dht.tpl dht_block_type.go
34var (
35 BLOCK_TYPE_ANY = 0 // Any type of block, used as a wildcard when searching.
36 BLOCK_TYPE_FS_DBLOCK = 1 // Data block (leaf) in the CHK tree.
37 BLOCK_TYPE_FS_IBLOCK = 2 // Inner block in the CHK tree.
38 BLOCK_TYPE_FS_KBLOCK = 3 // Legacy type, no longer in use.
39 BLOCK_TYPE_FS_SBLOCK = 4 // Legacy type, no longer in use.
40 BLOCK_TYPE_FS_NBLOCK = 5 // Legacy type, no longer in use.
41 BLOCK_TYPE_FS_ONDEMAND = 6 // Type of a block representing a block to be encoded on demand from disk.
42 BLOCK_TYPE_DHT_HELLO = 7 // Type of a block that contains a HELLO for a peer
43 BLOCK_TYPE_TEST = 8 // Block for testing.
44 BLOCK_TYPE_FS_UBLOCK = 9 // Type of a block representing any type of search result (universal).
45 BLOCK_TYPE_DNS = 10 // Block for storing DNS exit service advertisements.
46 BLOCK_TYPE_GNS_NAMERECORD = 11 // Block for storing record data
47 BLOCK_TYPE_REVOCATION = 12 // Block type for a revocation message by which a key is revoked.
48 34
49 BLOCK_TYPE_REGEX = 22 // Block to store a cadet regex state 35//go:generate stringer -type=BlockType dht_block_type.go
50 BLOCK_TYPE_REGEX_ACCEPT = 23 // Block to store a cadet regex accepting state
51 BLOCK_TYPE_SET_TEST = 24 // Block for testing set/consensus.
52 BLOCK_TYPE_CONSENSUS_ELEMENT = 25 // Block type for consensus elements.
53)
diff --git a/src/gnunet/enums/dht_block_type.go b/src/gnunet/enums/dht_block_type.go
new file mode 100644
index 0000000..e435419
--- /dev/null
+++ b/src/gnunet/enums/dht_block_type.go
@@ -0,0 +1,27 @@
1// Code generated by enum generator; DO NOT EDIT.
2
3package enums
4
5type BlockType int
6
7// DHT block types
8const (
9BLOCK_TYPE_ANY BlockType = 0 // Identifier for any block.
10BLOCK_TYPE_FS_DBLOCK BlockType = 1 // Data block (leaf) in the CHK tree.
11BLOCK_TYPE_FS_IBLOCK BlockType = 2 // Inner block in the CHK tree.
12BLOCK_TYPE_FS_ONDEMAND BlockType = 6 // Type of a block representing a block to be encoded on demand from disk. Should never appear on the network directly.
13BLOCK_TYPE_DHT_HELLO BlockType = 7 // Type of a block that contains a HELLO for a peer.
14BLOCK_TYPE_TEST BlockType = 8 // Block for testing.
15BLOCK_TYPE_FS_UBLOCK BlockType = 9 // Type of a block representing any type of search result (universal).
16BLOCK_TYPE_DNS BlockType = 10 // Block for storing DNS exit service advertisements.
17BLOCK_TYPE_GNS_NAMERECORD BlockType = 11 // Block for storing GNS record data.
18BLOCK_TYPE_REVOCATION BlockType = 12 // Block type for a revocation message by which a key is revoked.
19BLOCK_TYPE_DHT_URL_HELLO BlockType = 13 // Type of a block that contains a DHT-NG HELLO for a peer.
20BLOCK_TYPE_REGEX BlockType = 22 // Block to store a cadet regex state
21BLOCK_TYPE_REGEX_ACCEPT BlockType = 23 // Block to store a cadet regex accepting state
22BLOCK_TYPE_SET_TEST BlockType = 24 // Block for testing set/consensus. If first byte of the block is non-zero, the block is considered invalid.
23BLOCK_TYPE_CONSENSUS_ELEMENT BlockType = 25 // Block type for consensus elements. Contains either special marker elements or a nested block.
24BLOCK_TYPE_SETI_TEST BlockType = 26 // Block for testing set intersection. If first byte of the block is non-zero, the block is considered invalid.
25
26)
27
diff --git a/src/gnunet/enums/generate.go b/src/gnunet/enums/generate.go
new file mode 100644
index 0000000..0e02850
--- /dev/null
+++ b/src/gnunet/enums/generate.go
@@ -0,0 +1,134 @@
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//go:build ignore
20
21package main
22
23import (
24 "bufio"
25 "flag"
26 "fmt"
27 "io"
28 "log"
29 "os"
30 "strings"
31 "text/template"
32)
33
34// Record in the GANA registry (for a given type)
35type Record struct {
36 Number string
37 Name string
38 Comment string
39 References string
40}
41
42// String returns a readable record string
43func (rec *Record) String() string {
44 return fmt.Sprintf("[%s:%s]\n", rec.Number, rec.Name)
45}
46
47// go:generate generator to read recfiles and fill templates (not exactly
48// build on recutils but on recfiles).
49func main() {
50 // handle command-line arguments
51 flag.Parse()
52 args := flag.Args()
53 if len(args) != 3 {
54 log.Fatal("not enough arguments")
55 }
56
57 // read template
58 tpl, err := template.ParseFiles(args[1])
59 if err != nil {
60 log.Fatal(err)
61 }
62
63 // parse recfile
64 in, err := os.Open(args[0])
65 if err != nil {
66 log.Fatal(err)
67 }
68 defer in.Close()
69
70 rdr := bufio.NewReader(in)
71 state := 0
72 var recs []*Record
73 var rec *Record
74 for {
75 // read next line from recfile
76 buf, _, err := rdr.ReadLine()
77 if err != nil {
78 if err == io.EOF {
79 break
80 }
81 }
82 line := strings.TrimSpace(string(buf))
83 log.Printf("[%d] %s\n", state, line)
84
85 // perform state machine:
86 switch state {
87
88 // wait for record to start
89 case 0:
90 if len(line) == 0 || strings.Index("%#", string(line[0])) != -1 {
91 continue
92 }
93 // new record starts here
94 rec = new(Record)
95 state = 1
96 fallthrough
97
98 // read record data
99 case 1:
100 if len(line) == 0 {
101 // record done; add to list
102 log.Println("Record: " + rec.String())
103 recs = append(recs, rec)
104 rec = nil
105 state = 0
106 continue
107 }
108 // set attribute
109 kv := strings.SplitN(line, ":", 2)
110 switch kv[0] {
111 case "Number":
112 rec.Number = strings.TrimSpace(kv[1])
113 case "Name":
114 rec.Name = strings.TrimSpace(kv[1])
115 case "Comment":
116 rec.Comment = strings.TrimSpace(kv[1])
117 case "References":
118 rec.References = strings.TrimSpace(kv[1])
119 }
120 }
121 }
122
123 // open output file
124 out, err := os.Create(args[2])
125 if err != nil {
126 log.Fatal(err)
127 }
128 defer out.Close()
129
130 // Exeute template on data
131 if err := tpl.Execute(out, recs); err != nil {
132 log.Fatal(err)
133 }
134}
diff --git a/src/gnunet/enums/gns.go b/src/gnunet/enums/gns.go
index af9bbc7..5ab28ad 100644
--- a/src/gnunet/enums/gns.go
+++ b/src/gnunet/enums/gns.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -18,296 +18,21 @@
18 18
19package enums 19package enums
20 20
21// GNS constants 21const (
22var (
23 GNS_MAX_BLOCK_SIZE = (63 * 1024) // Maximum size of a value that can be stored in a GNS block.
24
25 // GNS record flags 22 // GNS record flags
26 GNS_FLAG_PRIVATE = 2 // Record is not shared on the DHT 23 GNS_FLAG_PRIVATE = 2 // Record is not shared on the DHT
27 GNS_FLAG_SUPPL = 4 // Supplemental records (e.g. NICK) in a block 24 GNS_FLAG_SUPPL = 4 // Supplemental records (e.g. NICK) in a block
28 GNS_FLAG_EXPREL = 8 // Expire time in record is in relative time. 25 GNS_FLAG_EXPREL = 8 // Expire time in record is in relative time.
29 GNS_FLAG_SHADOW = 16 // Record is ignored if non-expired records of same type exist in block 26 GNS_FLAG_SHADOW = 16 // Record is ignored if non-expired records of same type exist in block
30 27
31 // GNS record types
32 GNS_TYPE_ANY = 0 // Record type indicating any record/'*'
33 GNS_TYPE_DNS_A = 1 // [RFC1035] IPv4 Address record
34 GNS_TYPE_DNS_NS = 2 // [RFC1035] Name Server record
35 GNS_TYPE_DNS_CNAME = 5 // [RFC1035] Canonical Name record
36 GNS_TYPE_DNS_SOA = 6 // [RFC2308] Start Of [a zone of] Authority
37 GNS_TYPE_DNS_PTR = 12 // [RFC1035] Pointer record
38 GNS_TYPE_DNS_MX = 15 // [RFC7505] Mail eXchange record
39 GNS_TYPE_DNS_TXT = 16 // [RFC1035] Text record
40 GNS_TYPE_DNS_RP = 17 // [RFC1183] Responsible Person
41 GNS_TYPE_DNS_AFSDB = 18 // [RFC1183] AFS Database Record
42 GNS_TYPE_DNS_SIG = 24 // [RFC2535] Signature
43 GNS_TYPE_DNS_KEY = 25 // [RFC2930] Key record
44 GNS_TYPE_DNS_AAAA = 28 // [RFC3596] IPv6 Address record
45 GNS_TYPE_DNS_LOC = 29 // [RFC1876] Location record
46 GNS_TYPE_DNS_SRV = 33 // [RFC2782] Service locator
47 GNS_TYPE_DNS_NAPTR = 35 // [RFC3403] Naming Authority Pointer
48 GNS_TYPE_DNS_KX = 36 // [RFC2230] Key eXchanger record
49 GNS_TYPE_DNS_CERT = 37 // [RFC4398] Certificate record
50 GNS_TYPE_DNS_DNAME = 39 // [RFC2672] Delegation Name
51 GNS_TYPE_DNS_APL = 42 // [RFC3123] Address Prefix List
52 GNS_TYPE_DNS_DS = 43 // [RFC4034] Delegation Signer
53 GNS_TYPE_DNS_SSHFP = 44 // [RFC4255] SSH public key Fingerprint
54 GNS_TYPE_DNS_IPSECKEY = 45 // [RFC4025] IPsec Key
55 GNS_TYPE_DNS_RRSIG = 46 // [RFC4034] DNSSEC Signature
56 GNS_TYPE_DNS_NSEC = 47 // [RFC4034] Next-Secure record
57 GNS_TYPE_DNS_DNSKEY = 48 // [RFC4034] DNS Key record
58 GNS_TYPE_DNS_DHCID = 49 // [RFC4701] DHCP Identifier
59 GNS_TYPE_DNS_NSEC3 = 50 // [RFC5155] NSEC record version 3 or NSEC hashed
60 GNS_TYPE_DNS_NSEC3PARAM = 51 // [RFC5155] NSEC3 Parameters
61 GNS_TYPE_DNS_TLSA = 52 // [RFC6698] TLSA certificate association
62 GNS_TYPE_DNS_HIP = 55 // [RFC5205] Host Identity Protocol
63 GNS_TYPE_DNS_CDS = 59 // [RFC7344] Child DS
64 GNS_TYPE_DNS_CDNSKEY = 60 // [RFC7344] Child DNSKEY
65 GNS_TYPE_DNS_TKEY = 249 // [RFC2930] Secret Key
66 GNS_TYPE_DNS_TSIG = 250 // [RFC2845] Transaction Signature
67 GNS_TYPE_DNS_URI = 256 // [RFC7553] Uniform Resource Identifier
68 GNS_TYPE_DNS_CAA = 257 // [RFC6844] Certification Authority Authorization
69 GNS_TYPE_DNS_TA = 32768 // [–] DNSSEC Trust Authorities
70 GNS_TYPE_DNS_DLV = 32769 // [RFC4431] DNSSEC Lookaside Validation record
71 GNS_TYPE_PKEY = 65536 // Record type for GNS zone transfer ("PKEY").
72 GNS_TYPE_NICK = 65537 // Record type for GNS nick names ("NICK").
73 GNS_TYPE_LEHO = 65538 // Record type for GNS legacy hostnames ("LEHO").
74 GNS_TYPE_VPN = 65539 // Record type for VPN resolution
75 GNS_TYPE_GNS2DNS = 65540 // Record type for delegation to DNS.
76 GNS_TYPE_BOX = 65541 // Record type for a boxed record (see TLSA/SRV handling in GNS).
77 GNS_TYPE_PLACE = 65542 // Record type for a social place.
78 GNS_TYPE_PHONE = 65543 // Record type for a phone (of CONVERSATION).
79 GNS_TYPE_RECLAIM_ATTR = 65544 // Record type for identity attributes (of RECLAIM).
80 GNS_TYPE_RECLAIM_TICKET = 65545 // Record type for local ticket references
81 GNS_TYPE_CREDENTIAL = 65547 // Record type for credential
82 GNS_TYPE_POLICY = 65548 // Record type for policies
83 GNS_TYPE_ATTRIBUTE = 65549 // Record type for reverse lookups
84 GNS_TYPE_RECLAIM_ATTR_REF = 65550 // Record type for reclaim records
85 GNS_TYPE_RECLAIM_MASTER = 65551 // Record type for RECLAIM master
86 GNS_TYPE_RECLAIM_OIDC_CLIENT = 65552 // Record type for reclaim OIDC clients
87 GNS_TYPE_RECLAIM_OIDC_REDIRECT = 65553 // Record type for reclaim OIDC redirect URIs
88 GNS_TYPE_EDKEY = 65556 // Record type for GNS zone transfer ("EDKEY").
89
90 GNS_TYPE = map[int]string{
91 GNS_TYPE_ANY: "GNS_TYPE_ANY",
92 GNS_TYPE_DNS_A: "GNS_TYPE_DNS_A",
93 GNS_TYPE_DNS_NS: "GNS_TYPE_DNS_NS ",
94 GNS_TYPE_DNS_NS: "GNS_TYPE_DNS_NS",
95 GNS_TYPE_DNS_NS: "GNS_TYPE_DNS_NS",
96 GNS_TYPE_DNS_CNAME: "GNS_TYPE_DNS_CNAME ",
97 GNS_TYPE_DNS_NS: "GNS_TYPE_DNS_NS",
98 GNS_TYPE_DNS_CNAME: "GNS_TYPE_DNS_CNAME",
99 GNS_TYPE_DNS_CNAME: "GNS_TYPE_DNS_CNAME",
100 GNS_TYPE_DNS_SOA: "GNS_TYPE_DNS_SOA ",
101 GNS_TYPE_DNS_CNAME: "GNS_TYPE_DNS_CNAME",
102 GNS_TYPE_DNS_SOA: "GNS_TYPE_DNS_SOA",
103 GNS_TYPE_DNS_SOA: "GNS_TYPE_DNS_SOA",
104 GNS_TYPE_DNS_PTR: "GNS_TYPE_DNS_PTR ",
105 GNS_TYPE_DNS_SOA: "GNS_TYPE_DNS_SOA",
106 GNS_TYPE_DNS_PTR: "GNS_TYPE_DNS_PTR",
107 GNS_TYPE_DNS_PTR: "GNS_TYPE_DNS_PTR",
108 GNS_TYPE_DNS_MX: "GNS_TYPE_DNS_MX ",
109 GNS_TYPE_DNS_PTR: "GNS_TYPE_DNS_PTR",
110 GNS_TYPE_DNS_MX: "GNS_TYPE_DNS_MX",
111 GNS_TYPE_DNS_MX: "GNS_TYPE_DNS_MX",
112 GNS_TYPE_DNS_TXT: "GNS_TYPE_DNS_TXT ",
113 GNS_TYPE_DNS_MX: "GNS_TYPE_DNS_MX",
114 GNS_TYPE_DNS_TXT: "GNS_TYPE_DNS_TXT",
115 GNS_TYPE_DNS_TXT: "GNS_TYPE_DNS_TXT",
116 GNS_TYPE_DNS_RP: "GNS_TYPE_DNS_RP ",
117 GNS_TYPE_DNS_TXT: "GNS_TYPE_DNS_TXT",
118 GNS_TYPE_DNS_RP: "GNS_TYPE_DNS_RP",
119 GNS_TYPE_DNS_RP: "GNS_TYPE_DNS_RP",
120 GNS_TYPE_DNS_AFSDB: "GNS_TYPE_DNS_AFSDB ",
121 GNS_TYPE_DNS_RP: "GNS_TYPE_DNS_RP",
122 GNS_TYPE_DNS_AFSDB: "GNS_TYPE_DNS_AFSDB",
123 GNS_TYPE_DNS_AFSDB: "GNS_TYPE_DNS_AFSDB",
124 GNS_TYPE_DNS_SIG: "GNS_TYPE_DNS_SIG ",
125 GNS_TYPE_DNS_AFSDB: "GNS_TYPE_DNS_AFSDB",
126 GNS_TYPE_DNS_SIG: "GNS_TYPE_DNS_SIG",
127 GNS_TYPE_DNS_SIG: "GNS_TYPE_DNS_SIG",
128 GNS_TYPE_DNS_KEY: "GNS_TYPE_DNS_KEY ",
129 GNS_TYPE_DNS_SIG: "GNS_TYPE_DNS_SIG",
130 GNS_TYPE_DNS_KEY: "GNS_TYPE_DNS_KEY",
131 GNS_TYPE_DNS_KEY: "GNS_TYPE_DNS_KEY",
132 GNS_TYPE_DNS_AAAA: "GNS_TYPE_DNS_AAAA ",
133 GNS_TYPE_DNS_KEY: "GNS_TYPE_DNS_KEY",
134 GNS_TYPE_DNS_AAAA: "GNS_TYPE_DNS_AAAA",
135 GNS_TYPE_DNS_AAAA: "GNS_TYPE_DNS_AAAA",
136 GNS_TYPE_DNS_LOC: "GNS_TYPE_DNS_LOC ",
137 GNS_TYPE_DNS_AAAA: "GNS_TYPE_DNS_AAAA",
138 GNS_TYPE_DNS_LOC: "GNS_TYPE_DNS_LOC",
139 GNS_TYPE_DNS_LOC: "GNS_TYPE_DNS_LOC",
140 GNS_TYPE_DNS_SRV: "GNS_TYPE_DNS_SRV ",
141 GNS_TYPE_DNS_LOC: "GNS_TYPE_DNS_LOC",
142 GNS_TYPE_DNS_SRV: "GNS_TYPE_DNS_SRV",
143 GNS_TYPE_DNS_SRV: "GNS_TYPE_DNS_SRV",
144 GNS_TYPE_DNS_NAPTR: "GNS_TYPE_DNS_NAPTR ",
145 GNS_TYPE_DNS_SRV: "GNS_TYPE_DNS_SRV",
146 GNS_TYPE_DNS_NAPTR: "GNS_TYPE_DNS_NAPTR",
147 GNS_TYPE_DNS_NAPTR: "GNS_TYPE_DNS_NAPTR",
148 GNS_TYPE_DNS_KX: "GNS_TYPE_DNS_KX ",
149 GNS_TYPE_DNS_NAPTR: "GNS_TYPE_DNS_NAPTR",
150 GNS_TYPE_DNS_KX: "GNS_TYPE_DNS_KX",
151 GNS_TYPE_DNS_KX: "GNS_TYPE_DNS_KX",
152 GNS_TYPE_DNS_CERT: "GNS_TYPE_DNS_CERT ",
153 GNS_TYPE_DNS_KX: "GNS_TYPE_DNS_KX",
154 GNS_TYPE_DNS_CERT: "GNS_TYPE_DNS_CERT",
155 GNS_TYPE_DNS_CERT: "GNS_TYPE_DNS_CERT",
156 GNS_TYPE_DNS_DNAME: "GNS_TYPE_DNS_DNAME ",
157 GNS_TYPE_DNS_CERT: "GNS_TYPE_DNS_CERT",
158 GNS_TYPE_DNS_DNAME: "GNS_TYPE_DNS_DNAME",
159 GNS_TYPE_DNS_DNAME: "GNS_TYPE_DNS_DNAME",
160 GNS_TYPE_DNS_APL: "GNS_TYPE_DNS_APL ",
161 GNS_TYPE_DNS_DNAME: "GNS_TYPE_DNS_DNAME",
162 GNS_TYPE_DNS_APL: "GNS_TYPE_DNS_APL",
163 GNS_TYPE_DNS_APL: "GNS_TYPE_DNS_APL",
164 GNS_TYPE_DNS_DS: "GNS_TYPE_DNS_DS ",
165 GNS_TYPE_DNS_APL: "GNS_TYPE_DNS_APL",
166 GNS_TYPE_DNS_DS: "GNS_TYPE_DNS_DS",
167 GNS_TYPE_DNS_DS: "GNS_TYPE_DNS_DS",
168 GNS_TYPE_DNS_SSHFP: "GNS_TYPE_DNS_SSHFP ",
169 GNS_TYPE_DNS_DS: "GNS_TYPE_DNS_DS",
170 GNS_TYPE_DNS_SSHFP: "GNS_TYPE_DNS_SSHFP",
171 GNS_TYPE_DNS_SSHFP: "GNS_TYPE_DNS_SSHFP",
172 GNS_TYPE_DNS_IPSECKEY: "GNS_TYPE_DNS_IPSECKEY ",
173 GNS_TYPE_DNS_SSHFP: "GNS_TYPE_DNS_SSHFP",
174 GNS_TYPE_DNS_IPSECKEY: "GNS_TYPE_DNS_IPSECKEY",
175 GNS_TYPE_DNS_IPSECKEY: "GNS_TYPE_DNS_IPSECKEY",
176 GNS_TYPE_DNS_RRSIG: "GNS_TYPE_DNS_RRSIG ",
177 GNS_TYPE_DNS_IPSECKEY: "GNS_TYPE_DNS_IPSECKEY",
178 GNS_TYPE_DNS_RRSIG: "GNS_TYPE_DNS_RRSIG",
179 GNS_TYPE_DNS_RRSIG: "GNS_TYPE_DNS_RRSIG",
180 GNS_TYPE_DNS_NSEC: "GNS_TYPE_DNS_NSEC ",
181 GNS_TYPE_DNS_RRSIG: "GNS_TYPE_DNS_RRSIG",
182 GNS_TYPE_DNS_NSEC: "GNS_TYPE_DNS_NSEC",
183 GNS_TYPE_DNS_NSEC: "GNS_TYPE_DNS_NSEC",
184 GNS_TYPE_DNS_DNSKEY: "GNS_TYPE_DNS_DNSKEY ",
185 GNS_TYPE_DNS_NSEC: "GNS_TYPE_DNS_NSEC",
186 GNS_TYPE_DNS_DNSKEY: "GNS_TYPE_DNS_DNSKEY",
187 GNS_TYPE_DNS_DNSKEY: "GNS_TYPE_DNS_DNSKEY",
188 GNS_TYPE_DNS_DHCID: "GNS_TYPE_DNS_DHCID ",
189 GNS_TYPE_DNS_DNSKEY: "GNS_TYPE_DNS_DNSKEY",
190 GNS_TYPE_DNS_DHCID: "GNS_TYPE_DNS_DHCID",
191 GNS_TYPE_DNS_DHCID: "GNS_TYPE_DNS_DHCID",
192 GNS_TYPE_DNS_NSEC3: "GNS_TYPE_DNS_NSEC3 ",
193 GNS_TYPE_DNS_DHCID: "GNS_TYPE_DNS_DHCID",
194 GNS_TYPE_DNS_NSEC3: "GNS_TYPE_DNS_NSEC3",
195 GNS_TYPE_DNS_NSEC3: "GNS_TYPE_DNS_NSEC3",
196 GNS_TYPE_DNS_NSEC3PARAM: "GNS_TYPE_DNS_NSEC3PARAM ",
197 GNS_TYPE_DNS_NSEC3: "GNS_TYPE_DNS_NSEC3",
198 GNS_TYPE_DNS_NSEC3PARAM: "GNS_TYPE_DNS_NSEC3PARAM",
199 GNS_TYPE_DNS_NSEC3PARAM: "GNS_TYPE_DNS_NSEC3PARAM",
200 GNS_TYPE_DNS_TLSA: "GNS_TYPE_DNS_TLSA ",
201 GNS_TYPE_DNS_NSEC3PARAM: "GNS_TYPE_DNS_NSEC3PARAM",
202 GNS_TYPE_DNS_TLSA: "GNS_TYPE_DNS_TLSA",
203 GNS_TYPE_DNS_TLSA: "GNS_TYPE_DNS_TLSA",
204 GNS_TYPE_DNS_HIP: "GNS_TYPE_DNS_HIP ",
205 GNS_TYPE_DNS_TLSA: "GNS_TYPE_DNS_TLSA",
206 GNS_TYPE_DNS_HIP: "GNS_TYPE_DNS_HIP",
207 GNS_TYPE_DNS_HIP: "GNS_TYPE_DNS_HIP",
208 GNS_TYPE_DNS_CDS: "GNS_TYPE_DNS_CDS ",
209 GNS_TYPE_DNS_HIP: "GNS_TYPE_DNS_HIP",
210 GNS_TYPE_DNS_CDS: "GNS_TYPE_DNS_CDS",
211 GNS_TYPE_DNS_CDS: "GNS_TYPE_DNS_CDS",
212 GNS_TYPE_DNS_CDNSKEY: "GNS_TYPE_DNS_CDNSKEY ",
213 GNS_TYPE_DNS_CDS: "GNS_TYPE_DNS_CDS",
214 GNS_TYPE_DNS_CDNSKEY: "GNS_TYPE_DNS_CDNSKEY",
215 GNS_TYPE_DNS_CDNSKEY: "GNS_TYPE_DNS_CDNSKEY",
216 GNS_TYPE_DNS_TKEY: "GNS_TYPE_DNS_TKEY ",
217 GNS_TYPE_DNS_CDNSKEY: "GNS_TYPE_DNS_CDNSKEY",
218 GNS_TYPE_DNS_TKEY: "GNS_TYPE_DNS_TKEY",
219 GNS_TYPE_DNS_TKEY: "GNS_TYPE_DNS_TKEY",
220 GNS_TYPE_DNS_TSIG: "GNS_TYPE_DNS_TSIG ",
221 GNS_TYPE_DNS_TKEY: "GNS_TYPE_DNS_TKEY",
222 GNS_TYPE_DNS_TSIG: "GNS_TYPE_DNS_TSIG",
223 GNS_TYPE_DNS_TSIG: "GNS_TYPE_DNS_TSIG",
224 GNS_TYPE_DNS_URI: "GNS_TYPE_DNS_URI ",
225 GNS_TYPE_DNS_TSIG: "GNS_TYPE_DNS_TSIG",
226 GNS_TYPE_DNS_URI: "GNS_TYPE_DNS_URI",
227 GNS_TYPE_DNS_URI: "GNS_TYPE_DNS_URI",
228 GNS_TYPE_DNS_CAA: "GNS_TYPE_DNS_CAA ",
229 GNS_TYPE_DNS_URI: "GNS_TYPE_DNS_URI",
230 GNS_TYPE_DNS_CAA: "GNS_TYPE_DNS_CAA",
231 GNS_TYPE_DNS_CAA: "GNS_TYPE_DNS_CAA",
232 GNS_TYPE_DNS_TA: "GNS_TYPE_DNS_TA ",
233 GNS_TYPE_DNS_CAA: "GNS_TYPE_DNS_CAA",
234 GNS_TYPE_DNS_TA: "GNS_TYPE_DNS_TA",
235 GNS_TYPE_DNS_TA: "GNS_TYPE_DNS_TA",
236 GNS_TYPE_DNS_DLV: "GNS_TYPE_DNS_DLV ",
237 GNS_TYPE_DNS_TA: "GNS_TYPE_DNS_TA",
238 GNS_TYPE_DNS_DLV: "GNS_TYPE_DNS_DLV",
239 GNS_TYPE_DNS_DLV: "GNS_TYPE_DNS_DLV",
240 GNS_TYPE_PKEY: "GNS_TYPE_PKEY ",
241 GNS_TYPE_DNS_DLV: "GNS_TYPE_DNS_DLV",
242 GNS_TYPE_PKEY: "GNS_TYPE_PKEY",
243 GNS_TYPE_PKEY: "GNS_TYPE_PKEY",
244 GNS_TYPE_NICK: "GNS_TYPE_NICK ",
245 GNS_TYPE_PKEY: "GNS_TYPE_PKEY",
246 GNS_TYPE_NICK: "GNS_TYPE_NICK",
247 GNS_TYPE_NICK: "GNS_TYPE_NICK",
248 GNS_TYPE_LEHO: "GNS_TYPE_LEHO ",
249 GNS_TYPE_NICK: "GNS_TYPE_NICK",
250 GNS_TYPE_LEHO: "GNS_TYPE_LEHO",
251 GNS_TYPE_LEHO: "GNS_TYPE_LEHO",
252 GNS_TYPE_VPN: "GNS_TYPE_VPN ",
253 GNS_TYPE_LEHO: "GNS_TYPE_LEHO",
254 GNS_TYPE_VPN: "GNS_TYPE_VPN",
255 GNS_TYPE_VPN: "GNS_TYPE_VPN",
256 GNS_TYPE_GNS2DNS: "GNS_TYPE_GNS2DNS ",
257 GNS_TYPE_VPN: "GNS_TYPE_VPN",
258 GNS_TYPE_GNS2DNS: "GNS_TYPE_GNS2DNS",
259 GNS_TYPE_GNS2DNS: "GNS_TYPE_GNS2DNS",
260 GNS_TYPE_BOX: "GNS_TYPE_BOX ",
261 GNS_TYPE_GNS2DNS: "GNS_TYPE_GNS2DNS",
262 GNS_TYPE_BOX: "GNS_TYPE_BOX",
263 GNS_TYPE_BOX: "GNS_TYPE_BOX",
264 GNS_TYPE_PLACE: "GNS_TYPE_PLACE ",
265 GNS_TYPE_BOX: "GNS_TYPE_BOX",
266 GNS_TYPE_PLACE: "GNS_TYPE_PLACE",
267 GNS_TYPE_PLACE: "GNS_TYPE_PLACE",
268 GNS_TYPE_PHONE: "GNS_TYPE_PHONE ",
269 GNS_TYPE_PLACE: "GNS_TYPE_PLACE",
270 GNS_TYPE_PHONE: "GNS_TYPE_PHONE",
271 GNS_TYPE_PHONE: "GNS_TYPE_PHONE",
272 GNS_TYPE_RECLAIM_ATTR: "GNS_TYPE_RECLAIM_ATTR ",
273 GNS_TYPE_PHONE: "GNS_TYPE_PHONE",
274 GNS_TYPE_RECLAIM_ATTR: "GNS_TYPE_RECLAIM_ATTR",
275 GNS_TYPE_RECLAIM_ATTR: "GNS_TYPE_RECLAIM_ATTR",
276 GNS_TYPE_RECLAIM_TICKET: "GNS_TYPE_RECLAIM_TICKET ",
277 GNS_TYPE_RECLAIM_ATTR: "GNS_TYPE_RECLAIM_ATTR",
278 GNS_TYPE_RECLAIM_TICKET: "GNS_TYPE_RECLAIM_TICKET",
279 GNS_TYPE_RECLAIM_TICKET: "GNS_TYPE_RECLAIM_TICKET",
280 GNS_TYPE_CREDENTIAL: "GNS_TYPE_CREDENTIAL ",
281 GNS_TYPE_RECLAIM_TICKET: "GNS_TYPE_RECLAIM_TICKET",
282 GNS_TYPE_CREDENTIAL: "GNS_TYPE_CREDENTIAL",
283 GNS_TYPE_CREDENTIAL: "GNS_TYPE_CREDENTIAL",
284 GNS_TYPE_POLICY: "GNS_TYPE_POLICY ",
285 GNS_TYPE_CREDENTIAL: "GNS_TYPE_CREDENTIAL",
286 GNS_TYPE_POLICY: "GNS_TYPE_POLICY",
287 GNS_TYPE_POLICY: "GNS_TYPE_POLICY",
288 GNS_TYPE_ATTRIBUTE: "GNS_TYPE_ATTRIBUTE ",
289 GNS_TYPE_POLICY: "GNS_TYPE_POLICY",
290 GNS_TYPE_ATTRIBUTE: "GNS_TYPE_ATTRIBUTE",
291 GNS_TYPE_ATTRIBUTE: "GNS_TYPE_ATTRIBUTE",
292 GNS_TYPE_RECLAIM_ATTR_REF: "GNS_TYPE_RECLAIM_ATTR_REF ",
293 GNS_TYPE_ATTRIBUTE: "GNS_TYPE_ATTRIBUTE",
294 GNS_TYPE_RECLAIM_ATTR_REF: "GNS_TYPE_RECLAIM_ATTR_REF",
295 GNS_TYPE_RECLAIM_ATTR_REF: "GNS_TYPE_RECLAIM_ATTR_REF",
296 GNS_TYPE_RECLAIM_MASTER: "GNS_TYPE_RECLAIM_MASTER ",
297 GNS_TYPE_RECLAIM_ATTR_REF: "GNS_TYPE_RECLAIM_ATTR_REF",
298 GNS_TYPE_RECLAIM_MASTER: "GNS_TYPE_RECLAIM_MASTER",
299 GNS_TYPE_RECLAIM_MASTER: "GNS_TYPE_RECLAIM_MASTER",
300 GNS_TYPE_RECLAIM_OIDC_CLIENT: "GNS_TYPE_RECLAIM_OIDC_CLIENT ",
301 GNS_TYPE_RECLAIM_MASTER: "GNS_TYPE_RECLAIM_MASTER",
302 GNS_TYPE_RECLAIM_OIDC_CLIENT: "GNS_TYPE_RECLAIM_OIDC_CLIENT",
303 GNS_TYPE_RECLAIM_OIDC_CLIENT: "GNS_TYPE_RECLAIM_OIDC_CLIENT",
304 GNS_TYPE_RECLAIM_OIDC_REDIRECT: "GNS_TYPE_RECLAIM_OIDC_REDIRECT ",
305 GNS_TYPE_RECLAIM_OIDC_CLIENT: "GNS_TYPE_RECLAIM_OIDC_CLIENT",
306 GNS_TYPE_RECLAIM_OIDC_REDIRECT: "GNS_TYPE_RECLAIM_OIDC_REDIRECT",
307 }
308
309 // GNS_LocalOptions 28 // GNS_LocalOptions
310 GNS_LO_DEFAULT = 0 // Defaults, look in cache, then in DHT. 29 GNS_LO_DEFAULT = 0 // Defaults, look in cache, then in DHT.
311 GNS_LO_NO_DHT = 1 // Never look in the DHT, keep request to local cache. 30 GNS_LO_NO_DHT = 1 // Never look in the DHT, keep request to local cache.
312 GNS_LO_LOCAL_MASTER = 2 // For the rightmost label, only look in the cache. 31 GNS_LO_LOCAL_MASTER = 2 // For the rightmost label, only look in the cache.
32
33 GNS_MAX_BLOCK_SIZE = (63 * 1024) // Maximum size of a value that can be stored in a GNS block.
313) 34)
35
36//go:generate go run generate.go gnunet-gns.rec gnunet-gns.tpl gns_type.go
37
38//go:generate stringer -type=GNSType gns_type.go
diff --git a/src/gnunet/enums/gns_type.go b/src/gnunet/enums/gns_type.go
new file mode 100644
index 0000000..2b55817
--- /dev/null
+++ b/src/gnunet/enums/gns_type.go
@@ -0,0 +1,72 @@
1// Code generated by enum generator; DO NOT EDIT.
2
3package enums
4
5type GNSType int
6
7// GNS constants
8const (
9 // GNS record types
10 GNS_TYPE_ANY GNSType = 0 // Record type indicating any record/'*'
11 GNS_TYPE_DNS_A GNSType = 1 // [RFC1035] IPv4 Address record
12 GNS_TYPE_DNS_NS GNSType = 2 // [RFC1035] Name Server record
13 GNS_TYPE_DNS_CNAME GNSType = 5 // [RFC1035] Canonical Name record
14 GNS_TYPE_DNS_SOA GNSType = 6 // [RFC2308] Start Of [a zone of] Authority
15 GNS_TYPE_DNS_PTR GNSType = 12 // [RFC1035] Pointer record
16 GNS_TYPE_DNS_MX GNSType = 15 // [RFC7505] Mail eXchange record
17 GNS_TYPE_DNS_TXT GNSType = 16 // [RFC1035] Text record
18 GNS_TYPE_DNS_RP GNSType = 17 // [RFC1183] Responsible Person
19 GNS_TYPE_DNS_AFSDB GNSType = 18 // [RFC1183] AFS Database Record
20 GNS_TYPE_DNS_SIG GNSType = 24 // [RFC2535] Signature
21 GNS_TYPE_DNS_KEY GNSType = 25 // [RFC2930] Key record
22 GNS_TYPE_DNS_AAAA GNSType = 28 // [RFC3596] IPv6 Address record
23 GNS_TYPE_DNS_LOC GNSType = 29 // [RFC1876] Location record
24 GNS_TYPE_DNS_SRV GNSType = 33 // [RFC2782] Service locator
25 GNS_TYPE_DNS_NAPTR GNSType = 35 // [RFC3403] Naming Authority Pointer
26 GNS_TYPE_DNS_KX GNSType = 36 // [RFC2230] Key eXchanger record
27 GNS_TYPE_DNS_CERT GNSType = 37 // [RFC4398] Certificate record
28 GNS_TYPE_DNS_DNAME GNSType = 39 // [RFC2672] Delegation Name
29 GNS_TYPE_DNS_APL GNSType = 42 // [RFC3123] Address Prefix List
30 GNS_TYPE_DNS_DS GNSType = 43 // [RFC4034] Delegation Signer
31 GNS_TYPE_DNS_SSHFP GNSType = 44 // [RFC4255] SSH public key Fingerprint
32 GNS_TYPE_DNS_IPSECKEY GNSType = 45 // [RFC4025] IPsec Key
33 GNS_TYPE_DNS_RRSIG GNSType = 46 // [RFC4034] DNSSEC Signature
34 GNS_TYPE_DNS_NSEC GNSType = 47 // [RFC4034] Next-Secure record
35 GNS_TYPE_DNS_DNSKEY GNSType = 48 // [RFC4034] DNS Key record
36 GNS_TYPE_DNS_DHCID GNSType = 49 // [RFC4701] DHCP Identifier
37 GNS_TYPE_DNS_NSEC3 GNSType = 50 // [RFC5155] NSEC record version 3 or NSEC hashed
38 GNS_TYPE_DNS_NSEC3PARAM GNSType = 51 // [RFC5155] NSEC3 Parameters
39 GNS_TYPE_DNS_TLSA GNSType = 52 // [RFC6698] TLSA certificate association
40 GNS_TYPE_DNS_HIP GNSType = 55 // [RFC5205] Host Identity Protocol
41 GNS_TYPE_DNS_CDS GNSType = 59 // [RFC7344] Child DS
42 GNS_TYPE_DNS_CDNSKEY GNSType = 60 // [RFC7344] Child DNSKEY
43 GNS_TYPE_DNS_TKEY GNSType = 249 // [RFC2930] Secret Key
44 GNS_TYPE_DNS_TSIG GNSType = 250 // [RFC2845] Transaction Signature
45 GNS_TYPE_DNS_URI GNSType = 256 // [RFC7553] Uniform Resource Identifier
46 GNS_TYPE_DNS_CAA GNSType = 257 // [RFC6844] Certification Authority Authorization
47 GNS_TYPE_DNS_TA GNSType = 32768 // [–] DNSSEC Trust Authorities
48 GNS_TYPE_DNS_DLV GNSType = 32769 // [RFC4431] DNSSEC Lookaside Validation record
49GNS_TYPE_PKEY GNSType = 65536 // GNS zone transfer
50GNS_TYPE_NICK GNSType = 65537 // GNS nick names
51GNS_TYPE_LEHO GNSType = 65538 // legacy hostnames
52GNS_TYPE_VPN GNSType = 65539 // VPN resolution
53GNS_TYPE_GNS2DNS GNSType = 65540 // Delegation to DNS
54GNS_TYPE_BOX GNSType = 65541 // Boxed records (see TLSA/SRV handling in GNS)
55GNS_TYPE_PLACE GNSType = 65542 // social place for SecuShare
56GNS_TYPE_PHONE GNSType = 65543 // Endpoint for conversation
57GNS_TYPE_RECLAIM_ATTRIBUTE GNSType = 65544 // identity attribute
58GNS_TYPE_RECLAIM_TICKET GNSType = 65545 // local ticket reference
59GNS_TYPE_DELEGATE GNSType = 65548 // For ABD policies
60GNS_TYPE_ATTRIBUTE GNSType = 65549 // For ABD reverse lookups
61GNS_TYPE_RECLAIM_ATTRIBUTE_REF GNSType = 65550 // for reclaim records
62GNS_TYPE_REDIRECT GNSType = 65551 // Resolver redirects
63GNS_TYPE_RECLAIM_OIDC_CLIENT GNSType = 65552 // For reclaim OIDC client names.
64GNS_TYPE_RECLAIM_OIDC_REDIRECT GNSType = 65553 // Used reclaimID OIDC client redirect URIs.
65GNS_TYPE_RECLAIM_CREDENTIAL GNSType = 65554 // Record type for an attribute attestation (e.g. JWT).
66GNS_TYPE_RECLAIM_PRESENTATION GNSType = 65555 // Record type for a presentation of a credential.
67GNS_TYPE_EDKEY GNSType = 65556 // Record type for EDKEY zone delegations.
68GNS_TYPE_ERIS_READ_CAPABILITY GNSType = 65557 // Encoding for Robust Immutable Storage (ERIS) binary read capability
69GNS_TYPE_MESSENGER_ROOM_ENTRY GNSType = 65558 // Record type to share an entry of a messenger room
70GNS_TYPE_TOMBSTONE GNSType = 65559 // Record type to indicate a previously delete record (PRIVATE only)
71
72)
diff --git a/src/gnunet/enums/gnstype_string.go b/src/gnunet/enums/gnstype_string.go
new file mode 100644
index 0000000..1a55f01
--- /dev/null
+++ b/src/gnunet/enums/gnstype_string.go
@@ -0,0 +1,145 @@
1// Code generated by "stringer -type=GNSType gns_type.go"; DO NOT EDIT.
2
3package enums
4
5import "strconv"
6
7func _() {
8 // An "invalid array index" compiler error signifies that the constant values have changed.
9 // Re-run the stringer command to generate them again.
10 var x [1]struct{}
11 _ = x[GNS_TYPE_ANY-0]
12 _ = x[GNS_TYPE_DNS_A-1]
13 _ = x[GNS_TYPE_DNS_NS-2]
14 _ = x[GNS_TYPE_DNS_CNAME-5]
15 _ = x[GNS_TYPE_DNS_SOA-6]
16 _ = x[GNS_TYPE_DNS_PTR-12]
17 _ = x[GNS_TYPE_DNS_MX-15]
18 _ = x[GNS_TYPE_DNS_TXT-16]
19 _ = x[GNS_TYPE_DNS_RP-17]
20 _ = x[GNS_TYPE_DNS_AFSDB-18]
21 _ = x[GNS_TYPE_DNS_SIG-24]
22 _ = x[GNS_TYPE_DNS_KEY-25]
23 _ = x[GNS_TYPE_DNS_AAAA-28]
24 _ = x[GNS_TYPE_DNS_LOC-29]
25 _ = x[GNS_TYPE_DNS_SRV-33]
26 _ = x[GNS_TYPE_DNS_NAPTR-35]
27 _ = x[GNS_TYPE_DNS_KX-36]
28 _ = x[GNS_TYPE_DNS_CERT-37]
29 _ = x[GNS_TYPE_DNS_DNAME-39]
30 _ = x[GNS_TYPE_DNS_APL-42]
31 _ = x[GNS_TYPE_DNS_DS-43]
32 _ = x[GNS_TYPE_DNS_SSHFP-44]
33 _ = x[GNS_TYPE_DNS_IPSECKEY-45]
34 _ = x[GNS_TYPE_DNS_RRSIG-46]
35 _ = x[GNS_TYPE_DNS_NSEC-47]
36 _ = x[GNS_TYPE_DNS_DNSKEY-48]
37 _ = x[GNS_TYPE_DNS_DHCID-49]
38 _ = x[GNS_TYPE_DNS_NSEC3-50]
39 _ = x[GNS_TYPE_DNS_NSEC3PARAM-51]
40 _ = x[GNS_TYPE_DNS_TLSA-52]
41 _ = x[GNS_TYPE_DNS_HIP-55]
42 _ = x[GNS_TYPE_DNS_CDS-59]
43 _ = x[GNS_TYPE_DNS_CDNSKEY-60]
44 _ = x[GNS_TYPE_DNS_TKEY-249]
45 _ = x[GNS_TYPE_DNS_TSIG-250]
46 _ = x[GNS_TYPE_DNS_URI-256]
47 _ = x[GNS_TYPE_DNS_CAA-257]
48 _ = x[GNS_TYPE_DNS_TA-32768]
49 _ = x[GNS_TYPE_DNS_DLV-32769]
50 _ = x[GNS_TYPE_PKEY-65536]
51 _ = x[GNS_TYPE_NICK-65537]
52 _ = x[GNS_TYPE_LEHO-65538]
53 _ = x[GNS_TYPE_VPN-65539]
54 _ = x[GNS_TYPE_GNS2DNS-65540]
55 _ = x[GNS_TYPE_BOX-65541]
56 _ = x[GNS_TYPE_PLACE-65542]
57 _ = x[GNS_TYPE_PHONE-65543]
58 _ = x[GNS_TYPE_RECLAIM_ATTRIBUTE-65544]
59 _ = x[GNS_TYPE_RECLAIM_TICKET-65545]
60 _ = x[GNS_TYPE_DELEGATE-65548]
61 _ = x[GNS_TYPE_ATTRIBUTE-65549]
62 _ = x[GNS_TYPE_RECLAIM_ATTRIBUTE_REF-65550]
63 _ = x[GNS_TYPE_REDIRECT-65551]
64 _ = x[GNS_TYPE_RECLAIM_OIDC_CLIENT-65552]
65 _ = x[GNS_TYPE_RECLAIM_OIDC_REDIRECT-65553]
66 _ = x[GNS_TYPE_RECLAIM_CREDENTIAL-65554]
67 _ = x[GNS_TYPE_RECLAIM_PRESENTATION-65555]
68 _ = x[GNS_TYPE_EDKEY-65556]
69 _ = x[GNS_TYPE_ERIS_READ_CAPABILITY-65557]
70 _ = x[GNS_TYPE_MESSENGER_ROOM_ENTRY-65558]
71 _ = x[GNS_TYPE_TOMBSTONE-65559]
72}
73
74const _GNSType_name = "GNS_TYPE_ANYGNS_TYPE_DNS_AGNS_TYPE_DNS_NSGNS_TYPE_DNS_CNAMEGNS_TYPE_DNS_SOAGNS_TYPE_DNS_PTRGNS_TYPE_DNS_MXGNS_TYPE_DNS_TXTGNS_TYPE_DNS_RPGNS_TYPE_DNS_AFSDBGNS_TYPE_DNS_SIGGNS_TYPE_DNS_KEYGNS_TYPE_DNS_AAAAGNS_TYPE_DNS_LOCGNS_TYPE_DNS_SRVGNS_TYPE_DNS_NAPTRGNS_TYPE_DNS_KXGNS_TYPE_DNS_CERTGNS_TYPE_DNS_DNAMEGNS_TYPE_DNS_APLGNS_TYPE_DNS_DSGNS_TYPE_DNS_SSHFPGNS_TYPE_DNS_IPSECKEYGNS_TYPE_DNS_RRSIGGNS_TYPE_DNS_NSECGNS_TYPE_DNS_DNSKEYGNS_TYPE_DNS_DHCIDGNS_TYPE_DNS_NSEC3GNS_TYPE_DNS_NSEC3PARAMGNS_TYPE_DNS_TLSAGNS_TYPE_DNS_HIPGNS_TYPE_DNS_CDSGNS_TYPE_DNS_CDNSKEYGNS_TYPE_DNS_TKEYGNS_TYPE_DNS_TSIGGNS_TYPE_DNS_URIGNS_TYPE_DNS_CAAGNS_TYPE_DNS_TAGNS_TYPE_DNS_DLVGNS_TYPE_PKEYGNS_TYPE_NICKGNS_TYPE_LEHOGNS_TYPE_VPNGNS_TYPE_GNS2DNSGNS_TYPE_BOXGNS_TYPE_PLACEGNS_TYPE_PHONEGNS_TYPE_RECLAIM_ATTRIBUTEGNS_TYPE_RECLAIM_TICKETGNS_TYPE_DELEGATEGNS_TYPE_ATTRIBUTEGNS_TYPE_RECLAIM_ATTRIBUTE_REFGNS_TYPE_REDIRECTGNS_TYPE_RECLAIM_OIDC_CLIENTGNS_TYPE_RECLAIM_OIDC_REDIRECTGNS_TYPE_RECLAIM_CREDENTIALGNS_TYPE_RECLAIM_PRESENTATIONGNS_TYPE_EDKEYGNS_TYPE_ERIS_READ_CAPABILITYGNS_TYPE_MESSENGER_ROOM_ENTRYGNS_TYPE_TOMBSTONE"
75
76var _GNSType_map = map[GNSType]string{
77 0: _GNSType_name[0:12],
78 1: _GNSType_name[12:26],
79 2: _GNSType_name[26:41],
80 5: _GNSType_name[41:59],
81 6: _GNSType_name[59:75],
82 12: _GNSType_name[75:91],
83 15: _GNSType_name[91:106],
84 16: _GNSType_name[106:122],
85 17: _GNSType_name[122:137],
86 18: _GNSType_name[137:155],
87 24: _GNSType_name[155:171],
88 25: _GNSType_name[171:187],
89 28: _GNSType_name[187:204],
90 29: _GNSType_name[204:220],
91 33: _GNSType_name[220:236],
92 35: _GNSType_name[236:254],
93 36: _GNSType_name[254:269],
94 37: _GNSType_name[269:286],
95 39: _GNSType_name[286:304],
96 42: _GNSType_name[304:320],
97 43: _GNSType_name[320:335],
98 44: _GNSType_name[335:353],
99 45: _GNSType_name[353:374],
100 46: _GNSType_name[374:392],
101 47: _GNSType_name[392:409],
102 48: _GNSType_name[409:428],
103 49: _GNSType_name[428:446],
104 50: _GNSType_name[446:464],
105 51: _GNSType_name[464:487],
106 52: _GNSType_name[487:504],
107 55: _GNSType_name[504:520],
108 59: _GNSType_name[520:536],
109 60: _GNSType_name[536:556],
110 249: _GNSType_name[556:573],
111 250: _GNSType_name[573:590],
112 256: _GNSType_name[590:606],
113 257: _GNSType_name[606:622],
114 32768: _GNSType_name[622:637],
115 32769: _GNSType_name[637:653],
116 65536: _GNSType_name[653:666],
117 65537: _GNSType_name[666:679],
118 65538: _GNSType_name[679:692],
119 65539: _GNSType_name[692:704],
120 65540: _GNSType_name[704:720],
121 65541: _GNSType_name[720:732],
122 65542: _GNSType_name[732:746],
123 65543: _GNSType_name[746:760],
124 65544: _GNSType_name[760:786],
125 65545: _GNSType_name[786:809],
126 65548: _GNSType_name[809:826],
127 65549: _GNSType_name[826:844],
128 65550: _GNSType_name[844:874],
129 65551: _GNSType_name[874:891],
130 65552: _GNSType_name[891:919],
131 65553: _GNSType_name[919:949],
132 65554: _GNSType_name[949:976],
133 65555: _GNSType_name[976:1005],
134 65556: _GNSType_name[1005:1019],
135 65557: _GNSType_name[1019:1048],
136 65558: _GNSType_name[1048:1077],
137 65559: _GNSType_name[1077:1095],
138}
139
140func (i GNSType) String() string {
141 if str, ok := _GNSType_map[i]; ok {
142 return str
143 }
144 return "GNSType(" + strconv.FormatInt(int64(i), 10) + ")"
145}
diff --git a/src/gnunet/enums/gnunet-dht.rec b/src/gnunet/enums/gnunet-dht.rec
new file mode 100644
index 0000000..e2366d3
--- /dev/null
+++ b/src/gnunet/enums/gnunet-dht.rec
@@ -0,0 +1,102 @@
1# -*- mode: rec -*-
2#
3# Registry for GNU Name System record types
4#
5
6%rec: BlockType
7%key: Number
8%type: Number int
9%mandatory: Number
10%typedef: Name_t regexp /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-]*$/
11%type: Name Name_t
12%unique: Name
13%mandatory: Name
14%mandatory: Comment
15%allowed: Contact
16%allowed: References
17%sort: Number Name Contact References
18
19Number: 0
20Name: ANY
21Comment: Identifier for any block.
22References: None
23
24Number: 1
25Name: FS_DBLOCK
26Comment: Data block (leaf) in the CHK tree.
27References: None
28
29Number: 2
30Name: FS_IBLOCK
31Comment: Inner block in the CHK tree.
32References: None
33
34Number: 6
35Name: FS_ONDEMAND
36Comment: Type of a block representing a block to be encoded on demand from disk. Should never appear on the network directly.
37References: None
38
39Number: 7
40Name: DHT_HELLO
41Comment: Type of a block that contains a HELLO for a peer.
42References: None
43
44Number: 8
45Name: TEST
46Comment: Block for testing.
47References: None
48
49Number: 9
50Name: FS_UBLOCK
51Comment: Type of a block representing any type of search result (universal).
52References: None
53
54Number: 10
55Name: DNS
56Comment: Block for storing DNS exit service advertisements.
57References: None
58
59Number: 11
60Name: GNS_NAMERECORD
61Comment: Block for storing GNS record data.
62References: None
63
64Number: 12
65Name: REVOCATION
66Comment: Block type for a revocation message by which a key is revoked.
67References: None
68
69Number: 13
70Name: DHT_URL_HELLO
71Comment: Type of a block that contains a DHT-NG HELLO for a peer.
72References: None
73
74Number: 22
75Name: REGEX
76Comment: Block to store a cadet regex state
77References: None
78
79Number: 23
80Name: REGEX_ACCEPT
81Comment: Block to store a cadet regex accepting state
82References: None
83
84Number: 24
85Name: SET_TEST
86Comment: Block for testing set/consensus. If first byte of the block is non-zero, the block is considered invalid.
87References: None
88
89Number: 25
90Name: CONSENSUS_ELEMENT
91Comment: Block type for consensus elements. Contains either special marker elements or a nested block.
92References: None
93
94Number: 26
95Name: SETI_TEST
96Comment: Block for testing set intersection. If first byte of the block is non-zero, the block is considered invalid.
97References: None
98
99Number: 27
100Name: SETU_TEST
101Comment: Block for testing set union. If first byte of the block is non-zero, the block is considered invalid.
102References: None
diff --git a/src/gnunet/enums/gnunet-dht.tpl b/src/gnunet/enums/gnunet-dht.tpl
new file mode 100644
index 0000000..0010897
--- /dev/null
+++ b/src/gnunet/enums/gnunet-dht.tpl
@@ -0,0 +1,12 @@
1// Code generated by enum generator; DO NOT EDIT.
2
3package enums
4
5type BlockType int
6
7// DHT block types
8const (
9{{ range $i, $kv := . }}BLOCK_TYPE_{{.Name}} BlockType = {{.Number}} // {{.Comment}}
10{{ end }}
11)
12
diff --git a/src/gnunet/enums/gnunet-gns.rec b/src/gnunet/enums/gnunet-gns.rec
new file mode 100644
index 0000000..8fc0c77
--- /dev/null
+++ b/src/gnunet/enums/gnunet-gns.rec
@@ -0,0 +1,132 @@
1# -*- mode: rec -*-
2#
3# Registry for GNU Name System record types
4#
5
6%rec: RecordType
7%key: Number
8%type: Number int
9%mandatory: Number
10%typedef: Name_t regexp /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-]*$/
11%type: Name Name_t
12%unique: Name
13%mandatory: Name
14%mandatory: Comment
15%allowed: Contact
16%allowed: References
17%sort: Number Name Contact References
18
19Number: 65536
20Name: PKEY
21Comment: GNS zone transfer
22References: LSD0001
23
24Number: 65537
25Name: NICK
26Comment: GNS nick names
27References: LSD0001
28
29Number: 65538
30Name: LEHO
31Comment: legacy hostnames
32References: LSD0001
33
34Number: 65539
35Name: VPN
36Comment: VPN resolution
37References: LSD0001
38
39Number: 65540
40Name: GNS2DNS
41Comment: Delegation to DNS
42References: LSD0001
43
44Number: 65541
45Name: BOX
46Comment: Boxed records (see TLSA/SRV handling in GNS)
47References: LSD0001
48
49Number: 65542
50Name: PLACE
51Comment: social place for SecuShare
52Contact: lynx@gnunet.org
53
54Number: 65543
55Name: PHONE
56Comment: Endpoint for conversation
57Contact: grothoff@gnunet.org
58
59Number: 65544
60Name: RECLAIM_ATTRIBUTE
61Comment: identity attribute
62Contact: schanzen@gnunet.org
63
64Number: 65545
65Name: RECLAIM_TICKET
66Comment: local ticket reference
67Contact: schanzen@gnunet.org
68
69Number: 65548
70Name: DELEGATE
71Comment: For ABD policies
72Contact: schanzen@gnunet.org
73
74Number: 65549
75Name: ATTRIBUTE
76Comment: For ABD reverse lookups
77Contact: schanzen@gnunet.org
78
79Number: 65550
80Name: RECLAIM_ATTRIBUTE_REF
81Comment: for reclaim records
82Contact: schanzen@gnunet.org
83
84Number: 65551
85Name: REDIRECT
86Comment: Resolver redirects
87Contact: LSD0001
88
89Number: 65552
90Name: RECLAIM_OIDC_CLIENT
91Comment: For reclaim OIDC client names.
92Contact: schanzen@gnunet.org
93
94Number: 65553
95Name: RECLAIM_OIDC_REDIRECT
96Comment: Used reclaimID OIDC client redirect URIs.
97Contact: schanzen@gnunet.org
98
99
100Number: 65554
101Name: RECLAIM_CREDENTIAL
102Comment: Record type for an attribute attestation (e.g. JWT).
103Contact: schanzen@gnunet.org
104
105Number: 65555
106Name: RECLAIM_PRESENTATION
107Comment: Record type for a presentation of a credential.
108Contact: schanzen@gnunet.org
109
110Number: 65556
111Name: EDKEY
112Comment: Record type for EDKEY zone delegations.
113
114Number: 65557
115Name: ERIS_READ_CAPABILITY
116Comment: Encoding for Robust Immutable Storage (ERIS) binary read capability
117References: http://purl.org/eris
118
119Number: 65558
120Name: MESSENGER_ROOM_ENTRY
121Comment: Record type to share an entry of a messenger room
122Contact: thejackimonster@gmail.com
123
124Number: 65559
125Name: TOMBSTONE
126Comment: Record type to indicate a previously delete record (PRIVATE only)
127Contact: gnunet-developers@gnunet.org
128
129Number: 65560
130Name: MESSENGER_ROOM_DETAILS
131Comment: Record type to store details about a messenger room
132Contact: thejackimonster@gmail.com
diff --git a/src/gnunet/enums/gnunet-gns.tpl b/src/gnunet/enums/gnunet-gns.tpl
new file mode 100644
index 0000000..075fe73
--- /dev/null
+++ b/src/gnunet/enums/gnunet-gns.tpl
@@ -0,0 +1,51 @@
1// Code generated by enum generator; DO NOT EDIT.
2
3package enums
4
5type GNSType int
6
7// GNS constants
8const (
9 // GNS record types
10 GNS_TYPE_ANY GNSType = 0 // Record type indicating any record/'*'
11 GNS_TYPE_DNS_A GNSType = 1 // [RFC1035] IPv4 Address record
12 GNS_TYPE_DNS_NS GNSType = 2 // [RFC1035] Name Server record
13 GNS_TYPE_DNS_CNAME GNSType = 5 // [RFC1035] Canonical Name record
14 GNS_TYPE_DNS_SOA GNSType = 6 // [RFC2308] Start Of [a zone of] Authority
15 GNS_TYPE_DNS_PTR GNSType = 12 // [RFC1035] Pointer record
16 GNS_TYPE_DNS_MX GNSType = 15 // [RFC7505] Mail eXchange record
17 GNS_TYPE_DNS_TXT GNSType = 16 // [RFC1035] Text record
18 GNS_TYPE_DNS_RP GNSType = 17 // [RFC1183] Responsible Person
19 GNS_TYPE_DNS_AFSDB GNSType = 18 // [RFC1183] AFS Database Record
20 GNS_TYPE_DNS_SIG GNSType = 24 // [RFC2535] Signature
21 GNS_TYPE_DNS_KEY GNSType = 25 // [RFC2930] Key record
22 GNS_TYPE_DNS_AAAA GNSType = 28 // [RFC3596] IPv6 Address record
23 GNS_TYPE_DNS_LOC GNSType = 29 // [RFC1876] Location record
24 GNS_TYPE_DNS_SRV GNSType = 33 // [RFC2782] Service locator
25 GNS_TYPE_DNS_NAPTR GNSType = 35 // [RFC3403] Naming Authority Pointer
26 GNS_TYPE_DNS_KX GNSType = 36 // [RFC2230] Key eXchanger record
27 GNS_TYPE_DNS_CERT GNSType = 37 // [RFC4398] Certificate record
28 GNS_TYPE_DNS_DNAME GNSType = 39 // [RFC2672] Delegation Name
29 GNS_TYPE_DNS_APL GNSType = 42 // [RFC3123] Address Prefix List
30 GNS_TYPE_DNS_DS GNSType = 43 // [RFC4034] Delegation Signer
31 GNS_TYPE_DNS_SSHFP GNSType = 44 // [RFC4255] SSH public key Fingerprint
32 GNS_TYPE_DNS_IPSECKEY GNSType = 45 // [RFC4025] IPsec Key
33 GNS_TYPE_DNS_RRSIG GNSType = 46 // [RFC4034] DNSSEC Signature
34 GNS_TYPE_DNS_NSEC GNSType = 47 // [RFC4034] Next-Secure record
35 GNS_TYPE_DNS_DNSKEY GNSType = 48 // [RFC4034] DNS Key record
36 GNS_TYPE_DNS_DHCID GNSType = 49 // [RFC4701] DHCP Identifier
37 GNS_TYPE_DNS_NSEC3 GNSType = 50 // [RFC5155] NSEC record version 3 or NSEC hashed
38 GNS_TYPE_DNS_NSEC3PARAM GNSType = 51 // [RFC5155] NSEC3 Parameters
39 GNS_TYPE_DNS_TLSA GNSType = 52 // [RFC6698] TLSA certificate association
40 GNS_TYPE_DNS_HIP GNSType = 55 // [RFC5205] Host Identity Protocol
41 GNS_TYPE_DNS_CDS GNSType = 59 // [RFC7344] Child DS
42 GNS_TYPE_DNS_CDNSKEY GNSType = 60 // [RFC7344] Child DNSKEY
43 GNS_TYPE_DNS_TKEY GNSType = 249 // [RFC2930] Secret Key
44 GNS_TYPE_DNS_TSIG GNSType = 250 // [RFC2845] Transaction Signature
45 GNS_TYPE_DNS_URI GNSType = 256 // [RFC7553] Uniform Resource Identifier
46 GNS_TYPE_DNS_CAA GNSType = 257 // [RFC6844] Certification Authority Authorization
47 GNS_TYPE_DNS_TA GNSType = 32768 // [–] DNSSEC Trust Authorities
48 GNS_TYPE_DNS_DLV GNSType = 32769 // [RFC4431] DNSSEC Lookaside Validation record
49{{ range $i, $kv := . }}GNS_TYPE_{{.Name}} GNSType = {{.Number}} // {{.Comment}}
50{{ end }}
51)
diff --git a/src/gnunet/enums/gnunet-signature.rec b/src/gnunet/enums/gnunet-signature.rec
new file mode 100644
index 0000000..79f9796
--- /dev/null
+++ b/src/gnunet/enums/gnunet-signature.rec
@@ -0,0 +1,183 @@
1# -*- mode: rec -*-
2#
3# Registry for GNUnet Signature purposes
4#
5
6%rec: SignaturePurpose
7%key: Number
8%type: Number int
9%mandatory: Number
10%typedef: Name_t regexp /^[ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_][ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*$/
11%type: Name Name_t
12%unique: Name
13%mandatory: Name
14%mandatory: Comment
15%allowed: Subsystem
16%sort: Number Name
17
18
19Number: 0
20Name: TEST
21Comment: Test signature, not valid for anything other than writing a test. (Note that the signature verification code will accept this value).
22Subsystem: GNUnet
23
24Number: 1
25Name: TRANSPORT_PONG_OWN
26Comment: Signature for confirming that this peer uses a particular address.
27Subsystem: GNUnet-TRANSPORT
28
29Number: 2
30Name: TRANSPORT_DISCONNECT
31Comment: Signature for confirming that this peer intends to disconnect.
32Subsystem: GNUnet-TRANSPORT
33
34Number: 3
35Name: REVOCATION
36Comment: Signature for confirming a key revocation.
37Subsystem: GNUnet-Revocation
38
39Number: 4
40Name: NAMESPACE_ADVERTISEMENT
41Comment: Signature for a namespace/pseudonym advertisement (by the namespace owner).
42Subsystem: GNUnet-FS
43
44Number: 5
45Name: PEER_PLACEMENT
46Comment: Signature by which a peer affirms that it is providing a certain bit of content for use in LOCation URIs.
47Subsystem: GNUnet-FS
48
49Number: 6
50Name: DHT_HOP
51Comment: Signature by which a peer affirms that it forwarded a message in the DHT.
52Subsystem: GNUnet-DHT
53
54Number: 7
55Name: HELLO
56Comment: Signature by which a peer affirms its address.
57Subsystem: GNUnet-HELLO
58
59
60Number: 11
61Name: DNS_RECORD
62Comment: Signature on a GNUNET_DNS_Advertisement.
63Subsystem: GNUnet-DNS+Exit
64
65Number: 12
66Name: CHAT_MESSAGE
67Comment: Signature of a chat message.
68Subsystem: GNUnet-MESSENGER
69
70Number: 13
71Name: CHAT_RECEIPT
72Comment: Signature of confirmation receipt for a chat message.
73Subsystem: GNUnet-MESSENGER
74
75Number: 14
76Name: NSE_SEND
77Comment: Signature of a network size estimate message.
78Subsystem: GNUnet-NSE
79
80Number: 15
81Name: GNS_RECORD_SIGN
82Comment: Signature of a gnunet naming system record block
83Subsystem: GNUnet-GNSRECORD
84
85Number: 16
86Name: SET_ECC_KEY
87Comment: Purpose is to set a session key.
88Subsystem: GNUnet-CORE
89
90Number: 17
91Name: FS_UBLOCK
92Comment: UBlock Signature, done using DSS, not ECC
93Subsystem: GNUnet-FS
94
95Number: 18
96Name: REGEX_ACCEPT
97Comment: Accept state in regex DFA. Peer affirms that it offers the matching service.
98Subsystem: GNUnet-REGEX
99
100Number: 20
101Name: CONVERSATION_RING
102Comment: Signature of a conversation ring.
103Subsystem: GNUnet-CONVERSATION
104
105Number: 21
106Name: SECRETSHARING_DKG1
107Comment: Signature for the first round of distributed key generation.
108Subsystem: GNUnet-SECRETSHARING
109
110Number: 22
111Name: SECRETSHARING_DKG2
112Comment: Signature for the second round of distributed key generation.
113Subsystem: GNUnet-SECRETSHARING
114
115Number: 23
116Name: SECRETSHARING_DECRYPTION
117Comment: Signature for the cooperative decryption.
118Subsystem: GNUnet-SECRETSHARING
119
120Number: 27
121Name: RECLAIM_CODE_SIGN
122Comment: Signature for a GNUid Ticket
123Subsystem: Reclaim
124
125Number: 28
126Name: DELEGATE
127Comment: Signature for a GNUnet credential
128Subsystem: Reclaim
129
130Number: 29
131Name: TRANSPORT_ADDRESS
132Comment: Signature by a peer affirming that this is one of its addresses for the given time period.
133Subsystem: GNUnet-TRANSPORT
134
135Number: 30
136Name: TRANSPORT_EPHEMERAL
137Comment: Signature by a peer affirming that the given ephemeral key is currently in use by that peer's transport service.
138Subsystem: GNUnet-TRANSPORT
139
140Number: 31
141Name: COMMUNICATOR_TCP_HANDSHAKE
142Comment: Signature used by TCP communicator handshake.
143Subsystem: GNUnet-TRANSPORT-TCP
144
145Number: 32
146Name: COMMUNICATOR_TCP_REKEY
147Comment: Signature used by TCP communicator rekey.
148Subsystem: GNUnet-TRANSPORT-TCP
149
150Number: 33
151Name: COMMUNICATOR_UDP_HANDSHAKE
152Comment: Signature used by UDP communicator handshake.
153Subsystem: GNUnet-TRANSPORT-UDP
154
155Number: 34
156Name: COMMUNICATOR_UDP_BROADCAST
157Comment: Signature used by UDP broadcasts.
158Subsystem: GNUnet-TRANSPORT-UDP
159
160Number: 35
161Name: TRANSPORT_CHALLENGE
162Comment: Signature by a peer affirming that it received a challenge (and stating how long it expects the address on which the challenge was received to remain valid).
163Subsystem: GNUnet-TRANSPORT
164
165Number: 36
166Name: TRANSPORT_DV_HOP
167Comment: Signature by a peer affirming that it is on a DV path.
168Subsystem: GNUnet-TRANSPORT
169
170Number: 37
171Name: TRANSPORT_DV_INITIATOR
172Comment: Signature by a peer affirming that it originated the DV path.
173Subsystem: GNUnet-TRANSPORT
174
175Number: 38
176Name: CADET_CONNECTION_INITIATOR
177Comment: Signature by a peer that like to create a connection.
178Subsystem: GNUnet-CADET
179
180Number: 39
181Name: COMMUNICATOR_TCP_HANDSHAKE_ACK
182Comment: Signature by a peer sending back the nonce received at initial handshake.
183Subsystem: GNUnet-TRANSPORT-TCP
diff --git a/src/gnunet/enums/gnunet-signature.tpl b/src/gnunet/enums/gnunet-signature.tpl
new file mode 100644
index 0000000..009c086
--- /dev/null
+++ b/src/gnunet/enums/gnunet-signature.tpl
@@ -0,0 +1,11 @@
1// Code generated by enum generator; DO NOT EDIT.
2
3package enums
4
5type SigPurpose int
6
7// Signature purpose values
8const (
9{{ range $i, $kv := . }}SIG_{{.Name}} SigPurpose = {{.Number}} // {{.Comment}}
10{{ end }}
11)
diff --git a/src/gnunet/enums/signature.go b/src/gnunet/enums/signature.go
index 82b00bd..0c5cd5c 100644
--- a/src/gnunet/enums/signature.go
+++ b/src/gnunet/enums/signature.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -18,35 +18,6 @@
18 18
19package enums 19package enums
20 20
21// Signature purpose constants 21//go:generate go run generate.go gnunet-signature.rec gnunet-signature.tpl signature_purpose.go
22const ( 22
23 SIG_TEST = iota // Only used in test cases! 23//go:generate stringer -type=SigPurpose signature_purpose.go
24 SIG_TRANSPORT_PONG_OWN // Confirming a particular address.
25 SIG_TRANSPORT_DISCONNECT // Confirming intent to disconnect.
26 SIG_REVOCATION // Confirming a key revocation.
27 SIG_NAMESPACE_ADVERTISEMENT // Namespace/pseudonym advertisement.
28 SIG_PEER_PLACEMENT // Affirm certain content (LOCation URIs).
29 SIG_FS_KBLOCK // Obsolete, legacy value.
30 SIG_FS_SBLOCK // Obsolete, legacy value.
31 SIG_FS_NBLOCK // Obsolete, legacy value.
32 SIG_FS_NBLOCK_KSIG // Obsolete, legacy value.
33 SIG_RESOLVER_RESPONSE // DNS_Advertisement
34 SIG_DNS_RECORD //
35 SIG_CHAT_MESSAGE // Chat message.
36 SIG_CHAT_RECEIPT // Confirmation receipt for chat message.
37 SIG_NSE_SEND // Network size estimate message.
38 SIG_GNS_RECORD_SIGN // GNS record block.
39 SIG_ECC_KEY // Set a session key.
40 SIG_FS_UBLOCK // UBlock Signature, done using DSS, not ECC.
41 SIG_REGEX_ACCEPT // Accept state (affirm matching service).
42 SIG_MULTICAST_MESSAGE // Multicast message sent by origin.
43 SIG_CONVERSATION_RING // Conversation ring.
44 SIG_SECRETSHARING_DKG1 // First round of distributed key generation.
45 SIG_SECRETSHARING_DKG2 // Second round of distributed key generation.
46 SIG_SECRETSHARING_DECRYPTION // Cooperative decryption.
47 SIG_MULTICAST_REQUEST // Multicast request sent by member.
48 SIG_SENSOR_ANOMALY_REPORT // Sensor anomaly report message.
49 SIG_GNUID_TOKEN // GNUid Token.
50 SIG_GNUID_TICKET // GNUid Ticket.
51 SIG_CREDENTIAL // GNUnet credential.
52)
diff --git a/src/gnunet/enums/signature_purpose.go b/src/gnunet/enums/signature_purpose.go
new file mode 100644
index 0000000..ad4bf0a
--- /dev/null
+++ b/src/gnunet/enums/signature_purpose.go
@@ -0,0 +1,42 @@
1// Code generated by enum generator; DO NOT EDIT.
2
3package enums
4
5type SigPurpose int
6
7// Signature purpose values
8const (
9SIG_TEST SigPurpose = 0 // Test signature, not valid for anything other than writing a test. (Note that the signature verification code will accept this value).
10SIG_TRANSPORT_PONG_OWN SigPurpose = 1 // Signature for confirming that this peer uses a particular address.
11SIG_TRANSPORT_DISCONNECT SigPurpose = 2 // Signature for confirming that this peer intends to disconnect.
12SIG_REVOCATION SigPurpose = 3 // Signature for confirming a key revocation.
13SIG_NAMESPACE_ADVERTISEMENT SigPurpose = 4 // Signature for a namespace/pseudonym advertisement (by the namespace owner).
14SIG_PEER_PLACEMENT SigPurpose = 5 // Signature by which a peer affirms that it is providing a certain bit of content for use in LOCation URIs.
15SIG_DHT_HOP SigPurpose = 6 // Signature by which a peer affirms that it forwarded a message in the DHT.
16SIG_HELLO SigPurpose = 7 // Signature by which a peer affirms its address.
17SIG_DNS_RECORD SigPurpose = 11 // Signature on a GNUNET_DNS_Advertisement.
18SIG_CHAT_MESSAGE SigPurpose = 12 // Signature of a chat message.
19SIG_CHAT_RECEIPT SigPurpose = 13 // Signature of confirmation receipt for a chat message.
20SIG_NSE_SEND SigPurpose = 14 // Signature of a network size estimate message.
21SIG_GNS_RECORD_SIGN SigPurpose = 15 // Signature of a gnunet naming system record block
22SIG_SET_ECC_KEY SigPurpose = 16 // Purpose is to set a session key.
23SIG_FS_UBLOCK SigPurpose = 17 // UBlock Signature, done using DSS, not ECC
24SIG_REGEX_ACCEPT SigPurpose = 18 // Accept state in regex DFA. Peer affirms that it offers the matching service.
25SIG_CONVERSATION_RING SigPurpose = 20 // Signature of a conversation ring.
26SIG_SECRETSHARING_DKG1 SigPurpose = 21 // Signature for the first round of distributed key generation.
27SIG_SECRETSHARING_DKG2 SigPurpose = 22 // Signature for the second round of distributed key generation.
28SIG_SECRETSHARING_DECRYPTION SigPurpose = 23 // Signature for the cooperative decryption.
29SIG_RECLAIM_CODE_SIGN SigPurpose = 27 // Signature for a GNUid Ticket
30SIG_DELEGATE SigPurpose = 28 // Signature for a GNUnet credential
31SIG_TRANSPORT_ADDRESS SigPurpose = 29 // Signature by a peer affirming that this is one of its addresses for the given time period.
32SIG_TRANSPORT_EPHEMERAL SigPurpose = 30 // Signature by a peer affirming that the given ephemeral key is currently in use by that peer's transport service.
33SIG_COMMUNICATOR_TCP_HANDSHAKE SigPurpose = 31 // Signature used by TCP communicator handshake.
34SIG_COMMUNICATOR_TCP_REKEY SigPurpose = 32 // Signature used by TCP communicator rekey.
35SIG_COMMUNICATOR_UDP_HANDSHAKE SigPurpose = 33 // Signature used by UDP communicator handshake.
36SIG_COMMUNICATOR_UDP_BROADCAST SigPurpose = 34 // Signature used by UDP broadcasts.
37SIG_TRANSPORT_CHALLENGE SigPurpose = 35 // Signature by a peer affirming that it received a challenge (and stating how long it expects the address on which the challenge was received to remain valid).
38SIG_TRANSPORT_DV_HOP SigPurpose = 36 // Signature by a peer affirming that it is on a DV path.
39SIG_TRANSPORT_DV_INITIATOR SigPurpose = 37 // Signature by a peer affirming that it originated the DV path.
40SIG_CADET_CONNECTION_INITIATOR SigPurpose = 38 // Signature by a peer that like to create a connection.
41
42)
diff --git a/src/gnunet/enums/sigpurpose_string.go b/src/gnunet/enums/sigpurpose_string.go
new file mode 100644
index 0000000..cdbdfc8
--- /dev/null
+++ b/src/gnunet/enums/sigpurpose_string.go
@@ -0,0 +1,75 @@
1// Code generated by "stringer -type=SigPurpose signature_purpose.go"; DO NOT EDIT.
2
3package enums
4
5import "strconv"
6
7func _() {
8 // An "invalid array index" compiler error signifies that the constant values have changed.
9 // Re-run the stringer command to generate them again.
10 var x [1]struct{}
11 _ = x[SIG_TEST-0]
12 _ = x[SIG_TRANSPORT_PONG_OWN-1]
13 _ = x[SIG_TRANSPORT_DISCONNECT-2]
14 _ = x[SIG_REVOCATION-3]
15 _ = x[SIG_NAMESPACE_ADVERTISEMENT-4]
16 _ = x[SIG_PEER_PLACEMENT-5]
17 _ = x[SIG_DHT_HOP-6]
18 _ = x[SIG_HELLO-7]
19 _ = x[SIG_DNS_RECORD-11]
20 _ = x[SIG_CHAT_MESSAGE-12]
21 _ = x[SIG_CHAT_RECEIPT-13]
22 _ = x[SIG_NSE_SEND-14]
23 _ = x[SIG_GNS_RECORD_SIGN-15]
24 _ = x[SIG_SET_ECC_KEY-16]
25 _ = x[SIG_FS_UBLOCK-17]
26 _ = x[SIG_REGEX_ACCEPT-18]
27 _ = x[SIG_CONVERSATION_RING-20]
28 _ = x[SIG_SECRETSHARING_DKG1-21]
29 _ = x[SIG_SECRETSHARING_DKG2-22]
30 _ = x[SIG_SECRETSHARING_DECRYPTION-23]
31 _ = x[SIG_RECLAIM_CODE_SIGN-27]
32 _ = x[SIG_DELEGATE-28]
33 _ = x[SIG_TRANSPORT_ADDRESS-29]
34 _ = x[SIG_TRANSPORT_EPHEMERAL-30]
35 _ = x[SIG_COMMUNICATOR_TCP_HANDSHAKE-31]
36 _ = x[SIG_COMMUNICATOR_TCP_REKEY-32]
37 _ = x[SIG_COMMUNICATOR_UDP_HANDSHAKE-33]
38 _ = x[SIG_COMMUNICATOR_UDP_BROADCAST-34]
39 _ = x[SIG_TRANSPORT_CHALLENGE-35]
40 _ = x[SIG_TRANSPORT_DV_HOP-36]
41 _ = x[SIG_TRANSPORT_DV_INITIATOR-37]
42 _ = x[SIG_CADET_CONNECTION_INITIATOR-38]
43}
44
45const (
46 _SigPurpose_name_0 = "SIG_TESTSIG_TRANSPORT_PONG_OWNSIG_TRANSPORT_DISCONNECTSIG_REVOCATIONSIG_NAMESPACE_ADVERTISEMENTSIG_PEER_PLACEMENTSIG_DHT_HOPSIG_HELLO"
47 _SigPurpose_name_1 = "SIG_DNS_RECORDSIG_CHAT_MESSAGESIG_CHAT_RECEIPTSIG_NSE_SENDSIG_GNS_RECORD_SIGNSIG_SET_ECC_KEYSIG_FS_UBLOCKSIG_REGEX_ACCEPT"
48 _SigPurpose_name_2 = "SIG_CONVERSATION_RINGSIG_SECRETSHARING_DKG1SIG_SECRETSHARING_DKG2SIG_SECRETSHARING_DECRYPTION"
49 _SigPurpose_name_3 = "SIG_RECLAIM_CODE_SIGNSIG_DELEGATESIG_TRANSPORT_ADDRESSSIG_TRANSPORT_EPHEMERALSIG_COMMUNICATOR_TCP_HANDSHAKESIG_COMMUNICATOR_TCP_REKEYSIG_COMMUNICATOR_UDP_HANDSHAKESIG_COMMUNICATOR_UDP_BROADCASTSIG_TRANSPORT_CHALLENGESIG_TRANSPORT_DV_HOPSIG_TRANSPORT_DV_INITIATORSIG_CADET_CONNECTION_INITIATOR"
50)
51
52var (
53 _SigPurpose_index_0 = [...]uint8{0, 8, 30, 54, 68, 95, 113, 124, 133}
54 _SigPurpose_index_1 = [...]uint8{0, 14, 30, 46, 58, 77, 92, 105, 121}
55 _SigPurpose_index_2 = [...]uint8{0, 21, 43, 65, 93}
56 _SigPurpose_index_3 = [...]uint16{0, 21, 33, 54, 77, 107, 133, 163, 193, 216, 236, 262, 292}
57)
58
59func (i SigPurpose) String() string {
60 switch {
61 case 0 <= i && i <= 7:
62 return _SigPurpose_name_0[_SigPurpose_index_0[i]:_SigPurpose_index_0[i+1]]
63 case 11 <= i && i <= 18:
64 i -= 11
65 return _SigPurpose_name_1[_SigPurpose_index_1[i]:_SigPurpose_index_1[i+1]]
66 case 20 <= i && i <= 23:
67 i -= 20
68 return _SigPurpose_name_2[_SigPurpose_index_2[i]:_SigPurpose_index_2[i+1]]
69 case 27 <= i && i <= 38:
70 i -= 27
71 return _SigPurpose_name_3[_SigPurpose_index_3[i]:_SigPurpose_index_3[i+1]]
72 default:
73 return "SigPurpose(" + strconv.FormatInt(int64(i), 10) + ")"
74 }
75}
diff --git a/src/gnunet/message/const.go b/src/gnunet/message/const.go
index b07d211..9d62bab 100644
--- a/src/gnunet/message/const.go
+++ b/src/gnunet/message/const.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/message/factory.go b/src/gnunet/message/factory.go
index 6681eae..25506dc 100644
--- a/src/gnunet/message/factory.go
+++ b/src/gnunet/message/factory.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -66,6 +66,8 @@ func NewEmptyMessage(msgType uint16) (Message, error) {
66 return NewDHTClientResultMsg(nil), nil 66 return NewDHTClientResultMsg(nil), nil
67 case DHT_CLIENT_GET_RESULTS_KNOWN: 67 case DHT_CLIENT_GET_RESULTS_KNOWN:
68 return NewDHTClientGetResultsKnownMsg(nil), nil 68 return NewDHTClientGetResultsKnownMsg(nil), nil
69 case DHT_P2P_HELLO:
70 return NewHelloDHTMsg(), nil
69 71
70 //------------------------------------------------------------------ 72 //------------------------------------------------------------------
71 // GNS 73 // GNS
diff --git a/src/gnunet/message/message.go b/src/gnunet/message/message.go
index 60e36c9..4dfa8b3 100644
--- a/src/gnunet/message/message.go
+++ b/src/gnunet/message/message.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/message/msg_core.go b/src/gnunet/message/msg_core.go
index 90c8804..245c61d 100644
--- a/src/gnunet/message/msg_core.go
+++ b/src/gnunet/message/msg_core.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -60,7 +60,7 @@ func NewEphemeralKeyMsg() *EphemeralKeyMsg {
60 SignedBlock: &EphKeyBlock{ 60 SignedBlock: &EphKeyBlock{
61 Purpose: &crypto.SignaturePurpose{ 61 Purpose: &crypto.SignaturePurpose{
62 Size: 88, 62 Size: 88,
63 Purpose: enums.SIG_ECC_KEY, 63 Purpose: uint32(enums.SIG_SET_ECC_KEY),
64 }, 64 },
65 CreateTime: util.AbsoluteTimeNow(), 65 CreateTime: util.AbsoluteTimeNow(),
66 ExpireTime: util.NewRelativeTime(12 * time.Hour), 66 ExpireTime: util.NewRelativeTime(12 * time.Hour),
@@ -86,7 +86,7 @@ func (m *EphemeralKeyMsg) Header() *Header {
86 86
87// Public extracts the public key of an announcing peer. 87// Public extracts the public key of an announcing peer.
88func (m *EphemeralKeyMsg) Public() *ed25519.PublicKey { 88func (m *EphemeralKeyMsg) Public() *ed25519.PublicKey {
89 return ed25519.NewPublicKeyFromBytes(m.SignedBlock.PeerID.Key) 89 return m.SignedBlock.PeerID.PublicKey()
90} 90}
91 91
92// Verify the integrity of the message data using the public key of the 92// Verify the integrity of the message data using the public key of the
diff --git a/src/gnunet/message/msg_dht.go b/src/gnunet/message/msg_dht.go
index bb8fc1a..9e1a747 100644
--- a/src/gnunet/message/msg_dht.go
+++ b/src/gnunet/message/msg_dht.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/message/msg_gns.go b/src/gnunet/message/msg_gns.go
index 9b85e40..0f285ee 100644
--- a/src/gnunet/message/msg_gns.go
+++ b/src/gnunet/message/msg_gns.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -154,7 +154,7 @@ type ResourceRecord struct {
154// String returns a human-readable representation of the message. 154// String returns a human-readable representation of the message.
155func (r *ResourceRecord) String() string { 155func (r *ResourceRecord) String() string {
156 return fmt.Sprintf("GNSResourceRecord{type=%s,expire=%s,flags=%d,size=%d}", 156 return fmt.Sprintf("GNSResourceRecord{type=%s,expire=%s,flags=%d,size=%d}",
157 enums.GNS_TYPE[int(r.Type)], r.Expires, r.Flags, r.Size) 157 enums.GNSType(r.Type).String(), r.Expires, r.Flags, r.Size)
158} 158}
159 159
160// LookupResultMsg is a response message for a GNS name lookup request 160// LookupResultMsg is a response message for a GNS name lookup request
diff --git a/src/gnunet/message/msg_hello.go b/src/gnunet/message/msg_hello.go
index 25ef98a..407d0a0 100644
--- a/src/gnunet/message/msg_hello.go
+++ b/src/gnunet/message/msg_hello.go
@@ -19,82 +19,163 @@
19package message 19package message
20 20
21import ( 21import (
22 "bytes"
23 "encoding/binary"
22 "fmt" 24 "fmt"
23 "gnunet/util" 25 "gnunet/util"
26 "io"
24) 27)
25 28
26//---------------------------------------------------------------------- 29//----------------------------------------------------------------------
27// HELLO
28//
29// A HELLO message is used to exchange information about transports with
30// other peers. This struct is always followed by the actual network
31// addresses which have the format:
32//
33// 1) transport-name (0-terminated)
34// 2) address-length (uint16_t, network byte order)
35// 3) address expiration
36// 4) address (address-length bytes)
37//----------------------------------------------------------------------
38 30
39// HelloAddress represents a (generic) peer address with expiration date 31// HelloAddress represents a (generic) peer address with expiration date:
40type HelloAddress struct { 32type HelloAddress struct {
41 Transport string // Name of transport 33 transport string // Name of transport
42 AddrSize uint16 `order:"big"` // Size of address entry 34 addrSize uint16 // Size of address entry
43 ExpireOn util.AbsoluteTime // Expiry date 35 expires util.AbsoluteTime // Expiry date
44 Address []byte `size:"AddrSize"` // Address specification 36 address []byte // Address specification
45} 37}
46 38
47// NewHelloAddress create a new HELLO address from the given address 39// NewHelloAddress create a new HELLO address from the given address
48func NewHelloAddress(a *util.Address) *HelloAddress { 40func NewHelloAddress(a *util.Address) *HelloAddress {
49 addr := &HelloAddress{ 41 addr := &HelloAddress{
50 Transport: a.Netw, 42 transport: a.Netw,
51 AddrSize: uint16(len(a.Address)), 43 addrSize: uint16(len(a.Address)),
52 ExpireOn: a.Expires, 44 expires: a.Expires,
53 Address: make([]byte, len(a.Address)), 45 address: make([]byte, len(a.Address)),
54 } 46 }
55 copy(addr.Address, a.Address) 47 copy(addr.address, a.Address)
56 return addr 48 return addr
57} 49}
58 50
51// ParseHelloAddress from reader
52func ParseHelloAddr(rdr io.Reader) (a *HelloAddress, err error) {
53 // parse \0-terminated transport
54 var (
55 transport []byte
56 buf = make([]byte, 1)
57 )
58 for {
59 if _, err = rdr.Read(buf); err != nil {
60 return
61 }
62 if buf[0] == 0 {
63 break
64 }
65 transport = append(transport, buf[0])
66 }
67 // parse address size
68 var asize uint16
69 if err = binary.Read(rdr, binary.BigEndian, &asize); err != nil {
70 return
71 }
72 // parse expiration time
73 var exp uint64
74 if err = binary.Read(rdr, binary.BigEndian, &exp); err != nil {
75 return
76 }
77 // get address data
78 adata := make([]byte, asize)
79 if _, err = rdr.Read(adata); err != nil {
80 return
81 }
82 // assemble HELLO address
83 a = &HelloAddress{
84 transport: string(transport),
85 addrSize: asize,
86 expires: util.AbsoluteTime{Val: exp},
87 address: adata,
88 }
89 return
90}
91
92// Wrap a HelloAddress into a uitl.Address
93func (a *HelloAddress) Wrap() (addr *util.Address) {
94 addr = util.NewAddress(a.transport, string(a.address))
95 addr.Expires = a.expires
96 return
97}
98
59// String returns a human-readable representation of the message. 99// String returns a human-readable representation of the message.
60func (a *HelloAddress) String() string { 100func (a *HelloAddress) String() string {
61 return fmt.Sprintf("Address{%s,expire=%s}", 101 return fmt.Sprintf("Address{%s,expire=%s}",
62 util.URI(a.Transport, a.Address), a.ExpireOn) 102 util.URI(a.transport, a.address), a.expires)
103}
104
105// Bytes returns the binary representation of a HelloAddress
106func (a *HelloAddress) Bytes() []byte {
107 buf := new(bytes.Buffer)
108 buf.Write([]byte(a.transport))
109 buf.WriteByte(0)
110 binary.Write(buf, binary.BigEndian, a.addrSize)
111 binary.Write(buf, binary.BigEndian, a.expires.Val)
112 buf.Write(a.address)
113 return buf.Bytes()
63} 114}
64 115
116//----------------------------------------------------------------------
117// HELLO
118//
119// A HELLO message is used to exchange information about transports with
120// other peers. This struct is always followed by the actual network
121// addresses of type "HelloAddress"
122//----------------------------------------------------------------------
123
65// HelloMsg is a message send by peers to announce their presence 124// HelloMsg is a message send by peers to announce their presence
66type HelloMsg struct { 125type HelloMsg struct {
67 MsgSize uint16 `order:"big"` // total size of message 126 MsgSize uint16 `order:"big"` // total size of message
68 MsgType uint16 `order:"big"` // HELLO (17) 127 MsgType uint16 `order:"big"` // HELLO (17)
69 FriendOnly uint32 `order:"big"` // =1: do not gossip this HELLO 128 FriendsOnly uint32 `order:"big"` // Do not gossip this HELLO message
70 PeerID *util.PeerID // EdDSA public key (long-term) 129 Peer *util.PeerID `` // peer identifier for addresses
71 Addresses []*HelloAddress `size:"*"` // List of end-point addressess 130 AddrList []byte `size:"*"` // List of end-point addresses (HelloAddress)
72} 131}
73 132
74// NewHelloMsg creates a new HELLO msg for a given peer. 133// NewHelloMsg creates a new HELLO msg for a given peer.
75func NewHelloMsg(peerid *util.PeerID) *HelloMsg { 134func NewHelloMsg(peer *util.PeerID) *HelloMsg {
76 if peerid == nil { 135 // allocate peer id if none is specified
77 peerid = util.NewPeerID(nil) 136 if peer == nil {
137 peer = util.NewPeerID(nil)
78 } 138 }
139 // return empty HelloMessage
79 return &HelloMsg{ 140 return &HelloMsg{
80 MsgSize: 40, 141 MsgSize: 40, // size without 'AddrList'
81 MsgType: HELLO, 142 MsgType: HELLO, // HELLO (17)
82 FriendOnly: 0, 143 FriendsOnly: 0, // not used here
83 PeerID: peerid, 144 Peer: peer, // associated peer
84 Addresses: make([]*HelloAddress, 0), 145 AddrList: make([]byte, 0), // list of addresses
146 }
147}
148
149// Addresses returns the list of HelloAddress
150func (m *HelloMsg) Addresses() (list []*HelloAddress, err error) {
151 rdr := bytes.NewReader(m.AddrList)
152 var addr *HelloAddress
153 for {
154 // parse address from stream
155 if addr, err = ParseHelloAddr(rdr); err != nil {
156 // end of stream: no more addresses
157 if err == io.EOF {
158 err = nil
159 }
160 return
161 }
162 list = append(list, addr)
85 } 163 }
86} 164}
87 165
88// String returns a human-readable representation of the message. 166// String returns a human-readable representation of the message.
89func (m *HelloMsg) String() string { 167func (m *HelloMsg) String() string {
90 return fmt.Sprintf("HelloMsg{peer=%s,friendsonly=%d,addr=%v}", 168 return fmt.Sprintf("HelloMsg{%s: addrs=%d}", m.Peer, len(m.AddrList))
91 m.PeerID, m.FriendOnly, m.Addresses)
92} 169}
93 170
94// AddAddress adds a new address to the HELLO message. 171// SetAddresses adds addresses to the HELLO message.
95func (m *HelloMsg) AddAddress(a *HelloAddress) { 172func (m *HelloMsg) SetAddresses(list []*HelloAddress) {
96 m.Addresses = append(m.Addresses, a) 173 wrt := new(bytes.Buffer)
97 m.MsgSize += uint16(len(a.Transport)) + a.AddrSize + 11 174 for _, addr := range list {
175 n, _ := wrt.Write(addr.Bytes())
176 m.MsgSize += uint16(n)
177 }
178 m.AddrList = wrt.Bytes()
98} 179}
99 180
100// Header returns the message header in a separate instance. 181// Header returns the message header in a separate instance.
diff --git a/src/gnunet/message/msg_hello_dht.go b/src/gnunet/message/msg_hello_dht.go
new file mode 100644
index 0000000..a81d1fc
--- /dev/null
+++ b/src/gnunet/message/msg_hello_dht.go
@@ -0,0 +1,146 @@
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
19package message
20
21import (
22 "bytes"
23 "crypto/sha512"
24 "encoding/binary"
25 "fmt"
26 "gnunet/enums"
27 "gnunet/util"
28 "io"
29 "time"
30
31 "github.com/bfix/gospel/crypto/ed25519"
32 "github.com/bfix/gospel/logger"
33)
34
35//----------------------------------------------------------------------
36// HELLO-DHT
37//
38// A HELLO message is used to exchange information about transports with
39// other DHT nodes. This struct is always followed by the actual network
40// addresses of type "HelloAddress"
41//----------------------------------------------------------------------
42
43// HelloDHTMsg is a message send by peers to announce their presence
44type HelloDHTMsg struct {
45 MsgSize uint16 `order:"big"` // total size of message
46 MsgType uint16 `order:"big"` // DHT_P2P_HELLO (157)
47 Reserved uint16 `order:"big"` // Reserved for further use
48 NumAddr uint16 `order:"big"` // Number of addresses in list
49 Signature []byte `size:"64"` // Signature
50 Expires util.AbsoluteTime `` // expiration time
51 AddrList []byte `size:"*"` // List of end-point addresses (HelloAddress)
52}
53
54// NewHelloMsgDHT creates an empty DHT_P2P_HELLO message.
55func NewHelloDHTMsg() *HelloDHTMsg {
56 // return empty HelloMessage
57 exp := time.Now().Add(HelloAddressExpiration)
58 return &HelloDHTMsg{
59 MsgSize: 80, // size without 'AddrList'
60 MsgType: DHT_P2P_HELLO, // DHT_P2P_HELLO (157)
61 Reserved: 0, // not used here
62 NumAddr: 0, // start with empty address list
63 Signature: make([]byte, 64), // signature
64 Expires: util.NewAbsoluteTime(exp), // default expiration
65 AddrList: make([]byte, 0), // list of addresses
66 }
67}
68
69// Addresses returns the list of HelloAddress
70func (m *HelloDHTMsg) Addresses() (list []*HelloAddress, err error) {
71 rdr := bytes.NewReader(m.AddrList)
72 var addr *HelloAddress
73 num := 0
74 for {
75 // parse address from stream
76 if addr, err = ParseHelloAddr(rdr); err != nil {
77 // end of stream: no more addresses
78 if err == io.EOF {
79 err = nil
80 }
81 // check numbers
82 if num != int(m.NumAddr) {
83 logger.Printf(logger.WARN, "[HelloDHTMsg] Number of addresses doesn't match (got %d, expected %d)", num, m.NumAddr)
84 }
85 return
86 }
87 list = append(list, addr)
88 num++
89 }
90}
91
92// String returns a human-readable representation of the message.
93func (m *HelloDHTMsg) String() string {
94 return fmt.Sprintf("HelloDHTMsg{expire:%s,addrs=%d}", m.Expires, m.NumAddr)
95}
96
97// SetAddresses adds addresses to the HELLO message.
98func (m *HelloDHTMsg) SetAddresses(list []*HelloAddress) {
99 // write addresses as blob and track earliest expiration
100 exp := util.AbsoluteTimeNever()
101 wrt := new(bytes.Buffer)
102 for _, addr := range list {
103 // check if address expires before current expire
104 if _, after := exp.Diff(addr.expires); !after {
105 exp = addr.expires
106 }
107 n, _ := wrt.Write(addr.Bytes())
108 m.MsgSize += uint16(n)
109 m.NumAddr++
110 }
111 m.AddrList = wrt.Bytes()
112 m.Expires = exp
113}
114
115// Header returns the message header in a separate instance.
116func (m *HelloDHTMsg) Header() *Header {
117 return &Header{m.MsgSize, m.MsgType}
118}
119
120// Verify the message signature
121func (m *HelloDHTMsg) Verify(peer *util.PeerID) (bool, error) {
122 // assemble signed data and public key
123 sd := m.signedData()
124 pub := peer.PublicKey()
125 sig, err := ed25519.NewEdSignatureFromBytes(m.Signature)
126 if err != nil {
127 return false, err
128 }
129 return pub.EdVerify(sd, sig)
130}
131
132// signedData assembles a data block for sign and verify operations.
133func (m *HelloDHTMsg) signedData() []byte {
134 // hash address block
135 hAddr := sha512.Sum512(m.AddrList)
136 var size uint32 = 80
137 purpose := uint32(enums.SIG_HELLO)
138
139 // assemble signed data
140 buf := new(bytes.Buffer)
141 binary.Write(buf, binary.BigEndian, size)
142 binary.Write(buf, binary.BigEndian, purpose)
143 binary.Write(buf, binary.BigEndian, m.Expires.Epoch()*1000000)
144 buf.Write(hAddr[:])
145 return buf.Bytes()
146}
diff --git a/src/gnunet/message/msg_namecache.go b/src/gnunet/message/msg_namecache.go
index 5acb807..517f11b 100644
--- a/src/gnunet/message/msg_namecache.go
+++ b/src/gnunet/message/msg_namecache.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/message/msg_revocation.go b/src/gnunet/message/msg_revocation.go
index 3174c55..90f8dd1 100644
--- a/src/gnunet/message/msg_revocation.go
+++ b/src/gnunet/message/msg_revocation.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/message/msg_transport.go b/src/gnunet/message/msg_transport.go
index d0e927b..18d8ceb 100644
--- a/src/gnunet/message/msg_transport.go
+++ b/src/gnunet/message/msg_transport.go
@@ -145,7 +145,7 @@ func NewSignedAddress(a *util.Address) *SignedAddress {
145 addr := &SignedAddress{ 145 addr := &SignedAddress{
146 Purpose: &crypto.SignaturePurpose{ 146 Purpose: &crypto.SignaturePurpose{
147 Size: uint32(alen + 20), 147 Size: uint32(alen + 20),
148 Purpose: enums.SIG_TRANSPORT_PONG_OWN, 148 Purpose: uint32(enums.SIG_TRANSPORT_PONG_OWN),
149 }, 149 },
150 ExpireOn: util.AbsoluteTimeNow().Add(12 * time.Hour), 150 ExpireOn: util.AbsoluteTimeNow().Add(12 * time.Hour),
151 AddrSize: uint32(alen), 151 AddrSize: uint32(alen),
diff --git a/src/gnunet/message/types.go b/src/gnunet/message/types.go
index 31504c0..3b1cf7a 100644
--- a/src/gnunet/message/types.go
+++ b/src/gnunet/message/types.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -193,6 +193,10 @@ const (
193 DHT_MONITOR_START = 153 // Request information about transiting messages 193 DHT_MONITOR_START = 153 // Request information about transiting messages
194 DHT_MONITOR_STOP = 154 // Stop information about transiting messages 194 DHT_MONITOR_STOP = 154 // Stop information about transiting messages
195 DHT_CLIENT_GET_RESULTS_KNOWN = 156 // Certain results are already known to the client, filter those. 195 DHT_CLIENT_GET_RESULTS_KNOWN = 156 // Certain results are already known to the client, filter those.
196 DHT_P2P_HELLO = 157 // HELLO advertising a neighbours addresses.
197 DHT_CORE = 158 // Encapsulation of DHT messages in CORE service.
198 DHT_CLIENT_HELLO_URL = 159 // HELLO URL send between client and service (in either direction).
199 DHT_CLIENT_HELLO_GET = 161 // Client requests DHT service's HELLO URL.
196 200
197 //------------------------------------------------------------------ 201 //------------------------------------------------------------------
198 // HOSTLIST message types 202 // HOSTLIST message types
diff --git a/src/gnunet/service/client.go b/src/gnunet/service/client.go
index 19dc4c4..81a9f01 100644
--- a/src/gnunet/service/client.go
+++ b/src/gnunet/service/client.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/service/dht/blocks/hello.go b/src/gnunet/service/dht/blocks/hello.go
index eb3bf2a..a5ccf8c 100644
--- a/src/gnunet/service/dht/blocks/hello.go
+++ b/src/gnunet/service/dht/blocks/hello.go
@@ -20,8 +20,11 @@ package blocks
20 20
21import ( 21import (
22 "bytes" 22 "bytes"
23 "crypto/sha512"
23 "encoding/binary" 24 "encoding/binary"
25 "errors"
24 "fmt" 26 "fmt"
27 "gnunet/enums"
25 "gnunet/util" 28 "gnunet/util"
26 "net/url" 29 "net/url"
27 "strconv" 30 "strconv"
@@ -31,6 +34,12 @@ import (
31 "github.com/bfix/gospel/data" 34 "github.com/bfix/gospel/data"
32) 35)
33 36
37// HELLO-related errors
38var (
39 ErrHelloExpired = errors.New("expired HELLO")
40 ErrHelloSignature = errors.New("failed HELLO signature")
41)
42
34//---------------------------------------------------------------------- 43//----------------------------------------------------------------------
35// HELLO URLs are used for bootstrapping a node and for adding nodes 44// HELLO URLs are used for bootstrapping a node and for adding nodes
36// outside of GNUnet message exchange (e.g. command-line tools) 45// outside of GNUnet message exchange (e.g. command-line tools)
@@ -43,10 +52,10 @@ const helloPrefix = "gnunet://hello/"
43// All addresses expire at the same time /this different from HELLO 52// All addresses expire at the same time /this different from HELLO
44// messages (see message.HeeloMsg). 53// messages (see message.HeeloMsg).
45type HelloBlock struct { 54type HelloBlock struct {
46 PeerID *util.PeerID `` // peer identifier 55 PeerID *util.PeerID `` // peer identifier
47 Signature *ed25519.EdSignature `` // signature 56 Signature []byte `size:"64"` // signature
48 Expire util.AbsoluteTime `` // Expiration date 57 Expire util.AbsoluteTime `` // Expiration date
49 AddrBin []byte `size:"*"` // raw address data 58 AddrBin []byte `size:"*"` // raw address data
50 59
51 // transient attributes 60 // transient attributes
52 addrs []*util.Address // cooked address data 61 addrs []*util.Address // cooked address data
@@ -66,7 +75,7 @@ func (h *HelloBlock) Addresses() []*util.Address {
66// ParseHelloURL parses a HELLO URL of the following form: 75// ParseHelloURL parses a HELLO URL of the following form:
67// gnunet://hello/<PeerID>/<signature>/<expire>?<addrs> 76// gnunet://hello/<PeerID>/<signature>/<expire>?<addrs>
68// The addresses are encoded. 77// The addresses are encoded.
69func ParseHelloURL(u string) (h *HelloBlock, err error) { 78func ParseHelloURL(u string, checkExpiry bool) (h *HelloBlock, err error) {
70 // check and trim prefix 79 // check and trim prefix
71 if !strings.HasPrefix(u, helloPrefix) { 80 if !strings.HasPrefix(u, helloPrefix) {
72 err = fmt.Errorf("invalid HELLO-URL prefix: '%s'", u) 81 err = fmt.Errorf("invalid HELLO-URL prefix: '%s'", u)
@@ -92,10 +101,7 @@ func ParseHelloURL(u string) (h *HelloBlock, err error) {
92 h.PeerID = util.NewPeerID(buf) 101 h.PeerID = util.NewPeerID(buf)
93 102
94 // (2) parse signature 103 // (2) parse signature
95 if buf, err = util.DecodeStringToBinary(p[1], 64); err != nil { 104 if h.Signature, err = util.DecodeStringToBinary(p[1], 64); err != nil {
96 return
97 }
98 if h.Signature, err = ed25519.NewEdSignatureFromBytes(buf); err != nil {
99 return 105 return
100 } 106 }
101 107
@@ -108,18 +114,24 @@ func ParseHelloURL(u string) (h *HelloBlock, err error) {
108 return 114 return
109 } 115 }
110 h.Expire = util.NewAbsoluteTimeEpoch(exp) 116 h.Expire = util.NewAbsoluteTimeEpoch(exp)
117 if checkExpiry && h.Expire.Expired() {
118 err = ErrHelloExpired
119 return
120 }
111 121
112 // (5) process addresses. 122 // (5) process addresses.
113 h.addrs = make([]*util.Address, 0) 123 h.addrs = make([]*util.Address, 0)
114 var ua string
115 for _, a := range strings.Split(q[1], "&") { 124 for _, a := range strings.Split(q[1], "&") {
116 // unescape URL query 125 // reformat to standard address format
117 if ua, err = url.QueryUnescape(a); err != nil { 126 ap := strings.SplitN(a, "=", 2)
127 var q string
128 if q, err = url.QueryUnescape(ap[1]); err != nil {
118 return 129 return
119 } 130 }
131 as := ap[0] + "://" + q
120 // parse address and append it to list 132 // parse address and append it to list
121 var addr *util.Address 133 var addr *util.Address
122 if addr, err = util.ParseAddress(ua); err != nil { 134 if addr, err = util.ParseAddress(as); err != nil {
123 return 135 return
124 } 136 }
125 h.addrs = append(h.addrs, addr) 137 h.addrs = append(h.addrs, addr)
@@ -127,6 +139,15 @@ func ParseHelloURL(u string) (h *HelloBlock, err error) {
127 139
128 // (6) generate raw address data so block is complete 140 // (6) generate raw address data so block is complete
129 h.finalize() 141 h.finalize()
142
143 // check signature
144 var ok bool
145 if ok, err = h.Verify(); err != nil {
146 return
147 }
148 if !ok {
149 err = ErrHelloSignature
150 }
130 return 151 return
131} 152}
132 153
@@ -142,11 +163,26 @@ func ParseHelloFromBytes(buf []byte) (h *HelloBlock, err error) {
142// finalize block data (generate dependent fields) 163// finalize block data (generate dependent fields)
143func (h *HelloBlock) finalize() (err error) { 164func (h *HelloBlock) finalize() (err error) {
144 if h.addrs == nil { 165 if h.addrs == nil {
145 err = data.Unmarshal(h.addrs, h.AddrBin) 166 // read addresses from the binary representation
167 pos := 0
168 h.addrs = make([]*util.Address, 0)
169 for {
170 var as string
171 as, pos = util.ReadCString(h.AddrBin, pos)
172 if pos == -1 {
173 break
174 }
175 var addr *util.Address
176 if addr, err = util.ParseAddress(as); err != nil {
177 return
178 }
179 h.addrs = append(h.addrs, addr)
180 }
146 } else if h.AddrBin == nil { 181 } else if h.AddrBin == nil {
182 // generate binary representation of addresses
147 wrt := new(bytes.Buffer) 183 wrt := new(bytes.Buffer)
148 for _, a := range h.addrs { 184 for _, a := range h.addrs {
149 wrt.WriteString(a.String()) 185 wrt.WriteString(a.URI())
150 wrt.WriteByte(0) 186 wrt.WriteByte(0)
151 } 187 }
152 h.AddrBin = wrt.Bytes() 188 h.AddrBin = wrt.Bytes()
@@ -170,14 +206,16 @@ func (h *HelloBlock) URL() string {
170 u := fmt.Sprintf("%s%s/%s/%d?", 206 u := fmt.Sprintf("%s%s/%s/%d?",
171 helloPrefix, 207 helloPrefix,
172 h.PeerID.String(), 208 h.PeerID.String(),
173 util.EncodeBinaryToString(h.Signature.Bytes()), 209 util.EncodeBinaryToString(h.Signature),
174 h.Expire.Epoch(), 210 h.Expire.Epoch(),
175 ) 211 )
176 for i, a := range h.addrs { 212 for i, a := range h.addrs {
177 if i > 0 { 213 if i > 0 {
178 u += "&" 214 u += "&"
179 } 215 }
180 u += url.QueryEscape(a.URI()) 216 au := a.URI()
217 p := strings.SplitN(au, "://", 2)
218 u += p[0] + "=" + url.QueryEscape(p[1])
181 } 219 }
182 return u 220 return u
183} 221}
@@ -186,7 +224,7 @@ func (h *HelloBlock) URL() string {
186// timestamp is ignored in the comparision. 224// timestamp is ignored in the comparision.
187func (h *HelloBlock) Equals(g *HelloBlock) bool { 225func (h *HelloBlock) Equals(g *HelloBlock) bool {
188 if !h.PeerID.Equals(g.PeerID) || 226 if !h.PeerID.Equals(g.PeerID) ||
189 !util.Equals(h.Signature.Bytes(), g.Signature.Bytes()) || 227 !util.Equals(h.Signature, g.Signature) ||
190 len(h.addrs) != len(g.addrs) { 228 len(h.addrs) != len(g.addrs) {
191 return false 229 return false
192 } 230 }
@@ -202,25 +240,38 @@ func (h *HelloBlock) Equals(g *HelloBlock) bool {
202func (h *HelloBlock) Verify() (bool, error) { 240func (h *HelloBlock) Verify() (bool, error) {
203 // assemble signed data and public key 241 // assemble signed data and public key
204 sd := h.signedData() 242 sd := h.signedData()
205 pub := ed25519.NewPublicKeyFromBytes(h.PeerID.Key) 243 pub := h.PeerID.PublicKey()
206 return pub.EdVerify(sd, h.Signature) 244 sig, err := ed25519.NewEdSignatureFromBytes(h.Signature)
245 if err != nil {
246 return false, err
247 }
248 return pub.EdVerify(sd, sig)
207} 249}
208 250
209// Sign the HELLO data with private key 251// Sign the HELLO data with private key
210func (h *HelloBlock) Sign(prv *ed25519.PrivateKey) (err error) { 252func (h *HelloBlock) Sign(prv *ed25519.PrivateKey) error {
211 // assemble signed data 253 // assemble signed data
212 sd := h.signedData() 254 sd := h.signedData()
213 h.Signature, err = prv.EdSign(sd) 255 sig, err := prv.EdSign(sd)
214 return 256 if err != nil {
257 return err
258 }
259 h.Signature = sig.Bytes()
260 return nil
215} 261}
216 262
217// signedData assembles a data block for sign and verify operations. 263// signedData assembles a data block for sign and verify operations.
218func (h *HelloBlock) signedData() []byte { 264func (h *HelloBlock) signedData() []byte {
265 // hash address block
266 hAddr := sha512.Sum512(h.AddrBin)
267 var size uint32 = 80
268 purpose := uint32(enums.SIG_HELLO)
269
270 // assemble signed data
219 buf := new(bytes.Buffer) 271 buf := new(bytes.Buffer)
220 buf.Write(h.PeerID.Key) 272 binary.Write(buf, binary.BigEndian, size)
221 binary.Write(buf, binary.BigEndian, h.Expire) 273 binary.Write(buf, binary.BigEndian, purpose)
222 for _, a := range h.addrs { 274 binary.Write(buf, binary.BigEndian, h.Expire.Epoch()*1000000)
223 buf.Write(a.Address) 275 buf.Write(hAddr[:])
224 }
225 return buf.Bytes() 276 return buf.Bytes()
226} 277}
diff --git a/src/gnunet/service/dht/module.go b/src/gnunet/service/dht/module.go
index 3339aa2..323a4df 100644
--- a/src/gnunet/service/dht/module.go
+++ b/src/gnunet/service/dht/module.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -25,7 +25,6 @@ import (
25 "gnunet/message" 25 "gnunet/message"
26 "gnunet/service" 26 "gnunet/service"
27 "gnunet/service/dht/blocks" 27 "gnunet/service/dht/blocks"
28 "net/http"
29 "time" 28 "time"
30) 29)
31 30
@@ -50,16 +49,15 @@ type Module struct {
50 49
51// NewModule returns a new module instance. It initializes the storage 50// NewModule returns a new module instance. It initializes the storage
52// mechanism for persistence. 51// mechanism for persistence.
53func NewModule(ctx context.Context, c *core.Core) (m *Module) { 52func NewModule(ctx context.Context, c *core.Core) (m *Module, err error) {
54 // create permanent storage handler 53 // create permanent storage handler
55 store, err := service.NewDHTStore(config.Cfg.DHT.Storage) 54 var store, cache service.DHTStore
56 if err != nil { 55 if store, err = service.NewDHTStore(config.Cfg.DHT.Storage); err != nil {
57 return nil 56 return
58 } 57 }
59 // create cache handler 58 // create cache handler
60 cache, err := service.NewDHTStore(config.Cfg.DHT.Cache) 59 if cache, err = service.NewDHTStore(config.Cfg.DHT.Cache); err != nil {
61 if err != nil { 60 return
62 return nil
63 } 61 }
64 // create routing table 62 // create routing table
65 rt := NewRoutingTable(NewPeerAddress(c.PeerID())) 63 rt := NewRoutingTable(NewPeerAddress(c.PeerID()))
@@ -75,22 +73,21 @@ func NewModule(ctx context.Context, c *core.Core) (m *Module) {
75 // register as listener for core events 73 // register as listener for core events
76 listener := m.Run(ctx, m.event, m.Filter(), 15*time.Minute, m.heartbeat) 74 listener := m.Run(ctx, m.event, m.Filter(), 15*time.Minute, m.heartbeat)
77 c.Register("dht", listener) 75 c.Register("dht", listener)
78
79 return 76 return
80} 77}
81 78
82//---------------------------------------------------------------------- 79//----------------------------------------------------------------------
83 80
84// Get a block from the DHT ["dht:get"] 81// Get a block from the DHT ["dht:get"]
85func (nc *Module) Get(ctx context.Context, query blocks.Query) (block blocks.Block, err error) { 82func (m *Module) Get(ctx context.Context, query blocks.Query) (block blocks.Block, err error) {
86 83
87 // check if we have the requested block in cache or permanent storage. 84 // check if we have the requested block in cache or permanent storage.
88 block, err = nc.cache.Get(query) 85 block, err = m.cache.Get(query)
89 if err == nil { 86 if err == nil {
90 // yes: we are done 87 // yes: we are done
91 return 88 return
92 } 89 }
93 block, err = nc.store.Get(query) 90 block, err = m.store.Get(query)
94 if err == nil { 91 if err == nil {
95 // yes: we are done 92 // yes: we are done
96 return 93 return
@@ -101,7 +98,7 @@ func (nc *Module) Get(ctx context.Context, query blocks.Query) (block blocks.Blo
101} 98}
102 99
103// Put a block into the DHT ["dht:put"] 100// Put a block into the DHT ["dht:put"]
104func (nc *Module) Put(ctx context.Context, key blocks.Query, block blocks.Block) error { 101func (m *Module) Put(ctx context.Context, key blocks.Query, block blocks.Block) error {
105 return nil 102 return nil
106} 103}
107 104
@@ -126,9 +123,20 @@ func (m *Module) event(ctx context.Context, ev *core.Event) {
126 // New peer connected: 123 // New peer connected:
127 case core.EV_CONNECT: 124 case core.EV_CONNECT:
128 // Add peer to routing table 125 // Add peer to routing table
129 126 m.rtable.Add(NewPeerAddress(ev.Peer))
127
128 // Peer disconnected:
129 case core.EV_DISCONNECT:
130 // Remove peer from routing table
131 m.rtable.Remove(NewPeerAddress(ev.Peer))
132
133 // Message received.
134 case core.EV_MESSAGE:
135 // process message (if applicable)
136 if m.ProcessFcn != nil {
137 m.ProcessFcn(ctx, ev.Msg, ev.Resp)
138 }
130 } 139 }
131
132} 140}
133 141
134// Heartbeat handler for periodic tasks 142// Heartbeat handler for periodic tasks
@@ -153,12 +161,3 @@ func (m *Module) Export(fcn map[string]any) {
153func (m *Module) Import(fcm map[string]any) { 161func (m *Module) Import(fcm map[string]any) {
154 // nothing to import now. 162 // nothing to import now.
155} 163}
156
157//----------------------------------------------------------------------
158
159// RPC returns the route and handler function for a JSON-RPC request
160func (m *Module) RPC() (string, func(http.ResponseWriter, *http.Request)) {
161 return "/gns/", func(wrt http.ResponseWriter, req *http.Request) {
162 wrt.Write([]byte(`{"msg": "This is DHT" }`))
163 }
164}
diff --git a/src/gnunet/service/dht/blocks/hello_test.go b/src/gnunet/service/dht/rpc.go
index 089259a..3ec2b73 100644
--- a/src/gnunet/service/dht/blocks/hello_test.go
+++ b/src/gnunet/service/dht/rpc.go
@@ -16,29 +16,31 @@
16// 16//
17// SPDX-License-Identifier: AGPL3.0-or-later 17// SPDX-License-Identifier: AGPL3.0-or-later
18 18
19package blocks 19package dht
20 20
21import "testing" 21import (
22 "net/rpc"
23 "time"
24)
22 25
23const ( 26//----------------------------------------------------------------------
24 helloURL = "gnunet://hello" +
25 "/7KTBJ90340HF1Q2GB0A57E2XJER4FDHX8HP5GHEB9125VPWPD27G" +
26 27
27 "/BNMDFN6HJCPWSPNBSEC06MC1K8QN1Z2DHRQSRXDTFR7FTBD4JHN" + 28type DHTCommand struct{}
28 "BJ2RJAAEZ31FWG1Q3PMN3PXGZQ3Q7NTNEKQZFA7TE2Y46FM8E20R" +
29 "/1653499308" +
30 "?r5n%2Bip%2Budp%3A1.2.3.4%3A6789" +
31 "&gnunet%2Btcp%3A12.3.4.5"
32)
33 29
34func TestHelloURL(t *testing.T) { 30type DHTStats struct {
31 Started time.Time
32}
35 33
36 hd, err := ParseHelloURL(helloURL) 34func (c *DHTCommand) Status(mode int, stats *DHTStats) error {
37 if err != nil { 35 *stats = DHTStats{
38 t.Fatal(err) 36 Started: time.Now(),
39 }
40 u := hd.URL()
41 if u != helloURL {
42 t.Fatal("urls don't match")
43 } 37 }
38 return nil
39}
40
41//----------------------------------------------------------------------
42
43// InitRPC registers RPC commands for the module
44func (m *Module) InitRPC(srv *rpc.Server) {
45 srv.Register(new(DHTCommand))
44} 46}
diff --git a/src/gnunet/service/dht/service.go b/src/gnunet/service/dht/service.go
index 2a189bb..82937b9 100644
--- a/src/gnunet/service/dht/service.go
+++ b/src/gnunet/service/dht/service.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -26,6 +26,7 @@ import (
26 "gnunet/core" 26 "gnunet/core"
27 "gnunet/message" 27 "gnunet/message"
28 "gnunet/service" 28 "gnunet/service"
29 "gnunet/transport"
29 30
30 "github.com/bfix/gospel/logger" 31 "github.com/bfix/gospel/logger"
31) 32)
@@ -47,10 +48,16 @@ type Service struct {
47} 48}
48 49
49// NewService creates a new DHT service instance 50// NewService creates a new DHT service instance
50func NewService(ctx context.Context, c *core.Core) service.Service { 51func NewService(ctx context.Context, c *core.Core) (service.Service, error) {
51 return &Service{ 52 mod, err := NewModule(ctx, c)
52 Module: *NewModule(ctx, c), 53 if err != nil {
54 return nil, err
53 } 55 }
56 srv := &Service{
57 Module: *mod,
58 }
59 srv.ProcessFcn = srv.HandleMessage
60 return srv, nil
54} 61}
55 62
56// ServeClient processes a client channel. 63// ServeClient processes a client channel.
@@ -90,7 +97,7 @@ loop:
90 97
91// HandleMessage handles a DHT request/response message. If the transport channel 98// HandleMessage handles a DHT request/response message. If the transport channel
92// is nil, responses are send directly via the transport layer. 99// is nil, responses are send directly via the transport layer.
93func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back service.Responder) bool { 100func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back transport.Responder) bool {
94 // assemble log label 101 // assemble log label
95 label := "" 102 label := ""
96 if v := ctx.Value("label"); v != nil { 103 if v := ctx.Value("label"); v != nil {
diff --git a/src/gnunet/service/gns/block_handler.go b/src/gnunet/service/gns/block_handler.go
index c93fca1..4c49c99 100644
--- a/src/gnunet/service/gns/block_handler.go
+++ b/src/gnunet/service/gns/block_handler.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -46,7 +46,7 @@ var (
46 46
47// Mapping of RR types to BlockHandler instanciation functions 47// Mapping of RR types to BlockHandler instanciation functions
48var ( 48var (
49 customHandler = map[int]HdlrInst{ 49 customHandler = map[enums.GNSType]HdlrInst{
50 enums.GNS_TYPE_PKEY: NewZoneHandler, 50 enums.GNS_TYPE_PKEY: NewZoneHandler,
51 enums.GNS_TYPE_EDKEY: NewZoneHandler, 51 enums.GNS_TYPE_EDKEY: NewZoneHandler,
52 enums.GNS_TYPE_GNS2DNS: NewGns2DnsHandler, 52 enums.GNS_TYPE_GNS2DNS: NewGns2DnsHandler,
@@ -76,7 +76,7 @@ type BlockHandler interface {
76 // resource records in the same block. 'cm' maps the resource type 76 // resource records in the same block. 'cm' maps the resource type
77 // to an integer count (how many records of a type are present in the 77 // to an integer count (how many records of a type are present in the
78 // GNS block). 78 // GNS block).
79 Coexist(cm util.Counter[int]) bool 79 Coexist(cm util.Counter[enums.GNSType]) bool
80 80
81 // Records returns a list of RR of the given types associated with 81 // Records returns a list of RR of the given types associated with
82 // the custom handler 82 // the custom handler
@@ -102,8 +102,8 @@ type BlockHandler interface {
102 102
103// BlockHandlerList is a list of block handlers instantiated. 103// BlockHandlerList is a list of block handlers instantiated.
104type BlockHandlerList struct { 104type BlockHandlerList struct {
105 list map[int]BlockHandler // list of handler instances 105 list map[enums.GNSType]BlockHandler // list of handler instances
106 counts util.Counter[int] // count number of RRs by type 106 counts util.Counter[enums.GNSType] // count number of RRs by type
107} 107}
108 108
109// NewBlockHandlerList instantiates an a list of active block handlers 109// NewBlockHandlerList instantiates an a list of active block handlers
@@ -111,8 +111,8 @@ type BlockHandlerList struct {
111func NewBlockHandlerList(records []*message.ResourceRecord, labels []string) (*BlockHandlerList, []*message.ResourceRecord, error) { 111func NewBlockHandlerList(records []*message.ResourceRecord, labels []string) (*BlockHandlerList, []*message.ResourceRecord, error) {
112 // initialize block handler list 112 // initialize block handler list
113 hl := &BlockHandlerList{ 113 hl := &BlockHandlerList{
114 list: make(map[int]BlockHandler), 114 list: make(map[enums.GNSType]BlockHandler),
115 counts: make(util.Counter[int]), 115 counts: make(util.Counter[enums.GNSType]),
116 } 116 }
117 117
118 // first pass: build list of shadow records in this block 118 // first pass: build list of shadow records in this block
@@ -153,11 +153,11 @@ func NewBlockHandlerList(records []*message.ResourceRecord, labels []string) (*B
153 logger.Printf(logger.DBG, "[gns] handler_list: skip %v\n", rec) 153 logger.Printf(logger.DBG, "[gns] handler_list: skip %v\n", rec)
154 continue 154 continue
155 } 155 }
156 rrType := int(rec.Type) 156 rrType := enums.GNSType(rec.Type)
157 hl.counts.Add(rrType) 157 hl.counts.Add(rrType)
158 158
159 // check for custom handler type 159 // check for custom handler type
160 if creat, ok := customHandler[rrType]; ok { 160 if creat, ok := customHandler[enums.GNSType(rrType)]; ok {
161 // check if a handler for given type already exists 161 // check if a handler for given type already exists
162 var ( 162 var (
163 hdlr BlockHandler 163 hdlr BlockHandler
@@ -194,7 +194,7 @@ func NewBlockHandlerList(records []*message.ResourceRecord, labels []string) (*B
194// GetHandler returns a BlockHandler for the given GNS block type. 194// GetHandler returns a BlockHandler for the given GNS block type.
195// If more than one type is given, the first matching hanlder is 195// If more than one type is given, the first matching hanlder is
196// returned. 196// returned.
197func (hl *BlockHandlerList) GetHandler(types ...int) BlockHandler { 197func (hl *BlockHandlerList) GetHandler(types ...enums.GNSType) BlockHandler {
198 for _, t := range types { 198 for _, t := range types {
199 // return handler for given type if it exists 199 // return handler for given type if it exists
200 if hdlr, ok := hl.list[t]; ok { 200 if hdlr, ok := hl.list[t]; ok {
@@ -260,7 +260,7 @@ func (h *ZoneKeyHandler) AddRecord(rec *message.ResourceRecord, labels []string)
260 260
261// Coexist return a flag indicating how a resource record of a given type 261// Coexist return a flag indicating how a resource record of a given type
262// is to be treated (see BlockHandler interface) 262// is to be treated (see BlockHandler interface)
263func (h *ZoneKeyHandler) Coexist(cm util.Counter[int]) bool { 263func (h *ZoneKeyHandler) Coexist(cm util.Counter[enums.GNSType]) bool {
264 // only one type (GNS_TYPE_PKEY) is present 264 // only one type (GNS_TYPE_PKEY) is present
265 return len(cm) == 1 && cm.Num(enums.GNS_TYPE_PKEY) == 1 265 return len(cm) == 1 && cm.Num(enums.GNS_TYPE_PKEY) == 1
266} 266}
@@ -292,7 +292,7 @@ type Gns2DnsHandler struct {
292 292
293// NewGns2DnsHandler returns a new BlockHandler instance 293// NewGns2DnsHandler returns a new BlockHandler instance
294func NewGns2DnsHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) { 294func NewGns2DnsHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) {
295 if int(rec.Type) != enums.GNS_TYPE_GNS2DNS { 295 if enums.GNSType(rec.Type) != enums.GNS_TYPE_GNS2DNS {
296 return nil, ErrInvalidRecordType 296 return nil, ErrInvalidRecordType
297 } 297 }
298 h := &Gns2DnsHandler{ 298 h := &Gns2DnsHandler{
@@ -308,7 +308,7 @@ func NewGns2DnsHandler(rec *message.ResourceRecord, labels []string) (BlockHandl
308 308
309// AddRecord inserts a GNS2DNS record into the handler. 309// AddRecord inserts a GNS2DNS record into the handler.
310func (h *Gns2DnsHandler) AddRecord(rec *message.ResourceRecord, labels []string) error { 310func (h *Gns2DnsHandler) AddRecord(rec *message.ResourceRecord, labels []string) error {
311 if int(rec.Type) != enums.GNS_TYPE_GNS2DNS { 311 if enums.GNSType(rec.Type) != enums.GNS_TYPE_GNS2DNS {
312 return ErrInvalidRecordType 312 return ErrInvalidRecordType
313 } 313 }
314 logger.Printf(logger.DBG, "[gns] GNS2DNS data: %s\n", hex.EncodeToString(rec.Data)) 314 logger.Printf(logger.DBG, "[gns] GNS2DNS data: %s\n", hex.EncodeToString(rec.Data))
@@ -335,7 +335,7 @@ func (h *Gns2DnsHandler) AddRecord(rec *message.ResourceRecord, labels []string)
335 335
336// Coexist return a flag indicating how a resource record of a given type 336// Coexist return a flag indicating how a resource record of a given type
337// is to be treated (see BlockHandler interface) 337// is to be treated (see BlockHandler interface)
338func (h *Gns2DnsHandler) Coexist(cm util.Counter[int]) bool { 338func (h *Gns2DnsHandler) Coexist(cm util.Counter[enums.GNSType]) bool {
339 // only one type (GNS_TYPE_GNS2DNS) is present 339 // only one type (GNS_TYPE_GNS2DNS) is present
340 return len(cm) == 1 && cm.Num(enums.GNS_TYPE_GNS2DNS) > 0 340 return len(cm) == 1 && cm.Num(enums.GNS_TYPE_GNS2DNS) > 0
341} 341}
@@ -367,7 +367,7 @@ type BoxHandler struct {
367 367
368// NewBoxHandler returns a new BlockHandler instance 368// NewBoxHandler returns a new BlockHandler instance
369func NewBoxHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) { 369func NewBoxHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) {
370 if int(rec.Type) != enums.GNS_TYPE_BOX { 370 if enums.GNSType(rec.Type) != enums.GNS_TYPE_BOX {
371 return nil, ErrInvalidRecordType 371 return nil, ErrInvalidRecordType
372 } 372 }
373 h := &BoxHandler{ 373 h := &BoxHandler{
@@ -381,7 +381,7 @@ func NewBoxHandler(rec *message.ResourceRecord, labels []string) (BlockHandler,
381 381
382// AddRecord inserts a BOX record into the handler. 382// AddRecord inserts a BOX record into the handler.
383func (h *BoxHandler) AddRecord(rec *message.ResourceRecord, labels []string) error { 383func (h *BoxHandler) AddRecord(rec *message.ResourceRecord, labels []string) error {
384 if int(rec.Type) != enums.GNS_TYPE_BOX { 384 if enums.GNSType(rec.Type) != enums.GNS_TYPE_BOX {
385 return ErrInvalidRecordType 385 return ErrInvalidRecordType
386 } 386 }
387 logger.Printf(logger.DBG, "[box-rr] for labels %v\n", labels) 387 logger.Printf(logger.DBG, "[box-rr] for labels %v\n", labels)
@@ -405,7 +405,7 @@ func (h *BoxHandler) AddRecord(rec *message.ResourceRecord, labels []string) err
405 405
406// Coexist return a flag indicating how a resource record of a given type 406// Coexist return a flag indicating how a resource record of a given type
407// is to be treated (see BlockHandler interface) 407// is to be treated (see BlockHandler interface)
408func (h *BoxHandler) Coexist(cm util.Counter[int]) bool { 408func (h *BoxHandler) Coexist(cm util.Counter[enums.GNSType]) bool {
409 // anything goes... 409 // anything goes...
410 return true 410 return true
411} 411}
@@ -414,7 +414,7 @@ func (h *BoxHandler) Coexist(cm util.Counter[int]) bool {
414func (h *BoxHandler) Records(kind RRTypeList) *message.RecordSet { 414func (h *BoxHandler) Records(kind RRTypeList) *message.RecordSet {
415 rs := message.NewRecordSet() 415 rs := message.NewRecordSet()
416 for _, box := range h.boxes { 416 for _, box := range h.boxes {
417 if kind.HasType(int(box.Type)) { 417 if kind.HasType(enums.GNSType(box.Type)) {
418 // valid box found: assemble new resource record. 418 // valid box found: assemble new resource record.
419 rr := new(message.ResourceRecord) 419 rr := new(message.ResourceRecord)
420 rr.Expires = box.rec.Expires 420 rr.Expires = box.rec.Expires
@@ -445,7 +445,7 @@ type LehoHandler struct {
445 445
446// NewLehoHandler returns a new BlockHandler instance 446// NewLehoHandler returns a new BlockHandler instance
447func NewLehoHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) { 447func NewLehoHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) {
448 if int(rec.Type) != enums.GNS_TYPE_LEHO { 448 if enums.GNSType(rec.Type) != enums.GNS_TYPE_LEHO {
449 return nil, ErrInvalidRecordType 449 return nil, ErrInvalidRecordType
450 } 450 }
451 h := &LehoHandler{ 451 h := &LehoHandler{
@@ -459,7 +459,7 @@ func NewLehoHandler(rec *message.ResourceRecord, labels []string) (BlockHandler,
459 459
460// AddRecord inserts a LEHO record into the handler. 460// AddRecord inserts a LEHO record into the handler.
461func (h *LehoHandler) AddRecord(rec *message.ResourceRecord, labels []string) error { 461func (h *LehoHandler) AddRecord(rec *message.ResourceRecord, labels []string) error {
462 if int(rec.Type) != enums.GNS_TYPE_LEHO { 462 if enums.GNSType(rec.Type) != enums.GNS_TYPE_LEHO {
463 return ErrInvalidRecordType 463 return ErrInvalidRecordType
464 } 464 }
465 h.name = string(rec.Data) 465 h.name = string(rec.Data)
@@ -469,7 +469,7 @@ func (h *LehoHandler) AddRecord(rec *message.ResourceRecord, labels []string) er
469 469
470// Coexist return a flag indicating how a resource record of a given type 470// Coexist return a flag indicating how a resource record of a given type
471// is to be treated (see BlockHandler interface) 471// is to be treated (see BlockHandler interface)
472func (h *LehoHandler) Coexist(cm util.Counter[int]) bool { 472func (h *LehoHandler) Coexist(cm util.Counter[enums.GNSType]) bool {
473 // requires exactly one LEHO and any number of other records. 473 // requires exactly one LEHO and any number of other records.
474 return cm.Num(enums.GNS_TYPE_LEHO) == 1 474 return cm.Num(enums.GNS_TYPE_LEHO) == 1
475} 475}
@@ -500,7 +500,7 @@ type CnameHandler struct {
500 500
501// NewCnameHandler returns a new BlockHandler instance 501// NewCnameHandler returns a new BlockHandler instance
502func NewCnameHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) { 502func NewCnameHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) {
503 if int(rec.Type) != enums.GNS_TYPE_DNS_CNAME { 503 if enums.GNSType(rec.Type) != enums.GNS_TYPE_DNS_CNAME {
504 return nil, ErrInvalidRecordType 504 return nil, ErrInvalidRecordType
505 } 505 }
506 h := &CnameHandler{ 506 h := &CnameHandler{
@@ -514,7 +514,7 @@ func NewCnameHandler(rec *message.ResourceRecord, labels []string) (BlockHandler
514 514
515// AddRecord inserts a CNAME record into the handler. 515// AddRecord inserts a CNAME record into the handler.
516func (h *CnameHandler) AddRecord(rec *message.ResourceRecord, labels []string) error { 516func (h *CnameHandler) AddRecord(rec *message.ResourceRecord, labels []string) error {
517 if int(rec.Type) != enums.GNS_TYPE_DNS_CNAME { 517 if enums.GNSType(rec.Type) != enums.GNS_TYPE_DNS_CNAME {
518 return ErrInvalidRecordType 518 return ErrInvalidRecordType
519 } 519 }
520 if h.rec != nil { 520 if h.rec != nil {
@@ -527,7 +527,7 @@ func (h *CnameHandler) AddRecord(rec *message.ResourceRecord, labels []string) e
527 527
528// Coexist return a flag indicating how a resource record of a given type 528// Coexist return a flag indicating how a resource record of a given type
529// is to be treated (see BlockHandler interface) 529// is to be treated (see BlockHandler interface)
530func (h *CnameHandler) Coexist(cm util.Counter[int]) bool { 530func (h *CnameHandler) Coexist(cm util.Counter[enums.GNSType]) bool {
531 // only a single CNAME allowed 531 // only a single CNAME allowed
532 return len(cm) == 1 && cm.Num(enums.GNS_TYPE_DNS_CNAME) == 1 532 return len(cm) == 1 && cm.Num(enums.GNS_TYPE_DNS_CNAME) == 1
533} 533}
@@ -557,7 +557,7 @@ type VpnHandler struct {
557 557
558// NewVpnHandler returns a new BlockHandler instance 558// NewVpnHandler returns a new BlockHandler instance
559func NewVpnHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) { 559func NewVpnHandler(rec *message.ResourceRecord, labels []string) (BlockHandler, error) {
560 if int(rec.Type) != enums.GNS_TYPE_VPN { 560 if enums.GNSType(rec.Type) != enums.GNS_TYPE_VPN {
561 return nil, ErrInvalidRecordType 561 return nil, ErrInvalidRecordType
562 } 562 }
563 h := &VpnHandler{} 563 h := &VpnHandler{}
@@ -569,7 +569,7 @@ func NewVpnHandler(rec *message.ResourceRecord, labels []string) (BlockHandler,
569 569
570// AddRecord inserts a VPN record into the handler. 570// AddRecord inserts a VPN record into the handler.
571func (h *VpnHandler) AddRecord(rec *message.ResourceRecord, labels []string) error { 571func (h *VpnHandler) AddRecord(rec *message.ResourceRecord, labels []string) error {
572 if int(rec.Type) != enums.GNS_TYPE_VPN { 572 if enums.GNSType(rec.Type) != enums.GNS_TYPE_VPN {
573 return ErrInvalidRecordType 573 return ErrInvalidRecordType
574 } 574 }
575 if h.rec != nil { 575 if h.rec != nil {
@@ -581,7 +581,7 @@ func (h *VpnHandler) AddRecord(rec *message.ResourceRecord, labels []string) err
581 581
582// Coexist return a flag indicating how a resource record of a given type 582// Coexist return a flag indicating how a resource record of a given type
583// is to be treated (see BlockHandler interface) 583// is to be treated (see BlockHandler interface)
584func (h *VpnHandler) Coexist(cm util.Counter[int]) bool { 584func (h *VpnHandler) Coexist(cm util.Counter[enums.GNSType]) bool {
585 // anything goes 585 // anything goes
586 return true 586 return true
587} 587}
diff --git a/src/gnunet/service/gns/box.go b/src/gnunet/service/gns/box.go
index 1afd843..f97471e 100644
--- a/src/gnunet/service/gns/box.go
+++ b/src/gnunet/service/gns/box.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/service/gns/dns.go b/src/gnunet/service/gns/dns.go
index 8818ca6..4422c44 100644
--- a/src/gnunet/service/gns/dns.go
+++ b/src/gnunet/service/gns/dns.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -46,10 +46,10 @@ var (
46//---------------------------------------------------------------------- 46//----------------------------------------------------------------------
47 47
48// RRTypeList is a list of integers representing RR types. 48// RRTypeList is a list of integers representing RR types.
49type RRTypeList []int 49type RRTypeList []enums.GNSType
50 50
51// NewRRTypeList initializes a new type list with given type values 51// NewRRTypeList initializes a new type list with given type values
52func NewRRTypeList(args ...int) (res RRTypeList) { 52func NewRRTypeList(args ...enums.GNSType) (res RRTypeList) {
53 for _, val := range args { 53 for _, val := range args {
54 // if GNS_TYPE_ANY is encountered, it becomes the sole type 54 // if GNS_TYPE_ANY is encountered, it becomes the sole type
55 if val == enums.GNS_TYPE_ANY { 55 if val == enums.GNS_TYPE_ANY {
@@ -74,7 +74,7 @@ func (tl RRTypeList) IsAny() bool {
74} 74}
75 75
76// HasType returns true if the type is included in the list 76// HasType returns true if the type is included in the list
77func (tl RRTypeList) HasType(t int) bool { 77func (tl RRTypeList) HasType(t enums.GNSType) bool {
78 // return true if type is GNS_TYPE_ANY 78 // return true if type is GNS_TYPE_ANY
79 if tl[0] == enums.GNS_TYPE_ANY { 79 if tl[0] == enums.GNS_TYPE_ANY {
80 return true 80 return true
@@ -164,7 +164,7 @@ func QueryDNS(id int, name string, server net.IP, kind RRTypeList) *message.Reco
164 set := message.NewRecordSet() 164 set := message.NewRecordSet()
165 for _, record := range in.Answer { 165 for _, record := range in.Answer {
166 // check if answer record is of requested type 166 // check if answer record is of requested type
167 if kind.HasType(int(record.Header().Rrtype)) { 167 if kind.HasType(enums.GNSType(record.Header().Rrtype)) {
168 // get wire-format of resource record 168 // get wire-format of resource record
169 buf := make([]byte, 2048) 169 buf := make([]byte, 2048)
170 n, err := dns.PackRR(record, buf, 0, nil, false) 170 n, err := dns.PackRR(record, buf, 0, nil, false)
@@ -230,7 +230,7 @@ func (gns *Module) ResolveDNS(
230 // traverse resource records for 'A' and 'AAAA' records. 230 // traverse resource records for 'A' and 'AAAA' records.
231 rec_loop: 231 rec_loop:
232 for _, rec := range set.Records { 232 for _, rec := range set.Records {
233 switch int(rec.Type) { 233 switch enums.GNSType(rec.Type) {
234 case enums.GNS_TYPE_DNS_AAAA: 234 case enums.GNS_TYPE_DNS_AAAA:
235 addr = net.IP(rec.Data) 235 addr = net.IP(rec.Data)
236 // we prefer IPv6 236 // we prefer IPv6
diff --git a/src/gnunet/service/gns/module.go b/src/gnunet/service/gns/module.go
index 93f9bca..1129273 100644
--- a/src/gnunet/service/gns/module.go
+++ b/src/gnunet/service/gns/module.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -21,7 +21,6 @@ package gns
21import ( 21import (
22 "context" 22 "context"
23 "fmt" 23 "fmt"
24 "net/http"
25 "strings" 24 "strings"
26 25
27 "gnunet/config" 26 "gnunet/config"
@@ -106,7 +105,6 @@ func NewModule(ctx context.Context, c *core.Core) (m *Module) {
106 // register as listener for core events 105 // register as listener for core events
107 listener := m.Run(ctx, m.event, m.Filter(), 0, nil) 106 listener := m.Run(ctx, m.event, m.Filter(), 0, nil)
108 c.Register("gns", listener) 107 c.Register("gns", listener)
109
110 return 108 return
111} 109}
112 110
@@ -340,7 +338,7 @@ func (m *Module) ResolveRelative(
340 set = message.NewRecordSet() 338 set = message.NewRecordSet()
341 for _, rec := range records { 339 for _, rec := range records {
342 // is this the record type we are looking for? 340 // is this the record type we are looking for?
343 if kind.HasType(int(rec.Type)) { 341 if kind.HasType(enums.GNSType(rec.Type)) {
344 // add it to the result 342 // add it to the result
345 if rec = hdlrs.FinalizeRecord(rec); rec != nil { 343 if rec = hdlrs.FinalizeRecord(rec); rec != nil {
346 set.AddRecord(rec) 344 set.AddRecord(rec)
@@ -363,7 +361,7 @@ func (m *Module) ResolveRelative(
363 // asking for explicitly. 361 // asking for explicitly.
364 if set.Count > 0 { 362 if set.Count > 0 {
365 for _, rec := range records { 363 for _, rec := range records {
366 if !kind.HasType(int(rec.Type)) && (int(rec.Flags)&enums.GNS_FLAG_SUPPL) != 0 { 364 if !kind.HasType(enums.GNSType(rec.Type)) && (int(rec.Flags)&enums.GNS_FLAG_SUPPL) != 0 {
367 set.AddRecord(rec) 365 set.AddRecord(rec)
368 } 366 }
369 } 367 }
@@ -488,12 +486,3 @@ func (m *Module) records(buf []byte) ([]*message.ResourceRecord, error) {
488 } 486 }
489 return rs.Records, nil 487 return rs.Records, nil
490} 488}
491
492//----------------------------------------------------------------------
493
494// RPC returns the route and handler function for a JSON-RPC request
495func (m *Module) RPC() (string, func(http.ResponseWriter, *http.Request)) {
496 return "/gns/", func(wrt http.ResponseWriter, req *http.Request) {
497 wrt.Write([]byte(`{"msg": "This is GNS" }`))
498 }
499}
diff --git a/src/gnunet/service/gns/rpc.go b/src/gnunet/service/gns/rpc.go
new file mode 100644
index 0000000..33682d3
--- /dev/null
+++ b/src/gnunet/service/gns/rpc.go
@@ -0,0 +1,27 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 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
19package gns
20
21import "net/rpc"
22
23//----------------------------------------------------------------------
24
25// InitRPC registers RPC commands for the module
26func (m *Module) InitRPC(srv *rpc.Server) {
27}
diff --git a/src/gnunet/service/gns/service.go b/src/gnunet/service/gns/service.go
index 326d831..19ddc14 100644
--- a/src/gnunet/service/gns/service.go
+++ b/src/gnunet/service/gns/service.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -25,12 +25,14 @@ import (
25 "io" 25 "io"
26 26
27 "gnunet/config" 27 "gnunet/config"
28 "gnunet/core"
28 "gnunet/crypto" 29 "gnunet/crypto"
29 "gnunet/enums" 30 "gnunet/enums"
30 "gnunet/message" 31 "gnunet/message"
31 "gnunet/service" 32 "gnunet/service"
32 "gnunet/service/dht/blocks" 33 "gnunet/service/dht/blocks"
33 "gnunet/service/revocation" 34 "gnunet/service/revocation"
35 "gnunet/transport"
34 "gnunet/util" 36 "gnunet/util"
35 37
36 "github.com/bfix/gospel/data" 38 "github.com/bfix/gospel/data"
@@ -54,15 +56,22 @@ type Service struct {
54} 56}
55 57
56// NewService creates a new GNS service instance 58// NewService creates a new GNS service instance
57func NewService() service.Service { 59func NewService(ctx context.Context, c *core.Core) service.Service {
58 // instantiate service and assemble a new GNS handler. 60 // instantiate service
59 inst := new(Service) 61 mod := NewModule(ctx, c)
60 inst.LookupLocal = inst.LookupNamecache 62 srv := &Service{
61 inst.StoreLocal = inst.StoreNamecache 63 Module: *mod,
62 inst.LookupRemote = inst.LookupDHT 64 }
63 inst.RevocationQuery = inst.QueryKeyRevocation 65 srv.ProcessFcn = srv.HandleMessage
64 inst.RevocationRevoke = inst.RevokeKey 66
65 return inst 67 // set external function references (external services)
68 srv.LookupLocal = srv.LookupNamecache
69 srv.StoreLocal = srv.StoreNamecache
70 srv.LookupRemote = srv.LookupDHT
71 srv.RevocationQuery = srv.QueryKeyRevocation
72 srv.RevocationRevoke = srv.RevokeKey
73
74 return srv
66} 75}
67 76
68// ServeClient processes a client channel. 77// ServeClient processes a client channel.
@@ -100,7 +109,7 @@ func (s *Service) ServeClient(ctx context.Context, id int, mc *service.Connectio
100} 109}
101 110
102// Handle a single incoming message 111// Handle a single incoming message
103func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back service.Responder) bool { 112func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back transport.Responder) bool {
104 // assemble log label 113 // assemble log label
105 label := "" 114 label := ""
106 if v := ctx.Value("label"); v != nil { 115 if v := ctx.Value("label"); v != nil {
@@ -129,7 +138,7 @@ func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back s
129 }() 138 }()
130 139
131 label := m.GetName() 140 label := m.GetName()
132 kind := NewRRTypeList(int(m.Type)) 141 kind := NewRRTypeList(enums.GNSType(m.Type))
133 recset, err := s.Resolve(ctx, label, m.Zone, kind, int(m.Options), 0) 142 recset, err := s.Resolve(ctx, label, m.Zone, kind, int(m.Options), 0)
134 if err != nil { 143 if err != nil {
135 logger.Printf(logger.ERROR, "[gns%s] Failed to lookup block: %s\n", label, err.Error()) 144 logger.Printf(logger.ERROR, "[gns%s] Failed to lookup block: %s\n", label, err.Error())
@@ -152,7 +161,7 @@ func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back s
152 logger.Printf(logger.DBG, "[gns%s] Record #%d: %v\n", label, i, rec) 161 logger.Printf(logger.DBG, "[gns%s] Record #%d: %v\n", label, i, rec)
153 162
154 // is this the record type we are looking for? 163 // is this the record type we are looking for?
155 if rec.Type == m.Type || int(m.Type) == enums.GNS_TYPE_ANY { 164 if rec.Type == m.Type || enums.GNSType(m.Type) == enums.GNS_TYPE_ANY {
156 // add it to the response message 165 // add it to the response message
157 resp.AddRecord(rec) 166 resp.AddRecord(rec)
158 } 167 }
@@ -269,7 +278,7 @@ func (s *Service) LookupNamecache(ctx context.Context, query *blocks.GNSQuery) (
269 block.DerivedKeySig = m.DerivedKeySig 278 block.DerivedKeySig = m.DerivedKeySig
270 sb := new(blocks.SignedGNSBlockData) 279 sb := new(blocks.SignedGNSBlockData)
271 sb.Purpose = new(crypto.SignaturePurpose) 280 sb.Purpose = new(crypto.SignaturePurpose)
272 sb.Purpose.Purpose = enums.SIG_GNS_RECORD_SIGN 281 sb.Purpose.Purpose = uint32(enums.SIG_GNS_RECORD_SIGN)
273 sb.Purpose.Size = uint32(16 + len(m.EncData)) 282 sb.Purpose.Size = uint32(16 + len(m.EncData))
274 sb.Expire = m.Expire 283 sb.Expire = m.Expire
275 sb.Data = m.EncData 284 sb.Data = m.EncData
@@ -404,7 +413,7 @@ func (s *Service) LookupDHT(ctx context.Context, query blocks.Query) (block bloc
404 break 413 break
405 } 414 }
406 // check if result is of requested type 415 // check if result is of requested type
407 if int(m.Type) != enums.BLOCK_TYPE_GNS_NAMERECORD { 416 if enums.BlockType(m.Type) != enums.BLOCK_TYPE_GNS_NAMERECORD {
408 logger.Println(logger.ERROR, "[gns] DHT response has wrong type") 417 logger.Println(logger.ERROR, "[gns] DHT response has wrong type")
409 break 418 break
410 } 419 }
diff --git a/src/gnunet/service/module.go b/src/gnunet/service/module.go
index 4109f16..65b49d8 100644
--- a/src/gnunet/service/module.go
+++ b/src/gnunet/service/module.go
@@ -21,7 +21,9 @@ package service
21import ( 21import (
22 "context" 22 "context"
23 "gnunet/core" 23 "gnunet/core"
24 "net/http" 24 "gnunet/message"
25 "gnunet/transport"
26 "net/rpc"
25 "time" 27 "time"
26) 28)
27 29
@@ -63,8 +65,8 @@ type Module interface {
63 // Import functions by name 65 // Import functions by name
64 Import(map[string]any) 66 Import(map[string]any)
65 67
66 // RPC returns the route and handler for JSON-RPC requests 68 // InitRPC registers RPC commands for the module
67 RPC() (string, func(http.ResponseWriter, *http.Request)) 69 InitRPC(*rpc.Server)
68 70
69 // Filter returns the event filter for the module 71 // Filter returns the event filter for the module
70 Filter() *core.EventFilter 72 Filter() *core.EventFilter
@@ -78,13 +80,18 @@ type Heartbeat func(context.Context)
78 80
79// ModuleImpl is an event-handling type used by Module implementations. 81// ModuleImpl is an event-handling type used by Module implementations.
80type ModuleImpl struct { 82type ModuleImpl struct {
81 ch chan *core.Event // channel for core events. 83 // channel for core events.
84 ch chan *core.Event
85
86 // ProcessFcn message: function reference (implemented by service)
87 ProcessFcn func(ctx context.Context, msg message.Message, back transport.Responder) bool
82} 88}
83 89
84// NewModuleImplementation returns a new base module and starts 90// NewModuleImplementation returns a new base module and starts
85func NewModuleImpl() (m *ModuleImpl) { 91func NewModuleImpl() (m *ModuleImpl) {
86 return &ModuleImpl{ 92 return &ModuleImpl{
87 ch: make(chan *core.Event), 93 ch: make(chan *core.Event),
94 ProcessFcn: nil,
88 } 95 }
89} 96}
90 97
@@ -108,7 +115,8 @@ func (m *ModuleImpl) Run(
108 select { 115 select {
109 // Handle events 116 // Handle events
110 case event := <-m.ch: 117 case event := <-m.ch:
111 hdlr(ctx, event) 118 hCtx := context.WithValue(ctx, "label", event.Label)
119 hdlr(hCtx, event)
112 120
113 // wait for terminate signal 121 // wait for terminate signal
114 case <-ctx.Done(): 122 case <-ctx.Done():
diff --git a/src/gnunet/service/namecache/module.go b/src/gnunet/service/namecache/module.go
index b9aaad0..9251a58 100644
--- a/src/gnunet/service/namecache/module.go
+++ b/src/gnunet/service/namecache/module.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/service/revocation/module.go b/src/gnunet/service/revocation/module.go
index eade16b..6997060 100644
--- a/src/gnunet/service/revocation/module.go
+++ b/src/gnunet/service/revocation/module.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/service/revocation/pow.go b/src/gnunet/service/revocation/pow.go
index 57ddad7..cb35532 100644
--- a/src/gnunet/service/revocation/pow.go
+++ b/src/gnunet/service/revocation/pow.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -158,7 +158,7 @@ func (rd *RevData) Sign(skey *crypto.ZonePrivate) (err error) {
158 sigBlock := &SignedRevData{ 158 sigBlock := &SignedRevData{
159 Purpose: &crypto.SignaturePurpose{ 159 Purpose: &crypto.SignaturePurpose{
160 Size: uint32(20 + rd.ZoneKeySig.KeySize()), 160 Size: uint32(20 + rd.ZoneKeySig.KeySize()),
161 Purpose: enums.SIG_REVOCATION, 161 Purpose: uint32(enums.SIG_REVOCATION),
162 }, 162 },
163 Timestamp: rd.Timestamp, 163 Timestamp: rd.Timestamp,
164 ZoneKey: &rd.ZoneKeySig.ZoneKey, 164 ZoneKey: &rd.ZoneKeySig.ZoneKey,
@@ -180,7 +180,7 @@ func (rd *RevData) Verify(withSig bool) (zbits float64, rc int) {
180 sigBlock := &SignedRevData{ 180 sigBlock := &SignedRevData{
181 Purpose: &crypto.SignaturePurpose{ 181 Purpose: &crypto.SignaturePurpose{
182 Size: uint32(20 + rd.ZoneKeySig.KeySize()), 182 Size: uint32(20 + rd.ZoneKeySig.KeySize()),
183 Purpose: enums.SIG_REVOCATION, 183 Purpose: uint32(enums.SIG_REVOCATION),
184 }, 184 },
185 Timestamp: rd.Timestamp, 185 Timestamp: rd.Timestamp,
186 ZoneKey: &rd.ZoneKeySig.ZoneKey, 186 ZoneKey: &rd.ZoneKeySig.ZoneKey,
diff --git a/src/gnunet/service/revocation/pow_test.go b/src/gnunet/service/revocation/pow_test.go
index a59f92b..17eb695 100644
--- a/src/gnunet/service/revocation/pow_test.go
+++ b/src/gnunet/service/revocation/pow_test.go
@@ -118,7 +118,7 @@ func TestRevocationRFC(t *testing.T) {
118 sigBlock := &SignedRevData{ 118 sigBlock := &SignedRevData{
119 Purpose: &crypto.SignaturePurpose{ 119 Purpose: &crypto.SignaturePurpose{
120 Size: uint32(20 + revData.ZoneKeySig.KeySize()), 120 Size: uint32(20 + revData.ZoneKeySig.KeySize()),
121 Purpose: enums.SIG_REVOCATION, 121 Purpose: uint32(enums.SIG_REVOCATION),
122 }, 122 },
123 Timestamp: revData.Timestamp, 123 Timestamp: revData.Timestamp,
124 ZoneKey: &revData.ZoneKeySig.ZoneKey, 124 ZoneKey: &revData.ZoneKeySig.ZoneKey,
diff --git a/src/gnunet/service/revocation/rpc.go b/src/gnunet/service/revocation/rpc.go
new file mode 100644
index 0000000..1b8ea12
--- /dev/null
+++ b/src/gnunet/service/revocation/rpc.go
@@ -0,0 +1,27 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 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
19package revocation
20
21import "net/rpc"
22
23//----------------------------------------------------------------------
24
25// InitRPC registers RPC commands for the module
26func (m *Module) InitRPC(srv *rpc.Server) {
27}
diff --git a/src/gnunet/service/revocation/service.go b/src/gnunet/service/revocation/service.go
index 4d48d40..3d579e8 100644
--- a/src/gnunet/service/revocation/service.go
+++ b/src/gnunet/service/revocation/service.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -23,8 +23,10 @@ import (
23 "fmt" 23 "fmt"
24 "io" 24 "io"
25 25
26 "gnunet/core"
26 "gnunet/message" 27 "gnunet/message"
27 "gnunet/service" 28 "gnunet/service"
29 "gnunet/transport"
28 30
29 "github.com/bfix/gospel/logger" 31 "github.com/bfix/gospel/logger"
30) 32)
@@ -39,10 +41,14 @@ type Service struct {
39} 41}
40 42
41// NewService creates a new revocation service instance 43// NewService creates a new revocation service instance
42func NewService() service.Service { 44func NewService(ctx context.Context, c *core.Core) service.Service {
43 // instantiate service and assemble a new Revocation handler. 45 // instantiate service
44 inst := new(Service) 46 mod := NewModule(ctx, c)
45 return inst 47 srv := &Service{
48 Module: *mod,
49 }
50 srv.ProcessFcn = srv.HandleMessage
51 return srv
46} 52}
47 53
48// ServeClient processes a client channel. 54// ServeClient processes a client channel.
@@ -80,7 +86,7 @@ func (s *Service) ServeClient(ctx context.Context, id int, mc *service.Connectio
80} 86}
81 87
82// Handle a single incoming message 88// Handle a single incoming message
83func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back service.Responder) bool { 89func (s *Service) HandleMessage(ctx context.Context, msg message.Message, back transport.Responder) bool {
84 // assemble log label 90 // assemble log label
85 label := "" 91 label := ""
86 if v := ctx.Value("label"); v != nil { 92 if v := ctx.Value("label"); v != nil {
diff --git a/src/gnunet/rpc/server.go b/src/gnunet/service/rpc.go
index 760ecfc..a673c2b 100644
--- a/src/gnunet/rpc/server.go
+++ b/src/gnunet/service/rpc.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -16,29 +16,35 @@
16// 16//
17// SPDX-License-Identifier: AGPL3.0-or-later 17// SPDX-License-Identifier: AGPL3.0-or-later
18 18
19package rpc 19package service
20 20
21import ( 21import (
22 "context" 22 "context"
23 "gnunet/config"
24 "gnunet/service"
25 "net/http" 23 "net/http"
24 "net/rpc"
26 "time" 25 "time"
27 26
28 "github.com/bfix/gospel/logger" 27 "github.com/bfix/gospel/logger"
29 "github.com/gorilla/mux" 28 "github.com/gorilla/mux"
30) 29)
31 30
32// Router for JSON-RPC requests 31//----------------------------------------------------------------------
33var Router = mux.NewRouter() 32// JSON-RPC interface for services to be used as the primary client API
34var srv *http.Server 33// for perform, manage and monitor GNUnet activities.
34//----------------------------------------------------------------------
35
36// StartRPC the JSON-RPC server. It can be terminated by context
37func StartRPC(ctx context.Context, endpoint string) (srvRPC *rpc.Server, err error) {
38
39 // setup RPC request handler
40 router := mux.NewRouter()
41 srvRPC = rpc.NewServer()
42 router.HandleFunc("/", srvRPC.ServeHTTP)
35 43
36// Start the JSON-RPC server. It can be terminated by context
37func Start(ctx context.Context) error {
38 // instantiate a server and run it 44 // instantiate a server and run it
39 srv = &http.Server{ 45 srv := &http.Server{
40 Handler: Router, 46 Handler: router,
41 Addr: config.Cfg.RPC.Endpoint, 47 Addr: endpoint,
42 WriteTimeout: 15 * time.Second, 48 WriteTimeout: 15 * time.Second,
43 ReadTimeout: 15 * time.Second, 49 ReadTimeout: 15 * time.Second,
44 } 50 }
@@ -56,11 +62,5 @@ func Start(ctx context.Context) error {
56 } 62 }
57 } 63 }
58 }() 64 }()
59 return nil 65 return
60}
61
62// Register a JSON-RPC path in a service-specific processor
63func Register(m service.Module) {
64 path, hdlr := m.RPC()
65 Router.HandleFunc(path, hdlr)
66} 66}
diff --git a/src/gnunet/service/service.go b/src/gnunet/service/service.go
index 32ccf67..c47ff5c 100644
--- a/src/gnunet/service/service.go
+++ b/src/gnunet/service/service.go
@@ -20,9 +20,9 @@ package service
20 20
21import ( 21import (
22 "context" 22 "context"
23 "errors"
24 "fmt" 23 "fmt"
25 "gnunet/message" 24 "gnunet/message"
25 "gnunet/transport"
26 "gnunet/util" 26 "gnunet/util"
27 27
28 "github.com/bfix/gospel/logger" 28 "github.com/bfix/gospel/logger"
@@ -30,31 +30,6 @@ import (
30 30
31//---------------------------------------------------------------------- 31//----------------------------------------------------------------------
32 32
33// Responder is a back-channel for messages generated during
34// message processing. The Connection type is a responder
35// and used as such in ServeClient().
36type Responder interface {
37 // Handle outgoing message
38 Send(ctx context.Context, msg message.Message) error
39}
40
41// TransportResponder is used as a responder in message handling for
42// messages received from Transport.
43type TransportResponder struct {
44 Peer *util.PeerID
45 SendFcn func(context.Context, *util.PeerID, message.Message) error
46}
47
48// Send a message back to caller.
49func (r *TransportResponder) Send(ctx context.Context, msg message.Message) error {
50 if r.SendFcn == nil {
51 return errors.New("no send function defined")
52 }
53 return r.SendFcn(ctx, r.Peer, msg)
54}
55
56//----------------------------------------------------------------------
57
58// Service is an interface for GNUnet services 33// Service is an interface for GNUnet services
59type Service interface { 34type Service interface {
60 Module 35 Module
@@ -67,7 +42,7 @@ type Service interface {
67 // Handle a single incoming message (either locally from a socket 42 // Handle a single incoming message (either locally from a socket
68 // connection or from Transport). Response messages can be send 43 // connection or from Transport). Response messages can be send
69 // via a Responder. Returns true if message was processed. 44 // via a Responder. Returns true if message was processed.
70 HandleMessage(ctx context.Context, msg message.Message, resp Responder) bool 45 HandleMessage(ctx context.Context, msg message.Message, resp transport.Responder) bool
71} 46}
72 47
73// SocketHandler handles incoming connections on the local service socket. 48// SocketHandler handles incoming connections on the local service socket.
diff --git a/src/gnunet/service/store.go b/src/gnunet/service/store.go
index 1e5af8b..c599c54 100644
--- a/src/gnunet/service/store.go
+++ b/src/gnunet/service/store.go
@@ -79,7 +79,7 @@ type KVStore Store[string, string]
79// NewDHTStore creates a new storage handler with given spec 79// NewDHTStore creates a new storage handler with given spec
80// for use with DHT queries and blocks 80// for use with DHT queries and blocks
81func NewDHTStore(spec string) (DHTStore, error) { 81func NewDHTStore(spec string) (DHTStore, error) {
82 specs := strings.SplitN(spec, ":", 2) 82 specs := strings.Split(spec, ":")
83 if len(specs) < 2 { 83 if len(specs) < 2 {
84 return nil, ErrStoreInvalidSpec 84 return nil, ErrStoreInvalidSpec
85 } 85 }
diff --git a/src/gnunet/test/gnunet-dhtu/main.go b/src/gnunet/test/gnunet-dhtu/main.go
new file mode 100644
index 0000000..ce3651d
--- /dev/null
+++ b/src/gnunet/test/gnunet-dhtu/main.go
@@ -0,0 +1,218 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 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
19package main
20
21import (
22 "context"
23 "encoding/hex"
24 "flag"
25 "fmt"
26 "gnunet/config"
27 "gnunet/core"
28 "gnunet/service"
29 "gnunet/service/dht"
30 "gnunet/util"
31 "log"
32 "net/rpc"
33 "time"
34
35 "github.com/bfix/gospel/logger"
36)
37
38//----------------------------------------------------------------------
39// Test Go node with DHTU GNUnet nodes
40//----------------------------------------------------------------------
41
42func main() {
43 // handle command-line arguments
44 var (
45 remoteId string
46 remoteAddr string
47 cfgFile string
48 )
49 flag.StringVar(&cfgFile, "c", "gnunet-config.json", "configuration file")
50 flag.StringVar(&remoteId, "i", "", "peer id of remote node")
51 flag.StringVar(&remoteAddr, "a", "", "address of remote node")
52 flag.Parse()
53
54 // read configuration file and set missing arguments.
55 if err := config.ParseConfig(cfgFile); err != nil {
56 logger.Printf(logger.ERROR, "[gnunet-dhtu] Invalid configuration file: %s\n", err.Error())
57 return
58 }
59
60 // convert arguments
61 var (
62 rId *util.PeerID
63 rAddr *util.Address
64 buf []byte
65 err error
66 )
67 if rAddr, err = util.ParseAddress(remoteAddr); err != nil {
68 log.Fatal(err)
69 }
70 if len(remoteId) > 0 {
71 if buf, err = util.DecodeStringToBinary(remoteId, 32); err != nil {
72 log.Fatal(err)
73 }
74 rId = util.NewPeerID(buf)
75 }
76
77 // setup execution context
78 ctx, cancel := context.WithCancel(context.Background())
79 defer func() {
80 cancel()
81 time.Sleep(time.Second)
82 }()
83
84 // create and run node
85 node, err := NewTestNode(ctx)
86 if err != nil {
87 log.Fatal(err)
88 }
89 defer node.Shutdown()
90
91 // show our HELLO URL
92 ep := config.Cfg.Local.Endpoints[0]
93 as := fmt.Sprintf("%s://%s:%d", ep.Network, ep.Address, ep.Port)
94 listen, err := util.ParseAddress(as)
95 if err != nil {
96 log.Fatal(err)
97 }
98 aList := []*util.Address{listen}
99 logger.Println(logger.INFO, "HELLO: "+node.HelloURL(aList))
100
101 // learn bootstrap address (triggers HELLO)
102 node.Learn(ctx, rId, rAddr)
103
104 // run forever
105 var ch chan struct{}
106 <-ch
107}
108
109//----------------------------------------------------------------------
110// create and run a node with given spec
111//----------------------------------------------------------------------
112
113type TestNode struct {
114 id int
115 peer *core.Peer
116 core *core.Core
117 addr *util.Address
118}
119
120func (n *TestNode) Shutdown() {
121 n.core.Shutdown()
122}
123func (n *TestNode) HelloURL(a []*util.Address) string {
124 hd, err := n.peer.HelloData(time.Hour, a)
125 if err != nil {
126 return ""
127 }
128 return hd.URL()
129}
130
131func (n *TestNode) Learn(ctx context.Context, peer *util.PeerID, addr *util.Address) {
132 label := "@"
133 if peer != nil {
134 label = peer.String()
135 }
136 log.Printf("[%d] Learning %s for %s", n.id, addr.StringAll(), label)
137 if err := n.core.Learn(ctx, peer, addr); err != nil {
138 log.Println("Learn: " + err.Error())
139 }
140}
141
142func NewTestNode(ctx context.Context) (node *TestNode, err error) {
143
144 // create test node
145 node = new(TestNode)
146 node.id = util.NextID()
147
148 // create core service
149 if node.core, err = core.NewCore(ctx, config.Cfg.Local); err != nil {
150 return
151 }
152 node.peer = node.core.Peer()
153 log.Printf("[%d] Node %s starting", node.id, node.peer.GetID())
154 log.Printf("[%d] --> %s", node.id, hex.EncodeToString(node.peer.GetID().Key))
155
156 // start a new DHT service
157 dht, err := dht.NewService(ctx, node.core)
158 if err != nil {
159 log.Fatal(err)
160 }
161
162 // start JSON-RPC server on request
163 var rpc *rpc.Server
164 if rpc, err = service.StartRPC(ctx, config.Cfg.RPC.Endpoint); err != nil {
165 logger.Printf(logger.ERROR, "[gnunet-dhtu] RPC failed to start: %s", err.Error())
166 return
167 }
168 dht.InitRPC(rpc)
169
170 // start listening on the network
171 list, err := node.core.Addresses()
172 if err != nil {
173 log.Fatal(err)
174 }
175 for _, addr := range list {
176 s := addr.Network() + "://" + addr.String()
177 if node.addr, err = util.ParseAddress(s); err != nil {
178 continue
179 }
180 log.Printf("[%d] Listening on %s", node.id, s)
181 }
182
183 // register as event listener
184 incoming := make(chan *core.Event)
185 node.core.Register(config.Cfg.Local.Name, core.NewListener(incoming, nil))
186
187 // heart beat
188 tick := time.NewTicker(5 * time.Minute)
189
190 // run event handler
191 go func() {
192 for {
193 select {
194 // show incoming event
195 case ev := <-incoming:
196 switch ev.ID {
197 case core.EV_CONNECT:
198 log.Printf("[%d] <<< Peer %s connected", node.id, ev.Peer)
199 case core.EV_DISCONNECT:
200 log.Printf("[%d] <<< Peer %s diconnected", node.id, ev.Peer)
201 case core.EV_MESSAGE:
202 log.Printf("[%d] <<< Msg from %s of type %d", node.id, ev.Peer, ev.Msg.Header().MsgType)
203 log.Printf("[%d] <<< --> %s", node.id, ev.Msg.String())
204 }
205
206 // handle termination signal
207 case <-ctx.Done():
208 log.Printf("[%d] Shutting down node", node.id)
209 return
210
211 // handle heart beat
212 case now := <-tick.C:
213 log.Printf("[%d] Heart beat at %s", node.id, now.String())
214 }
215 }
216 }()
217 return
218}
diff --git a/src/gnunet/transport/endpoint.go b/src/gnunet/transport/endpoint.go
index 5dabfa2..26e4463 100644
--- a/src/gnunet/transport/endpoint.go
+++ b/src/gnunet/transport/endpoint.go
@@ -107,6 +107,8 @@ func (ep *PaketEndpoint) Run(ctx context.Context, hdlr chan *TransportMessage) (
107 if err != nil { 107 if err != nil {
108 break 108 break
109 } 109 }
110 // label message
111 tm.Label = ep.addr.String()
110 // send transport message to handler 112 // send transport message to handler
111 go func() { 113 go func() {
112 hdlr <- tm 114 hdlr <- tm
@@ -143,8 +145,10 @@ func (ep *PaketEndpoint) read() (tm *TransportMessage, err error) {
143 } 145 }
144 // return transport message 146 // return transport message
145 return &TransportMessage{ 147 return &TransportMessage{
146 Peer: peer, 148 Peer: peer,
147 Msg: msg, 149 Msg: msg,
150 Resp: nil,
151 Label: "",
148 }, nil 152 }, nil
149} 153}
150 154
diff --git a/src/gnunet/transport/responder.go b/src/gnunet/transport/responder.go
new file mode 100644
index 0000000..f0d9d66
--- /dev/null
+++ b/src/gnunet/transport/responder.go
@@ -0,0 +1,52 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 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
19package transport
20
21import (
22 "context"
23 "errors"
24 "gnunet/message"
25 "gnunet/util"
26)
27
28//----------------------------------------------------------------------
29// Responder is a back-channel for messages generated during
30// message processing. The Connection type is a responder
31// and used as such in ServeClient().
32type Responder interface {
33 // Handle outgoing message
34 Send(ctx context.Context, msg message.Message) error
35}
36
37//----------------------------------------------------------------------
38// TransportResponder is used as a responder in message handling for
39// messages received from Transport. It is used by Endpoint instances
40// to define custom responders for messages received.
41type TransportResponder struct {
42 Peer *util.PeerID
43 SendFcn func(context.Context, *util.PeerID, message.Message) error
44}
45
46// Send a message back to caller. The specifics are handled in the callback.
47func (r *TransportResponder) Send(ctx context.Context, msg message.Message) error {
48 if r.SendFcn == nil {
49 return errors.New("no send function defined")
50 }
51 return r.SendFcn(ctx, r.Peer, msg)
52}
diff --git a/src/gnunet/transport/transport.go b/src/gnunet/transport/transport.go
index d1e8249..2101849 100644
--- a/src/gnunet/transport/transport.go
+++ b/src/gnunet/transport/transport.go
@@ -43,8 +43,22 @@ var (
43// Msg is the exchanged GNUnet message. The packet itself satisfies the 43// Msg is the exchanged GNUnet message. The packet itself satisfies the
44// message.Message interface. 44// message.Message interface.
45type TransportMessage struct { 45type TransportMessage struct {
46 Peer *util.PeerID // remote peer 46 // Peer is a identifier for a remote peer
47 Msg message.Message // GNUnet message 47 Peer *util.PeerID
48
49 // Msg is a generic GNnet message
50 Msg message.Message
51
52 // Non-serialized (transient) attributes:
53
54 // Resp is an optional custom endpoint responder that can be set by
55 // endpoints for messages received from the internet if they want to
56 // handle responses directly (instead of core/transport/endpoint
57 // resolving the return path). Set to nil if not used.
58 Resp Responder
59
60 // Label for log messages during message processing
61 Label string
48} 62}
49 63
50// Bytes returns the binary representation of a transport message 64// Bytes returns the binary representation of a transport message
@@ -70,8 +84,10 @@ func NewTransportMessage(peer *util.PeerID, msg message.Message) (tm *TransportM
70 peer = util.NewPeerID(nil) 84 peer = util.NewPeerID(nil)
71 } 85 }
72 tm = &TransportMessage{ 86 tm = &TransportMessage{
73 Peer: peer, 87 Peer: peer,
74 Msg: msg, 88 Msg: msg,
89 Resp: nil,
90 Label: "",
75 } 91 }
76 return 92 return
77} 93}
@@ -109,13 +125,24 @@ func (t *Transport) Shutdown() {
109 125
110// Send a message over suitable endpoint 126// Send a message over suitable endpoint
111func (t *Transport) Send(ctx context.Context, addr net.Addr, msg *TransportMessage) (err error) { 127func (t *Transport) Send(ctx context.Context, addr net.Addr, msg *TransportMessage) (err error) {
112 // use the first endpoint able to handle address 128 // select best endpoint able to handle address
113 return t.endpoints.ProcessRange(func(_ int, ep Endpoint) error { 129 var bestEp Endpoint
130 err = t.endpoints.ProcessRange(func(_ int, ep Endpoint) error {
114 if ep.CanSendTo(addr) { 131 if ep.CanSendTo(addr) {
115 return ep.Send(ctx, addr, msg) 132 if bestEp == nil {
133 bestEp = ep
134 }
135 // TODO: compare endpoints, select better one:
136 // if ep.Better(bestEp) {
137 // bestEp = ep
138 // }
116 } 139 }
117 return nil 140 return nil
118 }, true) 141 }, true)
142 if err != nil {
143 return
144 }
145 return bestEp.Send(ctx, addr, msg)
119} 146}
120 147
121//---------------------------------------------------------------------- 148//----------------------------------------------------------------------
diff --git a/src/gnunet/util/address.go b/src/gnunet/util/address.go
index a56e95f..4cd07da 100644
--- a/src/gnunet/util/address.go
+++ b/src/gnunet/util/address.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/array.go b/src/gnunet/util/array.go
index c6d6371..99c74d9 100644
--- a/src/gnunet/util/array.go
+++ b/src/gnunet/util/array.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -120,3 +120,15 @@ func StringList(b []byte) []string {
120 } 120 }
121 return res 121 return res
122} 122}
123
124// ReadCString reads a \0-terminate string from a buffer starting at the
125// specified position. Returns the string and the new position (-1 for end
126// of buffer reached)
127func ReadCString(buf []byte, pos int) (string, int) {
128 for idx := pos; idx < len(buf); idx++ {
129 if buf[idx] == 0 {
130 return string(buf[pos:idx]), idx + 1
131 }
132 }
133 return "", -1
134}
diff --git a/src/gnunet/util/base32.go b/src/gnunet/util/base32.go
index e3e500e..f0b149a 100644
--- a/src/gnunet/util/base32.go
+++ b/src/gnunet/util/base32.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/base32_test.go b/src/gnunet/util/base32_test.go
index 23b4372..2ec7231 100644
--- a/src/gnunet/util/base32_test.go
+++ b/src/gnunet/util/base32_test.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/database.go b/src/gnunet/util/database.go
index f1d1e5f..852862b 100644
--- a/src/gnunet/util/database.go
+++ b/src/gnunet/util/database.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/format.go b/src/gnunet/util/format.go
index 7b7891a..22b0742 100644
--- a/src/gnunet/util/format.go
+++ b/src/gnunet/util/format.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/fs.go b/src/gnunet/util/fs.go
index b2a464e..3df641c 100644
--- a/src/gnunet/util/fs.go
+++ b/src/gnunet/util/fs.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/id.go b/src/gnunet/util/id.go
index f2fb4f0..990dfa7 100644
--- a/src/gnunet/util/id.go
+++ b/src/gnunet/util/id.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/misc.go b/src/gnunet/util/misc.go
index 4443737..2ee8f1d 100644
--- a/src/gnunet/util/misc.go
+++ b/src/gnunet/util/misc.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/peer_id.go b/src/gnunet/util/peer_id.go
index a74958d..384f46c 100644
--- a/src/gnunet/util/peer_id.go
+++ b/src/gnunet/util/peer_id.go
@@ -18,7 +18,11 @@
18 18
19package util 19package util
20 20
21import "bytes" 21import (
22 "bytes"
23
24 "github.com/bfix/gospel/crypto/ed25519"
25)
22 26
23// PeerID is the 32-byte binary representation od a Ed25519 key 27// PeerID is the 32-byte binary representation od a Ed25519 key
24type PeerID struct { 28type PeerID struct {
@@ -49,3 +53,7 @@ func (p *PeerID) Equals(q *PeerID) bool {
49func (p *PeerID) String() string { 53func (p *PeerID) String() string {
50 return EncodeBinaryToString(p.Key) 54 return EncodeBinaryToString(p.Key)
51} 55}
56
57func (p *PeerID) PublicKey() *ed25519.PublicKey {
58 return ed25519.NewPublicKeyFromBytes(p.Key)
59}
diff --git a/src/gnunet/util/rnd.go b/src/gnunet/util/rnd.go
index 9c8ee10..c01f331 100644
--- a/src/gnunet/util/rnd.go
+++ b/src/gnunet/util/rnd.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
diff --git a/src/gnunet/util/time.go b/src/gnunet/util/time.go
index 53589b8..9a9d365 100644
--- a/src/gnunet/util/time.go
+++ b/src/gnunet/util/time.go
@@ -1,5 +1,5 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang. 1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019, 2020 Bernd Fix >Y< 2// Copyright (C) 2019-2022 Bernd Fix >Y<
3// 3//
4// gnunet-go is free software: you can redistribute it and/or modify it 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 5// under the terms of the GNU Affero General Public License as published
@@ -28,7 +28,7 @@ import (
28//---------------------------------------------------------------------- 28//----------------------------------------------------------------------
29 29
30// AbsoluteTime refers to a unique point in time. 30// AbsoluteTime refers to a unique point in time.
31// The value is the elapsed time in milliseconds (Unix epoch), so no timestamp 31// The value is the elapsed time in microseconds (Unix epoch), so no timestamp
32// before January 1st, 1970 is possible (not a restriction for GNUnet). 32// before January 1st, 1970 is possible (not a restriction for GNUnet).
33type AbsoluteTime struct { 33type AbsoluteTime struct {
34 Val uint64 `order:"big"` 34 Val uint64 `order:"big"`