-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
143 lines (129 loc) · 3.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"encoding/binary"
"encoding/hex"
"flag"
"fmt"
"net/netip"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
wenr "github.com/waku-org/go-waku/waku/v2/protocol/enr"
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
"github.com/waku-org/go-waku/waku/v2/protocol/lightpush"
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
"github.com/waku-org/go-waku/waku/v2/protocol/store"
)
func main() {
var enrStr = flag.String("enr", "", "enr to be decoded")
flag.Parse()
node, err := enode.Parse(enode.ValidSchemes, *enrStr)
if err != nil {
panic(err)
}
fmt.Println("Decoded ENR:")
peerID, multiaddrs, err := wenr.Multiaddress(node)
if err != nil {
panic(err)
}
fmt.Println("seq:", node.Record().Seq())
fmt.Println("signature:", "0x"+hex.EncodeToString(node.Record().Signature()))
fmt.Println("peer-id: ", peerID)
ip, err := GetValue(node.Record(), "ip")
if err != nil {
panic(err)
} else {
if len(ip) > 0 {
ipaddr, ok := netip.AddrFromSlice(ip)
if ok {
fmt.Println("ipv4:", ipaddr)
}
} else {
fmt.Println("ipv4: field has no value")
}
}
port, err := GetValue(node.Record(), "tcp")
if err != nil {
panic(err)
} else {
if len(port) > 0 {
fmt.Println("tcp-port:", binary.BigEndian.Uint16(port))
} else {
fmt.Println("tcp-port:: field has no value")
}
}
uport, err := GetValue(node.Record(), "udp")
if err != nil {
panic(err)
} else {
if len(uport) > 0 {
fmt.Println("udp-port:", binary.BigEndian.Uint16(uport))
} else {
fmt.Println("udp-port: field has no value")
}
}
shards, err := wenr.RelaySharding(node.Record())
if err != nil {
panic(err)
}
if shards != nil {
fmt.Println("cluster-id: ", shards.ClusterID)
fmt.Println("shards: ", shards.ShardIDs)
} else {
fmt.Println("cluster-id:", "not available")
fmt.Println("shards:", "not available")
}
DecodeWaku2ENRField(node.Record())
fmt.Println("multiaddresses:")
for _, maddr := range multiaddrs {
fmt.Println(maddr)
}
}
func DecodeWaku2ENRField(record *enr.Record) {
//Decoding Waku2 field
var enrField wenr.WakuEnrBitfield
var protosSupported []string
if err := record.Load(enr.WithEntry("waku2", &enrField)); err != nil {
if enr.IsNotFound(err) {
fmt.Println("waku2:", "field contains no value")
} else {
panic(err)
}
}
if enrField&relay.WakuRelayENRField != 0 {
protosSupported = append(protosSupported, string(relay.WakuRelayID_v200))
}
if enrField&filter.FilterSubscribeENRField != 0 {
protosSupported = append(protosSupported, string(filter.FilterSubscribeID_v20beta1))
}
if enrField&lightpush.LightPushENRField != 0 {
protosSupported = append(protosSupported, string(lightpush.LightPushID_v20beta1))
}
if enrField&store.StoreENRField != 0 {
protosSupported = append(protosSupported, string(store.StoreID_v20beta4))
}
fmt.Println("Wakuv2 Protocols Supported:")
for _, proto := range protosSupported {
fmt.Println(proto)
}
}
func GetValue(record *enr.Record, name string) ([]byte, error) {
var field []byte
if err := record.Load(enr.WithEntry(name, &field)); err != nil {
if enr.IsNotFound(err) {
return nil, nil
}
return nil, err
}
return field, nil
}
func ReadAndPrintValue(record *enr.Record, name string) {
var field []byte
if err := record.Load(enr.WithEntry(name, &field)); err != nil {
if enr.IsNotFound(err) {
fmt.Println(name, ":", "field contains no value")
return
}
panic(err)
}
fmt.Println(name, ":", "0x"+hex.EncodeToString(field))
}