summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/internal
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-04-16 05:37:14 -0700
committerJoram Wilander <jwawilander@gmail.com>2018-04-16 08:37:14 -0400
commit6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch)
tree3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/golang.org/x/net/internal
parentbf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff)
downloadchat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz
chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2
chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/golang.org/x/net/internal')
-rw-r--r--vendor/golang.org/x/net/internal/iana/const.go51
-rw-r--r--vendor/golang.org/x/net/internal/iana/gen.go96
-rw-r--r--vendor/golang.org/x/net/internal/nettest/helper_bsd.go53
-rw-r--r--vendor/golang.org/x/net/internal/nettest/helper_nobsd.go15
-rw-r--r--vendor/golang.org/x/net/internal/nettest/helper_posix.go31
-rw-r--r--vendor/golang.org/x/net/internal/nettest/helper_stub.go32
-rw-r--r--vendor/golang.org/x/net/internal/nettest/helper_unix.go29
-rw-r--r--vendor/golang.org/x/net/internal/nettest/helper_windows.go42
-rw-r--r--vendor/golang.org/x/net/internal/nettest/interface.go94
-rw-r--r--vendor/golang.org/x/net/internal/nettest/rlimit.go11
-rw-r--r--vendor/golang.org/x/net/internal/nettest/stack.go152
-rw-r--r--vendor/golang.org/x/net/internal/socket/socket_go1_9_test.go259
-rw-r--r--vendor/golang.org/x/net/internal/socket/socket_test.go46
-rw-r--r--vendor/golang.org/x/net/internal/socket/zsys_netbsd_arm.go6
-rw-r--r--vendor/golang.org/x/net/internal/timeseries/timeseries.go525
-rw-r--r--vendor/golang.org/x/net/internal/timeseries/timeseries_test.go170
16 files changed, 150 insertions, 1462 deletions
diff --git a/vendor/golang.org/x/net/internal/iana/const.go b/vendor/golang.org/x/net/internal/iana/const.go
index c9df24d95..826633e1b 100644
--- a/vendor/golang.org/x/net/internal/iana/const.go
+++ b/vendor/golang.org/x/net/internal/iana/const.go
@@ -1,5 +1,5 @@
// go generate gen.go
-// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
+// Code generated by the command above; DO NOT EDIT.
// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).
package iana // import "golang.org/x/net/internal/iana"
@@ -38,7 +38,7 @@ const (
CongestionExperienced = 0x3 // CE (Congestion Experienced)
)
-// Protocol Numbers, Updated: 2016-06-22
+// Protocol Numbers, Updated: 2017-10-13
const (
ProtocolIP = 0 // IPv4 encapsulation, pseudo protocol number
ProtocolHOPOPT = 0 // IPv6 Hop-by-Hop Option
@@ -178,3 +178,50 @@ const (
ProtocolROHC = 142 // Robust Header Compression
ProtocolReserved = 255 // Reserved
)
+
+// Address Family Numbers, Updated: 2016-10-25
+const (
+ AddrFamilyIPv4 = 1 // IP (IP version 4)
+ AddrFamilyIPv6 = 2 // IP6 (IP version 6)
+ AddrFamilyNSAP = 3 // NSAP
+ AddrFamilyHDLC = 4 // HDLC (8-bit multidrop)
+ AddrFamilyBBN1822 = 5 // BBN 1822
+ AddrFamily802 = 6 // 802 (includes all 802 media plus Ethernet "canonical format")
+ AddrFamilyE163 = 7 // E.163
+ AddrFamilyE164 = 8 // E.164 (SMDS, Frame Relay, ATM)
+ AddrFamilyF69 = 9 // F.69 (Telex)
+ AddrFamilyX121 = 10 // X.121 (X.25, Frame Relay)
+ AddrFamilyIPX = 11 // IPX
+ AddrFamilyAppletalk = 12 // Appletalk
+ AddrFamilyDecnetIV = 13 // Decnet IV
+ AddrFamilyBanyanVines = 14 // Banyan Vines
+ AddrFamilyE164withSubaddress = 15 // E.164 with NSAP format subaddress
+ AddrFamilyDNS = 16 // DNS (Domain Name System)
+ AddrFamilyDistinguishedName = 17 // Distinguished Name
+ AddrFamilyASNumber = 18 // AS Number
+ AddrFamilyXTPoverIPv4 = 19 // XTP over IP version 4
+ AddrFamilyXTPoverIPv6 = 20 // XTP over IP version 6
+ AddrFamilyXTPnativemodeXTP = 21 // XTP native mode XTP
+ AddrFamilyFibreChannelWorldWidePortName = 22 // Fibre Channel World-Wide Port Name
+ AddrFamilyFibreChannelWorldWideNodeName = 23 // Fibre Channel World-Wide Node Name
+ AddrFamilyGWID = 24 // GWID
+ AddrFamilyL2VPN = 25 // AFI for L2VPN information
+ AddrFamilyMPLSTPSectionEndpointID = 26 // MPLS-TP Section Endpoint Identifier
+ AddrFamilyMPLSTPLSPEndpointID = 27 // MPLS-TP LSP Endpoint Identifier
+ AddrFamilyMPLSTPPseudowireEndpointID = 28 // MPLS-TP Pseudowire Endpoint Identifier
+ AddrFamilyMTIPv4 = 29 // MT IP: Multi-Topology IP version 4
+ AddrFamilyMTIPv6 = 30 // MT IPv6: Multi-Topology IP version 6
+ AddrFamilyEIGRPCommonServiceFamily = 16384 // EIGRP Common Service Family
+ AddrFamilyEIGRPIPv4ServiceFamily = 16385 // EIGRP IPv4 Service Family
+ AddrFamilyEIGRPIPv6ServiceFamily = 16386 // EIGRP IPv6 Service Family
+ AddrFamilyLISPCanonicalAddressFormat = 16387 // LISP Canonical Address Format (LCAF)
+ AddrFamilyBGPLS = 16388 // BGP-LS
+ AddrFamily48bitMAC = 16389 // 48-bit MAC
+ AddrFamily64bitMAC = 16390 // 64-bit MAC
+ AddrFamilyOUI = 16391 // OUI
+ AddrFamilyMACFinal24bits = 16392 // MAC/24
+ AddrFamilyMACFinal40bits = 16393 // MAC/40
+ AddrFamilyIPv6Initial64bits = 16394 // IPv6/64
+ AddrFamilyRBridgePortID = 16395 // RBridge Port ID
+ AddrFamilyTRILLNickname = 16396 // TRILL Nickname
+)
diff --git a/vendor/golang.org/x/net/internal/iana/gen.go b/vendor/golang.org/x/net/internal/iana/gen.go
index 2a5c310c2..2227e09e8 100644
--- a/vendor/golang.org/x/net/internal/iana/gen.go
+++ b/vendor/golang.org/x/net/internal/iana/gen.go
@@ -39,12 +39,16 @@ var registries = []struct {
"https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml",
parseProtocolNumbers,
},
+ {
+ "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xml",
+ parseAddrFamilyNumbers,
+ },
}
func main() {
var bb bytes.Buffer
fmt.Fprintf(&bb, "// go generate gen.go\n")
- fmt.Fprintf(&bb, "// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT\n\n")
+ fmt.Fprintf(&bb, "// Code generated by the command above; DO NOT EDIT.\n\n")
fmt.Fprintf(&bb, "// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).\n")
fmt.Fprintf(&bb, `package iana // import "golang.org/x/net/internal/iana"`+"\n\n")
for _, r := range registries {
@@ -291,3 +295,93 @@ func (pn *protocolNumbers) escape() []canonProtocolRecord {
}
return prs
}
+
+func parseAddrFamilyNumbers(w io.Writer, r io.Reader) error {
+ dec := xml.NewDecoder(r)
+ var afn addrFamilylNumbers
+ if err := dec.Decode(&afn); err != nil {
+ return err
+ }
+ afrs := afn.escape()
+ fmt.Fprintf(w, "// %s, Updated: %s\n", afn.Title, afn.Updated)
+ fmt.Fprintf(w, "const (\n")
+ for _, afr := range afrs {
+ if afr.Name == "" {
+ continue
+ }
+ fmt.Fprintf(w, "AddrFamily%s = %d", afr.Name, afr.Value)
+ fmt.Fprintf(w, "// %s\n", afr.Descr)
+ }
+ fmt.Fprintf(w, ")\n")
+ return nil
+}
+
+type addrFamilylNumbers struct {
+ XMLName xml.Name `xml:"registry"`
+ Title string `xml:"title"`
+ Updated string `xml:"updated"`
+ RegTitle string `xml:"registry>title"`
+ Note string `xml:"registry>note"`
+ Records []struct {
+ Value string `xml:"value"`
+ Descr string `xml:"description"`
+ } `xml:"registry>record"`
+}
+
+type canonAddrFamilyRecord struct {
+ Name string
+ Descr string
+ Value int
+}
+
+func (afn *addrFamilylNumbers) escape() []canonAddrFamilyRecord {
+ afrs := make([]canonAddrFamilyRecord, len(afn.Records))
+ sr := strings.NewReplacer(
+ "IP version 4", "IPv4",
+ "IP version 6", "IPv6",
+ "Identifier", "ID",
+ "-", "",
+ "-", "",
+ "/", "",
+ ".", "",
+ " ", "",
+ )
+ for i, afr := range afn.Records {
+ if strings.Contains(afr.Descr, "Unassigned") ||
+ strings.Contains(afr.Descr, "Reserved") {
+ continue
+ }
+ afrs[i].Descr = afr.Descr
+ s := strings.TrimSpace(afr.Descr)
+ switch s {
+ case "IP (IP version 4)":
+ afrs[i].Name = "IPv4"
+ case "IP6 (IP version 6)":
+ afrs[i].Name = "IPv6"
+ case "AFI for L2VPN information":
+ afrs[i].Name = "L2VPN"
+ case "E.164 with NSAP format subaddress":
+ afrs[i].Name = "E164withSubaddress"
+ case "MT IP: Multi-Topology IP version 4":
+ afrs[i].Name = "MTIPv4"
+ case "MAC/24":
+ afrs[i].Name = "MACFinal24bits"
+ case "MAC/40":
+ afrs[i].Name = "MACFinal40bits"
+ case "IPv6/64":
+ afrs[i].Name = "IPv6Initial64bits"
+ default:
+ n := strings.Index(s, "(")
+ if n > 0 {
+ s = s[:n]
+ }
+ n = strings.Index(s, ":")
+ if n > 0 {
+ s = s[:n]
+ }
+ afrs[i].Name = sr.Replace(s)
+ }
+ afrs[i].Value, _ = strconv.Atoi(afr.Value)
+ }
+ return afrs
+}
diff --git a/vendor/golang.org/x/net/internal/nettest/helper_bsd.go b/vendor/golang.org/x/net/internal/nettest/helper_bsd.go
deleted file mode 100644
index a6e433b58..000000000
--- a/vendor/golang.org/x/net/internal/nettest/helper_bsd.go
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build darwin dragonfly freebsd netbsd openbsd
-
-package nettest
-
-import (
- "runtime"
- "strconv"
- "strings"
- "syscall"
-)
-
-var darwinVersion int
-
-func init() {
- if runtime.GOOS == "darwin" {
- // See http://support.apple.com/kb/HT1633.
- s, err := syscall.Sysctl("kern.osrelease")
- if err != nil {
- return
- }
- ss := strings.Split(s, ".")
- if len(ss) == 0 {
- return
- }
- darwinVersion, _ = strconv.Atoi(ss[0])
- }
-}
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- switch runtime.GOOS {
- case "freebsd":
- // See http://www.freebsd.org/cgi/query-pr.cgi?pr=180065.
- // Even after the fix, it looks like the latest
- // kernels don't deliver link-local scoped multicast
- // packets correctly.
- return false
- case "darwin":
- return !causesIPv6Crash()
- default:
- return true
- }
-}
-
-func causesIPv6Crash() bool {
- // We see some kernel crash when running IPv6 with IP-level
- // options on Darwin kernel version 12 or below.
- // See golang.org/issues/17015.
- return darwinVersion < 13
-}
diff --git a/vendor/golang.org/x/net/internal/nettest/helper_nobsd.go b/vendor/golang.org/x/net/internal/nettest/helper_nobsd.go
deleted file mode 100644
index bc7da5e0d..000000000
--- a/vendor/golang.org/x/net/internal/nettest/helper_nobsd.go
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build linux solaris
-
-package nettest
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- return true
-}
-
-func causesIPv6Crash() bool {
- return false
-}
diff --git a/vendor/golang.org/x/net/internal/nettest/helper_posix.go b/vendor/golang.org/x/net/internal/nettest/helper_posix.go
deleted file mode 100644
index 963ed9965..000000000
--- a/vendor/golang.org/x/net/internal/nettest/helper_posix.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
-
-package nettest
-
-import (
- "os"
- "syscall"
-)
-
-func protocolNotSupported(err error) bool {
- switch err := err.(type) {
- case syscall.Errno:
- switch err {
- case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
- return true
- }
- case *os.SyscallError:
- switch err := err.Err.(type) {
- case syscall.Errno:
- switch err {
- case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
- return true
- }
- }
- }
- return false
-}
diff --git a/vendor/golang.org/x/net/internal/nettest/helper_stub.go b/vendor/golang.org/x/net/internal/nettest/helper_stub.go
deleted file mode 100644
index ea61b6f39..000000000
--- a/vendor/golang.org/x/net/internal/nettest/helper_stub.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build nacl plan9
-
-package nettest
-
-import (
- "fmt"
- "runtime"
-)
-
-func maxOpenFiles() int {
- return defaultMaxOpenFiles
-}
-
-func supportsRawIPSocket() (string, bool) {
- return fmt.Sprintf("not supported on %s", runtime.GOOS), false
-}
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- return false
-}
-
-func causesIPv6Crash() bool {
- return false
-}
-
-func protocolNotSupported(err error) bool {
- return false
-}
diff --git a/vendor/golang.org/x/net/internal/nettest/helper_unix.go b/vendor/golang.org/x/net/internal/nettest/helper_unix.go
deleted file mode 100644
index ed13e448b..000000000
--- a/vendor/golang.org/x/net/internal/nettest/helper_unix.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris
-
-package nettest
-
-import (
- "fmt"
- "os"
- "runtime"
- "syscall"
-)
-
-func maxOpenFiles() int {
- var rlim syscall.Rlimit
- if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil {
- return defaultMaxOpenFiles
- }
- return int(rlim.Cur)
-}
-
-func supportsRawIPSocket() (string, bool) {
- if os.Getuid() != 0 {
- return fmt.Sprintf("must be root on %s", runtime.GOOS), false
- }
- return "", true
-}
diff --git a/vendor/golang.org/x/net/internal/nettest/helper_windows.go b/vendor/golang.org/x/net/internal/nettest/helper_windows.go
deleted file mode 100644
index 3dcb727c9..000000000
--- a/vendor/golang.org/x/net/internal/nettest/helper_windows.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package nettest
-
-import (
- "fmt"
- "runtime"
- "syscall"
-)
-
-func maxOpenFiles() int {
- return 4 * defaultMaxOpenFiles /* actually it's 16581375 */
-}
-
-func supportsRawIPSocket() (string, bool) {
- // From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
- // Note: To use a socket of type SOCK_RAW requires administrative privileges.
- // Users running Winsock applications that use raw sockets must be a member of
- // the Administrators group on the local computer, otherwise raw socket calls
- // will fail with an error code of WSAEACCES. On Windows Vista and later, access
- // for raw sockets is enforced at socket creation. In earlier versions of Windows,
- // access for raw sockets is enforced during other socket operations.
- s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, 0)
- if err == syscall.WSAEACCES {
- return fmt.Sprintf("no access to raw socket allowed on %s", runtime.GOOS), false
- }
- if err != nil {
- return err.Error(), false
- }
- syscall.Closesocket(s)
- return "", true
-}
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- return true
-}
-
-func causesIPv6Crash() bool {
- return false
-}
diff --git a/vendor/golang.org/x/net/internal/nettest/interface.go b/vendor/golang.org/x/net/internal/nettest/interface.go
deleted file mode 100644
index 8e6333afe..000000000
--- a/vendor/golang.org/x/net/internal/nettest/interface.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package nettest
-
-import "net"
-
-// IsMulticastCapable reports whether ifi is an IP multicast-capable
-// network interface. Network must be "ip", "ip4" or "ip6".
-func IsMulticastCapable(network string, ifi *net.Interface) (net.IP, bool) {
- switch network {
- case "ip", "ip4", "ip6":
- default:
- return nil, false
- }
- if ifi == nil || ifi.Flags&net.FlagUp == 0 || ifi.Flags&net.FlagMulticast == 0 {
- return nil, false
- }
- return hasRoutableIP(network, ifi)
-}
-
-// RoutedInterface returns a network interface that can route IP
-// traffic and satisfies flags. It returns nil when an appropriate
-// network interface is not found. Network must be "ip", "ip4" or
-// "ip6".
-func RoutedInterface(network string, flags net.Flags) *net.Interface {
- switch network {
- case "ip", "ip4", "ip6":
- default:
- return nil
- }
- ift, err := net.Interfaces()
- if err != nil {
- return nil
- }
- for _, ifi := range ift {
- if ifi.Flags&flags != flags {
- continue
- }
- if _, ok := hasRoutableIP(network, &ifi); !ok {
- continue
- }
- return &ifi
- }
- return nil
-}
-
-func hasRoutableIP(network string, ifi *net.Interface) (net.IP, bool) {
- ifat, err := ifi.Addrs()
- if err != nil {
- return nil, false
- }
- for _, ifa := range ifat {
- switch ifa := ifa.(type) {
- case *net.IPAddr:
- if ip := routableIP(network, ifa.IP); ip != nil {
- return ip, true
- }
- case *net.IPNet:
- if ip := routableIP(network, ifa.IP); ip != nil {
- return ip, true
- }
- }
- }
- return nil, false
-}
-
-func routableIP(network string, ip net.IP) net.IP {
- if !ip.IsLoopback() && !ip.IsLinkLocalUnicast() && !ip.IsGlobalUnicast() {
- return nil
- }
- switch network {
- case "ip4":
- if ip := ip.To4(); ip != nil {
- return ip
- }
- case "ip6":
- if ip.IsLoopback() { // addressing scope of the loopback address depends on each implementation
- return nil
- }
- if ip := ip.To16(); ip != nil && ip.To4() == nil {
- return ip
- }
- default:
- if ip := ip.To4(); ip != nil {
- return ip
- }
- if ip := ip.To16(); ip != nil {
- return ip
- }
- }
- return nil
-}
diff --git a/vendor/golang.org/x/net/internal/nettest/rlimit.go b/vendor/golang.org/x/net/internal/nettest/rlimit.go
deleted file mode 100644
index bb34aec0b..000000000
--- a/vendor/golang.org/x/net/internal/nettest/rlimit.go
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package nettest
-
-const defaultMaxOpenFiles = 256
-
-// MaxOpenFiles returns the maximum number of open files for the
-// caller's process.
-func MaxOpenFiles() int { return maxOpenFiles() }
diff --git a/vendor/golang.org/x/net/internal/nettest/stack.go b/vendor/golang.org/x/net/internal/nettest/stack.go
deleted file mode 100644
index 06f4e09ef..000000000
--- a/vendor/golang.org/x/net/internal/nettest/stack.go
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2014 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package nettest provides utilities for network testing.
-package nettest // import "golang.org/x/net/internal/nettest"
-
-import (
- "fmt"
- "io/ioutil"
- "net"
- "os"
- "runtime"
-)
-
-var (
- supportsIPv4 bool
- supportsIPv6 bool
-)
-
-func init() {
- if ln, err := net.Listen("tcp4", "127.0.0.1:0"); err == nil {
- ln.Close()
- supportsIPv4 = true
- }
- if ln, err := net.Listen("tcp6", "[::1]:0"); err == nil {
- ln.Close()
- supportsIPv6 = true
- }
-}
-
-// SupportsIPv4 reports whether the platform supports IPv4 networking
-// functionality.
-func SupportsIPv4() bool { return supportsIPv4 }
-
-// SupportsIPv6 reports whether the platform supports IPv6 networking
-// functionality.
-func SupportsIPv6() bool { return supportsIPv6 }
-
-// SupportsRawIPSocket reports whether the platform supports raw IP
-// sockets.
-func SupportsRawIPSocket() (string, bool) {
- return supportsRawIPSocket()
-}
-
-// SupportsIPv6MulticastDeliveryOnLoopback reports whether the
-// platform supports IPv6 multicast packet delivery on software
-// loopback interface.
-func SupportsIPv6MulticastDeliveryOnLoopback() bool {
- return supportsIPv6MulticastDeliveryOnLoopback()
-}
-
-// ProtocolNotSupported reports whether err is a protocol not
-// supported error.
-func ProtocolNotSupported(err error) bool {
- return protocolNotSupported(err)
-}
-
-// TestableNetwork reports whether network is testable on the current
-// platform configuration.
-func TestableNetwork(network string) bool {
- // This is based on logic from standard library's
- // net/platform_test.go.
- switch network {
- case "unix", "unixgram":
- switch runtime.GOOS {
- case "android", "nacl", "plan9", "windows":
- return false
- }
- if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
- return false
- }
- case "unixpacket":
- switch runtime.GOOS {
- case "android", "darwin", "freebsd", "nacl", "plan9", "windows":
- return false
- case "netbsd":
- // It passes on amd64 at least. 386 fails (Issue 22927). arm is unknown.
- if runtime.GOARCH == "386" {
- return false
- }
- }
- }
- return true
-}
-
-// NewLocalListener returns a listener which listens to a loopback IP
-// address or local file system path.
-// Network must be "tcp", "tcp4", "tcp6", "unix" or "unixpacket".
-func NewLocalListener(network string) (net.Listener, error) {
- switch network {
- case "tcp":
- if supportsIPv4 {
- if ln, err := net.Listen("tcp4", "127.0.0.1:0"); err == nil {
- return ln, nil
- }
- }
- if supportsIPv6 {
- return net.Listen("tcp6", "[::1]:0")
- }
- case "tcp4":
- if supportsIPv4 {
- return net.Listen("tcp4", "127.0.0.1:0")
- }
- case "tcp6":
- if supportsIPv6 {
- return net.Listen("tcp6", "[::1]:0")
- }
- case "unix", "unixpacket":
- return net.Listen(network, localPath())
- }
- return nil, fmt.Errorf("%s is not supported", network)
-}
-
-// NewLocalPacketListener returns a packet listener which listens to a
-// loopback IP address or local file system path.
-// Network must be "udp", "udp4", "udp6" or "unixgram".
-func NewLocalPacketListener(network string) (net.PacketConn, error) {
- switch network {
- case "udp":
- if supportsIPv4 {
- if c, err := net.ListenPacket("udp4", "127.0.0.1:0"); err == nil {
- return c, nil
- }
- }
- if supportsIPv6 {
- return net.ListenPacket("udp6", "[::1]:0")
- }
- case "udp4":
- if supportsIPv4 {
- return net.ListenPacket("udp4", "127.0.0.1:0")
- }
- case "udp6":
- if supportsIPv6 {
- return net.ListenPacket("udp6", "[::1]:0")
- }
- case "unixgram":
- return net.ListenPacket(network, localPath())
- }
- return nil, fmt.Errorf("%s is not supported", network)
-}
-
-func localPath() string {
- f, err := ioutil.TempFile("", "nettest")
- if err != nil {
- panic(err)
- }
- path := f.Name()
- f.Close()
- os.Remove(path)
- return path
-}
diff --git a/vendor/golang.org/x/net/internal/socket/socket_go1_9_test.go b/vendor/golang.org/x/net/internal/socket/socket_go1_9_test.go
deleted file mode 100644
index c4edd4a8d..000000000
--- a/vendor/golang.org/x/net/internal/socket/socket_go1_9_test.go
+++ /dev/null
@@ -1,259 +0,0 @@
-// Copyright 2017 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build go1.9
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris
-
-package socket_test
-
-import (
- "bytes"
- "fmt"
- "net"
- "runtime"
- "testing"
-
- "golang.org/x/net/internal/nettest"
- "golang.org/x/net/internal/socket"
-)
-
-type mockControl struct {
- Level int
- Type int
- Data []byte
-}
-
-func TestControlMessage(t *testing.T) {
- for _, tt := range []struct {
- cs []mockControl
- }{
- {
- []mockControl{
- {Level: 1, Type: 1},
- },
- },
- {
- []mockControl{
- {Level: 2, Type: 2, Data: []byte{0xfe}},
- },
- },
- {
- []mockControl{
- {Level: 3, Type: 3, Data: []byte{0xfe, 0xff, 0xff, 0xfe}},
- },
- },
- {
- []mockControl{
- {Level: 4, Type: 4, Data: []byte{0xfe, 0xff, 0xff, 0xfe, 0xfe, 0xff, 0xff, 0xfe}},
- },
- },
- {
- []mockControl{
- {Level: 4, Type: 4, Data: []byte{0xfe, 0xff, 0xff, 0xfe, 0xfe, 0xff, 0xff, 0xfe}},
- {Level: 2, Type: 2, Data: []byte{0xfe}},
- },
- },
- } {
- var w []byte
- var tailPadLen int
- mm := socket.NewControlMessage([]int{0})
- for i, c := range tt.cs {
- m := socket.NewControlMessage([]int{len(c.Data)})
- l := len(m) - len(mm)
- if i == len(tt.cs)-1 && l > len(c.Data) {
- tailPadLen = l - len(c.Data)
- }
- w = append(w, m...)
- }
-
- var err error
- ww := make([]byte, len(w))
- copy(ww, w)
- m := socket.ControlMessage(ww)
- for _, c := range tt.cs {
- if err = m.MarshalHeader(c.Level, c.Type, len(c.Data)); err != nil {
- t.Fatalf("(%v).MarshalHeader() = %v", tt.cs, err)
- }
- copy(m.Data(len(c.Data)), c.Data)
- m = m.Next(len(c.Data))
- }
- m = socket.ControlMessage(w)
- for _, c := range tt.cs {
- m, err = m.Marshal(c.Level, c.Type, c.Data)
- if err != nil {
- t.Fatalf("(%v).Marshal() = %v", tt.cs, err)
- }
- }
- if !bytes.Equal(ww, w) {
- t.Fatalf("got %#v; want %#v", ww, w)
- }
-
- ws := [][]byte{w}
- if tailPadLen > 0 {
- // Test a message with no tail padding.
- nopad := w[:len(w)-tailPadLen]
- ws = append(ws, [][]byte{nopad}...)
- }
- for _, w := range ws {
- ms, err := socket.ControlMessage(w).Parse()
- if err != nil {
- t.Fatalf("(%v).Parse() = %v", tt.cs, err)
- }
- for i, m := range ms {
- lvl, typ, dataLen, err := m.ParseHeader()
- if err != nil {
- t.Fatalf("(%v).ParseHeader() = %v", tt.cs, err)
- }
- if lvl != tt.cs[i].Level || typ != tt.cs[i].Type || dataLen != len(tt.cs[i].Data) {
- t.Fatalf("%v: got %d, %d, %d; want %d, %d, %d", tt.cs[i], lvl, typ, dataLen, tt.cs[i].Level, tt.cs[i].Type, len(tt.cs[i].Data))
- }
- }
- }
- }
-}
-
-func TestUDP(t *testing.T) {
- c, err := nettest.NewLocalPacketListener("udp")
- if err != nil {
- t.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
- }
- defer c.Close()
- cc, err := socket.NewConn(c.(net.Conn))
- if err != nil {
- t.Fatal(err)
- }
-
- t.Run("Message", func(t *testing.T) {
- data := []byte("HELLO-R-U-THERE")
- wm := socket.Message{
- Buffers: bytes.SplitAfter(data, []byte("-")),
- Addr: c.LocalAddr(),
- }
- if err := cc.SendMsg(&wm, 0); err != nil {
- t.Fatal(err)
- }
- b := make([]byte, 32)
- rm := socket.Message{
- Buffers: [][]byte{b[:1], b[1:3], b[3:7], b[7:11], b[11:]},
- }
- if err := cc.RecvMsg(&rm, 0); err != nil {
- t.Fatal(err)
- }
- if !bytes.Equal(b[:rm.N], data) {
- t.Fatalf("got %#v; want %#v", b[:rm.N], data)
- }
- })
- switch runtime.GOOS {
- case "android", "linux":
- t.Run("Messages", func(t *testing.T) {
- data := []byte("HELLO-R-U-THERE")
- wmbs := bytes.SplitAfter(data, []byte("-"))
- wms := []socket.Message{
- {Buffers: wmbs[:1], Addr: c.LocalAddr()},
- {Buffers: wmbs[1:], Addr: c.LocalAddr()},
- }
- n, err := cc.SendMsgs(wms, 0)
- if err != nil {
- t.Fatal(err)
- }
- if n != len(wms) {
- t.Fatalf("got %d; want %d", n, len(wms))
- }
- b := make([]byte, 32)
- rmbs := [][][]byte{{b[:len(wmbs[0])]}, {b[len(wmbs[0]):]}}
- rms := []socket.Message{
- {Buffers: rmbs[0]},
- {Buffers: rmbs[1]},
- }
- n, err = cc.RecvMsgs(rms, 0)
- if err != nil {
- t.Fatal(err)
- }
- if n != len(rms) {
- t.Fatalf("got %d; want %d", n, len(rms))
- }
- nn := 0
- for i := 0; i < n; i++ {
- nn += rms[i].N
- }
- if !bytes.Equal(b[:nn], data) {
- t.Fatalf("got %#v; want %#v", b[:nn], data)
- }
- })
- }
-
- // The behavior of transmission for zero byte paylaod depends
- // on each platform implementation. Some may transmit only
- // protocol header and options, other may transmit nothing.
- // We test only that SendMsg and SendMsgs will not crash with
- // empty buffers.
- wm := socket.Message{
- Buffers: [][]byte{{}},
- Addr: c.LocalAddr(),
- }
- cc.SendMsg(&wm, 0)
- wms := []socket.Message{
- {Buffers: [][]byte{{}}, Addr: c.LocalAddr()},
- }
- cc.SendMsgs(wms, 0)
-}
-
-func BenchmarkUDP(b *testing.B) {
- c, err := nettest.NewLocalPacketListener("udp")
- if err != nil {
- b.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
- }
- defer c.Close()
- cc, err := socket.NewConn(c.(net.Conn))
- if err != nil {
- b.Fatal(err)
- }
- data := []byte("HELLO-R-U-THERE")
- wm := socket.Message{
- Buffers: [][]byte{data},
- Addr: c.LocalAddr(),
- }
- rm := socket.Message{
- Buffers: [][]byte{make([]byte, 128)},
- OOB: make([]byte, 128),
- }
-
- for M := 1; M <= 1<<9; M = M << 1 {
- b.Run(fmt.Sprintf("Iter-%d", M), func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- for j := 0; j < M; j++ {
- if err := cc.SendMsg(&wm, 0); err != nil {
- b.Fatal(err)
- }
- if err := cc.RecvMsg(&rm, 0); err != nil {
- b.Fatal(err)
- }
- }
- }
- })
- switch runtime.GOOS {
- case "android", "linux":
- wms := make([]socket.Message, M)
- for i := range wms {
- wms[i].Buffers = [][]byte{data}
- wms[i].Addr = c.LocalAddr()
- }
- rms := make([]socket.Message, M)
- for i := range rms {
- rms[i].Buffers = [][]byte{make([]byte, 128)}
- rms[i].OOB = make([]byte, 128)
- }
- b.Run(fmt.Sprintf("Batch-%d", M), func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- if _, err := cc.SendMsgs(wms, 0); err != nil {
- b.Fatal(err)
- }
- if _, err := cc.RecvMsgs(rms, 0); err != nil {
- b.Fatal(err)
- }
- }
- })
- }
- }
-}
diff --git a/vendor/golang.org/x/net/internal/socket/socket_test.go b/vendor/golang.org/x/net/internal/socket/socket_test.go
deleted file mode 100644
index bf3751b5e..000000000
--- a/vendor/golang.org/x/net/internal/socket/socket_test.go
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2017 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
-
-package socket_test
-
-import (
- "net"
- "runtime"
- "syscall"
- "testing"
-
- "golang.org/x/net/internal/nettest"
- "golang.org/x/net/internal/socket"
-)
-
-func TestSocket(t *testing.T) {
- t.Run("Option", func(t *testing.T) {
- testSocketOption(t, &socket.Option{Level: syscall.SOL_SOCKET, Name: syscall.SO_RCVBUF, Len: 4})
- })
-}
-
-func testSocketOption(t *testing.T, so *socket.Option) {
- c, err := nettest.NewLocalPacketListener("udp")
- if err != nil {
- t.Skipf("not supported on %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
- }
- defer c.Close()
- cc, err := socket.NewConn(c.(net.Conn))
- if err != nil {
- t.Fatal(err)
- }
- const N = 2048
- if err := so.SetInt(cc, N); err != nil {
- t.Fatal(err)
- }
- n, err := so.GetInt(cc)
- if err != nil {
- t.Fatal(err)
- }
- if n < N {
- t.Fatalf("got %d; want greater than or equal to %d", n, N)
- }
-}
diff --git a/vendor/golang.org/x/net/internal/socket/zsys_netbsd_arm.go b/vendor/golang.org/x/net/internal/socket/zsys_netbsd_arm.go
index 206ea2d11..db60491fe 100644
--- a/vendor/golang.org/x/net/internal/socket/zsys_netbsd_arm.go
+++ b/vendor/golang.org/x/net/internal/socket/zsys_netbsd_arm.go
@@ -26,6 +26,11 @@ type msghdr struct {
Flags int32
}
+type mmsghdr struct {
+ Hdr msghdr
+ Len uint32
+}
+
type cmsghdr struct {
Len uint32
Level int32
@@ -52,6 +57,7 @@ type sockaddrInet6 struct {
const (
sizeofIovec = 0x8
sizeofMsghdr = 0x1c
+ sizeofMmsghdr = 0x20
sizeofCmsghdr = 0xc
sizeofSockaddrInet = 0x10
diff --git a/vendor/golang.org/x/net/internal/timeseries/timeseries.go b/vendor/golang.org/x/net/internal/timeseries/timeseries.go
deleted file mode 100644
index 685f0e7ea..000000000
--- a/vendor/golang.org/x/net/internal/timeseries/timeseries.go
+++ /dev/null
@@ -1,525 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Package timeseries implements a time series structure for stats collection.
-package timeseries // import "golang.org/x/net/internal/timeseries"
-
-import (
- "fmt"
- "log"
- "time"
-)
-
-const (
- timeSeriesNumBuckets = 64
- minuteHourSeriesNumBuckets = 60
-)
-
-var timeSeriesResolutions = []time.Duration{
- 1 * time.Second,
- 10 * time.Second,
- 1 * time.Minute,
- 10 * time.Minute,
- 1 * time.Hour,
- 6 * time.Hour,
- 24 * time.Hour, // 1 day
- 7 * 24 * time.Hour, // 1 week
- 4 * 7 * 24 * time.Hour, // 4 weeks
- 16 * 7 * 24 * time.Hour, // 16 weeks
-}
-
-var minuteHourSeriesResolutions = []time.Duration{
- 1 * time.Second,
- 1 * time.Minute,
-}
-
-// An Observable is a kind of data that can be aggregated in a time series.
-type Observable interface {
- Multiply(ratio float64) // Multiplies the data in self by a given ratio
- Add(other Observable) // Adds the data from a different observation to self
- Clear() // Clears the observation so it can be reused.
- CopyFrom(other Observable) // Copies the contents of a given observation to self
-}
-
-// Float attaches the methods of Observable to a float64.
-type Float float64
-
-// NewFloat returns a Float.
-func NewFloat() Observable {
- f := Float(0)
- return &f
-}
-
-// String returns the float as a string.
-func (f *Float) String() string { return fmt.Sprintf("%g", f.Value()) }
-
-// Value returns the float's value.
-func (f *Float) Value() float64 { return float64(*f) }
-
-func (f *Float) Multiply(ratio float64) { *f *= Float(ratio) }
-
-func (f *Float) Add(other Observable) {
- o := other.(*Float)
- *f += *o
-}
-
-func (f *Float) Clear() { *f = 0 }
-
-func (f *Float) CopyFrom(other Observable) {
- o := other.(*Float)
- *f = *o
-}
-
-// A Clock tells the current time.
-type Clock interface {
- Time() time.Time
-}
-
-type defaultClock int
-
-var defaultClockInstance defaultClock
-
-func (defaultClock) Time() time.Time { return time.Now() }
-
-// Information kept per level. Each level consists of a circular list of
-// observations. The start of the level may be derived from end and the
-// len(buckets) * sizeInMillis.
-type tsLevel struct {
- oldest int // index to oldest bucketed Observable
- newest int // index to newest bucketed Observable
- end time.Time // end timestamp for this level
- size time.Duration // duration of the bucketed Observable
- buckets []Observable // collections of observations
- provider func() Observable // used for creating new Observable
-}
-
-func (l *tsLevel) Clear() {
- l.oldest = 0
- l.newest = len(l.buckets) - 1
- l.end = time.Time{}
- for i := range l.buckets {
- if l.buckets[i] != nil {
- l.buckets[i].Clear()
- l.buckets[i] = nil
- }
- }
-}
-
-func (l *tsLevel) InitLevel(size time.Duration, numBuckets int, f func() Observable) {
- l.size = size
- l.provider = f
- l.buckets = make([]Observable, numBuckets)
-}
-
-// Keeps a sequence of levels. Each level is responsible for storing data at
-// a given resolution. For example, the first level stores data at a one
-// minute resolution while the second level stores data at a one hour
-// resolution.
-
-// Each level is represented by a sequence of buckets. Each bucket spans an
-// interval equal to the resolution of the level. New observations are added
-// to the last bucket.
-type timeSeries struct {
- provider func() Observable // make more Observable
- numBuckets int // number of buckets in each level
- levels []*tsLevel // levels of bucketed Observable
- lastAdd time.Time // time of last Observable tracked
- total Observable // convenient aggregation of all Observable
- clock Clock // Clock for getting current time
- pending Observable // observations not yet bucketed
- pendingTime time.Time // what time are we keeping in pending
- dirty bool // if there are pending observations
-}
-
-// init initializes a level according to the supplied criteria.
-func (ts *timeSeries) init(resolutions []time.Duration, f func() Observable, numBuckets int, clock Clock) {
- ts.provider = f
- ts.numBuckets = numBuckets
- ts.clock = clock
- ts.levels = make([]*tsLevel, len(resolutions))
-
- for i := range resolutions {
- if i > 0 && resolutions[i-1] >= resolutions[i] {
- log.Print("timeseries: resolutions must be monotonically increasing")
- break
- }
- newLevel := new(tsLevel)
- newLevel.InitLevel(resolutions[i], ts.numBuckets, ts.provider)
- ts.levels[i] = newLevel
- }
-
- ts.Clear()
-}
-
-// Clear removes all observations from the time series.
-func (ts *timeSeries) Clear() {
- ts.lastAdd = time.Time{}
- ts.total = ts.resetObservation(ts.total)
- ts.pending = ts.resetObservation(ts.pending)
- ts.pendingTime = time.Time{}
- ts.dirty = false
-
- for i := range ts.levels {
- ts.levels[i].Clear()
- }
-}
-
-// Add records an observation at the current time.
-func (ts *timeSeries) Add(observation Observable) {
- ts.AddWithTime(observation, ts.clock.Time())
-}
-
-// AddWithTime records an observation at the specified time.
-func (ts *timeSeries) AddWithTime(observation Observable, t time.Time) {
-
- smallBucketDuration := ts.levels[0].size
-
- if t.After(ts.lastAdd) {
- ts.lastAdd = t
- }
-
- if t.After(ts.pendingTime) {
- ts.advance(t)
- ts.mergePendingUpdates()
- ts.pendingTime = ts.levels[0].end
- ts.pending.CopyFrom(observation)
- ts.dirty = true
- } else if t.After(ts.pendingTime.Add(-1 * smallBucketDuration)) {
- // The observation is close enough to go into the pending bucket.
- // This compensates for clock skewing and small scheduling delays
- // by letting the update stay in the fast path.
- ts.pending.Add(observation)
- ts.dirty = true
- } else {
- ts.mergeValue(observation, t)
- }
-}
-
-// mergeValue inserts the observation at the specified time in the past into all levels.
-func (ts *timeSeries) mergeValue(observation Observable, t time.Time) {
- for _, level := range ts.levels {
- index := (ts.numBuckets - 1) - int(level.end.Sub(t)/level.size)
- if 0 <= index && index < ts.numBuckets {
- bucketNumber := (level.oldest + index) % ts.numBuckets
- if level.buckets[bucketNumber] == nil {
- level.buckets[bucketNumber] = level.provider()
- }
- level.buckets[bucketNumber].Add(observation)
- }
- }
- ts.total.Add(observation)
-}
-
-// mergePendingUpdates applies the pending updates into all levels.
-func (ts *timeSeries) mergePendingUpdates() {
- if ts.dirty {
- ts.mergeValue(ts.pending, ts.pendingTime)
- ts.pending = ts.resetObservation(ts.pending)
- ts.dirty = false
- }
-}
-
-// advance cycles the buckets at each level until the latest bucket in
-// each level can hold the time specified.
-func (ts *timeSeries) advance(t time.Time) {
- if !t.After(ts.levels[0].end) {
- return
- }
- for i := 0; i < len(ts.levels); i++ {
- level := ts.levels[i]
- if !level.end.Before(t) {
- break
- }
-
- // If the time is sufficiently far, just clear the level and advance
- // directly.
- if !t.Before(level.end.Add(level.size * time.Duration(ts.numBuckets))) {
- for _, b := range level.buckets {
- ts.resetObservation(b)
- }
- level.end = time.Unix(0, (t.UnixNano()/level.size.Nanoseconds())*level.size.Nanoseconds())
- }
-
- for t.After(level.end) {
- level.end = level.end.Add(level.size)
- level.newest = level.oldest
- level.oldest = (level.oldest + 1) % ts.numBuckets
- ts.resetObservation(level.buckets[level.newest])
- }
-
- t = level.end
- }
-}
-
-// Latest returns the sum of the num latest buckets from the level.
-func (ts *timeSeries) Latest(level, num int) Observable {
- now := ts.clock.Time()
- if ts.levels[0].end.Before(now) {
- ts.advance(now)
- }
-
- ts.mergePendingUpdates()
-
- result := ts.provider()
- l := ts.levels[level]
- index := l.newest
-
- for i := 0; i < num; i++ {
- if l.buckets[index] != nil {
- result.Add(l.buckets[index])
- }
- if index == 0 {
- index = ts.numBuckets
- }
- index--
- }
-
- return result
-}
-
-// LatestBuckets returns a copy of the num latest buckets from level.
-func (ts *timeSeries) LatestBuckets(level, num int) []Observable {
- if level < 0 || level > len(ts.levels) {
- log.Print("timeseries: bad level argument: ", level)
- return nil
- }
- if num < 0 || num >= ts.numBuckets {
- log.Print("timeseries: bad num argument: ", num)
- return nil
- }
-
- results := make([]Observable, num)
- now := ts.clock.Time()
- if ts.levels[0].end.Before(now) {
- ts.advance(now)
- }
-
- ts.mergePendingUpdates()
-
- l := ts.levels[level]
- index := l.newest
-
- for i := 0; i < num; i++ {
- result := ts.provider()
- results[i] = result
- if l.buckets[index] != nil {
- result.CopyFrom(l.buckets[index])
- }
-
- if index == 0 {
- index = ts.numBuckets
- }
- index -= 1
- }
- return results
-}
-
-// ScaleBy updates observations by scaling by factor.
-func (ts *timeSeries) ScaleBy(factor float64) {
- for _, l := range ts.levels {
- for i := 0; i < ts.numBuckets; i++ {
- l.buckets[i].Multiply(factor)
- }
- }
-
- ts.total.Multiply(factor)
- ts.pending.Multiply(factor)
-}
-
-// Range returns the sum of observations added over the specified time range.
-// If start or finish times don't fall on bucket boundaries of the same
-// level, then return values are approximate answers.
-func (ts *timeSeries) Range(start, finish time.Time) Observable {
- return ts.ComputeRange(start, finish, 1)[0]
-}
-
-// Recent returns the sum of observations from the last delta.
-func (ts *timeSeries) Recent(delta time.Duration) Observable {
- now := ts.clock.Time()
- return ts.Range(now.Add(-delta), now)
-}
-
-// Total returns the total of all observations.
-func (ts *timeSeries) Total() Observable {
- ts.mergePendingUpdates()
- return ts.total
-}
-
-// ComputeRange computes a specified number of values into a slice using
-// the observations recorded over the specified time period. The return
-// values are approximate if the start or finish times don't fall on the
-// bucket boundaries at the same level or if the number of buckets spanning
-// the range is not an integral multiple of num.
-func (ts *timeSeries) ComputeRange(start, finish time.Time, num int) []Observable {
- if start.After(finish) {
- log.Printf("timeseries: start > finish, %v>%v", start, finish)
- return nil
- }
-
- if num < 0 {
- log.Printf("timeseries: num < 0, %v", num)
- return nil
- }
-
- results := make([]Observable, num)
-
- for _, l := range ts.levels {
- if !start.Before(l.end.Add(-l.size * time.Duration(ts.numBuckets))) {
- ts.extract(l, start, finish, num, results)
- return results
- }
- }
-
- // Failed to find a level that covers the desired range. So just
- // extract from the last level, even if it doesn't cover the entire
- // desired range.
- ts.extract(ts.levels[len(ts.levels)-1], start, finish, num, results)
-
- return results
-}
-
-// RecentList returns the specified number of values in slice over the most
-// recent time period of the specified range.
-func (ts *timeSeries) RecentList(delta time.Duration, num int) []Observable {
- if delta < 0 {
- return nil
- }
- now := ts.clock.Time()
- return ts.ComputeRange(now.Add(-delta), now, num)
-}
-
-// extract returns a slice of specified number of observations from a given
-// level over a given range.
-func (ts *timeSeries) extract(l *tsLevel, start, finish time.Time, num int, results []Observable) {
- ts.mergePendingUpdates()
-
- srcInterval := l.size
- dstInterval := finish.Sub(start) / time.Duration(num)
- dstStart := start
- srcStart := l.end.Add(-srcInterval * time.Duration(ts.numBuckets))
-
- srcIndex := 0
-
- // Where should scanning start?
- if dstStart.After(srcStart) {
- advance := dstStart.Sub(srcStart) / srcInterval
- srcIndex += int(advance)
- srcStart = srcStart.Add(advance * srcInterval)
- }
-
- // The i'th value is computed as show below.
- // interval = (finish/start)/num
- // i'th value = sum of observation in range
- // [ start + i * interval,
- // start + (i + 1) * interval )
- for i := 0; i < num; i++ {
- results[i] = ts.resetObservation(results[i])
- dstEnd := dstStart.Add(dstInterval)
- for srcIndex < ts.numBuckets && srcStart.Before(dstEnd) {
- srcEnd := srcStart.Add(srcInterval)
- if srcEnd.After(ts.lastAdd) {
- srcEnd = ts.lastAdd
- }
-
- if !srcEnd.Before(dstStart) {
- srcValue := l.buckets[(srcIndex+l.oldest)%ts.numBuckets]
- if !srcStart.Before(dstStart) && !srcEnd.After(dstEnd) {
- // dst completely contains src.
- if srcValue != nil {
- results[i].Add(srcValue)
- }
- } else {
- // dst partially overlaps src.
- overlapStart := maxTime(srcStart, dstStart)
- overlapEnd := minTime(srcEnd, dstEnd)
- base := srcEnd.Sub(srcStart)
- fraction := overlapEnd.Sub(overlapStart).Seconds() / base.Seconds()
-
- used := ts.provider()
- if srcValue != nil {
- used.CopyFrom(srcValue)
- }
- used.Multiply(fraction)
- results[i].Add(used)
- }
-
- if srcEnd.After(dstEnd) {
- break
- }
- }
- srcIndex++
- srcStart = srcStart.Add(srcInterval)
- }
- dstStart = dstStart.Add(dstInterval)
- }
-}
-
-// resetObservation clears the content so the struct may be reused.
-func (ts *timeSeries) resetObservation(observation Observable) Observable {
- if observation == nil {
- observation = ts.provider()
- } else {
- observation.Clear()
- }
- return observation
-}
-
-// TimeSeries tracks data at granularities from 1 second to 16 weeks.
-type TimeSeries struct {
- timeSeries
-}
-
-// NewTimeSeries creates a new TimeSeries using the function provided for creating new Observable.
-func NewTimeSeries(f func() Observable) *TimeSeries {
- return NewTimeSeriesWithClock(f, defaultClockInstance)
-}
-
-// NewTimeSeriesWithClock creates a new TimeSeries using the function provided for creating new Observable and the clock for
-// assigning timestamps.
-func NewTimeSeriesWithClock(f func() Observable, clock Clock) *TimeSeries {
- ts := new(TimeSeries)
- ts.timeSeries.init(timeSeriesResolutions, f, timeSeriesNumBuckets, clock)
- return ts
-}
-
-// MinuteHourSeries tracks data at granularities of 1 minute and 1 hour.
-type MinuteHourSeries struct {
- timeSeries
-}
-
-// NewMinuteHourSeries creates a new MinuteHourSeries using the function provided for creating new Observable.
-func NewMinuteHourSeries(f func() Observable) *MinuteHourSeries {
- return NewMinuteHourSeriesWithClock(f, defaultClockInstance)
-}
-
-// NewMinuteHourSeriesWithClock creates a new MinuteHourSeries using the function provided for creating new Observable and the clock for
-// assigning timestamps.
-func NewMinuteHourSeriesWithClock(f func() Observable, clock Clock) *MinuteHourSeries {
- ts := new(MinuteHourSeries)
- ts.timeSeries.init(minuteHourSeriesResolutions, f,
- minuteHourSeriesNumBuckets, clock)
- return ts
-}
-
-func (ts *MinuteHourSeries) Minute() Observable {
- return ts.timeSeries.Latest(0, 60)
-}
-
-func (ts *MinuteHourSeries) Hour() Observable {
- return ts.timeSeries.Latest(1, 60)
-}
-
-func minTime(a, b time.Time) time.Time {
- if a.Before(b) {
- return a
- }
- return b
-}
-
-func maxTime(a, b time.Time) time.Time {
- if a.After(b) {
- return a
- }
- return b
-}
diff --git a/vendor/golang.org/x/net/internal/timeseries/timeseries_test.go b/vendor/golang.org/x/net/internal/timeseries/timeseries_test.go
deleted file mode 100644
index 66325a912..000000000
--- a/vendor/golang.org/x/net/internal/timeseries/timeseries_test.go
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright 2015 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package timeseries
-
-import (
- "math"
- "testing"
- "time"
-)
-
-func isNear(x *Float, y float64, tolerance float64) bool {
- return math.Abs(x.Value()-y) < tolerance
-}
-
-func isApproximate(x *Float, y float64) bool {
- return isNear(x, y, 1e-2)
-}
-
-func checkApproximate(t *testing.T, o Observable, y float64) {
- x := o.(*Float)
- if !isApproximate(x, y) {
- t.Errorf("Wanted %g, got %g", y, x.Value())
- }
-}
-
-func checkNear(t *testing.T, o Observable, y, tolerance float64) {
- x := o.(*Float)
- if !isNear(x, y, tolerance) {
- t.Errorf("Wanted %g +- %g, got %g", y, tolerance, x.Value())
- }
-}
-
-var baseTime = time.Date(2013, 1, 1, 0, 0, 0, 0, time.UTC)
-
-func tu(s int64) time.Time {
- return baseTime.Add(time.Duration(s) * time.Second)
-}
-
-func tu2(s int64, ns int64) time.Time {
- return baseTime.Add(time.Duration(s)*time.Second + time.Duration(ns)*time.Nanosecond)
-}
-
-func TestBasicTimeSeries(t *testing.T) {
- ts := NewTimeSeries(NewFloat)
- fo := new(Float)
- *fo = Float(10)
- ts.AddWithTime(fo, tu(1))
- ts.AddWithTime(fo, tu(1))
- ts.AddWithTime(fo, tu(1))
- ts.AddWithTime(fo, tu(1))
- checkApproximate(t, ts.Range(tu(0), tu(1)), 40)
- checkApproximate(t, ts.Total(), 40)
- ts.AddWithTime(fo, tu(3))
- ts.AddWithTime(fo, tu(3))
- ts.AddWithTime(fo, tu(3))
- checkApproximate(t, ts.Range(tu(0), tu(2)), 40)
- checkApproximate(t, ts.Range(tu(2), tu(4)), 30)
- checkApproximate(t, ts.Total(), 70)
- ts.AddWithTime(fo, tu(1))
- ts.AddWithTime(fo, tu(1))
- checkApproximate(t, ts.Range(tu(0), tu(2)), 60)
- checkApproximate(t, ts.Range(tu(2), tu(4)), 30)
- checkApproximate(t, ts.Total(), 90)
- *fo = Float(100)
- ts.AddWithTime(fo, tu(100))
- checkApproximate(t, ts.Range(tu(99), tu(100)), 100)
- checkApproximate(t, ts.Range(tu(0), tu(4)), 36)
- checkApproximate(t, ts.Total(), 190)
- *fo = Float(10)
- ts.AddWithTime(fo, tu(1))
- ts.AddWithTime(fo, tu(1))
- checkApproximate(t, ts.Range(tu(0), tu(4)), 44)
- checkApproximate(t, ts.Range(tu(37), tu2(100, 100e6)), 100)
- checkApproximate(t, ts.Range(tu(50), tu2(100, 100e6)), 100)
- checkApproximate(t, ts.Range(tu(99), tu2(100, 100e6)), 100)
- checkApproximate(t, ts.Total(), 210)
-
- for i, l := range ts.ComputeRange(tu(36), tu(100), 64) {
- if i == 63 {
- checkApproximate(t, l, 100)
- } else {
- checkApproximate(t, l, 0)
- }
- }
-
- checkApproximate(t, ts.Range(tu(0), tu(100)), 210)
- checkApproximate(t, ts.Range(tu(10), tu(100)), 100)
-
- for i, l := range ts.ComputeRange(tu(0), tu(100), 100) {
- if i < 10 {
- checkApproximate(t, l, 11)
- } else if i >= 90 {
- checkApproximate(t, l, 10)
- } else {
- checkApproximate(t, l, 0)
- }
- }
-}
-
-func TestFloat(t *testing.T) {
- f := Float(1)
- if g, w := f.String(), "1"; g != w {
- t.Errorf("Float(1).String = %q; want %q", g, w)
- }
- f2 := Float(2)
- var o Observable = &f2
- f.Add(o)
- if g, w := f.Value(), 3.0; g != w {
- t.Errorf("Float post-add = %v; want %v", g, w)
- }
- f.Multiply(2)
- if g, w := f.Value(), 6.0; g != w {
- t.Errorf("Float post-multiply = %v; want %v", g, w)
- }
- f.Clear()
- if g, w := f.Value(), 0.0; g != w {
- t.Errorf("Float post-clear = %v; want %v", g, w)
- }
- f.CopyFrom(&f2)
- if g, w := f.Value(), 2.0; g != w {
- t.Errorf("Float post-CopyFrom = %v; want %v", g, w)
- }
-}
-
-type mockClock struct {
- time time.Time
-}
-
-func (m *mockClock) Time() time.Time { return m.time }
-func (m *mockClock) Set(t time.Time) { m.time = t }
-
-const buckets = 6
-
-var testResolutions = []time.Duration{
- 10 * time.Second, // level holds one minute of observations
- 100 * time.Second, // level holds ten minutes of observations
- 10 * time.Minute, // level holds one hour of observations
-}
-
-// TestTimeSeries uses a small number of buckets to force a higher
-// error rate on approximations from the timeseries.
-type TestTimeSeries struct {
- timeSeries
-}
-
-func TestExpectedErrorRate(t *testing.T) {
- ts := new(TestTimeSeries)
- fake := new(mockClock)
- fake.Set(time.Now())
- ts.timeSeries.init(testResolutions, NewFloat, buckets, fake)
- for i := 1; i <= 61*61; i++ {
- fake.Set(fake.Time().Add(1 * time.Second))
- ob := Float(1)
- ts.AddWithTime(&ob, fake.Time())
-
- // The results should be accurate within one missing bucket (1/6) of the observations recorded.
- checkNear(t, ts.Latest(0, buckets), min(float64(i), 60), 10)
- checkNear(t, ts.Latest(1, buckets), min(float64(i), 600), 100)
- checkNear(t, ts.Latest(2, buckets), min(float64(i), 3600), 600)
- }
-}
-
-func min(a, b float64) float64 {
- if a < b {
- return a
- }
- return b
-}