aboutsummaryrefslogtreecommitdiffstats
path: root/ethwire/client_identity.go
blob: e803406d87b5eea619ec06114b3df48e2b019948 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
}