2014-07-03 16:28:27 +00:00
|
|
|
package ethwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// should be used in Peer handleHandshake, incorporate Caps, ProtocolVersion, Pubkey etc.
|
|
|
|
type ClientIdentity interface {
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type SimpleClientIdentity struct {
|
|
|
|
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,
|
2014-09-17 23:02:15 +00:00
|
|
|
implementation: runtime.Version(),
|
2014-07-03 16:28:27 +00:00
|
|
|
}
|
2014-09-17 14:28:30 +00:00
|
|
|
|
2014-07-03 16:28:27 +00:00
|
|
|
return clientIdentity
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SimpleClientIdentity) init() {
|
2014-09-17 14:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SimpleClientIdentity) String() string {
|
|
|
|
var id string
|
|
|
|
if len(c.customIdentifier) > 0 {
|
|
|
|
id = "/" + c.customIdentifier
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s/v%s%s/%s/%s",
|
2014-07-03 16:28:27 +00:00
|
|
|
c.clientIdentifier,
|
|
|
|
c.version,
|
2014-09-17 14:28:30 +00:00
|
|
|
id,
|
2014-07-03 16:28:27 +00:00
|
|
|
c.os,
|
|
|
|
c.implementation)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SimpleClientIdentity) SetCustomIdentifier(customIdentifier string) {
|
|
|
|
c.customIdentifier = customIdentifier
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SimpleClientIdentity) GetCustomIdentifier() string {
|
|
|
|
return c.customIdentifier
|
|
|
|
}
|