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
c6462996
Commit
c6462996
authored
Jul 03, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ethwire.ClientIdentity now handles Client info sent in handshake + test
parent
de2da4fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
client_identity.go
ethwire/client_identity.go
+54
-0
client_identity_test.go
ethwire/client_identity_test.go
+30
-0
No files found.
ethwire/client_identity.go
0 → 100644
View file @
c6462996
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 @
c6462996
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
)
}
}
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