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
b42a5b11
Commit
b42a5b11
authored
Sep 16, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common, node: move datadir defaults into package node
parent
eeb322ae
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
49 deletions
+43
-49
main.go
cmd/gethrpctest/main.go
+4
-5
customflags.go
cmd/utils/customflags.go
+12
-2
flags.go
cmd/utils/flags.go
+8
-8
path.go
common/path.go
+0
-27
api.go
node/api.go
+2
-2
config.go
node/config.go
+3
-3
defaults.go
node/defaults.go
+14
-2
No files found.
cmd/gethrpctest/main.go
View file @
b42a5b11
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"os"
"os"
"os/signal"
"os/signal"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth"
...
@@ -89,11 +88,11 @@ func MakeSystemNode(privkey string, test *tests.BlockTest) (*node.Node, error) {
...
@@ -89,11 +88,11 @@ func MakeSystemNode(privkey string, test *tests.BlockTest) (*node.Node, error) {
stack
,
err
:=
node
.
New
(
&
node
.
Config
{
stack
,
err
:=
node
.
New
(
&
node
.
Config
{
UseLightweightKDF
:
true
,
UseLightweightKDF
:
true
,
IPCPath
:
node
.
DefaultIPCEndpoint
(
""
),
IPCPath
:
node
.
DefaultIPCEndpoint
(
""
),
HTTPHost
:
common
.
DefaultHTTPHost
,
HTTPHost
:
node
.
DefaultHTTPHost
,
HTTPPort
:
common
.
DefaultHTTPPort
,
HTTPPort
:
node
.
DefaultHTTPPort
,
HTTPModules
:
[]
string
{
"admin"
,
"db"
,
"eth"
,
"debug"
,
"miner"
,
"net"
,
"shh"
,
"txpool"
,
"personal"
,
"web3"
},
HTTPModules
:
[]
string
{
"admin"
,
"db"
,
"eth"
,
"debug"
,
"miner"
,
"net"
,
"shh"
,
"txpool"
,
"personal"
,
"web3"
},
WSHost
:
common
.
DefaultWSHost
,
WSHost
:
node
.
DefaultWSHost
,
WSPort
:
common
.
DefaultWSPort
,
WSPort
:
node
.
DefaultWSPort
,
WSModules
:
[]
string
{
"admin"
,
"db"
,
"eth"
,
"debug"
,
"miner"
,
"net"
,
"shh"
,
"txpool"
,
"personal"
,
"web3"
},
WSModules
:
[]
string
{
"admin"
,
"db"
,
"eth"
,
"debug"
,
"miner"
,
"net"
,
"shh"
,
"txpool"
,
"personal"
,
"web3"
},
NoDiscovery
:
true
,
NoDiscovery
:
true
,
})
})
...
...
cmd/utils/customflags.go
View file @
b42a5b11
...
@@ -137,9 +137,19 @@ func (self *DirectoryFlag) Set(value string) {
...
@@ -137,9 +137,19 @@ func (self *DirectoryFlag) Set(value string) {
// Note, it has limitations, e.g. ~someuser/tmp will not be expanded
// Note, it has limitations, e.g. ~someuser/tmp will not be expanded
func
expandPath
(
p
string
)
string
{
func
expandPath
(
p
string
)
string
{
if
strings
.
HasPrefix
(
p
,
"~/"
)
||
strings
.
HasPrefix
(
p
,
"~
\\
"
)
{
if
strings
.
HasPrefix
(
p
,
"~/"
)
||
strings
.
HasPrefix
(
p
,
"~
\\
"
)
{
if
user
,
err
:=
user
.
Current
();
err
==
nil
{
if
home
:=
homeDir
();
home
!=
""
{
p
=
user
.
HomeDir
+
p
[
1
:
]
p
=
home
+
p
[
1
:
]
}
}
}
}
return
path
.
Clean
(
os
.
ExpandEnv
(
p
))
return
path
.
Clean
(
os
.
ExpandEnv
(
p
))
}
}
func
homeDir
()
string
{
if
home
:=
os
.
Getenv
(
"HOME"
);
home
!=
""
{
return
home
}
if
usr
,
err
:=
user
.
Current
();
err
==
nil
{
return
usr
.
HomeDir
}
return
""
}
cmd/utils/flags.go
View file @
b42a5b11
...
@@ -105,7 +105,7 @@ var (
...
@@ -105,7 +105,7 @@ var (
DataDirFlag
=
DirectoryFlag
{
DataDirFlag
=
DirectoryFlag
{
Name
:
"datadir"
,
Name
:
"datadir"
,
Usage
:
"Data directory for the databases and keystore"
,
Usage
:
"Data directory for the databases and keystore"
,
Value
:
DirectoryString
{
common
.
DefaultDataDir
()},
Value
:
DirectoryString
{
node
.
DefaultDataDir
()},
}
}
KeyStoreDirFlag
=
DirectoryFlag
{
KeyStoreDirFlag
=
DirectoryFlag
{
Name
:
"keystore"
,
Name
:
"keystore"
,
...
@@ -139,7 +139,7 @@ var (
...
@@ -139,7 +139,7 @@ var (
DocRootFlag
=
DirectoryFlag
{
DocRootFlag
=
DirectoryFlag
{
Name
:
"docroot"
,
Name
:
"docroot"
,
Usage
:
"Document Root for HTTPClient file scheme"
,
Usage
:
"Document Root for HTTPClient file scheme"
,
Value
:
DirectoryString
{
common
.
H
omeDir
()},
Value
:
DirectoryString
{
h
omeDir
()},
}
}
CacheFlag
=
cli
.
IntFlag
{
CacheFlag
=
cli
.
IntFlag
{
Name
:
"cache"
,
Name
:
"cache"
,
...
@@ -245,12 +245,12 @@ var (
...
@@ -245,12 +245,12 @@ var (
RPCListenAddrFlag
=
cli
.
StringFlag
{
RPCListenAddrFlag
=
cli
.
StringFlag
{
Name
:
"rpcaddr"
,
Name
:
"rpcaddr"
,
Usage
:
"HTTP-RPC server listening interface"
,
Usage
:
"HTTP-RPC server listening interface"
,
Value
:
common
.
DefaultHTTPHost
,
Value
:
node
.
DefaultHTTPHost
,
}
}
RPCPortFlag
=
cli
.
IntFlag
{
RPCPortFlag
=
cli
.
IntFlag
{
Name
:
"rpcport"
,
Name
:
"rpcport"
,
Usage
:
"HTTP-RPC server listening port"
,
Usage
:
"HTTP-RPC server listening port"
,
Value
:
common
.
DefaultHTTPPort
,
Value
:
node
.
DefaultHTTPPort
,
}
}
RPCCORSDomainFlag
=
cli
.
StringFlag
{
RPCCORSDomainFlag
=
cli
.
StringFlag
{
Name
:
"rpccorsdomain"
,
Name
:
"rpccorsdomain"
,
...
@@ -268,13 +268,13 @@ var (
...
@@ -268,13 +268,13 @@ var (
}
}
IPCApiFlag
=
cli
.
StringFlag
{
IPCApiFlag
=
cli
.
StringFlag
{
Name
:
"ipcapi"
,
Name
:
"ipcapi"
,
Usage
:
"API
'
s offered over the IPC-RPC interface"
,
Usage
:
"APIs offered over the IPC-RPC interface"
,
Value
:
rpc
.
DefaultIPCApis
,
Value
:
rpc
.
DefaultIPCApis
,
}
}
IPCPathFlag
=
DirectoryFlag
{
IPCPathFlag
=
DirectoryFlag
{
Name
:
"ipcpath"
,
Name
:
"ipcpath"
,
Usage
:
"Filename for IPC socket/pipe within the datadir (explicit paths escape it)"
,
Usage
:
"Filename for IPC socket/pipe within the datadir (explicit paths escape it)"
,
Value
:
DirectoryString
{
common
.
DefaultIPCSocket
},
Value
:
DirectoryString
{
"geth.ipc"
},
}
}
WSEnabledFlag
=
cli
.
BoolFlag
{
WSEnabledFlag
=
cli
.
BoolFlag
{
Name
:
"ws"
,
Name
:
"ws"
,
...
@@ -283,12 +283,12 @@ var (
...
@@ -283,12 +283,12 @@ var (
WSListenAddrFlag
=
cli
.
StringFlag
{
WSListenAddrFlag
=
cli
.
StringFlag
{
Name
:
"wsaddr"
,
Name
:
"wsaddr"
,
Usage
:
"WS-RPC server listening interface"
,
Usage
:
"WS-RPC server listening interface"
,
Value
:
common
.
DefaultWSHost
,
Value
:
node
.
DefaultWSHost
,
}
}
WSPortFlag
=
cli
.
IntFlag
{
WSPortFlag
=
cli
.
IntFlag
{
Name
:
"wsport"
,
Name
:
"wsport"
,
Usage
:
"WS-RPC server listening port"
,
Usage
:
"WS-RPC server listening port"
,
Value
:
common
.
DefaultWSPort
,
Value
:
node
.
DefaultWSPort
,
}
}
WSApiFlag
=
cli
.
StringFlag
{
WSApiFlag
=
cli
.
StringFlag
{
Name
:
"wsapi"
,
Name
:
"wsapi"
,
...
...
common/path.go
View file @
b42a5b11
...
@@ -19,10 +19,8 @@ package common
...
@@ -19,10 +19,8 @@ package common
import
(
import
(
"fmt"
"fmt"
"os"
"os"
"os/user"
"path/filepath"
"path/filepath"
"runtime"
"runtime"
"strings"
)
)
// MakeName creates a node name that follows the ethereum convention
// MakeName creates a node name that follows the ethereum convention
...
@@ -32,21 +30,6 @@ func MakeName(name, version string) string {
...
@@ -32,21 +30,6 @@ func MakeName(name, version string) string {
return
fmt
.
Sprintf
(
"%s/v%s/%s/%s"
,
name
,
version
,
runtime
.
GOOS
,
runtime
.
Version
())
return
fmt
.
Sprintf
(
"%s/v%s/%s/%s"
,
name
,
version
,
runtime
.
GOOS
,
runtime
.
Version
())
}
}
func
ExpandHomePath
(
p
string
)
(
path
string
)
{
path
=
p
sep
:=
string
(
os
.
PathSeparator
)
// Check in case of paths like "/something/~/something/"
if
len
(
p
)
>
1
&&
p
[
:
1
+
len
(
sep
)]
==
"~"
+
sep
{
usr
,
_
:=
user
.
Current
()
dir
:=
usr
.
HomeDir
path
=
strings
.
Replace
(
p
,
"~"
,
dir
,
1
)
}
return
}
func
FileExist
(
filePath
string
)
bool
{
func
FileExist
(
filePath
string
)
bool
{
_
,
err
:=
os
.
Stat
(
filePath
)
_
,
err
:=
os
.
Stat
(
filePath
)
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
if
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
...
@@ -62,13 +45,3 @@ func AbsolutePath(Datadir string, filename string) string {
...
@@ -62,13 +45,3 @@ func AbsolutePath(Datadir string, filename string) string {
}
}
return
filepath
.
Join
(
Datadir
,
filename
)
return
filepath
.
Join
(
Datadir
,
filename
)
}
}
func
HomeDir
()
string
{
if
home
:=
os
.
Getenv
(
"HOME"
);
home
!=
""
{
return
home
}
if
usr
,
err
:=
user
.
Current
();
err
==
nil
{
return
usr
.
HomeDir
}
return
""
}
node/api.go
View file @
b42a5b11
...
@@ -84,7 +84,7 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *rpc.HexNumber, cors *st
...
@@ -84,7 +84,7 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *rpc.HexNumber, cors *st
}
}
if
host
==
nil
{
if
host
==
nil
{
h
:=
common
.
DefaultHTTPHost
h
:=
DefaultHTTPHost
if
api
.
node
.
config
.
HTTPHost
!=
""
{
if
api
.
node
.
config
.
HTTPHost
!=
""
{
h
=
api
.
node
.
config
.
HTTPHost
h
=
api
.
node
.
config
.
HTTPHost
}
}
...
@@ -133,7 +133,7 @@ func (api *PrivateAdminAPI) StartWS(host *string, port *rpc.HexNumber, allowedOr
...
@@ -133,7 +133,7 @@ func (api *PrivateAdminAPI) StartWS(host *string, port *rpc.HexNumber, allowedOr
}
}
if
host
==
nil
{
if
host
==
nil
{
h
:=
common
.
DefaultWSHost
h
:=
DefaultWSHost
if
api
.
node
.
config
.
WSHost
!=
""
{
if
api
.
node
.
config
.
WSHost
!=
""
{
h
=
api
.
node
.
config
.
WSHost
h
=
api
.
node
.
config
.
WSHost
}
}
...
...
node/config.go
View file @
b42a5b11
...
@@ -201,7 +201,7 @@ func DefaultIPCEndpoint(clientIdentifier string) string {
...
@@ -201,7 +201,7 @@ func DefaultIPCEndpoint(clientIdentifier string) string {
panic
(
"empty executable name"
)
panic
(
"empty executable name"
)
}
}
}
}
config
:=
&
Config
{
DataDir
:
common
.
DefaultDataDir
(),
IPCPath
:
clientIdentifier
+
".ipc"
}
config
:=
&
Config
{
DataDir
:
DefaultDataDir
(),
IPCPath
:
clientIdentifier
+
".ipc"
}
return
config
.
IPCEndpoint
()
return
config
.
IPCEndpoint
()
}
}
...
@@ -216,7 +216,7 @@ func (c *Config) HTTPEndpoint() string {
...
@@ -216,7 +216,7 @@ func (c *Config) HTTPEndpoint() string {
// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
func
DefaultHTTPEndpoint
()
string
{
func
DefaultHTTPEndpoint
()
string
{
config
:=
&
Config
{
HTTPHost
:
common
.
DefaultHTTPHost
,
HTTPPort
:
common
.
DefaultHTTPPort
}
config
:=
&
Config
{
HTTPHost
:
DefaultHTTPHost
,
HTTPPort
:
DefaultHTTPPort
}
return
config
.
HTTPEndpoint
()
return
config
.
HTTPEndpoint
()
}
}
...
@@ -231,7 +231,7 @@ func (c *Config) WSEndpoint() string {
...
@@ -231,7 +231,7 @@ func (c *Config) WSEndpoint() string {
// DefaultWSEndpoint returns the websocket endpoint used by default.
// DefaultWSEndpoint returns the websocket endpoint used by default.
func
DefaultWSEndpoint
()
string
{
func
DefaultWSEndpoint
()
string
{
config
:=
&
Config
{
WSHost
:
common
.
DefaultWSHost
,
WSPort
:
common
.
DefaultWSPort
}
config
:=
&
Config
{
WSHost
:
DefaultWSHost
,
WSPort
:
DefaultWSPort
}
return
config
.
WSEndpoint
()
return
config
.
WSEndpoint
()
}
}
...
...
common
/defaults.go
→
node
/defaults.go
View file @
b42a5b11
...
@@ -14,9 +14,11 @@
...
@@ -14,9 +14,11 @@
// You should have received a copy of the GNU Lesser General Public License
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
common
package
node
import
(
import
(
"os"
"os/user"
"path/filepath"
"path/filepath"
"runtime"
"runtime"
)
)
...
@@ -33,7 +35,7 @@ const (
...
@@ -33,7 +35,7 @@ const (
// persistence requirements.
// persistence requirements.
func
DefaultDataDir
()
string
{
func
DefaultDataDir
()
string
{
// Try to place the data folder in the user's home dir
// Try to place the data folder in the user's home dir
home
:=
H
omeDir
()
home
:=
h
omeDir
()
if
home
!=
""
{
if
home
!=
""
{
if
runtime
.
GOOS
==
"darwin"
{
if
runtime
.
GOOS
==
"darwin"
{
return
filepath
.
Join
(
home
,
"Library"
,
"Ethereum"
)
return
filepath
.
Join
(
home
,
"Library"
,
"Ethereum"
)
...
@@ -46,3 +48,13 @@ func DefaultDataDir() string {
...
@@ -46,3 +48,13 @@ func DefaultDataDir() string {
// As we cannot guess a stable location, return empty and handle later
// As we cannot guess a stable location, return empty and handle later
return
""
return
""
}
}
func
homeDir
()
string
{
if
home
:=
os
.
Getenv
(
"HOME"
);
home
!=
""
{
return
home
}
if
usr
,
err
:=
user
.
Current
();
err
==
nil
{
return
usr
.
HomeDir
}
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