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
138f0d74
Unverified
Commit
138f0d74
authored
Jun 07, 2022
by
Håvard Anda Estensen
Committed by
GitHub
Jun 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p: use errors.Is for error comparison (#24882)
Co-authored-by:
Felix Lange
<
fjl@twurst.com
>
parent
41e75480
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
24 additions
and
13 deletions
+24
-13
lookup.go
p2p/discover/lookup.go
+2
-1
v4_udp.go
p2p/discover/v4_udp.go
+2
-2
v5_udp.go
p2p/discover/v5_udp.go
+2
-2
encoding.go
p2p/discover/v5wire/encoding.go
+1
-1
client.go
p2p/dnsdisc/client.go
+3
-2
entries.go
p2p/enr/entries.go
+10
-2
peer.go
p2p/peer.go
+1
-1
peer_error.go
p2p/peer_error.go
+1
-1
http.go
p2p/simulations/http.go
+2
-1
No files found.
p2p/discover/lookup.go
View file @
138f0d74
...
@@ -18,6 +18,7 @@ package discover
...
@@ -18,6 +18,7 @@ package discover
import
(
import
(
"context"
"context"
"errors"
"time"
"time"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enode"
...
@@ -141,7 +142,7 @@ func (it *lookup) slowdown() {
...
@@ -141,7 +142,7 @@ func (it *lookup) slowdown() {
func
(
it
*
lookup
)
query
(
n
*
node
,
reply
chan
<-
[]
*
node
)
{
func
(
it
*
lookup
)
query
(
n
*
node
,
reply
chan
<-
[]
*
node
)
{
fails
:=
it
.
tab
.
db
.
FindFails
(
n
.
ID
(),
n
.
IP
())
fails
:=
it
.
tab
.
db
.
FindFails
(
n
.
ID
(),
n
.
IP
())
r
,
err
:=
it
.
queryfunc
(
n
)
r
,
err
:=
it
.
queryfunc
(
n
)
if
err
==
errClosed
{
if
err
ors
.
Is
(
err
,
errClosed
)
{
// Avoid recording failures on shutdown.
// Avoid recording failures on shutdown.
reply
<-
nil
reply
<-
nil
return
return
...
...
p2p/discover/v4_udp.go
View file @
138f0d74
...
@@ -328,7 +328,7 @@ func (t *UDPv4) findnode(toid enode.ID, toaddr *net.UDPAddr, target v4wire.Pubke
...
@@ -328,7 +328,7 @@ func (t *UDPv4) findnode(toid enode.ID, toaddr *net.UDPAddr, target v4wire.Pubke
// enough nodes the reply matcher will time out waiting for the second reply, but
// enough nodes the reply matcher will time out waiting for the second reply, but
// there's no need for an error in that case.
// there's no need for an error in that case.
err
:=
<-
rm
.
errc
err
:=
<-
rm
.
errc
if
err
==
errTimeout
&&
rm
.
reply
!=
nil
{
if
err
ors
.
Is
(
err
,
errTimeout
)
&&
rm
.
reply
!=
nil
{
err
=
nil
err
=
nil
}
}
return
nodes
,
err
return
nodes
,
err
...
@@ -526,7 +526,7 @@ func (t *UDPv4) readLoop(unhandled chan<- ReadPacket) {
...
@@ -526,7 +526,7 @@ func (t *UDPv4) readLoop(unhandled chan<- ReadPacket) {
continue
continue
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
// Shut down the loop for permament errors.
// Shut down the loop for permament errors.
if
err
!=
io
.
EOF
{
if
!
errors
.
Is
(
err
,
io
.
EOF
)
{
t
.
log
.
Debug
(
"UDP read error"
,
"err"
,
err
)
t
.
log
.
Debug
(
"UDP read error"
,
"err"
,
err
)
}
}
return
return
...
...
p2p/discover/v5_udp.go
View file @
138f0d74
...
@@ -305,7 +305,7 @@ func (t *UDPv5) lookupWorker(destNode *node, target enode.ID) ([]*node, error) {
...
@@ -305,7 +305,7 @@ func (t *UDPv5) lookupWorker(destNode *node, target enode.ID) ([]*node, error) {
)
)
var
r
[]
*
enode
.
Node
var
r
[]
*
enode
.
Node
r
,
err
=
t
.
findnode
(
unwrapNode
(
destNode
),
dists
)
r
,
err
=
t
.
findnode
(
unwrapNode
(
destNode
),
dists
)
if
err
==
errClosed
{
if
err
ors
.
Is
(
err
,
errClosed
)
{
return
nil
,
err
return
nil
,
err
}
}
for
_
,
n
:=
range
r
{
for
_
,
n
:=
range
r
{
...
@@ -623,7 +623,7 @@ func (t *UDPv5) readLoop() {
...
@@ -623,7 +623,7 @@ func (t *UDPv5) readLoop() {
continue
continue
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
// Shut down the loop for permament errors.
// Shut down the loop for permament errors.
if
err
!=
io
.
EOF
{
if
!
errors
.
Is
(
err
,
io
.
EOF
)
{
t
.
log
.
Debug
(
"UDP read error"
,
"err"
,
err
)
t
.
log
.
Debug
(
"UDP read error"
,
"err"
,
err
)
}
}
return
return
...
...
p2p/discover/v5wire/encoding.go
View file @
138f0d74
...
@@ -596,7 +596,7 @@ func (c *Codec) decodeMessage(fromAddr string, head *Header, headerData, msgData
...
@@ -596,7 +596,7 @@ func (c *Codec) decodeMessage(fromAddr string, head *Header, headerData, msgData
// Try decrypting the message.
// Try decrypting the message.
key
:=
c
.
sc
.
readKey
(
auth
.
SrcID
,
fromAddr
)
key
:=
c
.
sc
.
readKey
(
auth
.
SrcID
,
fromAddr
)
msg
,
err
:=
c
.
decryptMessage
(
msgData
,
head
.
Nonce
[
:
],
headerData
,
key
)
msg
,
err
:=
c
.
decryptMessage
(
msgData
,
head
.
Nonce
[
:
],
headerData
,
key
)
if
err
==
errMessageDecrypt
{
if
err
ors
.
Is
(
err
,
errMessageDecrypt
)
{
// It didn't work. Start the handshake since this is an ordinary message packet.
// It didn't work. Start the handshake since this is an ordinary message packet.
return
&
Unknown
{
Nonce
:
head
.
Nonce
},
nil
return
&
Unknown
{
Nonce
:
head
.
Nonce
},
nil
}
}
...
...
p2p/dnsdisc/client.go
View file @
138f0d74
...
@@ -19,6 +19,7 @@ package dnsdisc
...
@@ -19,6 +19,7 @@ package dnsdisc
import
(
import
(
"bytes"
"bytes"
"context"
"context"
"errors"
"fmt"
"fmt"
"math/rand"
"math/rand"
"net"
"net"
...
@@ -204,7 +205,7 @@ func (c *Client) doResolveEntry(ctx context.Context, domain, hash string) (entry
...
@@ -204,7 +205,7 @@ func (c *Client) doResolveEntry(ctx context.Context, domain, hash string) (entry
}
}
for
_
,
txt
:=
range
txts
{
for
_
,
txt
:=
range
txts
{
e
,
err
:=
parseEntry
(
txt
,
c
.
cfg
.
ValidSchemes
)
e
,
err
:=
parseEntry
(
txt
,
c
.
cfg
.
ValidSchemes
)
if
err
==
errUnknownEntry
{
if
err
ors
.
Is
(
err
,
errUnknownEntry
)
{
continue
continue
}
}
if
!
bytes
.
HasPrefix
(
crypto
.
Keccak256
([]
byte
(
txt
)),
wantHash
)
{
if
!
bytes
.
HasPrefix
(
crypto
.
Keccak256
([]
byte
(
txt
)),
wantHash
)
{
...
@@ -281,7 +282,7 @@ func (it *randomIterator) nextNode() *enode.Node {
...
@@ -281,7 +282,7 @@ func (it *randomIterator) nextNode() *enode.Node {
}
}
n
,
err
:=
ct
.
syncRandom
(
it
.
ctx
)
n
,
err
:=
ct
.
syncRandom
(
it
.
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
if
err
==
it
.
ctx
.
Err
(
)
{
if
err
ors
.
Is
(
err
,
it
.
ctx
.
Err
()
)
{
return
nil
// context canceled.
return
nil
// context canceled.
}
}
it
.
c
.
cfg
.
Logger
.
Debug
(
"Error in DNS random node sync"
,
"tree"
,
ct
.
loc
.
domain
,
"err"
,
err
)
it
.
c
.
cfg
.
Logger
.
Debug
(
"Error in DNS random node sync"
,
"tree"
,
ct
.
loc
.
domain
,
"err"
,
err
)
...
...
p2p/enr/entries.go
View file @
138f0d74
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
enr
package
enr
import
(
import
(
"errors"
"fmt"
"fmt"
"io"
"io"
"net"
"net"
...
@@ -180,9 +181,16 @@ func (err *KeyError) Error() string {
...
@@ -180,9 +181,16 @@ func (err *KeyError) Error() string {
return
fmt
.
Sprintf
(
"ENR key %q: %v"
,
err
.
Key
,
err
.
Err
)
return
fmt
.
Sprintf
(
"ENR key %q: %v"
,
err
.
Key
,
err
.
Err
)
}
}
func
(
err
*
KeyError
)
Unwrap
()
error
{
return
err
.
Err
}
// IsNotFound reports whether the given error means that a key/value pair is
// IsNotFound reports whether the given error means that a key/value pair is
// missing from a record.
// missing from a record.
func
IsNotFound
(
err
error
)
bool
{
func
IsNotFound
(
err
error
)
bool
{
kerr
,
ok
:=
err
.
(
*
KeyError
)
var
ke
*
KeyError
return
ok
&&
kerr
.
Err
==
errNotFound
if
errors
.
As
(
err
,
&
ke
)
{
return
ke
.
Err
==
errNotFound
}
return
false
}
}
p2p/peer.go
View file @
138f0d74
...
@@ -416,7 +416,7 @@ func (p *Peer) startProtocols(writeStart <-chan struct{}, writeErr chan<- error)
...
@@ -416,7 +416,7 @@ func (p *Peer) startProtocols(writeStart <-chan struct{}, writeErr chan<- error)
if
err
==
nil
{
if
err
==
nil
{
p
.
log
.
Trace
(
fmt
.
Sprintf
(
"Protocol %s/%d returned"
,
proto
.
Name
,
proto
.
Version
))
p
.
log
.
Trace
(
fmt
.
Sprintf
(
"Protocol %s/%d returned"
,
proto
.
Name
,
proto
.
Version
))
err
=
errProtocolReturned
err
=
errProtocolReturned
}
else
if
err
!=
io
.
EOF
{
}
else
if
!
errors
.
Is
(
err
,
io
.
EOF
)
{
p
.
log
.
Trace
(
fmt
.
Sprintf
(
"Protocol %s/%d failed"
,
proto
.
Name
,
proto
.
Version
),
"err"
,
err
)
p
.
log
.
Trace
(
fmt
.
Sprintf
(
"Protocol %s/%d failed"
,
proto
.
Name
,
proto
.
Version
),
"err"
,
err
)
}
}
p
.
protoErr
<-
err
p
.
protoErr
<-
err
...
...
p2p/peer_error.go
View file @
138f0d74
...
@@ -103,7 +103,7 @@ func discReasonForError(err error) DiscReason {
...
@@ -103,7 +103,7 @@ func discReasonForError(err error) DiscReason {
if
reason
,
ok
:=
err
.
(
DiscReason
);
ok
{
if
reason
,
ok
:=
err
.
(
DiscReason
);
ok
{
return
reason
return
reason
}
}
if
err
==
errProtocolReturned
{
if
err
ors
.
Is
(
err
,
errProtocolReturned
)
{
return
DiscQuitting
return
DiscQuitting
}
}
peerError
,
ok
:=
err
.
(
*
peerError
)
peerError
,
ok
:=
err
.
(
*
peerError
)
...
...
p2p/simulations/http.go
View file @
138f0d74
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"bytes"
"bytes"
"context"
"context"
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"html"
"html"
"io"
"io"
...
@@ -559,7 +560,7 @@ func (s *Server) CreateNode(w http.ResponseWriter, req *http.Request) {
...
@@ -559,7 +560,7 @@ func (s *Server) CreateNode(w http.ResponseWriter, req *http.Request) {
config
:=
&
adapters
.
NodeConfig
{}
config
:=
&
adapters
.
NodeConfig
{}
err
:=
json
.
NewDecoder
(
req
.
Body
)
.
Decode
(
config
)
err
:=
json
.
NewDecoder
(
req
.
Body
)
.
Decode
(
config
)
if
err
!=
nil
&&
err
!=
io
.
EOF
{
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
return
}
}
...
...
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