mirror of
https://github.com/logos-messaging/test-discv5.git
synced 2026-01-07 08:33:07 +00:00
feat: dns discovery
This commit is contained in:
parent
d16f4e47e0
commit
f86394a5b9
1
go.mod
1
go.mod
@ -24,4 +24,5 @@ require (
|
|||||||
golang.org/x/crypto v0.1.0 // indirect
|
golang.org/x/crypto v0.1.0 // indirect
|
||||||
golang.org/x/sync v0.1.0 // indirect
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
golang.org/x/sys v0.7.0 // indirect
|
golang.org/x/sys v0.7.0 // indirect
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
2
go.sum
2
go.sum
@ -88,6 +88,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
|
||||||
|
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|||||||
27
main.go
27
main.go
@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/dnsdisc"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enr"
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
@ -22,6 +23,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
var portFlag = flag.Int("port", 6000, "port number")
|
var portFlag = flag.Int("port", 6000, "port number")
|
||||||
var bootnodeFlag = flag.String("bootnodes", "", "comma separated bootnodes")
|
var bootnodeFlag = flag.String("bootnodes", "", "comma separated bootnodes")
|
||||||
|
var dnsdiscFlag = flag.String("dns-disc-url", "", "DNS discovery URL")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
db, err := enode.OpenDB("")
|
db, err := enode.OpenDB("")
|
||||||
@ -39,6 +42,7 @@ func main() {
|
|||||||
|
|
||||||
bootnodesStr := strings.Split(*bootnodeFlag, ",")
|
bootnodesStr := strings.Split(*bootnodeFlag, ",")
|
||||||
var bootnodes []*enode.Node
|
var bootnodes []*enode.Node
|
||||||
|
|
||||||
for _, addr := range bootnodesStr {
|
for _, addr := range bootnodesStr {
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
continue
|
continue
|
||||||
@ -50,6 +54,23 @@ func main() {
|
|||||||
bootnodes = append(bootnodes, bootnode)
|
bootnodes = append(bootnodes, bootnode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *dnsdiscFlag != "" {
|
||||||
|
c := dnsdisc.NewClient(dnsdisc.Config{})
|
||||||
|
tree, err := c.SyncTree(*dnsdiscFlag)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bootnodes = append(bootnodes, tree.Nodes()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bootnodes) > 0 {
|
||||||
|
fmt.Println("Bootnodes:")
|
||||||
|
for i, b := range bootnodes {
|
||||||
|
fmt.Println(i+1, "-", b.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config := discover.Config{
|
config := discover.Config{
|
||||||
PrivateKey: priv,
|
PrivateKey: priv,
|
||||||
Bootnodes: bootnodes,
|
Bootnodes: bootnodes,
|
||||||
@ -76,7 +97,7 @@ func main() {
|
|||||||
|
|
||||||
localnode.SetFallbackUDP(udpAddr.Port)
|
localnode.SetFallbackUDP(udpAddr.Port)
|
||||||
|
|
||||||
fmt.Println("YOUR NODE:")
|
fmt.Println("\nYour node:")
|
||||||
fmt.Println(localnode.Node())
|
fmt.Println(localnode.Node())
|
||||||
listener, err := discover.ListenV5(conn, localnode, config)
|
listener, err := discover.ListenV5(conn, localnode, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -144,9 +165,9 @@ func main() {
|
|||||||
seen[node.ID()] = node
|
seen[node.ID()] = node
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(len(seen), recType, node.String())
|
fmt.Println(len(seen), "-", recType, "-", node.String())
|
||||||
node.TCP()
|
node.TCP()
|
||||||
fmt.Println("ip", node.IP(), ":", node.TCP())
|
fmt.Println(fmt.Sprintf("ip %s:%d", node.IP(), node.TCP()))
|
||||||
|
|
||||||
rs, err := ReadValue(node.Record(), "rs")
|
rs, err := ReadValue(node.Record(), "rs")
|
||||||
if err == nil && len(rs) > 0 {
|
if err == nil && len(rs) > 0 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user