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
b90cdbaa
Commit
b90cdbaa
authored
Aug 22, 2019
by
alexwang
Committed by
Felix Lange
Aug 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p/enode: allow DNS names in enode URLs (#18524)
parent
4d358b9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
urlv4.go
p2p/enode/urlv4.go
+7
-5
urlv4_test.go
p2p/enode/urlv4_test.go
+3
-3
No files found.
p2p/enode/urlv4.go
View file @
b90cdbaa
...
@@ -125,15 +125,17 @@ func parseComplete(rawurl string) (*Node, error) {
...
@@ -125,15 +125,17 @@ 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.
host
,
port
,
err
:=
net
.
SplitHostPort
(
u
.
Host
)
ips
,
err
:=
net
.
LookupIP
(
u
.
Hostname
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid host: %v"
,
err
)
return
nil
,
err
}
}
if
ip
=
net
.
ParseIP
(
host
);
ip
==
nil
{
ip
=
ips
[
0
]
return
nil
,
errors
.
New
(
"invalid IP address"
)
// Ensure the IP is 4 bytes long for IPv4 addresses.
if
ipv4
:=
ip
.
To4
();
ipv4
!=
nil
{
ip
=
ipv4
}
}
// Parse the port numbers.
// Parse the port numbers.
if
tcpPort
,
err
=
strconv
.
ParseUint
(
port
,
10
,
16
);
err
!=
nil
{
if
tcpPort
,
err
=
strconv
.
ParseUint
(
u
.
Port
()
,
10
,
16
);
err
!=
nil
{
return
nil
,
errors
.
New
(
"invalid port"
)
return
nil
,
errors
.
New
(
"invalid port"
)
}
}
udpPort
=
tcpPort
udpPort
=
tcpPort
...
...
p2p/enode/urlv4_test.go
View file @
b90cdbaa
...
@@ -61,8 +61,8 @@ var parseNodeTests = []struct {
...
@@ -61,8 +61,8 @@ var parseNodeTests = []struct {
},
},
// Complete node URLs with IP address and ports
// Complete node URLs with IP address and ports
{
{
input
:
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@
hostname
:3"
,
input
:
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@
invalid.
:3"
,
wantError
:
`
invalid IP address
`
,
wantError
:
`
no such host
`
,
},
},
{
{
input
:
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:foo"
,
input
:
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:foo"
,
...
@@ -76,7 +76,7 @@ var parseNodeTests = []struct {
...
@@ -76,7 +76,7 @@ var parseNodeTests = []struct {
input
:
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:52150"
,
input
:
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:52150"
,
wantResult
:
NewV4
(
wantResult
:
NewV4
(
hexPubkey
(
"1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"
),
hexPubkey
(
"1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"
),
net
.
IP
{
0x7f
,
0x0
,
0x0
,
0x
1
},
net
.
IP
{
127
,
0
,
0
,
1
},
52150
,
52150
,
52150
,
52150
,
),
),
...
...
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