2014-07-03 11:28:27 -05: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 18:02:15 -05:00
|
|
|
implementation: runtime.Version(),
|
2014-07-03 11:28:27 -05:00
|
|
|
}
|
2014-09-17 09:28:30 -05:00
|
|
|
|
2014-07-03 11:28:27 -05:00
|
|
|
return clientIdentity
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SimpleClientIdentity) init() {
|
2014-09-17 09:28:30 -05: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 11:28:27 -05:00
|
|
|
c.clientIdentifier,
|
|
|
|
c.version,
|
2014-09-17 09:28:30 -05:00
|
|
|
id,
|
2014-07-03 11:28:27 -05:00
|
|
|
c.os,
|
|
|
|
c.implementation)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SimpleClientIdentity) SetCustomIdentifier(customIdentifier string) {
|
|
|
|
c.customIdentifier = customIdentifier
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SimpleClientIdentity) GetCustomIdentifier() string {
|
|
|
|
return c.customIdentifier
|
|
|
|
}
|