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
5f735d6f
Commit
5f735d6f
authored
Apr 23, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd, eth, p2p, p2p/discover: init and clean up the seed cache
parent
936c8e19
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
9 deletions
+29
-9
main.go
cmd/bootnode/main.go
+1
-1
backend.go
eth/backend.go
+2
-0
node.go
p2p/discover/node.go
+4
-0
table.go
p2p/discover/table.go
+13
-3
udp.go
p2p/discover/udp.go
+4
-4
server.go
p2p/server.go
+5
-1
No files found.
cmd/bootnode/main.go
View file @
5f735d6f
...
...
@@ -71,7 +71,7 @@ func main() {
}
}
if
_
,
err
:=
discover
.
ListenUDP
(
nodeKey
,
*
listenAddr
,
natm
);
err
!=
nil
{
if
_
,
err
:=
discover
.
ListenUDP
(
nodeKey
,
*
listenAddr
,
natm
,
""
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
select
{}
...
...
eth/backend.go
View file @
5f735d6f
...
...
@@ -179,6 +179,7 @@ func New(config *Config) (*Ethereum, error) {
if
err
!=
nil
{
return
nil
,
err
}
seedDbPath
:=
path
.
Join
(
config
.
DataDir
,
"seeds"
)
// Perform database sanity checks
d
,
_
:=
blockDb
.
Get
([]
byte
(
"ProtocolVersion"
))
...
...
@@ -243,6 +244,7 @@ func New(config *Config) (*Ethereum, error) {
NAT
:
config
.
NAT
,
NoDial
:
!
config
.
Dial
,
BootstrapNodes
:
config
.
parseBootNodes
(),
SeedCache
:
seedDbPath
,
}
if
len
(
config
.
Port
)
>
0
{
eth
.
net
.
ListenAddr
=
":"
+
config
.
Port
...
...
p2p/discover/node.go
View file @
5f735d6f
...
...
@@ -387,3 +387,7 @@ func (db *nodeDB) add(id NodeID, addr *net.UDPAddr, tcpPort uint16) *Node {
db
.
update
(
n
)
return
n
}
func
(
db
*
nodeDB
)
close
()
{
db
.
ldb
.
Close
()
}
p2p/discover/table.go
View file @
5f735d6f
...
...
@@ -11,6 +11,9 @@ import (
"sort"
"sync"
"time"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
)
const
(
...
...
@@ -58,8 +61,14 @@ type bucket struct {
entries
[]
*
Node
}
func
newTable
(
t
transport
,
ourID
NodeID
,
ourAddr
*
net
.
UDPAddr
)
*
Table
{
db
,
_
:=
newNodeDB
(
""
,
Version
)
func
newTable
(
t
transport
,
ourID
NodeID
,
ourAddr
*
net
.
UDPAddr
,
seedCache
string
)
*
Table
{
// Load the bootstrap seed cache (use in memory db upon failure)
db
,
err
:=
newNodeDB
(
seedCache
,
Version
)
if
err
!=
nil
{
glog
.
V
(
logger
.
Warn
)
.
Infoln
(
"Failed to open bootstrap seed cache:"
,
err
)
db
,
_
=
newNodeDB
(
""
,
Version
)
}
// Create the bootstrap table
tab
:=
&
Table
{
net
:
t
,
db
:
db
,
...
...
@@ -81,9 +90,10 @@ func (tab *Table) Self() *Node {
return
tab
.
self
}
// Close terminates the network listener.
// Close terminates the network listener
and flushes the seed cache
.
func
(
tab
*
Table
)
Close
()
{
tab
.
net
.
close
()
tab
.
db
.
close
()
}
// Bootstrap sets the bootstrap nodes. These nodes are used to connect
...
...
p2p/discover/udp.go
View file @
5f735d6f
...
...
@@ -144,7 +144,7 @@ type reply struct {
}
// ListenUDP returns a new table that listens for UDP packets on laddr.
func
ListenUDP
(
priv
*
ecdsa
.
PrivateKey
,
laddr
string
,
natm
nat
.
Interface
)
(
*
Table
,
error
)
{
func
ListenUDP
(
priv
*
ecdsa
.
PrivateKey
,
laddr
string
,
natm
nat
.
Interface
,
seedCache
string
)
(
*
Table
,
error
)
{
addr
,
err
:=
net
.
ResolveUDPAddr
(
"udp"
,
laddr
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -153,12 +153,12 @@ func ListenUDP(priv *ecdsa.PrivateKey, laddr string, natm nat.Interface) (*Table
if
err
!=
nil
{
return
nil
,
err
}
tab
,
_
:=
newUDP
(
priv
,
conn
,
natm
)
tab
,
_
:=
newUDP
(
priv
,
conn
,
natm
,
seedCache
)
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"Listening,"
,
tab
.
self
)
return
tab
,
nil
}
func
newUDP
(
priv
*
ecdsa
.
PrivateKey
,
c
conn
,
natm
nat
.
Interface
)
(
*
Table
,
*
udp
)
{
func
newUDP
(
priv
*
ecdsa
.
PrivateKey
,
c
conn
,
natm
nat
.
Interface
,
seedCache
string
)
(
*
Table
,
*
udp
)
{
udp
:=
&
udp
{
conn
:
c
,
priv
:
priv
,
...
...
@@ -176,7 +176,7 @@ func newUDP(priv *ecdsa.PrivateKey, c conn, natm nat.Interface) (*Table, *udp) {
realaddr
=
&
net
.
UDPAddr
{
IP
:
ext
,
Port
:
realaddr
.
Port
}
}
}
udp
.
Table
=
newTable
(
udp
,
PubkeyID
(
&
priv
.
PublicKey
),
realaddr
)
udp
.
Table
=
newTable
(
udp
,
PubkeyID
(
&
priv
.
PublicKey
),
realaddr
,
seedCache
)
go
udp
.
loop
()
go
udp
.
readLoop
()
return
udp
.
Table
,
udp
...
...
p2p/server.go
View file @
5f735d6f
...
...
@@ -59,6 +59,10 @@ type Server struct {
// with the rest of the network.
BootstrapNodes
[]
*
discover
.
Node
// SeedCache is the path to the database containing the previously seen live
// nodes in the network to use as potential bootstrap seeds.
SeedCache
string
// Protocols should contain the protocols supported
// by the server. Matching protocols are launched for
// each peer.
...
...
@@ -197,7 +201,7 @@ func (srv *Server) Start() (err error) {
}
// node table
ntab
,
err
:=
discover
.
ListenUDP
(
srv
.
PrivateKey
,
srv
.
ListenAddr
,
srv
.
NAT
)
ntab
,
err
:=
discover
.
ListenUDP
(
srv
.
PrivateKey
,
srv
.
ListenAddr
,
srv
.
NAT
,
srv
.
SeedCache
)
if
err
!=
nil
{
return
err
}
...
...
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