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
61a6911e
Commit
61a6911e
authored
Aug 19, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1689 from fjl/discover-ignore-temp-errors
p2p, p2p/discover: small fixes
parents
382d35bf
dd54fef8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
11 deletions
+51
-11
node.go
p2p/discover/node.go
+4
-0
table.go
p2p/discover/table.go
+11
-4
udp.go
p2p/discover/udp.go
+11
-1
server.go
p2p/server.go
+25
-6
No files found.
p2p/discover/node.go
View file @
61a6911e
...
...
@@ -48,6 +48,10 @@ type Node struct {
// In those tests, the content of sha will not actually correspond
// with ID.
sha
common
.
Hash
// whether this node is currently being pinged in order to replace
// it in a bucket
contested
bool
}
func
newNode
(
id
NodeID
,
ip
net
.
IP
,
udpPort
,
tcpPort
uint16
)
*
Node
{
...
...
p2p/discover/table.go
View file @
61a6911e
...
...
@@ -455,24 +455,31 @@ func (tab *Table) ping(id NodeID, addr *net.UDPAddr) error {
func
(
tab
*
Table
)
add
(
new
*
Node
)
{
b
:=
tab
.
buckets
[
logdist
(
tab
.
self
.
sha
,
new
.
sha
)]
tab
.
mutex
.
Lock
()
defer
tab
.
mutex
.
Unlock
()
if
b
.
bump
(
new
)
{
tab
.
mutex
.
Unlock
()
return
}
var
oldest
*
Node
if
len
(
b
.
entries
)
==
bucketSize
{
oldest
=
b
.
entries
[
bucketSize
-
1
]
if
oldest
.
contested
{
// The node is already being replaced, don't attempt
// to replace it.
return
}
oldest
.
contested
=
true
// Let go of the mutex so other goroutines can access
// the table while we ping the least recently active node.
tab
.
mutex
.
Unlock
()
if
err
:=
tab
.
ping
(
oldest
.
ID
,
oldest
.
addr
());
err
==
nil
{
err
:=
tab
.
ping
(
oldest
.
ID
,
oldest
.
addr
())
tab
.
mutex
.
Lock
()
oldest
.
contested
=
false
if
err
==
nil
{
// The node responded, don't replace it.
return
}
tab
.
mutex
.
Lock
()
}
added
:=
b
.
replace
(
new
,
oldest
)
tab
.
mutex
.
Unlock
()
if
added
&&
tab
.
nodeAddedHook
!=
nil
{
tab
.
nodeAddedHook
(
new
)
}
...
...
p2p/discover/udp.go
View file @
61a6911e
...
...
@@ -458,6 +458,10 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) ([]byte,
return
packet
,
nil
}
type
tempError
interface
{
Temporary
()
bool
}
// readLoop runs in its own goroutine. it handles incoming UDP packets.
func
(
t
*
udp
)
readLoop
()
{
defer
t
.
conn
.
Close
()
...
...
@@ -467,7 +471,13 @@ func (t *udp) readLoop() {
buf
:=
make
([]
byte
,
1280
)
for
{
nbytes
,
from
,
err
:=
t
.
conn
.
ReadFromUDP
(
buf
)
if
err
!=
nil
{
if
tempErr
,
ok
:=
err
.
(
tempError
);
ok
&&
tempErr
.
Temporary
()
{
// Ignore temporary read errors.
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Temporary read error: %v"
,
err
)
continue
}
else
if
err
!=
nil
{
// Shut down the loop for permament errors.
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Read error: %v"
,
err
)
return
}
t
.
handlePacket
(
from
,
buf
[
:
nbytes
])
...
...
p2p/server.go
View file @
61a6911e
...
...
@@ -542,6 +542,10 @@ func (srv *Server) encHandshakeChecks(peers map[discover.NodeID]*Peer, c *conn)
}
}
type
tempError
interface
{
Temporary
()
bool
}
// listenLoop runs in its own goroutine and accepts
// inbound connections.
func
(
srv
*
Server
)
listenLoop
()
{
...
...
@@ -561,16 +565,31 @@ func (srv *Server) listenLoop() {
}
for
{
// Wait for a handshake slot before accepting.
<-
slots
fd
,
err
:=
srv
.
listener
.
Accept
()
if
err
!=
nil
{
return
var
(
fd
net
.
Conn
err
error
)
for
{
fd
,
err
=
srv
.
listener
.
Accept
()
if
tempErr
,
ok
:=
err
.
(
tempError
);
ok
&&
tempErr
.
Temporary
()
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Temporary read error: %v"
,
err
)
continue
}
else
if
err
!=
nil
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Read error: %v"
,
err
)
return
}
break
}
mfd
:=
newMeteredConn
(
fd
,
true
)
fd
=
newMeteredConn
(
fd
,
true
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Accepted conn %v
\n
"
,
fd
.
RemoteAddr
())
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Accepted conn %v
\n
"
,
mfd
.
RemoteAddr
())
// Spawn the handler. It will give the slot back when the connection
// has been established.
go
func
()
{
srv
.
setupConn
(
m
fd
,
inboundConn
,
nil
)
srv
.
setupConn
(
fd
,
inboundConn
,
nil
)
slots
<-
struct
{}{}
}()
}
...
...
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