Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
adf007da
Unverified
Commit
adf007da
authored
Nov 07, 2019
by
Felix Lange
Committed by
GitHub
Nov 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/enode: mock DNS resolver in URL parsing test (#20252)
parent
4b8f56cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
urlv4.go
p2p/enode/urlv4.go
+11
-6
urlv4_test.go
p2p/enode/urlv4_test.go
+10
-0
No files found.
p2p/enode/urlv4.go
View file @
adf007da
...
@@ -31,7 +31,10 @@ import (
...
@@ -31,7 +31,10 @@ import (
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/p2p/enr"
)
)
var
incompleteNodeURL
=
regexp
.
MustCompile
(
"(?i)^(?:enode://)?([0-9a-f]+)$"
)
var
(
incompleteNodeURL
=
regexp
.
MustCompile
(
"(?i)^(?:enode://)?([0-9a-f]+)$"
)
lookupIPFunc
=
net
.
LookupIP
)
// MustParseV4 parses a node URL. It panics if the URL is not valid.
// MustParseV4 parses a node URL. It panics if the URL is not valid.
func
MustParseV4
(
rawurl
string
)
*
Node
{
func
MustParseV4
(
rawurl
string
)
*
Node
{
...
@@ -107,7 +110,6 @@ func isNewV4(n *Node) bool {
...
@@ -107,7 +110,6 @@ func isNewV4(n *Node) bool {
func
parseComplete
(
rawurl
string
)
(
*
Node
,
error
)
{
func
parseComplete
(
rawurl
string
)
(
*
Node
,
error
)
{
var
(
var
(
id
*
ecdsa
.
PublicKey
id
*
ecdsa
.
PublicKey
ip
net
.
IP
tcpPort
,
udpPort
uint64
tcpPort
,
udpPort
uint64
)
)
u
,
err
:=
url
.
Parse
(
rawurl
)
u
,
err
:=
url
.
Parse
(
rawurl
)
...
@@ -125,11 +127,14 @@ func parseComplete(rawurl string) (*Node, error) {
...
@@ -125,11 +127,14 @@ func parseComplete(rawurl string) (*Node, error) {
return
nil
,
fmt
.
Errorf
(
"invalid public key (%v)"
,
err
)
return
nil
,
fmt
.
Errorf
(
"invalid public key (%v)"
,
err
)
}
}
// Parse the IP address.
// Parse the IP address.
ips
,
err
:=
net
.
LookupIP
(
u
.
Hostname
())
ip
:=
net
.
ParseIP
(
u
.
Hostname
())
if
err
!=
nil
{
if
ip
==
nil
{
return
nil
,
err
ips
,
err
:=
lookupIPFunc
(
u
.
Hostname
())
if
err
!=
nil
{
return
nil
,
err
}
ip
=
ips
[
0
]
}
}
ip
=
ips
[
0
]
// Ensure the IP is 4 bytes long for IPv4 addresses.
// Ensure the IP is 4 bytes long for IPv4 addresses.
if
ipv4
:=
ip
.
To4
();
ipv4
!=
nil
{
if
ipv4
:=
ip
.
To4
();
ipv4
!=
nil
{
ip
=
ipv4
ip
=
ipv4
...
...
p2p/enode/urlv4_test.go
View file @
adf007da
...
@@ -18,6 +18,7 @@ package enode
...
@@ -18,6 +18,7 @@ package enode
import
(
import
(
"crypto/ecdsa"
"crypto/ecdsa"
"errors"
"net"
"net"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -27,6 +28,15 @@ import (
...
@@ -27,6 +28,15 @@ import (
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/p2p/enr"
)
)
func
init
()
{
lookupIPFunc
=
func
(
name
string
)
([]
net
.
IP
,
error
)
{
if
name
==
"node.example.org"
{
return
[]
net
.
IP
{{
33
,
44
,
55
,
66
}},
nil
}
return
nil
,
errors
.
New
(
"no such host"
)
}
}
var
parseNodeTests
=
[]
struct
{
var
parseNodeTests
=
[]
struct
{
input
string
input
string
wantError
string
wantError
string
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment