-
Notifications
You must be signed in to change notification settings - Fork 23
/
cconfig.go
116 lines (110 loc) · 3.15 KB
/
cconfig.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package irtt
import (
"encoding/json"
"net"
)
// ClientConfig defines the Client configuration.
type ClientConfig struct {
LocalAddress string
RemoteAddress string
LocalAddr net.Addr
RemoteAddr net.Addr
OpenTimeouts Durations
NoTest bool
Params
Loose bool
IPVersion IPVersion
DF DF
TTL int
Timer Timer
TimeSource TimeSource
Waiter Waiter
Filler Filler
FillOne bool
HMACKey []byte
Handler ClientHandler
ThreadLock bool
Supplied *ClientConfig
}
// NewClientConfig returns a new ClientConfig with the default settings.
func NewClientConfig() *ClientConfig {
return &ClientConfig{
LocalAddress: DefaultLocalAddress,
OpenTimeouts: DefaultOpenTimeouts,
Params: Params{
ProtocolVersion: ProtocolVersion,
Duration: DefaultDuration,
Interval: DefaultInterval,
Length: DefaultLength,
StampAt: DefaultStampAt,
Clock: DefaultClock,
DSCP: DefaultDSCP,
},
Loose: DefaultLoose,
IPVersion: DefaultIPVersion,
DF: DefaultDF,
TTL: DefaultTTL,
Timer: DefaultTimer,
TimeSource: DefaultTimeSource,
Waiter: DefaultWait,
ThreadLock: DefaultThreadLock,
}
}
// validate validates the configuration
func (c *ClientConfig) validate() error {
if c.Interval <= 0 {
return Errorf(IntervalNonPositive, "interval (%s) must be > 0", c.Interval)
}
if c.Duration <= 0 {
return Errorf(DurationNonPositive, "duration (%s) must be > 0", c.Duration)
}
if len(c.ServerFill) > maxServerFillLen {
return Errorf(ServerFillTooLong,
"server fill string (%s) must be less than %d characters",
c.ServerFill, maxServerFillLen)
}
return validateInterval(c.Interval)
}
// MarshalJSON implements the json.Marshaler interface.
func (c *ClientConfig) MarshalJSON() ([]byte, error) {
fstr := "none"
if c.Filler != nil {
fstr = c.Filler.String()
}
j := &struct {
LocalAddress string `json:"local_address"`
RemoteAddress string `json:"remote_address"`
OpenTimeouts string `json:"open_timeouts"`
Params `json:"params"`
Loose bool `json:"loose"`
IPVersion IPVersion `json:"ip_version"`
DF DF `json:"df"`
TTL int `json:"ttl"`
Timer string `json:"timer"`
TimeSource string `json:"time_source"`
Waiter string `json:"waiter"`
Filler string `json:"filler"`
FillOne bool `json:"fill_one"`
ServerFill string `json:"server_fill"`
ThreadLock bool `json:"thread_lock"`
Supplied *ClientConfig `json:"supplied,omitempty"`
}{
LocalAddress: c.LocalAddress,
RemoteAddress: c.RemoteAddress,
OpenTimeouts: c.OpenTimeouts.String(),
Params: c.Params,
Loose: c.Loose,
IPVersion: c.IPVersion,
DF: c.DF,
TTL: c.TTL,
Timer: c.Timer.String(),
TimeSource: c.TimeSource.String(),
Waiter: c.Waiter.String(),
Filler: fstr,
FillOne: c.FillOne,
ServerFill: c.ServerFill,
ThreadLock: c.ThreadLock,
Supplied: c.Supplied,
}
return json.Marshal(j)
}