mirror of https://github.com/hashicorp/consul
commit
0b98d5231e
|
@ -607,11 +607,12 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error {
|
||||||
if raw, ok := args.([]interface{}); hasArgs && ok {
|
if raw, ok := args.([]interface{}); hasArgs && ok {
|
||||||
var parsed []string
|
var parsed []string
|
||||||
for _, arg := range raw {
|
for _, arg := range raw {
|
||||||
if v, ok := arg.(string); !ok {
|
v, ok := arg.(string)
|
||||||
|
if !ok {
|
||||||
return fmt.Errorf("Watch args must be a list of strings")
|
return fmt.Errorf("Watch args must be a list of strings")
|
||||||
} else {
|
|
||||||
parsed = append(parsed, v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parsed = append(parsed, v)
|
||||||
}
|
}
|
||||||
wp.Exempt["args"] = parsed
|
wp.Exempt["args"] = parsed
|
||||||
} else if hasArgs && !ok {
|
} else if hasArgs && !ok {
|
||||||
|
|
|
@ -31,13 +31,13 @@ func (d *AutopilotDelegate) IsServer(m serf.Member) (*autopilot.ServerInfo, erro
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
port_str := m.Tags["port"]
|
portStr := m.Tags["port"]
|
||||||
port, err := strconv.Atoi(port_str)
|
port, err := strconv.Atoi(portStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
build_version, err := metadata.Build(&m)
|
buildVersion, err := metadata.Build(&m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func (d *AutopilotDelegate) IsServer(m serf.Member) (*autopilot.ServerInfo, erro
|
||||||
Name: m.Name,
|
Name: m.Name,
|
||||||
ID: m.Tags["id"],
|
ID: m.Tags["id"],
|
||||||
Addr: &net.TCPAddr{IP: m.Addr, Port: port},
|
Addr: &net.TCPAddr{IP: m.Addr, Port: port},
|
||||||
Build: *build_version,
|
Build: *buildVersion,
|
||||||
Status: m.Status,
|
Status: m.Status,
|
||||||
}
|
}
|
||||||
return server, nil
|
return server, nil
|
||||||
|
|
|
@ -75,18 +75,18 @@ func CanServersUnderstandProtocol(members []serf.Member, version uint8) (bool, e
|
||||||
}
|
}
|
||||||
numServers++
|
numServers++
|
||||||
|
|
||||||
vsn_min, err := strconv.Atoi(m.Tags["vsn_min"])
|
vsnMin, err := strconv.Atoi(m.Tags["vsn_min"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
vsn_max, err := strconv.Atoi(m.Tags["vsn_max"])
|
vsnMax, err := strconv.Atoi(m.Tags["vsn_max"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
v := int(version)
|
v := int(version)
|
||||||
if (v >= vsn_min) && (v <= vsn_max) {
|
if (v >= vsnMin) && (v <= vsnMax) {
|
||||||
numWhoGrok++
|
numWhoGrok++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,8 @@ func isConsulNode(m serf.Member) (bool, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns if the given IP is in a private block
|
// Returns if the given IP is in a private block
|
||||||
func isPrivateIP(ip_str string) bool {
|
func isPrivateIP(ipStr string) bool {
|
||||||
ip := net.ParseIP(ip_str)
|
ip := net.ParseIP(ipStr)
|
||||||
for _, priv := range privateBlocks {
|
for _, priv := range privateBlocks {
|
||||||
if priv.Contains(ip) {
|
if priv.Contains(ip) {
|
||||||
return true
|
return true
|
||||||
|
|
16
agent/dns.go
16
agent/dns.go
|
@ -107,24 +107,24 @@ func GetDNSConfig(conf *config.RuntimeConfig) *dnsConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DNSServer) ListenAndServe(network, addr string, notif func()) error {
|
func (d *DNSServer) ListenAndServe(network, addr string, notif func()) error {
|
||||||
mux := dns.NewServeMux()
|
mux := dns.NewServeMux()
|
||||||
mux.HandleFunc("arpa.", s.handlePtr)
|
mux.HandleFunc("arpa.", d.handlePtr)
|
||||||
mux.HandleFunc(s.domain, s.handleQuery)
|
mux.HandleFunc(d.domain, d.handleQuery)
|
||||||
if len(s.recursors) > 0 {
|
if len(d.recursors) > 0 {
|
||||||
mux.HandleFunc(".", s.handleRecurse)
|
mux.HandleFunc(".", d.handleRecurse)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Server = &dns.Server{
|
d.Server = &dns.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Net: network,
|
Net: network,
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
NotifyStartedFunc: notif,
|
NotifyStartedFunc: notif,
|
||||||
}
|
}
|
||||||
if network == "udp" {
|
if network == "udp" {
|
||||||
s.UDPSize = 65535
|
d.UDPSize = 65535
|
||||||
}
|
}
|
||||||
return s.Server.ListenAndServe()
|
return d.Server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursorAddr is used to add a port to the recursor if omitted.
|
// recursorAddr is used to add a port to the recursor if omitted.
|
||||||
|
|
|
@ -2877,7 +2877,7 @@ func TestDNS_ServiceLookup_LargeResponses(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDNS_ServiceLookup_responseLimits(t *testing.T, answerLimit int, qType uint16,
|
func testDNSServiceLookupResponseLimits(t *testing.T, answerLimit int, qType uint16,
|
||||||
expectedService, expectedQuery, expectedQueryID int) (bool, error) {
|
expectedService, expectedQuery, expectedQueryID int) (bool, error) {
|
||||||
a := NewTestAgent(t.Name(), `
|
a := NewTestAgent(t.Name(), `
|
||||||
node_name = "test-node"
|
node_name = "test-node"
|
||||||
|
@ -3007,7 +3007,7 @@ func TestDNS_ServiceLookup_AnswerLimits(t *testing.T) {
|
||||||
test := test // capture loop var
|
test := test // capture loop var
|
||||||
t.Run("A lookup", func(t *testing.T) {
|
t.Run("A lookup", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
ok, err := testDNS_ServiceLookup_responseLimits(t, test.udpAnswerLimit, dns.TypeA, test.expectedAService, test.expectedAQuery, test.expectedAQueryID)
|
ok, err := testDNSServiceLookupResponseLimits(t, test.udpAnswerLimit, dns.TypeA, test.expectedAService, test.expectedAQuery, test.expectedAQueryID)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Expected service A lookup %s to pass: %v", test.name, err)
|
t.Errorf("Expected service A lookup %s to pass: %v", test.name, err)
|
||||||
}
|
}
|
||||||
|
@ -3015,7 +3015,7 @@ func TestDNS_ServiceLookup_AnswerLimits(t *testing.T) {
|
||||||
|
|
||||||
t.Run("AAAA lookup", func(t *testing.T) {
|
t.Run("AAAA lookup", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
ok, err := testDNS_ServiceLookup_responseLimits(t, test.udpAnswerLimit, dns.TypeAAAA, test.expectedAAAAService, test.expectedAAAAQuery, test.expectedAAAAQueryID)
|
ok, err := testDNSServiceLookupResponseLimits(t, test.udpAnswerLimit, dns.TypeAAAA, test.expectedAAAAService, test.expectedAAAAQuery, test.expectedAAAAQueryID)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Expected service AAAA lookup %s to pass: %v", test.name, err)
|
t.Errorf("Expected service AAAA lookup %s to pass: %v", test.name, err)
|
||||||
}
|
}
|
||||||
|
@ -3023,7 +3023,7 @@ func TestDNS_ServiceLookup_AnswerLimits(t *testing.T) {
|
||||||
|
|
||||||
t.Run("ANY lookup", func(t *testing.T) {
|
t.Run("ANY lookup", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
ok, err := testDNS_ServiceLookup_responseLimits(t, test.udpAnswerLimit, dns.TypeANY, test.expectedANYService, test.expectedANYQuery, test.expectedANYQueryID)
|
ok, err := testDNSServiceLookupResponseLimits(t, test.udpAnswerLimit, dns.TypeANY, test.expectedANYService, test.expectedANYQuery, test.expectedANYQueryID)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("Expected service ANY lookup %s to pass: %v", test.name, err)
|
t.Errorf("Expected service ANY lookup %s to pass: %v", test.name, err)
|
||||||
}
|
}
|
||||||
|
@ -3620,8 +3620,8 @@ func TestDNS_PreparedQuery_Failover(t *testing.T) {
|
||||||
m.SetQuestion("my-query.query.consul.", dns.TypeSRV)
|
m.SetQuestion("my-query.query.consul.", dns.TypeSRV)
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
cl_addr := a1.config.DNSAddrs[0]
|
clAddr := a1.config.DNSAddrs[0]
|
||||||
in, _, err := c.Exchange(m, cl_addr.String())
|
in, _, err := c.Exchange(m, clAddr.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,64 +76,64 @@ func IsConsulServer(m serf.Member) (bool, *Server) {
|
||||||
_, useTLS := m.Tags["use_tls"]
|
_, useTLS := m.Tags["use_tls"]
|
||||||
|
|
||||||
expect := 0
|
expect := 0
|
||||||
expect_str, ok := m.Tags["expect"]
|
expectStr, ok := m.Tags["expect"]
|
||||||
var err error
|
var err error
|
||||||
if ok {
|
if ok {
|
||||||
expect, err = strconv.Atoi(expect_str)
|
expect, err = strconv.Atoi(expectStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
port_str := m.Tags["port"]
|
portStr := m.Tags["port"]
|
||||||
port, err := strconv.Atoi(port_str)
|
port, err := strconv.Atoi(portStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
segment_addrs := make(map[string]string)
|
segmentAddrs := make(map[string]string)
|
||||||
segment_ports := make(map[string]int)
|
segmentPorts := make(map[string]int)
|
||||||
for name, value := range m.Tags {
|
for name, value := range m.Tags {
|
||||||
if strings.HasPrefix(name, "sl_") {
|
if strings.HasPrefix(name, "sl_") {
|
||||||
addr, port, err := net.SplitHostPort(value)
|
addr, port, err := net.SplitHostPort(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
segment_port, err := strconv.Atoi(port)
|
segmentPort, err := strconv.Atoi(port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
segment_name := strings.TrimPrefix(name, "sl_")
|
segmentName := strings.TrimPrefix(name, "sl_")
|
||||||
segment_addrs[segment_name] = addr
|
segmentAddrs[segmentName] = addr
|
||||||
segment_ports[segment_name] = segment_port
|
segmentPorts[segmentName] = segmentPort
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build_version, err := Build(&m)
|
buildVersion, err := Build(&m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
wan_join_port := 0
|
wanJoinPort := 0
|
||||||
wan_join_port_str, ok := m.Tags["wan_join_port"]
|
wanJoinPortStr, ok := m.Tags["wan_join_port"]
|
||||||
if ok {
|
if ok {
|
||||||
wan_join_port, err = strconv.Atoi(wan_join_port_str)
|
wanJoinPort, err = strconv.Atoi(wanJoinPortStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vsn_str := m.Tags["vsn"]
|
vsnStr := m.Tags["vsn"]
|
||||||
vsn, err := strconv.Atoi(vsn_str)
|
vsn, err := strconv.Atoi(vsnStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
raft_vsn := 0
|
raftVsn := 0
|
||||||
raft_vsn_str, ok := m.Tags["raft_vsn"]
|
raftVsnStr, ok := m.Tags["raft_vsn"]
|
||||||
if ok {
|
if ok {
|
||||||
raft_vsn, err = strconv.Atoi(raft_vsn_str)
|
raftVsn, err = strconv.Atoi(raftVsnStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -147,15 +147,15 @@ func IsConsulServer(m serf.Member) (bool, *Server) {
|
||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
Segment: segment,
|
Segment: segment,
|
||||||
Port: port,
|
Port: port,
|
||||||
SegmentAddrs: segment_addrs,
|
SegmentAddrs: segmentAddrs,
|
||||||
SegmentPorts: segment_ports,
|
SegmentPorts: segmentPorts,
|
||||||
WanJoinPort: wan_join_port,
|
WanJoinPort: wanJoinPort,
|
||||||
Bootstrap: bootstrap,
|
Bootstrap: bootstrap,
|
||||||
Expect: expect,
|
Expect: expect,
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Build: *build_version,
|
Build: *buildVersion,
|
||||||
Version: vsn,
|
Version: vsn,
|
||||||
RaftVersion: raft_vsn,
|
RaftVersion: raftVsn,
|
||||||
Status: m.Status,
|
Status: m.Status,
|
||||||
UseTLS: useTLS,
|
UseTLS: useTLS,
|
||||||
}
|
}
|
||||||
|
|
22
api/agent.go
22
api/agent.go
|
@ -584,36 +584,36 @@ func (a *Agent) Monitor(loglevel string, stopCh <-chan struct{}, q *QueryOptions
|
||||||
|
|
||||||
// UpdateACLToken updates the agent's "acl_token". See updateToken for more
|
// UpdateACLToken updates the agent's "acl_token". See updateToken for more
|
||||||
// details.
|
// details.
|
||||||
func (c *Agent) UpdateACLToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
func (a *Agent) UpdateACLToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
||||||
return c.updateToken("acl_token", token, q)
|
return a.updateToken("acl_token", token, q)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateACLAgentToken updates the agent's "acl_agent_token". See updateToken
|
// UpdateACLAgentToken updates the agent's "acl_agent_token". See updateToken
|
||||||
// for more details.
|
// for more details.
|
||||||
func (c *Agent) UpdateACLAgentToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
func (a *Agent) UpdateACLAgentToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
||||||
return c.updateToken("acl_agent_token", token, q)
|
return a.updateToken("acl_agent_token", token, q)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateACLAgentMasterToken updates the agent's "acl_agent_master_token". See
|
// UpdateACLAgentMasterToken updates the agent's "acl_agent_master_token". See
|
||||||
// updateToken for more details.
|
// updateToken for more details.
|
||||||
func (c *Agent) UpdateACLAgentMasterToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
func (a *Agent) UpdateACLAgentMasterToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
||||||
return c.updateToken("acl_agent_master_token", token, q)
|
return a.updateToken("acl_agent_master_token", token, q)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateACLReplicationToken updates the agent's "acl_replication_token". See
|
// UpdateACLReplicationToken updates the agent's "acl_replication_token". See
|
||||||
// updateToken for more details.
|
// updateToken for more details.
|
||||||
func (c *Agent) UpdateACLReplicationToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
func (a *Agent) UpdateACLReplicationToken(token string, q *WriteOptions) (*WriteMeta, error) {
|
||||||
return c.updateToken("acl_replication_token", token, q)
|
return a.updateToken("acl_replication_token", token, q)
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateToken can be used to update an agent's ACL token after the agent has
|
// updateToken can be used to update an agent's ACL token after the agent has
|
||||||
// started. The tokens are not persisted, so will need to be updated again if
|
// started. The tokens are not persisted, so will need to be updated again if
|
||||||
// the agent is restarted.
|
// the agent is restarted.
|
||||||
func (c *Agent) updateToken(target, token string, q *WriteOptions) (*WriteMeta, error) {
|
func (a *Agent) updateToken(target, token string, q *WriteOptions) (*WriteMeta, error) {
|
||||||
r := c.c.newRequest("PUT", fmt.Sprintf("/v1/agent/token/%s", target))
|
r := a.c.newRequest("PUT", fmt.Sprintf("/v1/agent/token/%s", target))
|
||||||
r.setWriteOptions(q)
|
r.setWriteOptions(q)
|
||||||
r.obj = &AgentToken{Token: token}
|
r.obj = &AgentToken{Token: token}
|
||||||
rtt, resp, err := requireOK(c.c.doRequest(r))
|
rtt, resp, err := requireOK(a.c.doRequest(r))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -633,9 +633,9 @@ func (r *request) toHTTP() (*http.Request, error) {
|
||||||
}
|
}
|
||||||
if r.ctx != nil {
|
if r.ctx != nil {
|
||||||
return req.WithContext(r.ctx), nil
|
return req.WithContext(r.ctx), nil
|
||||||
} else {
|
|
||||||
return req, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRequest is used to create a new request
|
// newRequest is used to create a new request
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (c *cmd) Run(args []string) int {
|
||||||
|
|
||||||
// Order the map for consistent output
|
// Order the map for consistent output
|
||||||
order := make([]string, 0, len(services))
|
order := make([]string, 0, len(services))
|
||||||
for k, _ := range services {
|
for k := range services {
|
||||||
order = append(order, k)
|
order = append(order, k)
|
||||||
}
|
}
|
||||||
sort.Strings(order)
|
sort.Strings(order)
|
||||||
|
|
|
@ -57,7 +57,7 @@ func TestRTTCommand_LAN(t *testing.T) {
|
||||||
c1 := coordinate.NewCoordinate(coordinate.DefaultConfig())
|
c1 := coordinate.NewCoordinate(coordinate.DefaultConfig())
|
||||||
c2 := c1.Clone()
|
c2 := c1.Clone()
|
||||||
c2.Vec[0] = 0.123
|
c2.Vec[0] = 0.123
|
||||||
dist_str := fmt.Sprintf("%.3f ms", c1.DistanceTo(c2).Seconds()*1000.0)
|
distStr := fmt.Sprintf("%.3f ms", c1.DistanceTo(c2).Seconds()*1000.0)
|
||||||
{
|
{
|
||||||
req := structs.CoordinateUpdateRequest{
|
req := structs.CoordinateUpdateRequest{
|
||||||
Datacenter: a.Config.Datacenter,
|
Datacenter: a.Config.Datacenter,
|
||||||
|
@ -108,7 +108,7 @@ func TestRTTCommand_LAN(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the proper RTT was reported in the output.
|
// Make sure the proper RTT was reported in the output.
|
||||||
expected := fmt.Sprintf("rtt: %s", dist_str)
|
expected := fmt.Sprintf("rtt: %s", distStr)
|
||||||
if !strings.Contains(ui.OutputWriter.String(), expected) {
|
if !strings.Contains(ui.OutputWriter.String(), expected) {
|
||||||
r.Fatalf("bad: %#v", ui.OutputWriter.String())
|
r.Fatalf("bad: %#v", ui.OutputWriter.String())
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func TestRTTCommand_LAN(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the proper RTT was reported in the output.
|
// Make sure the proper RTT was reported in the output.
|
||||||
expected := fmt.Sprintf("rtt: %s", dist_str)
|
expected := fmt.Sprintf("rtt: %s", distStr)
|
||||||
if !strings.Contains(ui.OutputWriter.String(), expected) {
|
if !strings.Contains(ui.OutputWriter.String(), expected) {
|
||||||
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
t.Fatalf("bad: %#v", ui.OutputWriter.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,14 +36,14 @@ func (cs CoordinateSet) Intersect(other CoordinateSet) (*coordinate.Coordinate,
|
||||||
// we are possibly a client. Any node with more than one segment can only
|
// we are possibly a client. Any node with more than one segment can only
|
||||||
// be a server, which means it should be in all segments.
|
// be a server, which means it should be in all segments.
|
||||||
if len(cs) == 1 {
|
if len(cs) == 1 {
|
||||||
for s, _ := range cs {
|
for s := range cs {
|
||||||
segment = s
|
segment = s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Likewise for the other set.
|
// Likewise for the other set.
|
||||||
if len(other) == 1 {
|
if len(other) == 1 {
|
||||||
for s, _ := range other {
|
for s := range other {
|
||||||
segment = s
|
segment = s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,23 +70,23 @@ func TestRTT_ComputeDistance(t *testing.T) {
|
||||||
func TestRTT_Intersect(t *testing.T) {
|
func TestRTT_Intersect(t *testing.T) {
|
||||||
// The numbers here don't matter, we just want a unique coordinate for
|
// The numbers here don't matter, we just want a unique coordinate for
|
||||||
// each one.
|
// each one.
|
||||||
server_1 := CoordinateSet{
|
server1 := CoordinateSet{
|
||||||
"": GenerateCoordinate(1 * time.Millisecond),
|
"": GenerateCoordinate(1 * time.Millisecond),
|
||||||
"alpha": GenerateCoordinate(2 * time.Millisecond),
|
"alpha": GenerateCoordinate(2 * time.Millisecond),
|
||||||
"beta": GenerateCoordinate(3 * time.Millisecond),
|
"beta": GenerateCoordinate(3 * time.Millisecond),
|
||||||
}
|
}
|
||||||
server_2 := CoordinateSet{
|
server2 := CoordinateSet{
|
||||||
"": GenerateCoordinate(4 * time.Millisecond),
|
"": GenerateCoordinate(4 * time.Millisecond),
|
||||||
"alpha": GenerateCoordinate(5 * time.Millisecond),
|
"alpha": GenerateCoordinate(5 * time.Millisecond),
|
||||||
"beta": GenerateCoordinate(6 * time.Millisecond),
|
"beta": GenerateCoordinate(6 * time.Millisecond),
|
||||||
}
|
}
|
||||||
client_alpha := CoordinateSet{
|
clientAlpha := CoordinateSet{
|
||||||
"alpha": GenerateCoordinate(7 * time.Millisecond),
|
"alpha": GenerateCoordinate(7 * time.Millisecond),
|
||||||
}
|
}
|
||||||
client_beta_1 := CoordinateSet{
|
clientBeta1 := CoordinateSet{
|
||||||
"beta": GenerateCoordinate(8 * time.Millisecond),
|
"beta": GenerateCoordinate(8 * time.Millisecond),
|
||||||
}
|
}
|
||||||
client_beta_2 := CoordinateSet{
|
clientBeta2 := CoordinateSet{
|
||||||
"beta": GenerateCoordinate(9 * time.Millisecond),
|
"beta": GenerateCoordinate(9 * time.Millisecond),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,43 +104,43 @@ func TestRTT_Intersect(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"two servers",
|
"two servers",
|
||||||
server_1, server_2,
|
server1, server2,
|
||||||
server_1[""], server_2[""],
|
server1[""], server2[""],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"two clients",
|
"two clients",
|
||||||
client_beta_1, client_beta_2,
|
clientBeta1, clientBeta2,
|
||||||
client_beta_1["beta"], client_beta_2["beta"],
|
clientBeta1["beta"], clientBeta2["beta"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"server_1 and client alpha",
|
"server1 and client alpha",
|
||||||
server_1, client_alpha,
|
server1, clientAlpha,
|
||||||
server_1["alpha"], client_alpha["alpha"],
|
server1["alpha"], clientAlpha["alpha"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"server_1 and client beta 1",
|
"server1 and client beta 1",
|
||||||
server_1, client_beta_1,
|
server1, clientBeta1,
|
||||||
server_1["beta"], client_beta_1["beta"],
|
server1["beta"], clientBeta1["beta"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"server_1 and client alpha reversed",
|
"server1 and client alpha reversed",
|
||||||
client_alpha, server_1,
|
clientAlpha, server1,
|
||||||
client_alpha["alpha"], server_1["alpha"],
|
clientAlpha["alpha"], server1["alpha"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"server_1 and client beta 1 reversed",
|
"server1 and client beta 1 reversed",
|
||||||
client_beta_1, server_1,
|
clientBeta1, server1,
|
||||||
client_beta_1["beta"], server_1["beta"],
|
clientBeta1["beta"], server1["beta"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"nothing in common",
|
"nothing in common",
|
||||||
client_alpha, client_beta_1,
|
clientAlpha, clientBeta1,
|
||||||
nil, client_beta_1["beta"],
|
nil, clientBeta1["beta"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"nothing in common reversed",
|
"nothing in common reversed",
|
||||||
client_beta_1, client_alpha,
|
clientBeta1, clientAlpha,
|
||||||
nil, client_alpha["alpha"],
|
nil, clientAlpha["alpha"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
Loading…
Reference in New Issue