aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/core/peer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet/core/peer_test.go')
-rw-r--r--src/gnunet/core/peer_test.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/gnunet/core/peer_test.go b/src/gnunet/core/peer_test.go
new file mode 100644
index 0000000..28b328f
--- /dev/null
+++ b/src/gnunet/core/peer_test.go
@@ -0,0 +1,72 @@
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 "gnunet/config"
23 "gnunet/service/dht/blocks"
24 "testing"
25 "time"
26)
27
28// test data
29var (
30 cfg = &config.NodeConfig{
31 PrivateSeed: "YGoe6XFH3XdvFRl+agx9gIzPTvxA229WFdkazEMdcOs=",
32 Endpoints: []string{
33 "r5n+ip+udp://127.0.0.1:6666",
34 },
35 }
36 TTL = 6 * time.Hour
37)
38
39func TestPeerHello(t *testing.T) {
40
41 // generate new local node
42 node, err := NewLocalPeer(cfg)
43 if err != nil {
44 t.Fatal(err)
45 }
46
47 // get HELLO data for the node
48 h, err := node.HelloData(TTL)
49
50 // convert to URL and back
51 u := h.URL()
52 t.Log(u)
53 h2, err := blocks.ParseHelloURL(u)
54 if err != nil {
55 t.Fatal(err)
56 }
57 u2 := h2.URL()
58 t.Log(u2)
59
60 // check if HELLO data is the same
61 if !h.Equals(h2) {
62 t.Fatal("HELLO data mismatch")
63 }
64 // verify signature
65 ok, err := h.Verify()
66 if err != nil {
67 t.Fatal(err)
68 }
69 if !ok {
70 t.Fatal("failed to verify signature")
71 }
72}