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
d3d043db
Commit
d3d043db
authored
Jul 03, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ethersphere-feature/clientid' into develop
parents
cb7ebdf8
db60ebbb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
122 additions
and
38 deletions
+122
-38
state_manager.go
ethchain/state_manager.go
+1
-0
ethereum.go
ethereum.go
+16
-9
config.go
ethutil/config.go
+19
-27
client_identity.go
ethwire/client_identity.go
+54
-0
client_identity_test.go
ethwire/client_identity_test.go
+30
-0
peer.go
peer.go
+2
-2
No files found.
ethchain/state_manager.go
View file @
d3d043db
...
@@ -42,6 +42,7 @@ type EthManager interface {
...
@@ -42,6 +42,7 @@ type EthManager interface {
IsListening
()
bool
IsListening
()
bool
Peers
()
*
list
.
List
Peers
()
*
list
.
List
KeyManager
()
*
ethcrypto
.
KeyManager
KeyManager
()
*
ethcrypto
.
KeyManager
ClientIdentity
()
ethwire
.
ClientIdentity
}
}
type
StateManager
struct
{
type
StateManager
struct
{
...
...
ethereum.go
View file @
d3d043db
...
@@ -76,9 +76,11 @@ type Ethereum struct {
...
@@ -76,9 +76,11 @@ type Ethereum struct {
RpcServer
*
ethrpc
.
JsonRpcServer
RpcServer
*
ethrpc
.
JsonRpcServer
keyManager
*
ethcrypto
.
KeyManager
keyManager
*
ethcrypto
.
KeyManager
clientIdentity
ethwire
.
ClientIdentity
}
}
func
New
(
db
ethutil
.
Database
,
keyManager
*
ethcrypto
.
KeyManager
,
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
func
New
(
db
ethutil
.
Database
,
clientIdentity
ethwire
.
ClientIdentity
,
keyManager
*
ethcrypto
.
KeyManager
,
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
var
err
error
var
err
error
var
nat
NAT
var
nat
NAT
...
@@ -94,14 +96,15 @@ func New(db ethutil.Database, keyManager *ethcrypto.KeyManager, caps Caps, usePn
...
@@ -94,14 +96,15 @@ func New(db ethutil.Database, keyManager *ethcrypto.KeyManager, caps Caps, usePn
nonce
,
_
:=
ethutil
.
RandomUint64
()
nonce
,
_
:=
ethutil
.
RandomUint64
()
ethereum
:=
&
Ethereum
{
ethereum
:=
&
Ethereum
{
shutdownChan
:
make
(
chan
bool
),
shutdownChan
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
db
:
db
,
db
:
db
,
peers
:
list
.
New
(),
peers
:
list
.
New
(),
Nonce
:
nonce
,
Nonce
:
nonce
,
serverCaps
:
caps
,
serverCaps
:
caps
,
nat
:
nat
,
nat
:
nat
,
keyManager
:
keyManager
,
keyManager
:
keyManager
,
clientIdentity
:
clientIdentity
,
}
}
ethereum
.
reactor
=
ethutil
.
NewReactorEngine
()
ethereum
.
reactor
=
ethutil
.
NewReactorEngine
()
...
@@ -123,6 +126,10 @@ func (s *Ethereum) KeyManager() *ethcrypto.KeyManager {
...
@@ -123,6 +126,10 @@ func (s *Ethereum) KeyManager() *ethcrypto.KeyManager {
return
s
.
keyManager
return
s
.
keyManager
}
}
func
(
s
*
Ethereum
)
ClientIdentity
()
ethwire
.
ClientIdentity
{
return
s
.
clientIdentity
}
func
(
s
*
Ethereum
)
BlockChain
()
*
ethchain
.
BlockChain
{
func
(
s
*
Ethereum
)
BlockChain
()
*
ethchain
.
BlockChain
{
return
s
.
blockChain
return
s
.
blockChain
}
}
...
...
ethutil/config.go
View file @
d3d043db
...
@@ -5,29 +5,25 @@ import (
...
@@ -5,29 +5,25 @@ import (
"fmt"
"fmt"
"github.com/rakyll/globalconf"
"github.com/rakyll/globalconf"
"os"
"os"
"runtime"
)
)
// Config struct
// Config struct
type
config
struct
{
type
ConfigManager
struct
{
Db
Database
Db
Database
ExecPath
string
ExecPath
string
Debug
bool
Debug
bool
Paranoia
bool
Paranoia
bool
Ver
string
ClientString
string
Identifier
string
conf
*
globalconf
.
GlobalConf
conf
*
globalconf
.
GlobalConf
}
}
var
Config
*
config
var
Config
*
ConfigManager
// Read config
// Read config
//
//
// Initialize Config from Config File
// Initialize Config from Config File
func
ReadConfig
(
ConfigFile
string
,
Datadir
string
,
Identifier
string
,
EnvPrefix
string
)
*
config
{
func
ReadConfig
(
ConfigFile
string
,
Datadir
string
,
EnvPrefix
string
)
*
ConfigManager
{
if
Config
==
nil
{
if
Config
==
nil
{
// create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags
// create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags
_
,
err
:=
os
.
Stat
(
ConfigFile
)
_
,
err
:=
os
.
Stat
(
ConfigFile
)
...
@@ -44,34 +40,30 @@ func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix
...
@@ -44,34 +40,30 @@ func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix
}
else
{
}
else
{
g
.
ParseAll
()
g
.
ParseAll
()
}
}
Config
=
&
config
{
ExecPath
:
Datadir
,
Debug
:
true
,
Ver
:
"0.5.16"
,
conf
:
g
,
Identifier
:
Identifier
,
Paranoia
:
true
}
Config
=
&
ConfigManager
{
ExecPath
:
Datadir
,
Debug
:
true
,
conf
:
g
,
Paranoia
:
true
}
Config
.
SetClientString
(
"Ethereum(G)"
)
}
}
return
Config
return
Config
}
}
// Set client string
//
func
(
c
*
config
)
SetClientString
(
str
string
)
{
os
:=
runtime
.
GOOS
cust
:=
c
.
Identifier
Config
.
ClientString
=
fmt
.
Sprintf
(
"%s/v%s/%s/%s/Go"
,
str
,
c
.
Ver
,
cust
,
os
)
}
func
(
c
*
config
)
SetIdentifier
(
id
string
)
{
c
.
Identifier
=
id
c
.
Set
(
"id"
,
id
)
}
// provides persistence for flags
// provides persistence for flags
func
(
c
*
config
)
Set
(
key
,
value
string
)
{
func
(
c
*
ConfigManager
)
Save
(
key
string
,
value
interface
{}
)
{
f
:=
&
flag
.
Flag
{
Name
:
key
,
Value
:
&
confValue
{
value
}
}
f
:=
&
flag
.
Flag
{
Name
:
key
,
Value
:
newConfValue
(
value
)
}
c
.
conf
.
Set
(
""
,
f
)
c
.
conf
.
Set
(
""
,
f
)
}
}
func
(
c
*
ConfigManager
)
Delete
(
key
string
)
{
c
.
conf
.
Delete
(
""
,
key
)
}
// private type implementing flag.Value
type
confValue
struct
{
type
confValue
struct
{
value
string
value
string
}
}
// generic constructor to allow persising non-string values directly
func
newConfValue
(
value
interface
{})
*
confValue
{
return
&
confValue
{
fmt
.
Sprintf
(
"%v"
,
value
)}
}
func
(
self
confValue
)
String
()
string
{
return
self
.
value
}
func
(
self
confValue
)
String
()
string
{
return
self
.
value
}
func
(
self
confValue
)
Set
(
s
string
)
error
{
self
.
value
=
s
;
return
nil
}
func
(
self
confValue
)
Set
(
s
string
)
error
{
self
.
value
=
s
;
return
nil
}
ethwire/client_identity.go
0 → 100644
View file @
d3d043db
package
ethwire
import
(
"fmt"
"runtime"
)
// should be used in Peer handleHandshake, incorporate Caps, ProtocolVersion, Pubkey etc.
type
ClientIdentity
interface
{
String
()
string
}
type
SimpleClientIdentity
struct
{
clientString
string
clientIdentifier
string
version
string
customIdentifier
string
os
string
implementation
string
}
func
NewSimpleClientIdentity
(
clientIdentifier
string
,
version
string
,
customIdentifier
string
)
*
SimpleClientIdentity
{
clientIdentity
:=
&
SimpleClientIdentity
{
clientIdentifier
:
clientIdentifier
,
version
:
version
,
customIdentifier
:
customIdentifier
,
os
:
runtime
.
GOOS
,
implementation
:
"Go"
,
}
clientIdentity
.
init
()
return
clientIdentity
}
func
(
c
*
SimpleClientIdentity
)
init
()
{
c
.
clientString
=
fmt
.
Sprintf
(
"%s/v%s/%s/%s/%s"
,
c
.
clientIdentifier
,
c
.
version
,
c
.
customIdentifier
,
c
.
os
,
c
.
implementation
)
}
func
(
c
*
SimpleClientIdentity
)
String
()
string
{
return
c
.
clientString
}
func
(
c
*
SimpleClientIdentity
)
SetCustomIdentifier
(
customIdentifier
string
)
{
c
.
customIdentifier
=
customIdentifier
c
.
init
()
}
func
(
c
*
SimpleClientIdentity
)
GetCustomIdentifier
()
string
{
return
c
.
customIdentifier
}
ethwire/client_identity_test.go
0 → 100644
View file @
d3d043db
package
ethwire
import
(
"fmt"
"runtime"
"testing"
)
func
TestClientIdentity
(
t
*
testing
.
T
)
{
clientIdentity
:=
NewSimpleClientIdentity
(
"Ethereum(G)"
,
"0.5.16"
,
"test"
)
clientString
:=
clientIdentity
.
String
()
expected
:=
fmt
.
Sprintf
(
"Ethereum(G)/v0.5.16/test/%s/Go"
,
runtime
.
GOOS
)
if
clientString
!=
expected
{
t
.
Error
(
"Expected clientIdentity to be %v, got %v"
,
expected
,
clientString
)
}
customIdentifier
:=
clientIdentity
.
GetCustomIdentifier
()
if
customIdentifier
!=
"test"
{
t
.
Error
(
"Expected clientIdentity.GetCustomIdentifier() to be 'test', got %v"
,
customIdentifier
)
}
clientIdentity
.
SetCustomIdentifier
(
"test2"
)
customIdentifier
=
clientIdentity
.
GetCustomIdentifier
()
if
customIdentifier
!=
"test2"
{
t
.
Error
(
"Expected clientIdentity.GetCustomIdentifier() to be 'test2', got %v"
,
customIdentifier
)
}
clientString
=
clientIdentity
.
String
()
expected
=
fmt
.
Sprintf
(
"Ethereum(G)/v0.5.16/test2/%s/Go"
,
runtime
.
GOOS
)
if
clientString
!=
expected
{
t
.
Error
(
"Expected clientIdentity to be %v, got %v"
,
expected
,
clientString
)
}
}
peer.go
View file @
d3d043db
...
@@ -162,7 +162,7 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
...
@@ -162,7 +162,7 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
pubkey
:
pubkey
,
pubkey
:
pubkey
,
blocksRequested
:
10
,
blocksRequested
:
10
,
caps
:
ethereum
.
ServerCaps
(),
caps
:
ethereum
.
ServerCaps
(),
version
:
eth
util
.
Config
.
ClientString
,
version
:
eth
ereum
.
ClientIdentity
()
.
String
()
,
}
}
}
}
...
@@ -175,7 +175,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
...
@@ -175,7 +175,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
connected
:
0
,
connected
:
0
,
disconnect
:
0
,
disconnect
:
0
,
caps
:
caps
,
caps
:
caps
,
version
:
eth
util
.
Config
.
ClientString
,
version
:
eth
ereum
.
ClientIdentity
()
.
String
()
,
}
}
// Set up the connection in another goroutine so we don't block the main thread
// Set up the connection in another goroutine so we don't block the main thread
...
...
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