diff options
author | zelig <viktor.tron@gmail.com> | 2014-07-04 00:28:27 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2014-07-04 00:28:27 +0800 |
commit | c64629964fb96e5ddc8aa590abc7cee4b14c8e84 (patch) | |
tree | 10af8ce2f45052f89f46b9377c83e86531dc5f58 /ethwire/client_identity.go | |
parent | de2da4fd19b53a541ffbddfa4360ceabef14f1a9 (diff) | |
download | dexon-c64629964fb96e5ddc8aa590abc7cee4b14c8e84.tar.gz dexon-c64629964fb96e5ddc8aa590abc7cee4b14c8e84.tar.zst dexon-c64629964fb96e5ddc8aa590abc7cee4b14c8e84.zip |
ethwire.ClientIdentity now handles Client info sent in handshake + test
Diffstat (limited to 'ethwire/client_identity.go')
-rw-r--r-- | ethwire/client_identity.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ethwire/client_identity.go b/ethwire/client_identity.go new file mode 100644 index 000000000..e803406d8 --- /dev/null +++ b/ethwire/client_identity.go @@ -0,0 +1,54 @@ +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 +} |