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