Updating server dependancies (#6712)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
6b39c308d8
Коммит
42f28ab8e3
9
vendor/golang.org/x/crypto/acme/autocert/listener.go
сгенерированный
поставляемый
9
vendor/golang.org/x/crypto/acme/autocert/listener.go
сгенерированный
поставляемый
@@ -36,6 +36,9 @@ import (
|
||||
// operating system-specific cache or temp directory. This may not
|
||||
// be suitable for servers spanning multiple machines.
|
||||
//
|
||||
// The returned listener uses a *tls.Config that enables HTTP/2, and
|
||||
// should only be used with servers that support HTTP/2.
|
||||
//
|
||||
// The returned Listener also enables TCP keep-alives on the accepted
|
||||
// connections. The returned *tls.Conn are returned before their TLS
|
||||
// handshake has completed.
|
||||
@@ -58,6 +61,9 @@ func NewListener(domains ...string) net.Listener {
|
||||
// Listener listens on the standard TLS port (443) on all interfaces
|
||||
// and returns a net.Listener returning *tls.Conn connections.
|
||||
//
|
||||
// The returned listener uses a *tls.Config that enables HTTP/2, and
|
||||
// should only be used with servers that support HTTP/2.
|
||||
//
|
||||
// The returned Listener also enables TCP keep-alives on the accepted
|
||||
// connections. The returned *tls.Conn are returned before their TLS
|
||||
// handshake has completed.
|
||||
@@ -68,7 +74,8 @@ func (m *Manager) Listener() net.Listener {
|
||||
ln := &listener{
|
||||
m: m,
|
||||
conf: &tls.Config{
|
||||
GetCertificate: m.GetCertificate, // bonus: panic on nil m
|
||||
GetCertificate: m.GetCertificate, // bonus: panic on nil m
|
||||
NextProtos: []string{"h2", "http/1.1"}, // Enable HTTP/2
|
||||
},
|
||||
}
|
||||
ln.tcpListener, ln.tcpListenErr = net.Listen("tcp", ":443")
|
||||
|
||||
7
vendor/golang.org/x/crypto/bcrypt/bcrypt.go
сгенерированный
поставляемый
7
vendor/golang.org/x/crypto/bcrypt/bcrypt.go
сгенерированный
поставляемый
@@ -12,9 +12,10 @@ import (
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/blowfish"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/crypto/blowfish"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -205,7 +206,6 @@ func bcrypt(password []byte, cost int, salt []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func expensiveBlowfishSetup(key []byte, cost uint32, salt []byte) (*blowfish.Cipher, error) {
|
||||
|
||||
csalt, err := base64Decode(salt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -213,7 +213,8 @@ func expensiveBlowfishSetup(key []byte, cost uint32, salt []byte) (*blowfish.Cip
|
||||
|
||||
// Bug compatibility with C bcrypt implementations. They use the trailing
|
||||
// NULL in the key string during expansion.
|
||||
ckey := append(key, 0)
|
||||
// We copy the key to prevent changing the underlying array.
|
||||
ckey := append(key[:len(key):len(key)], 0)
|
||||
|
||||
c, err := blowfish.NewSaltedCipher(ckey, csalt)
|
||||
if err != nil {
|
||||
|
||||
17
vendor/golang.org/x/crypto/bcrypt/bcrypt_test.go
сгенерированный
поставляемый
17
vendor/golang.org/x/crypto/bcrypt/bcrypt_test.go
сгенерированный
поставляемый
@@ -224,3 +224,20 @@ func BenchmarkGeneration(b *testing.B) {
|
||||
GenerateFromPassword(passwd, 10)
|
||||
}
|
||||
}
|
||||
|
||||
// See Issue https://github.com/golang/go/issues/20425.
|
||||
func TestNoSideEffectsFromCompare(t *testing.T) {
|
||||
source := []byte("passw0rd123456")
|
||||
password := source[:len(source)-6]
|
||||
token := source[len(source)-6:]
|
||||
want := make([]byte, len(source))
|
||||
copy(want, source)
|
||||
|
||||
wantHash := []byte("$2a$10$LK9XRuhNxHHCvjX3tdkRKei1QiCDUKrJRhZv7WWZPuQGRUM92rOUa")
|
||||
_ = CompareHashAndPassword(wantHash, password)
|
||||
|
||||
got := bytes.Join([][]byte{password, token}, []byte(""))
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Errorf("got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
15
vendor/golang.org/x/crypto/blake2s/blake2s.go
сгенерированный
поставляемый
15
vendor/golang.org/x/crypto/blake2s/blake2s.go
сгенерированный
поставляемый
@@ -15,8 +15,12 @@ import (
|
||||
const (
|
||||
// The blocksize of BLAKE2s in bytes.
|
||||
BlockSize = 64
|
||||
|
||||
// The hash size of BLAKE2s-256 in bytes.
|
||||
Size = 32
|
||||
|
||||
// The hash size of BLAKE2s-128 in bytes.
|
||||
Size128 = 16
|
||||
)
|
||||
|
||||
var errKeySize = errors.New("blake2s: invalid key size")
|
||||
@@ -37,6 +41,17 @@ func Sum256(data []byte) [Size]byte {
|
||||
// key turns the hash into a MAC. The key must between zero and 32 bytes long.
|
||||
func New256(key []byte) (hash.Hash, error) { return newDigest(Size, key) }
|
||||
|
||||
// New128 returns a new hash.Hash computing the BLAKE2s-128 checksum given a
|
||||
// non-empty key. Note that a 128-bit digest is too small to be secure as a
|
||||
// cryptographic hash and should only be used as a MAC, thus the key argument
|
||||
// is not optional.
|
||||
func New128(key []byte) (hash.Hash, error) {
|
||||
if len(key) == 0 {
|
||||
return nil, errors.New("blake2s: a key is required for a 128-bit hash")
|
||||
}
|
||||
return newDigest(Size128, key)
|
||||
}
|
||||
|
||||
func newDigest(hashSize int, key []byte) (*digest, error) {
|
||||
if len(key) > Size {
|
||||
return nil, errKeySize
|
||||
|
||||
296
vendor/golang.org/x/crypto/blake2s/blake2s_test.go
сгенерированный
поставляемый
296
vendor/golang.org/x/crypto/blake2s/blake2s_test.go
сгенерированный
поставляемый
@@ -18,21 +18,25 @@ func TestHashes(t *testing.T) {
|
||||
if useSSE4 {
|
||||
t.Log("SSE4 version")
|
||||
testHashes(t)
|
||||
testHashes128(t)
|
||||
useSSE4 = false
|
||||
}
|
||||
if useSSSE3 {
|
||||
t.Log("SSSE3 version")
|
||||
testHashes(t)
|
||||
testHashes128(t)
|
||||
useSSSE3 = false
|
||||
}
|
||||
if useSSE2 {
|
||||
t.Log("SSE2 version")
|
||||
testHashes(t)
|
||||
testHashes128(t)
|
||||
useSSE2 = false
|
||||
}
|
||||
if useGeneric {
|
||||
t.Log("generic version")
|
||||
testHashes(t)
|
||||
testHashes128(t)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +73,39 @@ func testHashes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testHashes128(t *testing.T) {
|
||||
key, _ := hex.DecodeString("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f")
|
||||
|
||||
input := make([]byte, 255)
|
||||
for i := range input {
|
||||
input[i] = byte(i)
|
||||
}
|
||||
|
||||
for i, expectedHex := range hashes128 {
|
||||
h, err := New128(key)
|
||||
if err != nil {
|
||||
t.Fatalf("#%d: error from New128: %v", i, err)
|
||||
}
|
||||
|
||||
h.Write(input[:i])
|
||||
sum := h.Sum(nil)
|
||||
|
||||
if gotHex := fmt.Sprintf("%x", sum); gotHex != expectedHex {
|
||||
t.Fatalf("#%d (single write): got %s, wanted %s", i, gotHex, expectedHex)
|
||||
}
|
||||
|
||||
h.Reset()
|
||||
for j := 0; j < i; j++ {
|
||||
h.Write(input[j : j+1])
|
||||
}
|
||||
|
||||
sum = h.Sum(sum[:0])
|
||||
if gotHex := fmt.Sprintf("%x", sum); gotHex != expectedHex {
|
||||
t.Fatalf("#%d (byte-by-byte): got %s, wanted %s", i, gotHex, expectedHex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmarks
|
||||
|
||||
func benchmarkSum(b *testing.B, size int) {
|
||||
@@ -355,3 +392,262 @@ var hashes = []string{
|
||||
"db444c15597b5f1a03d1f9edd16e4a9f43a667cc275175dfa2b704e3bb1a9b83",
|
||||
"3fb735061abc519dfe979e54c1ee5bfad0a9d858b3315bad34bde999efd724dd",
|
||||
}
|
||||
|
||||
var hashes128 = []string{
|
||||
"9536f9b267655743dee97b8a670f9f53",
|
||||
"13bacfb85b48a1223c595f8c1e7e82cb",
|
||||
"d47a9b1645e2feae501cd5fe44ce6333",
|
||||
"1e2a79436a7796a3e9826bfedf07659f",
|
||||
"7640360ed3c4f3054dba79a21dda66b7",
|
||||
"d1207ac2bf5ac84fc9ef016da5a46a86",
|
||||
"3123987871e59305ece3125abfc0099a",
|
||||
"cf9e072ad522f2cda2d825218086731c",
|
||||
"95d22870392efe2846b12b6e8e84efbb",
|
||||
"7d63c30e2d51333f245601b038c0b93b",
|
||||
"ed608b98e13976bdf4bedc63fa35e443",
|
||||
"ed704b5cd1abf8e0dd67a6ac667a3fa5",
|
||||
"77dc70109827dc74c70fd26cba379ae5",
|
||||
"d2bf34508b07825ee934f33958f4560e",
|
||||
"a340baa7b8a93a6e658adef42e78eeb7",
|
||||
"b85c5ceaecbe9a251eac76f6932ba395",
|
||||
"246519722001f6e8e97a2183f5985e53",
|
||||
"5bce5aa0b7c6cac2ecf6406183cd779a",
|
||||
"13408f1647c02f6efd0047ad8344f695",
|
||||
"a63970f196760aa36cb965ab62f0e0fa",
|
||||
"bc26f48421dd99fd45e15e736d3e7dac",
|
||||
"4c6f70f9e3237cde918afb52d26f1823",
|
||||
"45ed610cfbc37db80c4bf0eef14ae8d6",
|
||||
"87c4c150705ea5078209ec008200539c",
|
||||
"54de21f5e0e6f2afe04daeb822b6931e",
|
||||
"9732a04e505064e19de3d542e7e71631",
|
||||
"d2bd27e95531d6957eef511c4ba64ad4",
|
||||
"7a36c9f70dcc7c3063b547101a5f6c35",
|
||||
"322007d1a44c4257bc7903b183305529",
|
||||
"dbcc9a09f412290ca2e0d53dfd142ddb",
|
||||
"df12ed43b8e53a56db20e0f83764002c",
|
||||
"d114cc11e7d5b33a360c45f18d4c7c6e",
|
||||
"c43b5e836af88620a8a71b1652cb8640",
|
||||
"9491c653e8867ed73c1b4ac6b5a9bb4d",
|
||||
"06d0e988df94ada6c6f9f36f588ab7c5",
|
||||
"561efad2480e93262c8eeaa3677615c4",
|
||||
"ba8ffc702e5adc93503045eca8702312",
|
||||
"5782be6ccdc78c8425285e85de8ccdc6",
|
||||
"aa1c4393e4c07b53ea6e2b5b1e970771",
|
||||
"42a229dc50e52271c51e8666023ebc1e",
|
||||
"53706110e919f84de7f8d6c7f0e7b831",
|
||||
"fc5ac8ee39cc1dd1424391323e2901bd",
|
||||
"bed27b62ff66cac2fbb68193c727106a",
|
||||
"cd5e689b96d0b9ea7e08dac36f7b211e",
|
||||
"0b4c7f604eba058d18e322c6e1baf173",
|
||||
"eb838227fdfad09a27f0f8413120675d",
|
||||
"3149cf9d19a7fd529e6154a8b4c3b3ad",
|
||||
"ca1e20126df930fd5fb7afe4422191e5",
|
||||
"b23398f910599f3c09b6549fa81bcb46",
|
||||
"27fb17c11b34fa5d8b5afe5ee3321ead",
|
||||
"0f665f5f04cf2d46b7fead1a1f328158",
|
||||
"8f068be73b3681f99f3b282e3c02bba5",
|
||||
"ba189bbd13808dcf4e002a4dd21660d5",
|
||||
"2732dcd1b16668ae6ab6a61595d0d62a",
|
||||
"d410ccdd059f0e02b472ec9ec54bdd3c",
|
||||
"b2eaa07b055b3a03a399971327f7e8c2",
|
||||
"2e8a225655e9f99b69c60dc8b4d8e566",
|
||||
"4eb55416c853f2152e67f8a224133cec",
|
||||
"49552403790d8de0505a8e317a443687",
|
||||
"7f2747cd41f56942752e868212c7d5ac",
|
||||
"02a28f10e193b430df7112d2d98cf759",
|
||||
"d4213404a9f1cf759017747cf5958270",
|
||||
"faa34884344f9c65e944882db8476d34",
|
||||
"ece382a8bd5018f1de5da44b72cea75b",
|
||||
"f1efa90d2547036841ecd3627fafbc36",
|
||||
"811ff8686d23a435ecbd0bdafcd27b1b",
|
||||
"b21beea9c7385f657a76558530438721",
|
||||
"9cb969da4f1b4fc5b13bf78fe366f0c4",
|
||||
"8850d16d7b614d3268ccfa009d33c7fc",
|
||||
"aa98a2b6176ea86415b9aff3268c6f6d",
|
||||
"ec3e1efa5ed195eff667e16b1af1e39e",
|
||||
"e40787dca57411d2630db2de699beb08",
|
||||
"554835890735babd06318de23d31e78a",
|
||||
"493957feecddc302ee2bb2086b6ebfd3",
|
||||
"f6069709ad5b0139163717e9ce1114ab",
|
||||
"ba5ed386098da284484b211555505a01",
|
||||
"9244c8dfad8cbb68c118fa51465b3ae4",
|
||||
"51e309a5008eb1f5185e5cc007cfb36f",
|
||||
"6ce9ff712121b4f6087955f4911eafd4",
|
||||
"59b51d8dcda031218ccdd7c760828155",
|
||||
"0012878767a3d4f1c8194458cf1f8832",
|
||||
"82900708afd5b6582dc16f008c655edd",
|
||||
"21302c7e39b5a4cdf1d6f86b4f00c9b4",
|
||||
"e894c7431591eab8d1ce0fe2aa1f01df",
|
||||
"b67e1c40ee9d988226d605621854d955",
|
||||
"6237bdafa34137cbbec6be43ea9bd22c",
|
||||
"4172a8e19b0dcb09b978bb9eff7af52b",
|
||||
"5714abb55bd4448a5a6ad09fbd872fdf",
|
||||
"7ce1700bef423e1f958a94a77a94d44a",
|
||||
"3742ec50cded528527775833453e0b26",
|
||||
"5d41b135724c7c9c689495324b162f18",
|
||||
"85c523333c6442c202e9e6e0f1185f93",
|
||||
"5c71f5222d40ff5d90e7570e71ab2d30",
|
||||
"6e18912e83d012efb4c66250ced6f0d9",
|
||||
"4add4448c2e35e0b138a0bac7b4b1775",
|
||||
"c0376c6bc5e7b8b9d2108ec25d2aab53",
|
||||
"f72261d5ed156765c977751c8a13fcc1",
|
||||
"cff4156c48614b6ceed3dd6b9058f17e",
|
||||
"36bfb513f76c15f514bcb593419835aa",
|
||||
"166bf48c6bffaf8291e6fdf63854bef4",
|
||||
"0b67d33f8b859c3157fbabd9e6e47ed0",
|
||||
"e4da659ca76c88e73a9f9f10f3d51789",
|
||||
"33c1ae2a86b3f51c0642e6ed5b5aa1f1",
|
||||
"27469b56aca2334449c1cf4970dcd969",
|
||||
"b7117b2e363378aa0901b0d6a9f6ddc0",
|
||||
"a9578233b09e5cd5231943fdb12cd90d",
|
||||
"486d7d75253598b716a068243c1c3e89",
|
||||
"66f6b02d682b78ffdc85e9ec86852489",
|
||||
"38a07b9a4b228fbcc305476e4d2e05d2",
|
||||
"aedb61c7970e7d05bf9002dae3c6858c",
|
||||
"c03ef441f7dd30fdb61ad2d4d8e4c7da",
|
||||
"7f45cc1eea9a00cb6aeb2dd748361190",
|
||||
"a59538b358459132e55160899e47bd65",
|
||||
"137010fef72364411820c3fbed15c8df",
|
||||
"d8362b93fc504500dbd33ac74e1b4d70",
|
||||
"a7e49f12c8f47e3b29cf8c0889b0a9c8",
|
||||
"072e94ffbfc684bd8ab2a1b9dade2fd5",
|
||||
"5ab438584bd2229e452052e002631a5f",
|
||||
"f233d14221097baef57d3ec205c9e086",
|
||||
"3a95db000c4a8ff98dc5c89631a7f162",
|
||||
"0544f18c2994ab4ddf1728f66041ff16",
|
||||
"0bc02116c60a3cc331928d6c9d3ba37e",
|
||||
"b189dca6cb5b813c74200834fba97f29",
|
||||
"ac8aaab075b4a5bc24419da239212650",
|
||||
"1e9f19323dc71c29ae99c479dc7e8df9",
|
||||
"12d944c3fa7caa1b3d62adfc492274dd",
|
||||
"b4c68f1fffe8f0030e9b18aad8c9dc96",
|
||||
"25887fab1422700d7fa3edc0b20206e2",
|
||||
"8c09f698d03eaf88abf69f8147865ef6",
|
||||
"5c363ae42a5bec26fbc5e996428d9bd7",
|
||||
"7fdfc2e854fbb3928150d5e3abcf56d6",
|
||||
"f0c944023f714df115f9e4f25bcdb89b",
|
||||
"6d19534b4c332741c8ddd79a9644de2d",
|
||||
"32595eb23764fbfc2ee7822649f74a12",
|
||||
"5a51391aab33c8d575019b6e76ae052a",
|
||||
"98b861ce2c620f10f913af5d704a5afd",
|
||||
"b7fe2fc8b77fb1ce434f8465c7ddf793",
|
||||
"0e8406e0cf8e9cc840668ece2a0fc64e",
|
||||
"b89922db99c58f6a128ccffe19b6ce60",
|
||||
"e1be9af665f0932b77d7f5631a511db7",
|
||||
"74b96f20f58de8dc9ff5e31f91828523",
|
||||
"36a4cfef5a2a7d8548db6710e50b3009",
|
||||
"007e95e8d3b91948a1dedb91f75de76b",
|
||||
"a87a702ce08f5745edf765bfcd5fbe0d",
|
||||
"847e69a388a749a9c507354d0dddfe09",
|
||||
"07176eefbc107a78f058f3d424ca6a54",
|
||||
"ad7e80682333b68296f6cb2b4a8e446d",
|
||||
"53c4aba43896ae422e5de5b9edbd46bf",
|
||||
"33bd6c20ca2a7ab916d6e98003c6c5f8",
|
||||
"060d088ea94aa093f9981a79df1dfcc8",
|
||||
"5617b214b9df08d4f11e58f5e76d9a56",
|
||||
"ca3a60ee85bd971e1daf9f7db059d909",
|
||||
"cd2b7754505d8c884eddf736f1ec613e",
|
||||
"f496163b252f1439e7e113ba2ecabd8e",
|
||||
"5719c7dcf9d9f756d6213354acb7d5cf",
|
||||
"6f7dd40b245c54411e7a9be83ae5701c",
|
||||
"c8994dd9fdeb077a45ea04a30358b637",
|
||||
"4b1184f1e35458c1c747817d527a252f",
|
||||
"fc7df674afeac7a3fd994183f4c67a74",
|
||||
"4f68e05ce4dcc533acf9c7c01d95711e",
|
||||
"d4ebc59e918400720035dfc88e0c486a",
|
||||
"d3105dd6fa123e543b0b3a6e0eeaea9e",
|
||||
"874196128ed443f5bdb2800ca048fcad",
|
||||
"01645f134978dc8f9cf0abc93b53780e",
|
||||
"5b8b64caa257873a0ffd47c981ef6c3f",
|
||||
"4ee208fc50ba0a6e65c5b58cec44c923",
|
||||
"53f409a52427b3b7ffabb057ca088428",
|
||||
"c1d6cd616f5341a93d921e356e5887a9",
|
||||
"e85c20fea67fa7320dc23379181183c8",
|
||||
"7912b6409489df001b7372bc94aebde7",
|
||||
"e559f761ec866a87f1f331767fafc60f",
|
||||
"20a6f5a36bc37043d977ed7708465ef8",
|
||||
"6a72f526965ab120826640dd784c6cc4",
|
||||
"bf486d92ad68e87c613689dd370d001b",
|
||||
"d339fd0eb35edf3abd6419c8d857acaf",
|
||||
"9521cd7f32306d969ddabc4e6a617f52",
|
||||
"a1cd9f3e81520842f3cf6cc301cb0021",
|
||||
"18e879b6f154492d593edd3f4554e237",
|
||||
"66e2329c1f5137589e051592587e521e",
|
||||
"e899566dd6c3e82cbc83958e69feb590",
|
||||
"8a4b41d7c47e4e80659d77b4e4bfc9ae",
|
||||
"f1944f6fcfc17803405a1101998c57dd",
|
||||
"f6bcec07567b4f72851b307139656b18",
|
||||
"22e7bb256918fe9924dce9093e2d8a27",
|
||||
"dd25b925815fe7b50b7079f5f65a3970",
|
||||
"0457f10f299acf0c230dd4007612e58f",
|
||||
"ecb420c19efd93814fae2964d69b54af",
|
||||
"14eb47b06dff685d88751c6e32789db4",
|
||||
"e8f072dbb50d1ab6654aa162604a892d",
|
||||
"69cff9c62092332f03a166c7b0034469",
|
||||
"d3619f98970b798ca32c6c14cd25af91",
|
||||
"2246d423774ee9d51a551e89c0539d9e",
|
||||
"75e5d1a1e374a04a699247dad827b6cf",
|
||||
"6d087dd1d4cd15bf47db07c7a96b1db8",
|
||||
"967e4c055ac51b4b2a3e506cebd5826f",
|
||||
"7417aa79247e473401bfa92a25b62e2a",
|
||||
"24f3f4956da34b5c533d9a551ccd7b16",
|
||||
"0c40382de693a5304e2331eb951cc962",
|
||||
"9436f949d51b347db5c8e6258dafaaac",
|
||||
"d2084297fe84c4ba6e04e4fb73d734fe",
|
||||
"42a6f8ff590af21b512e9e088257aa34",
|
||||
"c484ad06b1cdb3a54f3f6464a7a2a6fd",
|
||||
"1b8ac860f5ceb4365400a201ed2917aa",
|
||||
"c43eadabbe7b7473f3f837fc52650f54",
|
||||
"0e5d3205406126b1f838875deb150d6a",
|
||||
"6bf4946f8ec8a9c417f50cd1e67565be",
|
||||
"42f09a2522314799c95b3fc121a0e3e8",
|
||||
"06b8f1487f691a3f7c3f74e133d55870",
|
||||
"1a70a65fb4f314dcf6a31451a9d2704f",
|
||||
"7d4acdd0823279fd28a1e48b49a04669",
|
||||
"09545cc8822a5dfc93bbab708fd69174",
|
||||
"efc063db625013a83c9a426d39a9bddb",
|
||||
"213bbf89b3f5be0ffdb14854bbcb2588",
|
||||
"b69624d89fe2774df9a6f43695d755d4",
|
||||
"c0f9ff9ded82bd73c512e365a894774d",
|
||||
"d1b68507ed89c17ead6f69012982db71",
|
||||
"14cf16db04648978e35c44850855d1b0",
|
||||
"9f254d4eccab74cd91d694df863650a8",
|
||||
"8f8946e2967baa4a814d36ff01d20813",
|
||||
"6b9dc4d24ecba166cb2915d7a6cba43b",
|
||||
"eb35a80418a0042b850e294db7898d4d",
|
||||
"f55f925d280c637d54055c9df088ef5f",
|
||||
"f48427a04f67e33f3ba0a17f7c9704a7",
|
||||
"4a9f5bfcc0321aea2eced896cee65894",
|
||||
"8723a67d1a1df90f1cef96e6fe81e702",
|
||||
"c166c343ee25998f80bad4067960d3fd",
|
||||
"dab67288d16702e676a040fd42344d73",
|
||||
"c8e9e0d80841eb2c116dd14c180e006c",
|
||||
"92294f546bacf0dea9042c93ecba8b34",
|
||||
"013705b1502b37369ad22fe8237d444e",
|
||||
"9b97f8837d5f2ebab0768fc9a6446b93",
|
||||
"7e7e5236b05ec35f89edf8bf655498e7",
|
||||
"7be8f2362c174c776fb9432fe93bf259",
|
||||
"2422e80420276d2df5702c6470879b01",
|
||||
"df645795db778bcce23bbe819a76ba48",
|
||||
"3f97a4ac87dfc58761cda1782d749074",
|
||||
"50e3f45df21ebfa1b706b9c0a1c245a8",
|
||||
"7879541c7ff612c7ddf17cb8f7260183",
|
||||
"67f6542b903b7ba1945eba1a85ee6b1c",
|
||||
"b34b73d36ab6234b8d3f5494d251138e",
|
||||
"0aea139641fdba59ab1103479a96e05f",
|
||||
"02776815a87b8ba878453666d42afe3c",
|
||||
"5929ab0a90459ebac5a16e2fb37c847e",
|
||||
"c244def5b20ce0468f2b5012d04ac7fd",
|
||||
"12116add6fefce36ed8a0aeccce9b6d3",
|
||||
"3cd743841e9d8b878f34d91b793b4fad",
|
||||
"45e87510cf5705262185f46905fae35f",
|
||||
"276047016b0bfb501b2d4fc748165793",
|
||||
"ddd245df5a799417d350bd7f4e0b0b7e",
|
||||
"d34d917a54a2983f3fdbc4b14caae382",
|
||||
"7730fbc09d0c1fb1939a8fc436f6b995",
|
||||
"eb4899ef257a1711cc9270a19702e5b5",
|
||||
"8a30932014bce35bba620895d374df7a",
|
||||
"1924aabf9c50aa00bee5e1f95b5d9e12",
|
||||
"1758d6f8b982aec9fbe50f20e3082b46",
|
||||
"cd075928ab7e6883e697fe7fd3ac43ee",
|
||||
}
|
||||
|
||||
95
vendor/golang.org/x/crypto/nacl/box/example_test.go
сгенерированный
поставляемый
Обычный файл
95
vendor/golang.org/x/crypto/nacl/box/example_test.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,95 @@
|
||||
package box_test
|
||||
|
||||
import (
|
||||
crypto_rand "crypto/rand" // Custom so it's clear which rand we're using.
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/nacl/box"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
senderPublicKey, senderPrivateKey, err := box.GenerateKey(crypto_rand.Reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
recipientPublicKey, recipientPrivateKey, err := box.GenerateKey(crypto_rand.Reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// You must use a different nonce for each message you encrypt with the
|
||||
// same key. Since the nonce here is 192 bits long, a random value
|
||||
// provides a sufficiently small probability of repeats.
|
||||
var nonce [24]byte
|
||||
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
msg := []byte("Alas, poor Yorick! I knew him, Horatio")
|
||||
// This encrypts msg and appends the result to the nonce.
|
||||
encrypted := box.Seal(nonce[:], msg, &nonce, recipientPublicKey, senderPrivateKey)
|
||||
|
||||
// The recipient can decrypt the message using their private key and the
|
||||
// sender's public key. When you decrypt, you must use the same nonce you
|
||||
// used to encrypt the message. One way to achieve this is to store the
|
||||
// nonce alongside the encrypted message. Above, we stored the nonce in the
|
||||
// first 24 bytes of the encrypted text.
|
||||
var decryptNonce [24]byte
|
||||
copy(decryptNonce[:], encrypted[:24])
|
||||
decrypted, ok := box.Open(nil, encrypted[24:], &decryptNonce, senderPublicKey, recipientPrivateKey)
|
||||
if !ok {
|
||||
panic("decryption error")
|
||||
}
|
||||
fmt.Println(string(decrypted))
|
||||
// Output: Alas, poor Yorick! I knew him, Horatio
|
||||
}
|
||||
|
||||
func Example_precompute() {
|
||||
senderPublicKey, senderPrivateKey, err := box.GenerateKey(crypto_rand.Reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
recipientPublicKey, recipientPrivateKey, err := box.GenerateKey(crypto_rand.Reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// The shared key can be used to speed up processing when using the same
|
||||
// pair of keys repeatedly.
|
||||
sharedEncryptKey := new([32]byte)
|
||||
box.Precompute(sharedEncryptKey, recipientPublicKey, senderPrivateKey)
|
||||
|
||||
// You must use a different nonce for each message you encrypt with the
|
||||
// same key. Since the nonce here is 192 bits long, a random value
|
||||
// provides a sufficiently small probability of repeats.
|
||||
var nonce [24]byte
|
||||
if _, err := io.ReadFull(crypto_rand.Reader, nonce[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
msg := []byte("A fellow of infinite jest, of most excellent fancy")
|
||||
// This encrypts msg and appends the result to the nonce.
|
||||
encrypted := box.SealAfterPrecomputation(nonce[:], msg, &nonce, sharedEncryptKey)
|
||||
|
||||
// The shared key can be used to speed up processing when using the same
|
||||
// pair of keys repeatedly.
|
||||
var sharedDecryptKey [32]byte
|
||||
box.Precompute(&sharedDecryptKey, senderPublicKey, recipientPrivateKey)
|
||||
|
||||
// The recipient can decrypt the message using the shared key. When you
|
||||
// decrypt, you must use the same nonce you used to encrypt the message.
|
||||
// One way to achieve this is to store the nonce alongside the encrypted
|
||||
// message. Above, we stored the nonce in the first 24 bytes of the
|
||||
// encrypted text.
|
||||
var decryptNonce [24]byte
|
||||
copy(decryptNonce[:], encrypted[:24])
|
||||
decrypted, ok := box.OpenAfterPrecomputation(nil, encrypted[24:], &decryptNonce, &sharedDecryptKey)
|
||||
if !ok {
|
||||
panic("decryption error")
|
||||
}
|
||||
fmt.Println(string(decrypted))
|
||||
// Output: A fellow of infinite jest, of most excellent fancy
|
||||
}
|
||||
2
vendor/golang.org/x/crypto/nacl/secretbox/example_test.go
сгенерированный
поставляемый
2
vendor/golang.org/x/crypto/nacl/secretbox/example_test.go
сгенерированный
поставляемый
@@ -43,7 +43,7 @@ func Example() {
|
||||
// 24 bytes of the encrypted text.
|
||||
var decryptNonce [24]byte
|
||||
copy(decryptNonce[:], encrypted[:24])
|
||||
decrypted, ok := secretbox.Open([]byte{}, encrypted[24:], &decryptNonce, &secretKey)
|
||||
decrypted, ok := secretbox.Open(nil, encrypted[24:], &decryptNonce, &secretKey)
|
||||
if !ok {
|
||||
panic("decryption error")
|
||||
}
|
||||
|
||||
63
vendor/golang.org/x/crypto/nacl/secretbox/secretbox_test.go
сгенерированный
поставляемый
63
vendor/golang.org/x/crypto/nacl/secretbox/secretbox_test.go
сгенерированный
поставляемый
@@ -89,3 +89,66 @@ func TestAppend(t *testing.T) {
|
||||
t.Fatalf("Seal didn't correctly append with sufficient capacity.")
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkSealSize(b *testing.B, size int) {
|
||||
message := make([]byte, size)
|
||||
out := make([]byte, size+Overhead)
|
||||
var nonce [24]byte
|
||||
var key [32]byte
|
||||
|
||||
b.SetBytes(int64(size))
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
out = Seal(out[:0], message, &nonce, &key)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSeal8Bytes(b *testing.B) {
|
||||
benchmarkSealSize(b, 8)
|
||||
}
|
||||
|
||||
func BenchmarkSeal100Bytes(b *testing.B) {
|
||||
benchmarkSealSize(b, 100)
|
||||
}
|
||||
|
||||
func BenchmarkSeal1K(b *testing.B) {
|
||||
benchmarkSealSize(b, 1024)
|
||||
}
|
||||
|
||||
func BenchmarkSeal8K(b *testing.B) {
|
||||
benchmarkSealSize(b, 8192)
|
||||
}
|
||||
|
||||
func benchmarkOpenSize(b *testing.B, size int) {
|
||||
msg := make([]byte, size)
|
||||
result := make([]byte, size)
|
||||
var nonce [24]byte
|
||||
var key [32]byte
|
||||
box := Seal(nil, msg, &nonce, &key)
|
||||
|
||||
b.SetBytes(int64(size))
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, ok := Open(result[:0], box, &nonce, &key); !ok {
|
||||
panic("Open failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkOpen8Bytes(b *testing.B) {
|
||||
benchmarkOpenSize(b, 8)
|
||||
}
|
||||
|
||||
func BenchmarkOpen100Bytes(b *testing.B) {
|
||||
benchmarkOpenSize(b, 100)
|
||||
}
|
||||
|
||||
func BenchmarkOpen1K(b *testing.B) {
|
||||
benchmarkOpenSize(b, 1024)
|
||||
}
|
||||
|
||||
func BenchmarkOpen8K(b *testing.B) {
|
||||
benchmarkOpenSize(b, 8192)
|
||||
}
|
||||
|
||||
57
vendor/golang.org/x/crypto/ocsp/ocsp.go
сгенерированный
поставляемый
57
vendor/golang.org/x/crypto/ocsp/ocsp.go
сгенерированный
поставляемый
@@ -450,8 +450,8 @@ func ParseRequest(bytes []byte) (*Request, error) {
|
||||
// then the signature over the response is checked. If issuer is not nil then
|
||||
// it will be used to validate the signature or embedded certificate.
|
||||
//
|
||||
// Invalid signatures or parse failures will result in a ParseError. Error
|
||||
// responses will result in a ResponseError.
|
||||
// Invalid responses and parse failures will result in a ParseError.
|
||||
// Error responses will result in a ResponseError.
|
||||
func ParseResponse(bytes []byte, issuer *x509.Certificate) (*Response, error) {
|
||||
return ParseResponseForCert(bytes, nil, issuer)
|
||||
}
|
||||
@@ -462,8 +462,8 @@ func ParseResponse(bytes []byte, issuer *x509.Certificate) (*Response, error) {
|
||||
// issuer is not nil then it will be used to validate the signature or embedded
|
||||
// certificate.
|
||||
//
|
||||
// Invalid signatures or parse failures will result in a ParseError. Error
|
||||
// responses will result in a ResponseError.
|
||||
// Invalid responses and parse failures will result in a ParseError.
|
||||
// Error responses will result in a ResponseError.
|
||||
func ParseResponseForCert(bytes []byte, cert, issuer *x509.Certificate) (*Response, error) {
|
||||
var resp responseASN1
|
||||
rest, err := asn1.Unmarshal(bytes, &resp)
|
||||
@@ -496,10 +496,32 @@ func ParseResponseForCert(bytes []byte, cert, issuer *x509.Certificate) (*Respon
|
||||
return nil, ParseError("OCSP response contains bad number of responses")
|
||||
}
|
||||
|
||||
var singleResp singleResponse
|
||||
if cert == nil {
|
||||
singleResp = basicResp.TBSResponseData.Responses[0]
|
||||
} else {
|
||||
match := false
|
||||
for _, resp := range basicResp.TBSResponseData.Responses {
|
||||
if cert == nil || cert.SerialNumber.Cmp(resp.CertID.SerialNumber) == 0 {
|
||||
singleResp = resp
|
||||
match = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !match {
|
||||
return nil, ParseError("no response matching the supplied certificate")
|
||||
}
|
||||
}
|
||||
|
||||
ret := &Response{
|
||||
TBSResponseData: basicResp.TBSResponseData.Raw,
|
||||
Signature: basicResp.Signature.RightAlign(),
|
||||
SignatureAlgorithm: getSignatureAlgorithmFromOID(basicResp.SignatureAlgorithm.Algorithm),
|
||||
Extensions: singleResp.SingleExtensions,
|
||||
SerialNumber: singleResp.CertID.SerialNumber,
|
||||
ProducedAt: basicResp.TBSResponseData.ProducedAt,
|
||||
ThisUpdate: singleResp.ThisUpdate,
|
||||
NextUpdate: singleResp.NextUpdate,
|
||||
}
|
||||
|
||||
// Handle the ResponderID CHOICE tag. ResponderID can be flattened into
|
||||
@@ -542,25 +564,14 @@ func ParseResponseForCert(bytes []byte, cert, issuer *x509.Certificate) (*Respon
|
||||
}
|
||||
}
|
||||
|
||||
var r singleResponse
|
||||
for _, resp := range basicResp.TBSResponseData.Responses {
|
||||
if cert == nil || cert.SerialNumber.Cmp(resp.CertID.SerialNumber) == 0 {
|
||||
r = resp
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, ext := range r.SingleExtensions {
|
||||
for _, ext := range singleResp.SingleExtensions {
|
||||
if ext.Critical {
|
||||
return nil, ParseError("unsupported critical extension")
|
||||
}
|
||||
}
|
||||
ret.Extensions = r.SingleExtensions
|
||||
|
||||
ret.SerialNumber = r.CertID.SerialNumber
|
||||
|
||||
for h, oid := range hashOIDs {
|
||||
if r.CertID.HashAlgorithm.Algorithm.Equal(oid) {
|
||||
if singleResp.CertID.HashAlgorithm.Algorithm.Equal(oid) {
|
||||
ret.IssuerHash = h
|
||||
break
|
||||
}
|
||||
@@ -570,20 +581,16 @@ func ParseResponseForCert(bytes []byte, cert, issuer *x509.Certificate) (*Respon
|
||||
}
|
||||
|
||||
switch {
|
||||
case bool(r.Good):
|
||||
case bool(singleResp.Good):
|
||||
ret.Status = Good
|
||||
case bool(r.Unknown):
|
||||
case bool(singleResp.Unknown):
|
||||
ret.Status = Unknown
|
||||
default:
|
||||
ret.Status = Revoked
|
||||
ret.RevokedAt = r.Revoked.RevocationTime
|
||||
ret.RevocationReason = int(r.Revoked.Reason)
|
||||
ret.RevokedAt = singleResp.Revoked.RevocationTime
|
||||
ret.RevocationReason = int(singleResp.Revoked.Reason)
|
||||
}
|
||||
|
||||
ret.ProducedAt = basicResp.TBSResponseData.ProducedAt
|
||||
ret.ThisUpdate = r.ThisUpdate
|
||||
ret.NextUpdate = r.NextUpdate
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
15
vendor/golang.org/x/crypto/ocsp/ocsp_test.go
сгенерированный
поставляемый
15
vendor/golang.org/x/crypto/ocsp/ocsp_test.go
сгенерированный
поставляемый
@@ -343,6 +343,21 @@ func TestOCSPDecodeMultiResponse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOCSPDecodeMultiResponseWithoutMatchingCert(t *testing.T) {
|
||||
wrongCert, _ := hex.DecodeString(startComHex)
|
||||
cert, err := x509.ParseCertificate(wrongCert)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
responseBytes, _ := hex.DecodeString(ocspMultiResponseHex)
|
||||
_, err = ParseResponseForCert(responseBytes, cert, nil)
|
||||
want := ParseError("no response matching the supplied certificate")
|
||||
if err != want {
|
||||
t.Errorf("err: got %q, want %q", err, want)
|
||||
}
|
||||
}
|
||||
|
||||
// This OCSP response was taken from Thawte's public OCSP responder.
|
||||
// To recreate:
|
||||
// $ openssl s_client -tls1 -showcerts -servername www.google.com -connect www.google.com:443
|
||||
|
||||
24
vendor/golang.org/x/crypto/ssh/certs.go
сгенерированный
поставляемый
24
vendor/golang.org/x/crypto/ssh/certs.go
сгенерированный
поставляемый
@@ -298,8 +298,17 @@ func (c *CertChecker) CheckHostKey(addr string, remote net.Addr, key PublicKey)
|
||||
if cert.CertType != HostCert {
|
||||
return fmt.Errorf("ssh: certificate presented as a host key has type %d", cert.CertType)
|
||||
}
|
||||
if !c.IsHostAuthority(cert.SignatureKey, addr) {
|
||||
return fmt.Errorf("ssh: no authorities for hostname: %v", addr)
|
||||
}
|
||||
|
||||
return c.CheckCert(addr, cert)
|
||||
hostname, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Pass hostname only as principal for host certificates (consistent with OpenSSH)
|
||||
return c.CheckCert(hostname, cert)
|
||||
}
|
||||
|
||||
// Authenticate checks a user certificate. Authenticate can be used as
|
||||
@@ -316,6 +325,9 @@ func (c *CertChecker) Authenticate(conn ConnMetadata, pubKey PublicKey) (*Permis
|
||||
if cert.CertType != UserCert {
|
||||
return nil, fmt.Errorf("ssh: cert has type %d", cert.CertType)
|
||||
}
|
||||
if !c.IsUserAuthority(cert.SignatureKey) {
|
||||
return nil, fmt.Errorf("ssh: certificate signed by unrecognized authority")
|
||||
}
|
||||
|
||||
if err := c.CheckCert(conn.User(), cert); err != nil {
|
||||
return nil, err
|
||||
@@ -364,16 +376,6 @@ func (c *CertChecker) CheckCert(principal string, cert *Certificate) error {
|
||||
}
|
||||
}
|
||||
|
||||
// if this is a host cert, principal is the remote hostname as passed
|
||||
// to CheckHostCert.
|
||||
if cert.CertType == HostCert && !c.IsHostAuthority(cert.SignatureKey, principal) {
|
||||
return fmt.Errorf("ssh: no authorities for hostname: %v", principal)
|
||||
}
|
||||
|
||||
if cert.CertType == UserCert && !c.IsUserAuthority(cert.SignatureKey) {
|
||||
return fmt.Errorf("ssh: certificate signed by unrecognized authority")
|
||||
}
|
||||
|
||||
clock := c.Clock
|
||||
if clock == nil {
|
||||
clock = time.Now
|
||||
|
||||
24
vendor/golang.org/x/crypto/ssh/certs_test.go
сгенерированный
поставляемый
24
vendor/golang.org/x/crypto/ssh/certs_test.go
сгенерированный
поставляемый
@@ -168,8 +168,8 @@ func TestHostKeyCert(t *testing.T) {
|
||||
cert.SignCert(rand.Reader, testSigners["ecdsa"])
|
||||
|
||||
checker := &CertChecker{
|
||||
IsHostAuthority: func(p PublicKey, h string) bool {
|
||||
return h == "hostname" && bytes.Equal(testPublicKeys["ecdsa"].Marshal(), p.Marshal())
|
||||
IsHostAuthority: func(p PublicKey, addr string) bool {
|
||||
return addr == "hostname:22" && bytes.Equal(testPublicKeys["ecdsa"].Marshal(), p.Marshal())
|
||||
},
|
||||
}
|
||||
|
||||
@@ -178,7 +178,14 @@ func TestHostKeyCert(t *testing.T) {
|
||||
t.Errorf("NewCertSigner: %v", err)
|
||||
}
|
||||
|
||||
for _, name := range []string{"hostname", "otherhost", "lasthost"} {
|
||||
for _, test := range []struct {
|
||||
addr string
|
||||
succeed bool
|
||||
}{
|
||||
{addr: "hostname:22", succeed: true},
|
||||
{addr: "otherhost:22", succeed: false}, // The certificate is valid for 'otherhost' as hostname, but we only recognize the authority of the signer for the address 'hostname:22'
|
||||
{addr: "lasthost:22", succeed: false},
|
||||
} {
|
||||
c1, c2, err := netPipe()
|
||||
if err != nil {
|
||||
t.Fatalf("netPipe: %v", err)
|
||||
@@ -201,16 +208,15 @@ func TestHostKeyCert(t *testing.T) {
|
||||
User: "user",
|
||||
HostKeyCallback: checker.CheckHostKey,
|
||||
}
|
||||
_, _, _, err = NewClientConn(c2, name, config)
|
||||
_, _, _, err = NewClientConn(c2, test.addr, config)
|
||||
|
||||
succeed := name == "hostname"
|
||||
if (err == nil) != succeed {
|
||||
t.Fatalf("NewClientConn(%q): %v", name, err)
|
||||
if (err == nil) != test.succeed {
|
||||
t.Fatalf("NewClientConn(%q): %v", test.addr, err)
|
||||
}
|
||||
|
||||
err = <-errc
|
||||
if (err == nil) != succeed {
|
||||
t.Fatalf("NewServerConn(%q): %v", name, err)
|
||||
if (err == nil) != test.succeed {
|
||||
t.Fatalf("NewServerConn(%q): %v", test.addr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
vendor/golang.org/x/crypto/ssh/connection.go
сгенерированный
поставляемый
2
vendor/golang.org/x/crypto/ssh/connection.go
сгенерированный
поставляемый
@@ -25,7 +25,7 @@ type ConnMetadata interface {
|
||||
// User returns the user ID for this connection.
|
||||
User() string
|
||||
|
||||
// SessionID returns the sesson hash, also denoted by H.
|
||||
// SessionID returns the session hash, also denoted by H.
|
||||
SessionID() []byte
|
||||
|
||||
// ClientVersion returns the client's version string as hashed
|
||||
|
||||
11
vendor/golang.org/x/crypto/ssh/example_test.go
сгенерированный
поставляемый
11
vendor/golang.org/x/crypto/ssh/example_test.go
сгенерированный
поставляемый
@@ -56,7 +56,12 @@ func ExampleNewServerConn() {
|
||||
// Remove to disable public key auth.
|
||||
PublicKeyCallback: func(c ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
|
||||
if authorizedKeysMap[string(pubKey.Marshal())] {
|
||||
return nil, nil
|
||||
return &ssh.Permissions{
|
||||
// Record the public key used for authentication.
|
||||
Extensions: map[string]string{
|
||||
"pubkey-fp": ssh.FingerprintSHA256(pubKey),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("unknown public key for %q", c.User())
|
||||
},
|
||||
@@ -87,10 +92,12 @@ func ExampleNewServerConn() {
|
||||
|
||||
// Before use, a handshake must be performed on the incoming
|
||||
// net.Conn.
|
||||
_, chans, reqs, err := ssh.NewServerConn(nConn, config)
|
||||
conn, chans, reqs, err := ssh.NewServerConn(nConn, config)
|
||||
if err != nil {
|
||||
log.Fatal("failed to handshake: ", err)
|
||||
}
|
||||
log.Printf("logged in with key %s", conn.Permissions.Extensions["pubkey-fp"])
|
||||
|
||||
// The incoming Request channel must be serviced.
|
||||
go ssh.DiscardRequests(reqs)
|
||||
|
||||
|
||||
8
vendor/golang.org/x/crypto/ssh/kex.go
сгенерированный
поставляемый
8
vendor/golang.org/x/crypto/ssh/kex.go
сгенерированный
поставляемый
@@ -383,8 +383,8 @@ func init() {
|
||||
// 4253 and Oakley Group 2 in RFC 2409.
|
||||
p, _ := new(big.Int).SetString("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF", 16)
|
||||
kexAlgoMap[kexAlgoDH1SHA1] = &dhGroup{
|
||||
g: new(big.Int).SetInt64(2),
|
||||
p: p,
|
||||
g: new(big.Int).SetInt64(2),
|
||||
p: p,
|
||||
pMinus1: new(big.Int).Sub(p, bigOne),
|
||||
}
|
||||
|
||||
@@ -393,8 +393,8 @@ func init() {
|
||||
p, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF", 16)
|
||||
|
||||
kexAlgoMap[kexAlgoDH14SHA1] = &dhGroup{
|
||||
g: new(big.Int).SetInt64(2),
|
||||
p: p,
|
||||
g: new(big.Int).SetInt64(2),
|
||||
p: p,
|
||||
pMinus1: new(big.Int).Sub(p, bigOne),
|
||||
}
|
||||
|
||||
|
||||
43
vendor/golang.org/x/crypto/ssh/keys.go
сгенерированный
поставляемый
43
vendor/golang.org/x/crypto/ssh/keys.go
сгенерированный
поставляемый
@@ -756,6 +756,18 @@ func ParsePrivateKey(pemBytes []byte) (Signer, error) {
|
||||
return NewSignerFromKey(key)
|
||||
}
|
||||
|
||||
// ParsePrivateKeyWithPassphrase returns a Signer from a PEM encoded private
|
||||
// key and passphrase. It supports the same keys as
|
||||
// ParseRawPrivateKeyWithPassphrase.
|
||||
func ParsePrivateKeyWithPassphrase(pemBytes, passPhrase []byte) (Signer, error) {
|
||||
key, err := ParseRawPrivateKeyWithPassphrase(pemBytes, passPhrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewSignerFromKey(key)
|
||||
}
|
||||
|
||||
// encryptedBlock tells whether a private key is
|
||||
// encrypted by examining its Proc-Type header
|
||||
// for a mention of ENCRYPTED
|
||||
@@ -790,6 +802,37 @@ func ParseRawPrivateKey(pemBytes []byte) (interface{}, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func ParseRawPrivateKeyWithPassphrase(pemBytes, passPhrase []byte) (interface{}, error) {
|
||||
block, _ := pem.Decode(pemBytes)
|
||||
if block == nil {
|
||||
return nil, errors.New("ssh: no key found")
|
||||
}
|
||||
buf := block.Bytes
|
||||
|
||||
if encryptedBlock(block) {
|
||||
if x509.IsEncryptedPEMBlock(block) {
|
||||
var err error
|
||||
buf, err = x509.DecryptPEMBlock(block, passPhrase)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ssh: cannot decode encrypted private keys: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch block.Type {
|
||||
case "RSA PRIVATE KEY":
|
||||
return x509.ParsePKCS1PrivateKey(buf)
|
||||
case "EC PRIVATE KEY":
|
||||
return x509.ParseECPrivateKey(buf)
|
||||
case "DSA PRIVATE KEY":
|
||||
return ParseDSAPrivateKey(buf)
|
||||
case "OPENSSH PRIVATE KEY":
|
||||
return parseOpenSSHPrivateKey(buf)
|
||||
default:
|
||||
return nil, fmt.Errorf("ssh: unsupported key type %q", block.Type)
|
||||
}
|
||||
}
|
||||
|
||||
// ParseDSAPrivateKey returns a DSA private key from its ASN.1 DER encoding, as
|
||||
// specified by the OpenSSL DSA man page.
|
||||
func ParseDSAPrivateKey(der []byte) (*dsa.PrivateKey, error) {
|
||||
|
||||
19
vendor/golang.org/x/crypto/ssh/keys_test.go
сгенерированный
поставляемый
19
vendor/golang.org/x/crypto/ssh/keys_test.go
сгенерированный
поставляемый
@@ -148,6 +148,25 @@ func TestParseEncryptedPrivateKeysFails(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse encrypted private keys with passphrase
|
||||
func TestParseEncryptedPrivateKeysWithPassphrase(t *testing.T) {
|
||||
data := []byte("sign me")
|
||||
for _, tt := range testdata.PEMEncryptedKeys {
|
||||
s, err := ParsePrivateKeyWithPassphrase(tt.PEMBytes, []byte(tt.EncryptionKey))
|
||||
if err != nil {
|
||||
t.Fatalf("ParsePrivateKeyWithPassphrase returned error: %s", err)
|
||||
continue
|
||||
}
|
||||
sig, err := s.Sign(rand.Reader, data)
|
||||
if err != nil {
|
||||
t.Fatalf("dsa.Sign: %v", err)
|
||||
}
|
||||
if err := s.PublicKey().Verify(data, sig); err != nil {
|
||||
t.Errorf("Verify failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDSA(t *testing.T) {
|
||||
// We actually exercise the ParsePrivateKey codepath here, as opposed to
|
||||
// using the ParseRawPrivateKey+NewSignerFromKey path that testdata_test.go
|
||||
|
||||
48
vendor/golang.org/x/crypto/ssh/server.go
сгенерированный
поставляемый
48
vendor/golang.org/x/crypto/ssh/server.go
сгенерированный
поставляемый
@@ -14,23 +14,34 @@ import (
|
||||
)
|
||||
|
||||
// The Permissions type holds fine-grained permissions that are
|
||||
// specific to a user or a specific authentication method for a
|
||||
// user. Permissions, except for "source-address", must be enforced in
|
||||
// the server application layer, after successful authentication. The
|
||||
// Permissions are passed on in ServerConn so a server implementation
|
||||
// can honor them.
|
||||
// specific to a user or a specific authentication method for a user.
|
||||
// The Permissions value for a successful authentication attempt is
|
||||
// available in ServerConn, so it can be used to pass information from
|
||||
// the user-authentication phase to the application layer.
|
||||
type Permissions struct {
|
||||
// Critical options restrict default permissions. Common
|
||||
// restrictions are "source-address" and "force-command". If
|
||||
// the server cannot enforce the restriction, or does not
|
||||
// recognize it, the user should not authenticate.
|
||||
// CriticalOptions indicate restrictions to the default
|
||||
// permissions, and are typically used in conjunction with
|
||||
// user certificates. The standard for SSH certificates
|
||||
// defines "force-command" (only allow the given command to
|
||||
// execute) and "source-address" (only allow connections from
|
||||
// the given address). The SSH package currently only enforces
|
||||
// the "source-address" critical option. It is up to server
|
||||
// implementations to enforce other critical options, such as
|
||||
// "force-command", by checking them after the SSH handshake
|
||||
// is successful. In general, SSH servers should reject
|
||||
// connections that specify critical options that are unknown
|
||||
// or not supported.
|
||||
CriticalOptions map[string]string
|
||||
|
||||
// Extensions are extra functionality that the server may
|
||||
// offer on authenticated connections. Common extensions are
|
||||
// "permit-agent-forwarding", "permit-X11-forwarding". Lack of
|
||||
// support for an extension does not preclude authenticating a
|
||||
// user.
|
||||
// offer on authenticated connections. Lack of support for an
|
||||
// extension does not preclude authenticating a user. Common
|
||||
// extensions are "permit-agent-forwarding",
|
||||
// "permit-X11-forwarding". The Go SSH library currently does
|
||||
// not act on any extension, and it is up to server
|
||||
// implementations to honor them. Extensions can be used to
|
||||
// pass data from the authentication callbacks to the server
|
||||
// application layer.
|
||||
Extensions map[string]string
|
||||
}
|
||||
|
||||
@@ -55,9 +66,14 @@ type ServerConfig struct {
|
||||
// attempts to authenticate using a password.
|
||||
PasswordCallback func(conn ConnMetadata, password []byte) (*Permissions, error)
|
||||
|
||||
// PublicKeyCallback, if non-nil, is called when a client attempts public
|
||||
// key authentication. It must return true if the given public key is
|
||||
// valid for the given user. For example, see CertChecker.Authenticate.
|
||||
// PublicKeyCallback, if non-nil, is called when a client
|
||||
// offers a public key for authentication. It must return true
|
||||
// if the given public key can be used to authenticate the
|
||||
// given user. For example, see CertChecker.Authenticate. A
|
||||
// call to this function does not guarantee that the key
|
||||
// offered is in fact used to authenticate. To record any data
|
||||
// depending on the public key, store it inside a
|
||||
// Permissions.Extensions entry.
|
||||
PublicKeyCallback func(conn ConnMetadata, key PublicKey) (*Permissions, error)
|
||||
|
||||
// KeyboardInteractiveCallback, if non-nil, is called when
|
||||
|
||||
41
vendor/golang.org/x/crypto/ssh/test/cert_test.go
сгенерированный
поставляемый
41
vendor/golang.org/x/crypto/ssh/test/cert_test.go
сгенерированный
поставляемый
@@ -7,12 +7,14 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
// Test both logging in with a cert, and also that the certificate presented by an OpenSSH host can be validated correctly
|
||||
func TestCertLogin(t *testing.T) {
|
||||
s := newServer(t)
|
||||
defer s.Shutdown()
|
||||
@@ -36,13 +38,40 @@ func TestCertLogin(t *testing.T) {
|
||||
}
|
||||
|
||||
conf := &ssh.ClientConfig{
|
||||
User: username(),
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
User: username(),
|
||||
HostKeyCallback: (&ssh.CertChecker{
|
||||
IsHostAuthority: func(pk ssh.PublicKey, addr string) bool {
|
||||
return bytes.Equal(pk.Marshal(), testPublicKeys["ca"].Marshal())
|
||||
},
|
||||
}).CheckHostKey,
|
||||
}
|
||||
conf.Auth = append(conf.Auth, ssh.PublicKeys(certSigner))
|
||||
client, err := s.TryDial(conf)
|
||||
if err != nil {
|
||||
t.Fatalf("TryDial: %v", err)
|
||||
|
||||
for _, test := range []struct {
|
||||
addr string
|
||||
succeed bool
|
||||
}{
|
||||
{addr: "host.example.com:22", succeed: true},
|
||||
{addr: "host.example.com:10000", succeed: true}, // non-standard port must be OK
|
||||
{addr: "host.example.com", succeed: false}, // port must be specified
|
||||
{addr: "host.ex4mple.com:22", succeed: false}, // wrong host
|
||||
} {
|
||||
client, err := s.TryDialWithAddr(conf, test.addr)
|
||||
|
||||
// Always close client if opened successfully
|
||||
if err == nil {
|
||||
client.Close()
|
||||
}
|
||||
|
||||
// Now evaluate whether the test failed or passed
|
||||
if test.succeed {
|
||||
if err != nil {
|
||||
t.Fatalf("TryDialWithAddr: %v", err)
|
||||
}
|
||||
} else {
|
||||
if err == nil {
|
||||
t.Fatalf("TryDialWithAddr, unexpected success")
|
||||
}
|
||||
}
|
||||
}
|
||||
client.Close()
|
||||
}
|
||||
|
||||
19
vendor/golang.org/x/crypto/ssh/test/test_unix_test.go
сгенерированный
поставляемый
19
vendor/golang.org/x/crypto/ssh/test/test_unix_test.go
сгенерированный
поставляемый
@@ -30,6 +30,7 @@ Protocol 2
|
||||
HostKey {{.Dir}}/id_rsa
|
||||
HostKey {{.Dir}}/id_dsa
|
||||
HostKey {{.Dir}}/id_ecdsa
|
||||
HostCertificate {{.Dir}}/id_rsa-cert.pub
|
||||
Pidfile {{.Dir}}/sshd.pid
|
||||
#UsePrivilegeSeparation no
|
||||
KeyRegenerationInterval 3600
|
||||
@@ -119,6 +120,11 @@ func clientConfig() *ssh.ClientConfig {
|
||||
ssh.PublicKeys(testSigners["user"]),
|
||||
},
|
||||
HostKeyCallback: hostKeyDB().Check,
|
||||
HostKeyAlgorithms: []string{ // by default, don't allow certs as this affects the hostKeyDB checker
|
||||
ssh.KeyAlgoECDSA256, ssh.KeyAlgoECDSA384, ssh.KeyAlgoECDSA521,
|
||||
ssh.KeyAlgoRSA, ssh.KeyAlgoDSA,
|
||||
ssh.KeyAlgoED25519,
|
||||
},
|
||||
}
|
||||
return config
|
||||
}
|
||||
@@ -154,6 +160,12 @@ func unixConnection() (*net.UnixConn, *net.UnixConn, error) {
|
||||
}
|
||||
|
||||
func (s *server) TryDial(config *ssh.ClientConfig) (*ssh.Client, error) {
|
||||
return s.TryDialWithAddr(config, "")
|
||||
}
|
||||
|
||||
// addr is the user specified host:port. While we don't actually dial it,
|
||||
// we need to know this for host key matching
|
||||
func (s *server) TryDialWithAddr(config *ssh.ClientConfig, addr string) (*ssh.Client, error) {
|
||||
sshd, err := exec.LookPath("sshd")
|
||||
if err != nil {
|
||||
s.t.Skipf("skipping test: %v", err)
|
||||
@@ -179,7 +191,7 @@ func (s *server) TryDial(config *ssh.ClientConfig) (*ssh.Client, error) {
|
||||
s.t.Fatalf("s.cmd.Start: %v", err)
|
||||
}
|
||||
s.clientConn = c1
|
||||
conn, chans, reqs, err := ssh.NewClientConn(c1, "", config)
|
||||
conn, chans, reqs, err := ssh.NewClientConn(c1, addr, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -250,6 +262,11 @@ func newServer(t *testing.T) *server {
|
||||
writeFile(filepath.Join(dir, filename+".pub"), ssh.MarshalAuthorizedKey(testPublicKeys[k]))
|
||||
}
|
||||
|
||||
for k, v := range testdata.SSHCertificates {
|
||||
filename := "id_" + k + "-cert.pub"
|
||||
writeFile(filepath.Join(dir, filename), v)
|
||||
}
|
||||
|
||||
var authkeys bytes.Buffer
|
||||
for k, _ := range testdata.PEMBytes {
|
||||
authkeys.Write(ssh.MarshalAuthorizedKey(testPublicKeys[k]))
|
||||
|
||||
41
vendor/golang.org/x/crypto/ssh/testdata/keys.go
сгенерированный
поставляемый
41
vendor/golang.org/x/crypto/ssh/testdata/keys.go
сгенерированный
поставляемый
@@ -69,6 +69,47 @@ MHcCAQEEILYCAeq8f7V4vSSypRw7pxy8yz3V5W4qg8kSC3zJhqpQoAoGCCqGSM49
|
||||
AwEHoUQDQgAEYcO2xNKiRUYOLEHM7VYAp57HNyKbOdYtHD83Z4hzNPVC4tM5mdGD
|
||||
PLL8IEwvYu2wq+lpXfGQnNMbzYf9gspG0w==
|
||||
-----END EC PRIVATE KEY-----
|
||||
`),
|
||||
"ca": []byte(`-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEAvg9dQ9IRG59lYJb+GESfKWTch4yBpr7Ydw1jkK6vvtrx9jLo
|
||||
5hkA8X6+ElRPRqTAZSlN5cBm6YCAcQIOsmXDUn6Oj1lVPQAoOjTBTvsjM3NjGhvv
|
||||
52kHTY0nsMsBeY9q5DTtlzmlYkVUq2a6Htgf2mNi01dIw5fJ7uTTo8EbNf7O0i3u
|
||||
c9a8P19HaZl5NKiWN4EIZkfB2WdXYRJCVBsGgQj3dE/GrEmH9QINq1A+GkNvK96u
|
||||
vZm8H1jjmuqzHplWa7lFeXcx8FTVTbVb/iJrZ2Lc/JvIPitKZWhqbR59yrGjpwEp
|
||||
Id7bo4WhO5L3OB0fSIJYvfu+o4WYnt4f3UzecwIDAQABAoIBABRD9yHgKErVuC2Q
|
||||
bA+SYZY8VvdtF/X7q4EmQFORDNRA7EPgMc03JU6awRGbQ8i4kHs46EFzPoXvWcKz
|
||||
AXYsO6N0Myc900Tp22A5d9NAHATEbPC/wdje7hRq1KyZONMJY9BphFv3nZbY5apR
|
||||
Dc90JBFZP5RhXjTc3n9GjvqLAKfFEKVmPRCvqxCOZunw6XR+SgIQLJo36nsIsbhW
|
||||
QUXIVaCI6cXMN8bRPm8EITdBNZu06Fpu4ZHm6VaxlXN9smERCDkgBSNXNWHKxmmA
|
||||
c3Glo2DByUr2/JFBOrLEe9fkYgr24KNCQkHVcSaFxEcZvTggr7StjKISVHlCNEaB
|
||||
7Q+kPoECgYEA3zE9FmvFGoQCU4g4Nl3dpQHs6kaAW8vJlrmq3xsireIuaJoa2HMe
|
||||
wYdIvgCnK9DIjyxd5OWnE4jXtAEYPsyGD32B5rSLQrRO96lgb3f4bESCLUb3Bsn/
|
||||
sdgeE3p1xZMA0B59htqCrvVgN9k8WxyevBxYl3/gSBm/p8OVH1RTW/ECgYEA2f9Z
|
||||
95OLj0KQHQtxQXf+I3VjhCw3LkLW39QZOXVI0QrCJfqqP7uxsJXH9NYX0l0GFTcR
|
||||
kRrlyoaSU1EGQosZh+n1MvplGBTkTSV47/bPsTzFpgK2NfEZuFm9RoWgltS+nYeH
|
||||
Y2k4mnAN3PhReCMwuprmJz8GRLsO3Cs2s2YylKMCgYEA2UX+uO/q7jgqZ5UJW+ue
|
||||
1H5+W0aMuFA3i7JtZEnvRaUVFqFGlwXin/WJ2+WY1++k/rPrJ+Rk9IBXtBUIvEGw
|
||||
FC5TIfsKQsJyyWgqx/jbbtJ2g4s8+W/1qfTAuqeRNOg5d2DnRDs90wJuS4//0JaY
|
||||
9HkHyVwkQyxFxhSA/AHEMJECgYA2MvyFR1O9bIk0D3I7GsA+xKLXa77Ua53MzIjw
|
||||
9i4CezBGDQpjCiFli/fI8am+jY5DnAtsDknvjoG24UAzLy5L0mk6IXMdB6SzYYut
|
||||
7ak5oahqW+Y9hxIj+XvLmtGQbphtxhJtLu35x75KoBpxSh6FZpmuTEccs31AVCYn
|
||||
eFM/DQKBgQDOPUwbLKqVi6ddFGgrV9MrWw+SWsDa43bPuyvYppMM3oqesvyaX1Dt
|
||||
qDvN7owaNxNM4OnfKcZr91z8YPVCFo4RbBif3DXRzjNNBlxEjHBtuMOikwvsmucN
|
||||
vIrbeEpjTiUMTEAr6PoTiVHjsfS8WAM6MDlF5M+2PNswDsBpa2yLgA==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`),
|
||||
}
|
||||
|
||||
var SSHCertificates = map[string][]byte{
|
||||
// The following are corresponding certificates for the private keys above, signed by the CA key
|
||||
// Generated by the following commands:
|
||||
//
|
||||
// 1. Assumes "rsa" key above in file named "rsa", write out the public key to "rsa.pub":
|
||||
// ssh-keygen -y -f rsa > rsa.pu
|
||||
//
|
||||
// 2. Assumes "ca" key above in file named "ca", sign a cert for "rsa.pub":
|
||||
// ssh-keygen -s ca -h -n host.example.com -V +500w -I host.example.com-key rsa.pub
|
||||
"rsa": []byte(`ssh-rsa-cert-v01@openssh.com AAAAHHNzaC1yc2EtY2VydC12MDFAb3BlbnNzaC5jb20AAAAgLjYqmmuTSEmjVhSfLQphBSTJMLwIZhRgmpn8FHKLiEIAAAADAQABAAAAgQC8A6FGHDiWCSREAXCq6yBfNVr0xCVG2CzvktFNRpue+RXrGs/2a6ySEJQb3IYquw7HlJgu6fg3WIWhOmHCjfpG0PrL4CRwbqQ2LaPPXhJErWYejcD8Di00cF3677+G10KMZk9RXbmHtuBFZT98wxg8j+ZsBMqGM1+7yrWUvynswQAAAAAAAAAAAAAAAgAAABRob3N0LmV4YW1wbGUuY29tLWtleQAAABQAAAAQaG9zdC5leGFtcGxlLmNvbQAAAABZHN8UAAAAAGsjIYUAAAAAAAAAAAAAAAAAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQC+D11D0hEbn2Vglv4YRJ8pZNyHjIGmvth3DWOQrq++2vH2MujmGQDxfr4SVE9GpMBlKU3lwGbpgIBxAg6yZcNSfo6PWVU9ACg6NMFO+yMzc2MaG+/naQdNjSewywF5j2rkNO2XOaViRVSrZroe2B/aY2LTV0jDl8nu5NOjwRs1/s7SLe5z1rw/X0dpmXk0qJY3gQhmR8HZZ1dhEkJUGwaBCPd0T8asSYf1Ag2rUD4aQ28r3q69mbwfWOOa6rMemVZruUV5dzHwVNVNtVv+ImtnYtz8m8g+K0plaGptHn3KsaOnASkh3tujhaE7kvc4HR9Igli9+76jhZie3h/dTN5zAAABDwAAAAdzc2gtcnNhAAABALeDea+60H6xJGhktAyosHaSY7AYzLocaqd8hJQjEIDifBwzoTlnBmcK9CxGhKuaoJFThdCLdaevCeOSuquh8HTkf+2ebZZc/G5T+2thPvPqmcuEcmMosWo+SIjYhbP3S6KD49aLC1X0kz8IBQeauFvURhkZ5ZjhA1L4aQYt9NjL73nqOl8PplRui+Ov5w8b4ldul4zOvYAFrzfcP6wnnXk3c1Zzwwf5wynD5jakO8GpYKBuhM7Z4crzkKSQjU3hla7xqgfomC5Gz4XbR2TNjcQiRrJQ0UlKtX3X3ObRCEhuvG0Kzjklhv+Ddw6txrhKjMjiSi/Yyius/AE8TmC1p4U= host.example.com
|
||||
`),
|
||||
}
|
||||
|
||||
|
||||
39
vendor/golang.org/x/crypto/xts/xts.go
сгенерированный
поставляемый
39
vendor/golang.org/x/crypto/xts/xts.go
сгенерированный
поставляемый
@@ -23,6 +23,7 @@ package xts // import "golang.org/x/crypto/xts"
|
||||
|
||||
import (
|
||||
"crypto/cipher"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
)
|
||||
|
||||
@@ -65,21 +66,20 @@ func (c *Cipher) Encrypt(ciphertext, plaintext []byte, sectorNum uint64) {
|
||||
}
|
||||
|
||||
var tweak [blockSize]byte
|
||||
for i := 0; i < 8; i++ {
|
||||
tweak[i] = byte(sectorNum)
|
||||
sectorNum >>= 8
|
||||
}
|
||||
binary.LittleEndian.PutUint64(tweak[:8], sectorNum)
|
||||
|
||||
c.k2.Encrypt(tweak[:], tweak[:])
|
||||
|
||||
for i := 0; i < len(plaintext); i += blockSize {
|
||||
for j := 0; j < blockSize; j++ {
|
||||
ciphertext[i+j] = plaintext[i+j] ^ tweak[j]
|
||||
for len(plaintext) > 0 {
|
||||
for j := range tweak {
|
||||
ciphertext[j] = plaintext[j] ^ tweak[j]
|
||||
}
|
||||
c.k1.Encrypt(ciphertext[i:], ciphertext[i:])
|
||||
for j := 0; j < blockSize; j++ {
|
||||
ciphertext[i+j] ^= tweak[j]
|
||||
c.k1.Encrypt(ciphertext, ciphertext)
|
||||
for j := range tweak {
|
||||
ciphertext[j] ^= tweak[j]
|
||||
}
|
||||
plaintext = plaintext[blockSize:]
|
||||
ciphertext = ciphertext[blockSize:]
|
||||
|
||||
mul2(&tweak)
|
||||
}
|
||||
@@ -97,21 +97,20 @@ func (c *Cipher) Decrypt(plaintext, ciphertext []byte, sectorNum uint64) {
|
||||
}
|
||||
|
||||
var tweak [blockSize]byte
|
||||
for i := 0; i < 8; i++ {
|
||||
tweak[i] = byte(sectorNum)
|
||||
sectorNum >>= 8
|
||||
}
|
||||
binary.LittleEndian.PutUint64(tweak[:8], sectorNum)
|
||||
|
||||
c.k2.Encrypt(tweak[:], tweak[:])
|
||||
|
||||
for i := 0; i < len(plaintext); i += blockSize {
|
||||
for j := 0; j < blockSize; j++ {
|
||||
plaintext[i+j] = ciphertext[i+j] ^ tweak[j]
|
||||
for len(ciphertext) > 0 {
|
||||
for j := range tweak {
|
||||
plaintext[j] = ciphertext[j] ^ tweak[j]
|
||||
}
|
||||
c.k1.Decrypt(plaintext[i:], plaintext[i:])
|
||||
for j := 0; j < blockSize; j++ {
|
||||
plaintext[i+j] ^= tweak[j]
|
||||
c.k1.Decrypt(plaintext, plaintext)
|
||||
for j := range tweak {
|
||||
plaintext[j] ^= tweak[j]
|
||||
}
|
||||
plaintext = plaintext[blockSize:]
|
||||
ciphertext = ciphertext[blockSize:]
|
||||
|
||||
mul2(&tweak)
|
||||
}
|
||||
|
||||
20
vendor/golang.org/x/crypto/xts/xts_test.go
сгенерированный
поставляемый
20
vendor/golang.org/x/crypto/xts/xts_test.go
сгенерированный
поставляемый
@@ -83,3 +83,23 @@ func TestXTS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestShorterCiphertext(t *testing.T) {
|
||||
// Decrypt used to panic if the input was shorter than the output. See
|
||||
// https://go-review.googlesource.com/c/39954/
|
||||
c, err := NewCipher(aes.NewCipher, make([]byte, 32))
|
||||
if err != nil {
|
||||
t.Fatalf("NewCipher failed: %s", err)
|
||||
}
|
||||
|
||||
plaintext := make([]byte, 32)
|
||||
encrypted := make([]byte, 48)
|
||||
decrypted := make([]byte, 48)
|
||||
|
||||
c.Encrypt(encrypted, plaintext, 0)
|
||||
c.Decrypt(decrypted, encrypted[:len(plaintext)], 0)
|
||||
|
||||
if !bytes.Equal(plaintext, decrypted[:len(plaintext)]) {
|
||||
t.Errorf("En/Decryption is not inverse")
|
||||
}
|
||||
}
|
||||
|
||||
41
vendor/golang.org/x/image/font/sfnt/postscript.go
сгенерированный
поставляемый
41
vendor/golang.org/x/image/font/sfnt/postscript.go
сгенерированный
поставляемый
@@ -969,7 +969,8 @@ var psOperators = [...][2][]psOperator{
|
||||
31: {-1, "hvcurveto", t2CHvcurveto},
|
||||
}, {
|
||||
// 2-byte operators. The first byte is the escape byte.
|
||||
0: {}, // Reserved.
|
||||
34: {+7, "hflex", t2CHflex},
|
||||
36: {+9, "hflex1", t2CHflex1},
|
||||
// TODO: more operators.
|
||||
}},
|
||||
}
|
||||
@@ -1271,6 +1272,44 @@ func t2CRrcurveto(p *psInterpreter) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// For the flex operators, we ignore the flex depth and always produce cubic
|
||||
// segments, not linear segments. It's not obvious why the Type 2 Charstring
|
||||
// format cares about switching behavior based on a metric in pixels, not in
|
||||
// ideal font units. The Go vector rasterizer has no problems with almost
|
||||
// linear cubic segments.
|
||||
|
||||
func t2CHflex(p *psInterpreter) error {
|
||||
p.type2Charstrings.cubeTo(
|
||||
p.argStack.a[0], 0,
|
||||
p.argStack.a[1], +p.argStack.a[2],
|
||||
p.argStack.a[3], 0,
|
||||
)
|
||||
p.type2Charstrings.cubeTo(
|
||||
p.argStack.a[4], 0,
|
||||
p.argStack.a[5], -p.argStack.a[2],
|
||||
p.argStack.a[6], 0,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
func t2CHflex1(p *psInterpreter) error {
|
||||
dy1 := p.argStack.a[1]
|
||||
dy2 := p.argStack.a[3]
|
||||
dy5 := p.argStack.a[7]
|
||||
dy6 := -dy1 - dy2 - dy5
|
||||
p.type2Charstrings.cubeTo(
|
||||
p.argStack.a[0], dy1,
|
||||
p.argStack.a[2], dy2,
|
||||
p.argStack.a[4], 0,
|
||||
)
|
||||
p.type2Charstrings.cubeTo(
|
||||
p.argStack.a[5], 0,
|
||||
p.argStack.a[6], dy5,
|
||||
p.argStack.a[8], dy6,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
// subrBias returns the subroutine index bias as per 5177.Type2.pdf section 4.7
|
||||
// "Subroutine Operators".
|
||||
func subrBias(numSubroutines int) int32 {
|
||||
|
||||
125
vendor/golang.org/x/image/font/sfnt/proprietary_test.go
сгенерированный
поставляемый
125
vendor/golang.org/x/image/font/sfnt/proprietary_test.go
сгенерированный
поставляемый
@@ -23,15 +23,14 @@ go test golang.org/x/image/font/sfnt -args -proprietary \
|
||||
-adobeDir=$HOME/fonts/adobe \
|
||||
-appleDir=$HOME/fonts/apple \
|
||||
-dejavuDir=$HOME/fonts/dejavu \
|
||||
-microsoftDir=$HOME/fonts/microsoft
|
||||
-microsoftDir=$HOME/fonts/microsoft \
|
||||
-notoDir=$HOME/fonts/noto
|
||||
|
||||
To only run those tests for the Microsoft fonts:
|
||||
|
||||
go test golang.org/x/image/font/sfnt -test.run=ProprietaryMicrosoft -args -proprietary etc
|
||||
*/
|
||||
|
||||
// TODO: add Google fonts (Droid? Noto?)? Emoji fonts?
|
||||
|
||||
// TODO: enable Apple/Microsoft tests by default on Darwin/Windows?
|
||||
|
||||
import (
|
||||
@@ -88,26 +87,41 @@ var (
|
||||
"/usr/share/fonts/truetype/msttcorefonts",
|
||||
"directory name for the Microsoft proprietary fonts",
|
||||
)
|
||||
|
||||
notoDir = flag.String(
|
||||
"notoDir",
|
||||
// Get the fonts from https://www.google.com/get/noto/
|
||||
"",
|
||||
"directory name for the Noto proprietary fonts",
|
||||
)
|
||||
)
|
||||
|
||||
func TestProprietaryAdobeSourceCodeProOTF(t *testing.T) {
|
||||
func TestProprietaryAdobeSourceCodeProRegularOTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceCodePro-Regular.otf", 1500, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAdobeSourceCodeProTTF(t *testing.T) {
|
||||
func TestProprietaryAdobeSourceCodeProRegularTTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceCodePro-Regular.ttf", 1500, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAdobeSourceHanSansSC(t *testing.T) {
|
||||
func TestProprietaryAdobeSourceHanSansSCRegularOTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceHanSansSC-Regular.otf", 65535, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAdobeSourceSansProOTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceSansPro-Regular.otf", 1800, -1)
|
||||
func TestProprietaryAdobeSourceSansProBlackOTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceSansPro-Black.otf", 1900, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAdobeSourceSansProTTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceSansPro-Regular.ttf", 1800, -1)
|
||||
func TestProprietaryAdobeSourceSansProBlackTTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceSansPro-Black.ttf", 1900, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAdobeSourceSansProRegularOTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceSansPro-Regular.otf", 1900, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAdobeSourceSansProRegularTTF(t *testing.T) {
|
||||
testProprietary(t, "adobe", "SourceSansPro-Regular.ttf", 1900, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryAppleAppleSymbols(t *testing.T) {
|
||||
@@ -186,6 +200,14 @@ func TestProprietaryMicrosoftWebdings(t *testing.T) {
|
||||
testProprietary(t, "microsoft", "Webdings.ttf", 200, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryNotoColorEmoji(t *testing.T) {
|
||||
testProprietary(t, "noto", "NotoColorEmoji.ttf", 2300, -1)
|
||||
}
|
||||
|
||||
func TestProprietaryNotoSansRegular(t *testing.T) {
|
||||
testProprietary(t, "noto", "NotoSans-Regular.ttf", 2400, -1)
|
||||
}
|
||||
|
||||
// testProprietary tests that we can load every glyph in the named font.
|
||||
//
|
||||
// The exact number of glyphs in the font can differ across its various
|
||||
@@ -219,6 +241,8 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi
|
||||
dir = *dejavuDir
|
||||
case "microsoft":
|
||||
dir = *microsoftDir
|
||||
case "noto":
|
||||
dir = *notoDir
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -287,7 +311,7 @@ func testProprietary(t *testing.T, proprietor, filename string, minNumGlyphs, fi
|
||||
iMax = firstUnsupportedGlyph
|
||||
}
|
||||
for i, numErrors := 0, 0; i < iMax; i++ {
|
||||
if _, err := f.LoadGlyph(&buf, GlyphIndex(i), ppem, nil); err != nil {
|
||||
if _, err := f.LoadGlyph(&buf, GlyphIndex(i), ppem, nil); err != nil && err != ErrColoredGlyph {
|
||||
t.Errorf("LoadGlyph(%d): %v", i, err)
|
||||
numErrors++
|
||||
}
|
||||
@@ -385,6 +409,8 @@ var proprietaryVersions = map[string]string{
|
||||
"adobe/SourceCodePro-Regular.otf": "Version 2.030;PS 1.0;hotconv 16.6.51;makeotf.lib2.5.65220",
|
||||
"adobe/SourceCodePro-Regular.ttf": "Version 2.030;PS 1.000;hotconv 16.6.51;makeotf.lib2.5.65220",
|
||||
"adobe/SourceHanSansSC-Regular.otf": "Version 1.004;PS 1.004;hotconv 1.0.82;makeotf.lib2.5.63406",
|
||||
"adobe/SourceSansPro-Black.otf": "Version 2.020;PS 2.0;hotconv 1.0.86;makeotf.lib2.5.63406",
|
||||
"adobe/SourceSansPro-Black.ttf": "Version 2.020;PS 2.000;hotconv 1.0.86;makeotf.lib2.5.63406",
|
||||
"adobe/SourceSansPro-Regular.otf": "Version 2.020;PS 2.0;hotconv 1.0.86;makeotf.lib2.5.63406",
|
||||
"adobe/SourceSansPro-Regular.ttf": "Version 2.020;PS 2.000;hotconv 1.0.86;makeotf.lib2.5.63406",
|
||||
|
||||
@@ -409,6 +435,9 @@ var proprietaryVersions = map[string]string{
|
||||
"microsoft/Comic_Sans_MS.ttf": "Version 2.10",
|
||||
"microsoft/Times_New_Roman.ttf": "Version 2.82",
|
||||
"microsoft/Webdings.ttf": "Version 1.03",
|
||||
|
||||
"noto/NotoColorEmoji.ttf": "Version 1.33",
|
||||
"noto/NotoSans-Regular.ttf": "Version 1.06",
|
||||
}
|
||||
|
||||
// proprietaryFullNames holds the expected full name of each proprietary font
|
||||
@@ -417,6 +446,8 @@ var proprietaryFullNames = map[string]string{
|
||||
"adobe/SourceCodePro-Regular.otf": "Source Code Pro",
|
||||
"adobe/SourceCodePro-Regular.ttf": "Source Code Pro",
|
||||
"adobe/SourceHanSansSC-Regular.otf": "Source Han Sans SC Regular",
|
||||
"adobe/SourceSansPro-Black.otf": "Source Sans Pro Black",
|
||||
"adobe/SourceSansPro-Black.ttf": "Source Sans Pro Black",
|
||||
"adobe/SourceSansPro-Regular.otf": "Source Sans Pro",
|
||||
"adobe/SourceSansPro-Regular.ttf": "Source Sans Pro",
|
||||
|
||||
@@ -441,6 +472,9 @@ var proprietaryFullNames = map[string]string{
|
||||
"microsoft/Comic_Sans_MS.ttf": "Comic Sans MS",
|
||||
"microsoft/Times_New_Roman.ttf": "Times New Roman",
|
||||
"microsoft/Webdings.ttf": "Webdings",
|
||||
|
||||
"noto/NotoColorEmoji.ttf": "Noto Color Emoji",
|
||||
"noto/NotoSans-Regular.ttf": "Noto Sans",
|
||||
}
|
||||
|
||||
// proprietaryGlyphIndexTestCases hold a sample of each font's rune to glyph
|
||||
@@ -617,6 +651,54 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{
|
||||
},
|
||||
},
|
||||
|
||||
"adobe/SourceSansPro-Black.otf": {
|
||||
'¤': { // U+00A4 CURRENCY SIGN
|
||||
// -45 147 99 168 98 hstem
|
||||
// 44 152 148 152 vstem
|
||||
// 102 76 rmoveto
|
||||
moveTo(102, 76),
|
||||
// 71 71 rlineto
|
||||
lineTo(173, 147),
|
||||
// 31 -13 33 -6 33 32 34 6 31 hflex1
|
||||
cubeTo(204, 134, 237, 128, 270, 128),
|
||||
cubeTo(302, 128, 336, 134, 367, 147),
|
||||
// 71 -71 85 85 -61 60 rlineto
|
||||
lineTo(438, 76),
|
||||
lineTo(523, 161),
|
||||
lineTo(462, 221),
|
||||
// 21 30 13 36 43 vvcurveto
|
||||
cubeTo(483, 251, 496, 287, 496, 330),
|
||||
// 42 -12 36 -21 29 vhcurveto
|
||||
cubeTo(496, 372, 484, 408, 463, 437),
|
||||
// 60 60 -85 85 -70 -70 rlineto
|
||||
lineTo(523, 497),
|
||||
lineTo(438, 582),
|
||||
lineTo(368, 512),
|
||||
// -31 13 -34 7 -33 -33 -34 -7 -31 hflex1
|
||||
cubeTo(337, 525, 303, 532, 270, 532),
|
||||
cubeTo(237, 532, 203, 525, 172, 512),
|
||||
// -70 70 -85 -85 59 -60 rlineto
|
||||
lineTo(102, 582),
|
||||
lineTo(17, 497),
|
||||
lineTo(76, 437),
|
||||
// -20 -29 -12 -36 -42 vvcurveto
|
||||
cubeTo(56, 408, 44, 372, 44, 330),
|
||||
// -43 12 -36 21 -30 vhcurveto
|
||||
cubeTo(44, 287, 56, 251, 77, 221),
|
||||
// -60 -60 rlineto
|
||||
lineTo(17, 161),
|
||||
// 253 85 rmoveto
|
||||
lineTo(102, 76),
|
||||
moveTo(270, 246),
|
||||
// -42 -32 32 52 52 32 32 42 42 32 -32 -52 -52 -32 -32 -42 hvcurveto
|
||||
cubeTo(228, 246, 196, 278, 196, 330),
|
||||
cubeTo(196, 382, 228, 414, 270, 414),
|
||||
cubeTo(312, 414, 344, 382, 344, 330),
|
||||
cubeTo(344, 278, 312, 246, 270, 246),
|
||||
// endchar
|
||||
},
|
||||
},
|
||||
|
||||
"adobe/SourceSansPro-Regular.otf": {
|
||||
',': {
|
||||
// -309 -1 115 hstem
|
||||
@@ -1152,6 +1234,27 @@ var proprietaryGlyphTestCases = map[string]map[rune][]Segment{
|
||||
transform(-1<<14, 0, 0, +1<<14, 653, 0, quadTo(482, -217, 560, -384)),
|
||||
},
|
||||
},
|
||||
|
||||
"noto/NotoSans-Regular.ttf": {
|
||||
'i': {
|
||||
// - contour #0
|
||||
moveTo(354, 0),
|
||||
lineTo(174, 0),
|
||||
lineTo(174, 1098),
|
||||
lineTo(354, 1098),
|
||||
lineTo(354, 0),
|
||||
// - contour #1
|
||||
moveTo(160, 1395),
|
||||
quadTo(160, 1455, 190, 1482),
|
||||
quadTo(221, 1509, 266, 1509),
|
||||
quadTo(308, 1509, 339, 1482),
|
||||
quadTo(371, 1455, 371, 1395),
|
||||
quadTo(371, 1336, 339, 1308),
|
||||
quadTo(308, 1280, 266, 1280),
|
||||
quadTo(221, 1280, 190, 1308),
|
||||
quadTo(160, 1336, 160, 1395),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
type kernTestCase struct {
|
||||
|
||||
50
vendor/golang.org/x/image/font/sfnt/sfnt.go
сгенерированный
поставляемый
50
vendor/golang.org/x/image/font/sfnt/sfnt.go
сгенерированный
поставляемый
@@ -64,6 +64,9 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrColoredGlyph indicates that the requested glyph is not a monochrome
|
||||
// vector glyph, such as a colored (bitmap or vector) emoji glyph.
|
||||
ErrColoredGlyph = errors.New("sfnt: colored glyph")
|
||||
// ErrNotFound indicates that the requested value was not found.
|
||||
ErrNotFound = errors.New("sfnt: not found")
|
||||
|
||||
@@ -543,6 +546,12 @@ type Font struct {
|
||||
// TODO: cff2, vorg?
|
||||
cff table
|
||||
|
||||
// https://www.microsoft.com/typography/otspec/otff.htm#otttables
|
||||
// "Tables Related to Bitmap Glyphs".
|
||||
//
|
||||
// TODO: Others?
|
||||
cblc table
|
||||
|
||||
// https://www.microsoft.com/typography/otspec/otff.htm#otttables
|
||||
// "Advanced Typographic Tables".
|
||||
//
|
||||
@@ -559,6 +568,7 @@ type Font struct {
|
||||
glyphIndex glyphIndexFunc
|
||||
bounds [4]int16
|
||||
indexToLocFormat bool // false means short, true means long.
|
||||
isColorBitmap bool
|
||||
isPostScript bool
|
||||
kernNumPairs int32
|
||||
kernOffset int32
|
||||
@@ -599,7 +609,7 @@ func (f *Font) initialize(offset int, isDfont bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf, glyphData, err := f.parseGlyphData(buf, numGlyphs, indexToLocFormat, isPostScript)
|
||||
buf, glyphData, isColorBitmap, err := f.parseGlyphData(buf, numGlyphs, indexToLocFormat, isPostScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -628,6 +638,7 @@ func (f *Font) initialize(offset int, isDfont bool) error {
|
||||
f.cached.glyphIndex = glyphIndex
|
||||
f.cached.bounds = bounds
|
||||
f.cached.indexToLocFormat = indexToLocFormat
|
||||
f.cached.isColorBitmap = isColorBitmap
|
||||
f.cached.isPostScript = isPostScript
|
||||
f.cached.kernNumPairs = kernNumPairs
|
||||
f.cached.kernOffset = kernOffset
|
||||
@@ -701,6 +712,8 @@ func (f *Font) initializeTables(offset int, isDfont bool) (buf1 []byte, isPostSc
|
||||
|
||||
// Match the 4-byte tag as a uint32. For example, "OS/2" is 0x4f532f32.
|
||||
switch tag {
|
||||
case 0x43424c43:
|
||||
f.cblc = table{o, n}
|
||||
case 0x43464620:
|
||||
f.cff = table{o, n}
|
||||
case 0x4f532f32:
|
||||
@@ -983,7 +996,7 @@ type glyphData struct {
|
||||
fdSelect fdSelect
|
||||
}
|
||||
|
||||
func (f *Font) parseGlyphData(buf []byte, numGlyphs int32, indexToLocFormat, isPostScript bool) (buf1 []byte, ret glyphData, err error) {
|
||||
func (f *Font) parseGlyphData(buf []byte, numGlyphs int32, indexToLocFormat, isPostScript bool) (buf1 []byte, ret glyphData, isColorBitmap bool, err error) {
|
||||
if isPostScript {
|
||||
p := cffParser{
|
||||
src: &f.src,
|
||||
@@ -993,19 +1006,25 @@ func (f *Font) parseGlyphData(buf []byte, numGlyphs int32, indexToLocFormat, isP
|
||||
}
|
||||
ret, err = p.parse(numGlyphs)
|
||||
if err != nil {
|
||||
return nil, glyphData{}, err
|
||||
return nil, glyphData{}, false, err
|
||||
}
|
||||
} else {
|
||||
} else if f.loca.length != 0 {
|
||||
ret.locations, err = parseLoca(&f.src, f.loca, f.glyf.offset, indexToLocFormat, numGlyphs)
|
||||
if err != nil {
|
||||
return nil, glyphData{}, err
|
||||
return nil, glyphData{}, false, err
|
||||
}
|
||||
}
|
||||
if len(ret.locations) != int(numGlyphs+1) {
|
||||
return nil, glyphData{}, errInvalidLocationData
|
||||
} else if f.cblc.length != 0 {
|
||||
isColorBitmap = true
|
||||
// TODO: parse the CBLC (and CBDT) tables. For now, we return a font
|
||||
// with empty glyphs.
|
||||
ret.locations = make([]uint32, numGlyphs+1)
|
||||
}
|
||||
|
||||
return buf, ret, nil
|
||||
if len(ret.locations) != int(numGlyphs+1) {
|
||||
return nil, glyphData{}, false, errInvalidLocationData
|
||||
}
|
||||
|
||||
return buf, ret, isColorBitmap, nil
|
||||
}
|
||||
|
||||
func (f *Font) parsePost(buf []byte, numGlyphs int32) (buf1 []byte, postTableVersion uint32, err error) {
|
||||
@@ -1105,13 +1124,18 @@ type LoadGlyphOptions struct {
|
||||
//
|
||||
// In the returned Segments' (x, y) coordinates, the Y axis increases down.
|
||||
//
|
||||
// It returns ErrNotFound if the glyph index is out of range.
|
||||
// It returns ErrNotFound if the glyph index is out of range. It returns
|
||||
// ErrColoredGlyph if the glyph is not a monochrome vector glyph, such as a
|
||||
// colored (bitmap or vector) emoji glyph.
|
||||
func (f *Font) LoadGlyph(b *Buffer, x GlyphIndex, ppem fixed.Int26_6, opts *LoadGlyphOptions) ([]Segment, error) {
|
||||
if b == nil {
|
||||
b = &Buffer{}
|
||||
}
|
||||
|
||||
b.segments = b.segments[:0]
|
||||
if f.cached.isColorBitmap {
|
||||
return nil, ErrColoredGlyph
|
||||
}
|
||||
if f.cached.isPostScript {
|
||||
buf, offset, length, err := f.viewGlyphData(b, x)
|
||||
if err != nil {
|
||||
@@ -1124,10 +1148,8 @@ func (f *Font) LoadGlyph(b *Buffer, x GlyphIndex, ppem fixed.Int26_6, opts *Load
|
||||
if !b.psi.type2Charstrings.ended {
|
||||
return nil, errInvalidCFFTable
|
||||
}
|
||||
} else {
|
||||
if err := loadGlyf(f, b, x, 0, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if err := loadGlyf(f, b, x, 0, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Scale the segments. If we want to support hinting, we'll have to push
|
||||
|
||||
30
vendor/golang.org/x/net/bpf/constants.go
сгенерированный
поставляемый
30
vendor/golang.org/x/net/bpf/constants.go
сгенерированный
поставляемый
@@ -76,54 +76,54 @@ const (
|
||||
// ExtLen returns the length of the packet.
|
||||
ExtLen Extension = 1
|
||||
// ExtProto returns the packet's L3 protocol type.
|
||||
ExtProto = 0
|
||||
ExtProto Extension = 0
|
||||
// ExtType returns the packet's type (skb->pkt_type in the kernel)
|
||||
//
|
||||
// TODO: better documentation. How nice an API do we want to
|
||||
// provide for these esoteric extensions?
|
||||
ExtType = 4
|
||||
ExtType Extension = 4
|
||||
// ExtPayloadOffset returns the offset of the packet payload, or
|
||||
// the first protocol header that the kernel does not know how to
|
||||
// parse.
|
||||
ExtPayloadOffset = 52
|
||||
ExtPayloadOffset Extension = 52
|
||||
// ExtInterfaceIndex returns the index of the interface on which
|
||||
// the packet was received.
|
||||
ExtInterfaceIndex = 8
|
||||
ExtInterfaceIndex Extension = 8
|
||||
// ExtNetlinkAttr returns the netlink attribute of type X at
|
||||
// offset A.
|
||||
ExtNetlinkAttr = 12
|
||||
ExtNetlinkAttr Extension = 12
|
||||
// ExtNetlinkAttrNested returns the nested netlink attribute of
|
||||
// type X at offset A.
|
||||
ExtNetlinkAttrNested = 16
|
||||
ExtNetlinkAttrNested Extension = 16
|
||||
// ExtMark returns the packet's mark value.
|
||||
ExtMark = 20
|
||||
ExtMark Extension = 20
|
||||
// ExtQueue returns the packet's assigned hardware queue.
|
||||
ExtQueue = 24
|
||||
ExtQueue Extension = 24
|
||||
// ExtLinkLayerType returns the packet's hardware address type
|
||||
// (e.g. Ethernet, Infiniband).
|
||||
ExtLinkLayerType = 28
|
||||
ExtLinkLayerType Extension = 28
|
||||
// ExtRXHash returns the packets receive hash.
|
||||
//
|
||||
// TODO: figure out what this rxhash actually is.
|
||||
ExtRXHash = 32
|
||||
ExtRXHash Extension = 32
|
||||
// ExtCPUID returns the ID of the CPU processing the current
|
||||
// packet.
|
||||
ExtCPUID = 36
|
||||
ExtCPUID Extension = 36
|
||||
// ExtVLANTag returns the packet's VLAN tag.
|
||||
ExtVLANTag = 44
|
||||
ExtVLANTag Extension = 44
|
||||
// ExtVLANTagPresent returns non-zero if the packet has a VLAN
|
||||
// tag.
|
||||
//
|
||||
// TODO: I think this might be a lie: it reads bit 0x1000 of the
|
||||
// VLAN header, which changed meaning in recent revisions of the
|
||||
// spec - this extension may now return meaningless information.
|
||||
ExtVLANTagPresent = 48
|
||||
ExtVLANTagPresent Extension = 48
|
||||
// ExtVLANProto returns 0x8100 if the frame has a VLAN header,
|
||||
// 0x88a8 if the frame has a "Q-in-Q" double VLAN header, or some
|
||||
// other value if no VLAN information is present.
|
||||
ExtVLANProto = 60
|
||||
ExtVLANProto Extension = 60
|
||||
// ExtRand returns a uniformly random uint32.
|
||||
ExtRand = 56
|
||||
ExtRand Extension = 56
|
||||
)
|
||||
|
||||
// The following gives names to various bit patterns used in opcode construction.
|
||||
|
||||
10
vendor/golang.org/x/net/bpf/setter.go
сгенерированный
поставляемый
Обычный файл
10
vendor/golang.org/x/net/bpf/setter.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,10 @@
|
||||
// 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.
|
||||
|
||||
package bpf
|
||||
|
||||
// A Setter is a type which can attach a compiled BPF filter to itself.
|
||||
type Setter interface {
|
||||
SetBPF(filter []RawInstruction) error
|
||||
}
|
||||
3
vendor/golang.org/x/net/bpf/vm_bpf_test.go
сгенерированный
поставляемый
3
vendor/golang.org/x/net/bpf/vm_bpf_test.go
сгенерированный
поставляемый
@@ -149,9 +149,6 @@ func testOSVM(t *testing.T, filter []bpf.Instruction) (virtualMachine, func()) {
|
||||
|
||||
p := ipv4.NewPacketConn(l)
|
||||
if err = p.SetBPF(prog); err != nil {
|
||||
if err.Error() == "operation not supported" { // TODO: gross. remove once 19051 fixed.
|
||||
t.Skip("Skipping until Issue 19051 is fixed.")
|
||||
}
|
||||
t.Fatalf("failed to attach BPF program to listener: %v", err)
|
||||
}
|
||||
|
||||
|
||||
2
vendor/golang.org/x/net/http2/configure_transport.go
сгенерированный
поставляемый
2
vendor/golang.org/x/net/http2/configure_transport.go
сгенерированный
поставляемый
@@ -56,7 +56,7 @@ func configureTransport(t1 *http.Transport) (*Transport, error) {
|
||||
}
|
||||
|
||||
// registerHTTPSProtocol calls Transport.RegisterProtocol but
|
||||
// convering panics into errors.
|
||||
// converting panics into errors.
|
||||
func registerHTTPSProtocol(t *http.Transport, rt http.RoundTripper) (err error) {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
|
||||
8
vendor/golang.org/x/net/http2/databuffer_test.go
сгенерированный
поставляемый
8
vendor/golang.org/x/net/http2/databuffer_test.go
сгенерированный
поставляемый
@@ -71,13 +71,13 @@ func testDataBuffer(t *testing.T, wantBytes []byte, setup func(t *testing.T) *da
|
||||
func TestDataBufferAllocation(t *testing.T) {
|
||||
writes := [][]byte{
|
||||
bytes.Repeat([]byte("a"), 1*1024-1),
|
||||
[]byte{'a'},
|
||||
[]byte("a"),
|
||||
bytes.Repeat([]byte("b"), 4*1024-1),
|
||||
[]byte{'b'},
|
||||
[]byte("b"),
|
||||
bytes.Repeat([]byte("c"), 8*1024-1),
|
||||
[]byte{'c'},
|
||||
[]byte("c"),
|
||||
bytes.Repeat([]byte("d"), 16*1024-1),
|
||||
[]byte{'d'},
|
||||
[]byte("d"),
|
||||
bytes.Repeat([]byte("e"), 32*1024),
|
||||
}
|
||||
var wantRead bytes.Buffer
|
||||
|
||||
13
vendor/golang.org/x/net/http2/errors.go
сгенерированный
поставляемый
13
vendor/golang.org/x/net/http2/errors.go
сгенерированный
поставляемый
@@ -87,13 +87,16 @@ type goAwayFlowError struct{}
|
||||
|
||||
func (goAwayFlowError) Error() string { return "connection exceeded flow control window size" }
|
||||
|
||||
// connErrorReason wraps a ConnectionError with an informative error about why it occurs.
|
||||
|
||||
// connError represents an HTTP/2 ConnectionError error code, along
|
||||
// with a string (for debugging) explaining why.
|
||||
//
|
||||
// Errors of this type are only returned by the frame parser functions
|
||||
// and converted into ConnectionError(ErrCodeProtocol).
|
||||
// and converted into ConnectionError(Code), after stashing away
|
||||
// the Reason into the Framer's errDetail field, accessible via
|
||||
// the (*Framer).ErrorDetail method.
|
||||
type connError struct {
|
||||
Code ErrCode
|
||||
Reason string
|
||||
Code ErrCode // the ConnectionError error code
|
||||
Reason string // additional reason
|
||||
}
|
||||
|
||||
func (e connError) Error() string {
|
||||
|
||||
2
vendor/golang.org/x/net/http2/go18.go
сгенерированный
поставляемый
2
vendor/golang.org/x/net/http2/go18.go
сгенерированный
поставляемый
@@ -52,3 +52,5 @@ func reqGetBody(req *http.Request) func() (io.ReadCloser, error) {
|
||||
func reqBodyIsNoBody(body io.ReadCloser) bool {
|
||||
return body == http.NoBody
|
||||
}
|
||||
|
||||
func go18httpNoBody() io.ReadCloser { return http.NoBody } // for tests only
|
||||
|
||||
16
vendor/golang.org/x/net/http2/go19.go
сгенерированный
поставляемый
Обычный файл
16
vendor/golang.org/x/net/http2/go19.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,16 @@
|
||||
// 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 go1.9
|
||||
|
||||
package http2
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func configureServer19(s *http.Server, conf *Server) error {
|
||||
s.RegisterOnShutdown(conf.state.startGracefulShutdown)
|
||||
return nil
|
||||
}
|
||||
60
vendor/golang.org/x/net/http2/go19_test.go
сгенерированный
поставляемый
Обычный файл
60
vendor/golang.org/x/net/http2/go19_test.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,60 @@
|
||||
// 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
|
||||
|
||||
package http2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestServerGracefulShutdown(t *testing.T) {
|
||||
var st *serverTester
|
||||
handlerDone := make(chan struct{})
|
||||
st = newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
defer close(handlerDone)
|
||||
go st.ts.Config.Shutdown(context.Background())
|
||||
|
||||
ga := st.wantGoAway()
|
||||
if ga.ErrCode != ErrCodeNo {
|
||||
t.Errorf("GOAWAY error = %v; want ErrCodeNo", ga.ErrCode)
|
||||
}
|
||||
if ga.LastStreamID != 1 {
|
||||
t.Errorf("GOAWAY LastStreamID = %v; want 1", ga.LastStreamID)
|
||||
}
|
||||
|
||||
w.Header().Set("x-foo", "bar")
|
||||
})
|
||||
defer st.Close()
|
||||
|
||||
st.greet()
|
||||
st.bodylessReq1()
|
||||
|
||||
select {
|
||||
case <-handlerDone:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("server did not shutdown?")
|
||||
}
|
||||
hf := st.wantHeaders()
|
||||
goth := st.decodeHeader(hf.HeaderBlockFragment())
|
||||
wanth := [][2]string{
|
||||
{":status", "200"},
|
||||
{"x-foo", "bar"},
|
||||
{"content-type", "text/plain; charset=utf-8"},
|
||||
{"content-length", "0"},
|
||||
}
|
||||
if !reflect.DeepEqual(goth, wanth) {
|
||||
t.Errorf("Got headers %v; want %v", goth, wanth)
|
||||
}
|
||||
|
||||
n, err := st.cc.Read([]byte{0})
|
||||
if n != 0 || err == nil {
|
||||
t.Errorf("Read = %v, %v; want 0, non-nil", n, err)
|
||||
}
|
||||
}
|
||||
4
vendor/golang.org/x/net/http2/hpack/hpack_test.go
сгенерированный
поставляемый
4
vendor/golang.org/x/net/http2/hpack/hpack_test.go
сгенерированный
поставляемый
@@ -648,6 +648,10 @@ func TestHuffmanFuzzCrash(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func pair(name, value string) HeaderField {
|
||||
return HeaderField{Name: name, Value: value}
|
||||
}
|
||||
|
||||
func dehex(s string) []byte {
|
||||
s = strings.Replace(s, " ", "", -1)
|
||||
s = strings.Replace(s, "\n", "", -1)
|
||||
|
||||
126
vendor/golang.org/x/net/http2/hpack/tables.go
сгенерированный
поставляемый
126
vendor/golang.org/x/net/http2/hpack/tables.go
сгенерированный
поставляемый
@@ -125,74 +125,70 @@ func (t *headerFieldTable) idToIndex(id uint64) uint64 {
|
||||
return k + 1
|
||||
}
|
||||
|
||||
func pair(name, value string) HeaderField {
|
||||
return HeaderField{Name: name, Value: value}
|
||||
}
|
||||
|
||||
// http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-07#appendix-B
|
||||
var staticTable = newStaticTable()
|
||||
var staticTableEntries = [...]HeaderField{
|
||||
pair(":authority", ""),
|
||||
pair(":method", "GET"),
|
||||
pair(":method", "POST"),
|
||||
pair(":path", "/"),
|
||||
pair(":path", "/index.html"),
|
||||
pair(":scheme", "http"),
|
||||
pair(":scheme", "https"),
|
||||
pair(":status", "200"),
|
||||
pair(":status", "204"),
|
||||
pair(":status", "206"),
|
||||
pair(":status", "304"),
|
||||
pair(":status", "400"),
|
||||
pair(":status", "404"),
|
||||
pair(":status", "500"),
|
||||
pair("accept-charset", ""),
|
||||
pair("accept-encoding", "gzip, deflate"),
|
||||
pair("accept-language", ""),
|
||||
pair("accept-ranges", ""),
|
||||
pair("accept", ""),
|
||||
pair("access-control-allow-origin", ""),
|
||||
pair("age", ""),
|
||||
pair("allow", ""),
|
||||
pair("authorization", ""),
|
||||
pair("cache-control", ""),
|
||||
pair("content-disposition", ""),
|
||||
pair("content-encoding", ""),
|
||||
pair("content-language", ""),
|
||||
pair("content-length", ""),
|
||||
pair("content-location", ""),
|
||||
pair("content-range", ""),
|
||||
pair("content-type", ""),
|
||||
pair("cookie", ""),
|
||||
pair("date", ""),
|
||||
pair("etag", ""),
|
||||
pair("expect", ""),
|
||||
pair("expires", ""),
|
||||
pair("from", ""),
|
||||
pair("host", ""),
|
||||
pair("if-match", ""),
|
||||
pair("if-modified-since", ""),
|
||||
pair("if-none-match", ""),
|
||||
pair("if-range", ""),
|
||||
pair("if-unmodified-since", ""),
|
||||
pair("last-modified", ""),
|
||||
pair("link", ""),
|
||||
pair("location", ""),
|
||||
pair("max-forwards", ""),
|
||||
pair("proxy-authenticate", ""),
|
||||
pair("proxy-authorization", ""),
|
||||
pair("range", ""),
|
||||
pair("referer", ""),
|
||||
pair("refresh", ""),
|
||||
pair("retry-after", ""),
|
||||
pair("server", ""),
|
||||
pair("set-cookie", ""),
|
||||
pair("strict-transport-security", ""),
|
||||
pair("transfer-encoding", ""),
|
||||
pair("user-agent", ""),
|
||||
pair("vary", ""),
|
||||
pair("via", ""),
|
||||
pair("www-authenticate", ""),
|
||||
{Name: ":authority"},
|
||||
{Name: ":method", Value: "GET"},
|
||||
{Name: ":method", Value: "POST"},
|
||||
{Name: ":path", Value: "/"},
|
||||
{Name: ":path", Value: "/index.html"},
|
||||
{Name: ":scheme", Value: "http"},
|
||||
{Name: ":scheme", Value: "https"},
|
||||
{Name: ":status", Value: "200"},
|
||||
{Name: ":status", Value: "204"},
|
||||
{Name: ":status", Value: "206"},
|
||||
{Name: ":status", Value: "304"},
|
||||
{Name: ":status", Value: "400"},
|
||||
{Name: ":status", Value: "404"},
|
||||
{Name: ":status", Value: "500"},
|
||||
{Name: "accept-charset"},
|
||||
{Name: "accept-encoding", Value: "gzip, deflate"},
|
||||
{Name: "accept-language"},
|
||||
{Name: "accept-ranges"},
|
||||
{Name: "accept"},
|
||||
{Name: "access-control-allow-origin"},
|
||||
{Name: "age"},
|
||||
{Name: "allow"},
|
||||
{Name: "authorization"},
|
||||
{Name: "cache-control"},
|
||||
{Name: "content-disposition"},
|
||||
{Name: "content-encoding"},
|
||||
{Name: "content-language"},
|
||||
{Name: "content-length"},
|
||||
{Name: "content-location"},
|
||||
{Name: "content-range"},
|
||||
{Name: "content-type"},
|
||||
{Name: "cookie"},
|
||||
{Name: "date"},
|
||||
{Name: "etag"},
|
||||
{Name: "expect"},
|
||||
{Name: "expires"},
|
||||
{Name: "from"},
|
||||
{Name: "host"},
|
||||
{Name: "if-match"},
|
||||
{Name: "if-modified-since"},
|
||||
{Name: "if-none-match"},
|
||||
{Name: "if-range"},
|
||||
{Name: "if-unmodified-since"},
|
||||
{Name: "last-modified"},
|
||||
{Name: "link"},
|
||||
{Name: "location"},
|
||||
{Name: "max-forwards"},
|
||||
{Name: "proxy-authenticate"},
|
||||
{Name: "proxy-authorization"},
|
||||
{Name: "range"},
|
||||
{Name: "referer"},
|
||||
{Name: "refresh"},
|
||||
{Name: "retry-after"},
|
||||
{Name: "server"},
|
||||
{Name: "set-cookie"},
|
||||
{Name: "strict-transport-security"},
|
||||
{Name: "transfer-encoding"},
|
||||
{Name: "user-agent"},
|
||||
{Name: "vary"},
|
||||
{Name: "via"},
|
||||
{Name: "www-authenticate"},
|
||||
}
|
||||
|
||||
func newStaticTable() *headerFieldTable {
|
||||
|
||||
8
vendor/golang.org/x/net/http2/http2.go
сгенерированный
поставляемый
8
vendor/golang.org/x/net/http2/http2.go
сгенерированный
поставляемый
@@ -376,12 +376,16 @@ func (s *sorter) SortStrings(ss []string) {
|
||||
// validPseudoPath reports whether v is a valid :path pseudo-header
|
||||
// value. It must be either:
|
||||
//
|
||||
// *) a non-empty string starting with '/', but not with with "//",
|
||||
// *) a non-empty string starting with '/'
|
||||
// *) the string '*', for OPTIONS requests.
|
||||
//
|
||||
// For now this is only used a quick check for deciding when to clean
|
||||
// up Opaque URLs before sending requests from the Transport.
|
||||
// See golang.org/issue/16847
|
||||
//
|
||||
// We used to enforce that the path also didn't start with "//", but
|
||||
// Google's GFE accepts such paths and Chrome sends them, so ignore
|
||||
// that part of the spec. See golang.org/issue/19103.
|
||||
func validPseudoPath(v string) bool {
|
||||
return (len(v) > 0 && v[0] == '/' && (len(v) == 1 || v[1] != '/')) || v == "*"
|
||||
return (len(v) > 0 && v[0] == '/') || v == "*"
|
||||
}
|
||||
|
||||
2
vendor/golang.org/x/net/http2/not_go18.go
сгенерированный
поставляемый
2
vendor/golang.org/x/net/http2/not_go18.go
сгенерированный
поставляемый
@@ -25,3 +25,5 @@ func reqGetBody(req *http.Request) func() (io.ReadCloser, error) {
|
||||
}
|
||||
|
||||
func reqBodyIsNoBody(io.ReadCloser) bool { return false }
|
||||
|
||||
func go18httpNoBody() io.ReadCloser { return nil } // for tests only
|
||||
|
||||
16
vendor/golang.org/x/net/http2/not_go19.go
сгенерированный
поставляемый
Обычный файл
16
vendor/golang.org/x/net/http2/not_go19.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,16 @@
|
||||
// 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 !go1.9
|
||||
|
||||
package http2
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func configureServer19(s *http.Server, conf *Server) error {
|
||||
// not supported prior to go1.9
|
||||
return nil
|
||||
}
|
||||
16
vendor/golang.org/x/net/http2/pipe.go
сгенерированный
поставляемый
16
vendor/golang.org/x/net/http2/pipe.go
сгенерированный
поставляемый
@@ -15,8 +15,8 @@ import (
|
||||
// underlying buffer is an interface. (io.Pipe is always unbuffered)
|
||||
type pipe struct {
|
||||
mu sync.Mutex
|
||||
c sync.Cond // c.L lazily initialized to &p.mu
|
||||
b pipeBuffer
|
||||
c sync.Cond // c.L lazily initialized to &p.mu
|
||||
b pipeBuffer // nil when done reading
|
||||
err error // read error once empty. non-nil means closed.
|
||||
breakErr error // immediate read error (caller doesn't see rest of b)
|
||||
donec chan struct{} // closed on error
|
||||
@@ -32,6 +32,9 @@ type pipeBuffer interface {
|
||||
func (p *pipe) Len() int {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.b == nil {
|
||||
return 0
|
||||
}
|
||||
return p.b.Len()
|
||||
}
|
||||
|
||||
@@ -47,7 +50,7 @@ func (p *pipe) Read(d []byte) (n int, err error) {
|
||||
if p.breakErr != nil {
|
||||
return 0, p.breakErr
|
||||
}
|
||||
if p.b.Len() > 0 {
|
||||
if p.b != nil && p.b.Len() > 0 {
|
||||
return p.b.Read(d)
|
||||
}
|
||||
if p.err != nil {
|
||||
@@ -55,6 +58,7 @@ func (p *pipe) Read(d []byte) (n int, err error) {
|
||||
p.readFn() // e.g. copy trailers
|
||||
p.readFn = nil // not sticky like p.err
|
||||
}
|
||||
p.b = nil
|
||||
return 0, p.err
|
||||
}
|
||||
p.c.Wait()
|
||||
@@ -75,6 +79,9 @@ func (p *pipe) Write(d []byte) (n int, err error) {
|
||||
if p.err != nil {
|
||||
return 0, errClosedPipeWrite
|
||||
}
|
||||
if p.breakErr != nil {
|
||||
return len(d), nil // discard when there is no reader
|
||||
}
|
||||
return p.b.Write(d)
|
||||
}
|
||||
|
||||
@@ -109,6 +116,9 @@ func (p *pipe) closeWithError(dst *error, err error, fn func()) {
|
||||
return
|
||||
}
|
||||
p.readFn = fn
|
||||
if dst == &p.breakErr {
|
||||
p.b = nil
|
||||
}
|
||||
*dst = err
|
||||
p.closeDoneLocked()
|
||||
}
|
||||
|
||||
21
vendor/golang.org/x/net/http2/pipe_test.go
сгенерированный
поставляемый
21
vendor/golang.org/x/net/http2/pipe_test.go
сгенерированный
поставляемый
@@ -92,6 +92,13 @@ func TestPipeCloseWithError(t *testing.T) {
|
||||
if err != a {
|
||||
t.Logf("read error = %v, %v", err, a)
|
||||
}
|
||||
// Read and Write should fail.
|
||||
if n, err := p.Write([]byte("abc")); err != errClosedPipeWrite || n != 0 {
|
||||
t.Errorf("Write(abc) after close\ngot %v, %v\nwant 0, %v", n, err, errClosedPipeWrite)
|
||||
}
|
||||
if n, err := p.Read(make([]byte, 1)); err == nil || n != 0 {
|
||||
t.Errorf("Read() after close\ngot %v, nil\nwant 0, %v", n, errClosedPipeWrite)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPipeBreakWithError(t *testing.T) {
|
||||
@@ -106,4 +113,18 @@ func TestPipeBreakWithError(t *testing.T) {
|
||||
if err != a {
|
||||
t.Logf("read error = %v, %v", err, a)
|
||||
}
|
||||
if p.b != nil {
|
||||
t.Errorf("buffer should be nil after BreakWithError")
|
||||
}
|
||||
// Write should succeed silently.
|
||||
if n, err := p.Write([]byte("abc")); err != nil || n != 3 {
|
||||
t.Errorf("Write(abc) after break\ngot %v, %v\nwant 0, nil", n, err)
|
||||
}
|
||||
if p.b != nil {
|
||||
t.Errorf("buffer should be nil after Write")
|
||||
}
|
||||
// Read should fail.
|
||||
if n, err := p.Read(make([]byte, 1)); err == nil || n != 0 {
|
||||
t.Errorf("Read() after close\ngot %v, nil\nwant 0, not nil", n)
|
||||
}
|
||||
}
|
||||
|
||||
141
vendor/golang.org/x/net/http2/server.go
сгенерированный
поставляемый
141
vendor/golang.org/x/net/http2/server.go
сгенерированный
поставляемый
@@ -126,6 +126,11 @@ type Server struct {
|
||||
// NewWriteScheduler constructs a write scheduler for a connection.
|
||||
// If nil, a default scheduler is chosen.
|
||||
NewWriteScheduler func() WriteScheduler
|
||||
|
||||
// Internal state. This is a pointer (rather than embedded directly)
|
||||
// so that we don't embed a Mutex in this struct, which will make the
|
||||
// struct non-copyable, which might break some callers.
|
||||
state *serverInternalState
|
||||
}
|
||||
|
||||
func (s *Server) initialConnRecvWindowSize() int32 {
|
||||
@@ -156,6 +161,40 @@ func (s *Server) maxConcurrentStreams() uint32 {
|
||||
return defaultMaxStreams
|
||||
}
|
||||
|
||||
type serverInternalState struct {
|
||||
mu sync.Mutex
|
||||
activeConns map[*serverConn]struct{}
|
||||
}
|
||||
|
||||
func (s *serverInternalState) registerConn(sc *serverConn) {
|
||||
if s == nil {
|
||||
return // if the Server was used without calling ConfigureServer
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.activeConns[sc] = struct{}{}
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *serverInternalState) unregisterConn(sc *serverConn) {
|
||||
if s == nil {
|
||||
return // if the Server was used without calling ConfigureServer
|
||||
}
|
||||
s.mu.Lock()
|
||||
delete(s.activeConns, sc)
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *serverInternalState) startGracefulShutdown() {
|
||||
if s == nil {
|
||||
return // if the Server was used without calling ConfigureServer
|
||||
}
|
||||
s.mu.Lock()
|
||||
for sc := range s.activeConns {
|
||||
sc.startGracefulShutdown()
|
||||
}
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
// ConfigureServer adds HTTP/2 support to a net/http Server.
|
||||
//
|
||||
// The configuration conf may be nil.
|
||||
@@ -168,9 +207,13 @@ func ConfigureServer(s *http.Server, conf *Server) error {
|
||||
if conf == nil {
|
||||
conf = new(Server)
|
||||
}
|
||||
conf.state = &serverInternalState{activeConns: make(map[*serverConn]struct{})}
|
||||
if err := configureServer18(s, conf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := configureServer19(s, conf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.TLSConfig == nil {
|
||||
s.TLSConfig = new(tls.Config)
|
||||
@@ -305,6 +348,9 @@ func (s *Server) ServeConn(c net.Conn, opts *ServeConnOpts) {
|
||||
pushEnabled: true,
|
||||
}
|
||||
|
||||
s.state.registerConn(sc)
|
||||
defer s.state.unregisterConn(sc)
|
||||
|
||||
// The net/http package sets the write deadline from the
|
||||
// http.Server.WriteTimeout during the TLS handshake, but then
|
||||
// passes the connection off to us with the deadline already set.
|
||||
@@ -445,6 +491,9 @@ type serverConn struct {
|
||||
// Owned by the writeFrameAsync goroutine:
|
||||
headerWriteBuf bytes.Buffer
|
||||
hpackEncoder *hpack.Encoder
|
||||
|
||||
// Used by startGracefulShutdown.
|
||||
shutdownOnce sync.Once
|
||||
}
|
||||
|
||||
func (sc *serverConn) maxHeaderListSize() uint32 {
|
||||
@@ -749,15 +798,6 @@ func (sc *serverConn) serve() {
|
||||
defer sc.idleTimer.Stop()
|
||||
}
|
||||
|
||||
var gracefulShutdownCh chan struct{}
|
||||
if sc.hs != nil {
|
||||
ch := h1ServerShutdownChan(sc.hs)
|
||||
if ch != nil {
|
||||
gracefulShutdownCh = make(chan struct{})
|
||||
go sc.awaitGracefulShutdown(ch, gracefulShutdownCh)
|
||||
}
|
||||
}
|
||||
|
||||
go sc.readFrames() // closed by defer sc.conn.Close above
|
||||
|
||||
settingsTimer := time.AfterFunc(firstSettingsTimeout, sc.onSettingsTimer)
|
||||
@@ -786,14 +826,11 @@ func (sc *serverConn) serve() {
|
||||
}
|
||||
case m := <-sc.bodyReadCh:
|
||||
sc.noteBodyRead(m.st, m.n)
|
||||
case <-gracefulShutdownCh:
|
||||
gracefulShutdownCh = nil
|
||||
sc.startGracefulShutdown()
|
||||
case msg := <-sc.serveMsgCh:
|
||||
switch v := msg.(type) {
|
||||
case func(int):
|
||||
v(loopNum) // for testing
|
||||
case *timerMessage:
|
||||
case *serverMessage:
|
||||
switch v {
|
||||
case settingsTimerMsg:
|
||||
sc.logf("timeout waiting for SETTINGS frames from %v", sc.conn.RemoteAddr())
|
||||
@@ -804,6 +841,8 @@ func (sc *serverConn) serve() {
|
||||
case shutdownTimerMsg:
|
||||
sc.vlogf("GOAWAY close timer fired; closing conn from %v", sc.conn.RemoteAddr())
|
||||
return
|
||||
case gracefulShutdownMsg:
|
||||
sc.startGracefulShutdownInternal()
|
||||
default:
|
||||
panic("unknown timer")
|
||||
}
|
||||
@@ -828,13 +867,14 @@ func (sc *serverConn) awaitGracefulShutdown(sharedCh <-chan struct{}, privateCh
|
||||
}
|
||||
}
|
||||
|
||||
type timerMessage int
|
||||
type serverMessage int
|
||||
|
||||
// Timeout message values sent to serveMsgCh.
|
||||
// Message values sent to serveMsgCh.
|
||||
var (
|
||||
settingsTimerMsg = new(timerMessage)
|
||||
idleTimerMsg = new(timerMessage)
|
||||
shutdownTimerMsg = new(timerMessage)
|
||||
settingsTimerMsg = new(serverMessage)
|
||||
idleTimerMsg = new(serverMessage)
|
||||
shutdownTimerMsg = new(serverMessage)
|
||||
gracefulShutdownMsg = new(serverMessage)
|
||||
)
|
||||
|
||||
func (sc *serverConn) onSettingsTimer() { sc.sendServeMsg(settingsTimerMsg) }
|
||||
@@ -1166,10 +1206,19 @@ func (sc *serverConn) scheduleFrameWrite() {
|
||||
sc.inFrameScheduleLoop = false
|
||||
}
|
||||
|
||||
// startGracefulShutdown sends a GOAWAY with ErrCodeNo to tell the
|
||||
// client we're gracefully shutting down. The connection isn't closed
|
||||
// until all current streams are done.
|
||||
// startGracefulShutdown gracefully shuts down a connection. This
|
||||
// sends GOAWAY with ErrCodeNo to tell the client we're gracefully
|
||||
// shutting down. The connection isn't closed until all current
|
||||
// streams are done.
|
||||
//
|
||||
// startGracefulShutdown returns immediately; it does not wait until
|
||||
// the connection has shut down.
|
||||
func (sc *serverConn) startGracefulShutdown() {
|
||||
sc.serveG.checkNotOn() // NOT
|
||||
sc.shutdownOnce.Do(func() { sc.sendServeMsg(gracefulShutdownMsg) })
|
||||
}
|
||||
|
||||
func (sc *serverConn) startGracefulShutdownInternal() {
|
||||
sc.goAwayIn(ErrCodeNo, 0)
|
||||
}
|
||||
|
||||
@@ -1399,7 +1448,7 @@ func (sc *serverConn) closeStream(st *stream, err error) {
|
||||
sc.idleTimer.Reset(sc.srv.IdleTimeout)
|
||||
}
|
||||
if h1ServerKeepAlivesDisabled(sc.hs) {
|
||||
sc.startGracefulShutdown()
|
||||
sc.startGracefulShutdownInternal()
|
||||
}
|
||||
}
|
||||
if p := st.body; p != nil {
|
||||
@@ -1586,7 +1635,7 @@ func (sc *serverConn) processGoAway(f *GoAwayFrame) error {
|
||||
} else {
|
||||
sc.vlogf("http2: received GOAWAY %+v, starting graceful shutdown", f)
|
||||
}
|
||||
sc.startGracefulShutdown()
|
||||
sc.startGracefulShutdownInternal()
|
||||
// http://tools.ietf.org/html/rfc7540#section-6.8
|
||||
// We should not create any new streams, which means we should disable push.
|
||||
sc.pushEnabled = false
|
||||
@@ -2203,6 +2252,7 @@ type responseWriterState struct {
|
||||
wroteHeader bool // WriteHeader called (explicitly or implicitly). Not necessarily sent to user yet.
|
||||
sentHeader bool // have we sent the header frame?
|
||||
handlerDone bool // handler has finished
|
||||
dirty bool // a Write failed; don't reuse this responseWriterState
|
||||
|
||||
sentContentLen int64 // non-zero if handler set a Content-Length header
|
||||
wroteBytes int64
|
||||
@@ -2284,6 +2334,7 @@ func (rws *responseWriterState) writeChunk(p []byte) (n int, err error) {
|
||||
date: date,
|
||||
})
|
||||
if err != nil {
|
||||
rws.dirty = true
|
||||
return 0, err
|
||||
}
|
||||
if endStream {
|
||||
@@ -2305,6 +2356,7 @@ func (rws *responseWriterState) writeChunk(p []byte) (n int, err error) {
|
||||
if len(p) > 0 || endStream {
|
||||
// only send a 0 byte DATA frame if we're ending the stream.
|
||||
if err := rws.conn.writeDataFromHandler(rws.stream, p, endStream); err != nil {
|
||||
rws.dirty = true
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
@@ -2316,6 +2368,9 @@ func (rws *responseWriterState) writeChunk(p []byte) (n int, err error) {
|
||||
trailers: rws.trailers,
|
||||
endStream: true,
|
||||
})
|
||||
if err != nil {
|
||||
rws.dirty = true
|
||||
}
|
||||
return len(p), err
|
||||
}
|
||||
return len(p), nil
|
||||
@@ -2455,7 +2510,7 @@ func cloneHeader(h http.Header) http.Header {
|
||||
//
|
||||
// * Handler calls w.Write or w.WriteString ->
|
||||
// * -> rws.bw (*bufio.Writer) ->
|
||||
// * (Handler migth call Flush)
|
||||
// * (Handler might call Flush)
|
||||
// * -> chunkWriter{rws}
|
||||
// * -> responseWriterState.writeChunk(p []byte)
|
||||
// * -> responseWriterState.writeChunk (most of the magic; see comment there)
|
||||
@@ -2494,10 +2549,19 @@ func (w *responseWriter) write(lenData int, dataB []byte, dataS string) (n int,
|
||||
|
||||
func (w *responseWriter) handlerDone() {
|
||||
rws := w.rws
|
||||
dirty := rws.dirty
|
||||
rws.handlerDone = true
|
||||
w.Flush()
|
||||
w.rws = nil
|
||||
responseWriterStatePool.Put(rws)
|
||||
if !dirty {
|
||||
// Only recycle the pool if all prior Write calls to
|
||||
// the serverConn goroutine completed successfully. If
|
||||
// they returned earlier due to resets from the peer
|
||||
// there might still be write goroutines outstanding
|
||||
// from the serverConn referencing the rws memory. See
|
||||
// issue 20704.
|
||||
responseWriterStatePool.Put(rws)
|
||||
}
|
||||
}
|
||||
|
||||
// Push errors.
|
||||
@@ -2653,7 +2717,7 @@ func (sc *serverConn) startPush(msg *startPushRequest) {
|
||||
// A server that is unable to establish a new stream identifier can send a GOAWAY
|
||||
// frame so that the client is forced to open a new connection for new streams.
|
||||
if sc.maxPushPromiseID+2 >= 1<<31 {
|
||||
sc.startGracefulShutdown()
|
||||
sc.startGracefulShutdownInternal()
|
||||
return 0, ErrPushLimitReached
|
||||
}
|
||||
sc.maxPushPromiseID += 2
|
||||
@@ -2778,31 +2842,6 @@ var badTrailer = map[string]bool{
|
||||
"Www-Authenticate": true,
|
||||
}
|
||||
|
||||
// h1ServerShutdownChan returns a channel that will be closed when the
|
||||
// provided *http.Server wants to shut down.
|
||||
//
|
||||
// This is a somewhat hacky way to get at http1 innards. It works
|
||||
// when the http2 code is bundled into the net/http package in the
|
||||
// standard library. The alternatives ended up making the cmd/go tool
|
||||
// depend on http Servers. This is the lightest option for now.
|
||||
// This is tested via the TestServeShutdown* tests in net/http.
|
||||
func h1ServerShutdownChan(hs *http.Server) <-chan struct{} {
|
||||
if fn := testh1ServerShutdownChan; fn != nil {
|
||||
return fn(hs)
|
||||
}
|
||||
var x interface{} = hs
|
||||
type I interface {
|
||||
getDoneChan() <-chan struct{}
|
||||
}
|
||||
if hs, ok := x.(I); ok {
|
||||
return hs.getDoneChan()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// optional test hook for h1ServerShutdownChan.
|
||||
var testh1ServerShutdownChan func(hs *http.Server) <-chan struct{}
|
||||
|
||||
// h1ServerKeepAlivesDisabled reports whether hs has its keep-alives
|
||||
// disabled. See comments on h1ServerShutdownChan above for why
|
||||
// the code is written this way.
|
||||
|
||||
63
vendor/golang.org/x/net/http2/server_test.go
сгенерированный
поставляемый
63
vendor/golang.org/x/net/http2/server_test.go
сгенерированный
поставляемый
@@ -3686,47 +3686,36 @@ func TestRequestBodyReadCloseRace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerGracefulShutdown(t *testing.T) {
|
||||
shutdownCh := make(chan struct{})
|
||||
defer func() { testh1ServerShutdownChan = nil }()
|
||||
testh1ServerShutdownChan = func(*http.Server) <-chan struct{} { return shutdownCh }
|
||||
func TestIssue20704Race(t *testing.T) {
|
||||
if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" {
|
||||
t.Skip("skipping in short mode")
|
||||
}
|
||||
const (
|
||||
itemSize = 1 << 10
|
||||
itemCount = 100
|
||||
)
|
||||
|
||||
var st *serverTester
|
||||
handlerDone := make(chan struct{})
|
||||
st = newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
defer close(handlerDone)
|
||||
close(shutdownCh)
|
||||
|
||||
ga := st.wantGoAway()
|
||||
if ga.ErrCode != ErrCodeNo {
|
||||
t.Errorf("GOAWAY error = %v; want ErrCodeNo", ga.ErrCode)
|
||||
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
for i := 0; i < itemCount; i++ {
|
||||
_, err := w.Write(make([]byte, itemSize))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if ga.LastStreamID != 1 {
|
||||
t.Errorf("GOAWAY LastStreamID = %v; want 1", ga.LastStreamID)
|
||||
}
|
||||
|
||||
w.Header().Set("x-foo", "bar")
|
||||
})
|
||||
}, optOnlyServer)
|
||||
defer st.Close()
|
||||
|
||||
st.greet()
|
||||
st.bodylessReq1()
|
||||
tr := &Transport{TLSClientConfig: tlsConfigInsecure}
|
||||
defer tr.CloseIdleConnections()
|
||||
cl := &http.Client{Transport: tr}
|
||||
|
||||
<-handlerDone
|
||||
hf := st.wantHeaders()
|
||||
goth := st.decodeHeader(hf.HeaderBlockFragment())
|
||||
wanth := [][2]string{
|
||||
{":status", "200"},
|
||||
{"x-foo", "bar"},
|
||||
{"content-type", "text/plain; charset=utf-8"},
|
||||
{"content-length", "0"},
|
||||
}
|
||||
if !reflect.DeepEqual(goth, wanth) {
|
||||
t.Errorf("Got headers %v; want %v", goth, wanth)
|
||||
}
|
||||
|
||||
n, err := st.cc.Read([]byte{0})
|
||||
if n != 0 || err == nil {
|
||||
t.Errorf("Read = %v, %v; want 0, non-nil", n, err)
|
||||
for i := 0; i < 1000; i++ {
|
||||
resp, err := cl.Get(st.ts.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Force a RST stream to the server by closing without
|
||||
// reading the body:
|
||||
resp.Body.Close()
|
||||
}
|
||||
}
|
||||
|
||||
11
vendor/golang.org/x/net/http2/transport.go
сгенерированный
поставляемый
11
vendor/golang.org/x/net/http2/transport.go
сгенерированный
поставляемый
@@ -694,7 +694,7 @@ func checkConnHeaders(req *http.Request) error {
|
||||
// req.ContentLength, where 0 actually means zero (not unknown) and -1
|
||||
// means unknown.
|
||||
func actualContentLength(req *http.Request) int64 {
|
||||
if req.Body == nil {
|
||||
if req.Body == nil || reqBodyIsNoBody(req.Body) {
|
||||
return 0
|
||||
}
|
||||
if req.ContentLength != 0 {
|
||||
@@ -725,8 +725,8 @@ func (cc *ClientConn) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
}
|
||||
|
||||
body := req.Body
|
||||
hasBody := body != nil
|
||||
contentLen := actualContentLength(req)
|
||||
hasBody := contentLen != 0
|
||||
|
||||
// TODO(bradfitz): this is a copy of the logic in net/http. Unify somewhere?
|
||||
var requestedGzip bool
|
||||
@@ -1655,6 +1655,7 @@ func (b transportResponseBody) Close() error {
|
||||
cc.wmu.Lock()
|
||||
if !serverSentStreamEnd {
|
||||
cc.fr.WriteRSTStream(cs.ID, ErrCodeCancel)
|
||||
cs.didReset = true
|
||||
}
|
||||
// Return connection-level flow control.
|
||||
if unread > 0 {
|
||||
@@ -1702,12 +1703,6 @@ func (rl *clientConnReadLoop) processData(f *DataFrame) error {
|
||||
return nil
|
||||
}
|
||||
if f.Length > 0 {
|
||||
if len(data) > 0 && cs.bufPipe.b == nil {
|
||||
// Data frame after it's already closed?
|
||||
cc.logf("http2: Transport received DATA frame for closed stream; closing connection")
|
||||
return ConnectionError(ErrCodeProtocol)
|
||||
}
|
||||
|
||||
// Check connection-level flow control.
|
||||
cc.mu.Lock()
|
||||
if cs.inflow.available() >= int32(f.Length) {
|
||||
|
||||
108
vendor/golang.org/x/net/http2/transport_test.go
сгенерированный
поставляемый
108
vendor/golang.org/x/net/http2/transport_test.go
сгенерированный
поставляемый
@@ -417,6 +417,11 @@ func TestActualContentLength(t *testing.T) {
|
||||
req: &http.Request{Body: panicReader{}, ContentLength: 5},
|
||||
want: 5,
|
||||
},
|
||||
// http.NoBody means 0, not -1.
|
||||
3: {
|
||||
req: &http.Request{Body: go18httpNoBody()},
|
||||
want: 0,
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := actualContentLength(tt.req)
|
||||
@@ -2529,7 +2534,7 @@ func TestTransportBodyDoubleEndStream(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// golangorg/issue/16847
|
||||
// golang.org/issue/16847, golang.org/issue/19103
|
||||
func TestTransportRequestPathPseudo(t *testing.T) {
|
||||
type result struct {
|
||||
path string
|
||||
@@ -2549,9 +2554,9 @@ func TestTransportRequestPathPseudo(t *testing.T) {
|
||||
},
|
||||
want: result{path: "/foo"},
|
||||
},
|
||||
// I guess we just don't let users request "//foo" as
|
||||
// a path, since it's illegal to start with two
|
||||
// slashes....
|
||||
// In Go 1.7, we accepted paths of "//foo".
|
||||
// In Go 1.8, we rejected it (issue 16847).
|
||||
// In Go 1.9, we accepted it again (issue 19103).
|
||||
1: {
|
||||
req: &http.Request{
|
||||
Method: "GET",
|
||||
@@ -2560,7 +2565,7 @@ func TestTransportRequestPathPseudo(t *testing.T) {
|
||||
Path: "//foo",
|
||||
},
|
||||
},
|
||||
want: result{err: `invalid request :path "//foo"`},
|
||||
want: result{path: "//foo"},
|
||||
},
|
||||
|
||||
// Opaque with //$Matching_Hostname/path
|
||||
@@ -2915,3 +2920,96 @@ func TestAuthorityAddr(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 20448: stop allocating for DATA frames' payload after
|
||||
// Response.Body.Close is called.
|
||||
func TestTransportAllocationsAfterResponseBodyClose(t *testing.T) {
|
||||
megabyteZero := make([]byte, 1<<20)
|
||||
|
||||
writeErr := make(chan error, 1)
|
||||
|
||||
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
w.(http.Flusher).Flush()
|
||||
var sum int64
|
||||
for i := 0; i < 100; i++ {
|
||||
n, err := w.Write(megabyteZero)
|
||||
sum += int64(n)
|
||||
if err != nil {
|
||||
writeErr <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Logf("wrote all %d bytes", sum)
|
||||
writeErr <- nil
|
||||
}, optOnlyServer)
|
||||
defer st.Close()
|
||||
|
||||
tr := &Transport{TLSClientConfig: tlsConfigInsecure}
|
||||
defer tr.CloseIdleConnections()
|
||||
c := &http.Client{Transport: tr}
|
||||
res, err := c.Get(st.ts.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var buf [1]byte
|
||||
if _, err := res.Body.Read(buf[:]); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := res.Body.Close(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
trb, ok := res.Body.(transportResponseBody)
|
||||
if !ok {
|
||||
t.Fatalf("res.Body = %T; want transportResponseBody", res.Body)
|
||||
}
|
||||
if trb.cs.bufPipe.b != nil {
|
||||
t.Errorf("response body pipe is still open")
|
||||
}
|
||||
|
||||
gotErr := <-writeErr
|
||||
if gotErr == nil {
|
||||
t.Errorf("Handler unexpectedly managed to write its entire response without getting an error")
|
||||
} else if gotErr != errStreamClosed {
|
||||
t.Errorf("Handler Write err = %v; want errStreamClosed", gotErr)
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 18891: make sure Request.Body == NoBody means no DATA frame
|
||||
// is ever sent, even if empty.
|
||||
func TestTransportNoBodyMeansNoDATA(t *testing.T) {
|
||||
ct := newClientTester(t)
|
||||
|
||||
unblockClient := make(chan bool)
|
||||
|
||||
ct.client = func() error {
|
||||
req, _ := http.NewRequest("GET", "https://dummy.tld/", go18httpNoBody())
|
||||
ct.tr.RoundTrip(req)
|
||||
<-unblockClient
|
||||
return nil
|
||||
}
|
||||
ct.server = func() error {
|
||||
defer close(unblockClient)
|
||||
defer ct.cc.(*net.TCPConn).Close()
|
||||
ct.greet()
|
||||
|
||||
for {
|
||||
f, err := ct.fr.ReadFrame()
|
||||
if err != nil {
|
||||
return fmt.Errorf("ReadFrame while waiting for Headers: %v", err)
|
||||
}
|
||||
switch f := f.(type) {
|
||||
default:
|
||||
return fmt.Errorf("Got %T; want HeadersFrame", f)
|
||||
case *WindowUpdateFrame, *SettingsFrame:
|
||||
continue
|
||||
case *HeadersFrame:
|
||||
if !f.StreamEnded() {
|
||||
return fmt.Errorf("got headers frame without END_STREAM")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
ct.run()
|
||||
}
|
||||
|
||||
2
vendor/golang.org/x/net/http2/writesched_priority.go
сгенерированный
поставляемый
2
vendor/golang.org/x/net/http2/writesched_priority.go
сгенерированный
поставляемый
@@ -53,7 +53,7 @@ type PriorityWriteSchedulerConfig struct {
|
||||
}
|
||||
|
||||
// NewPriorityWriteScheduler constructs a WriteScheduler that schedules
|
||||
// frames by following HTTP/2 priorities as described in RFC 7340 Section 5.3.
|
||||
// frames by following HTTP/2 priorities as described in RFC 7540 Section 5.3.
|
||||
// If cfg is nil, default options are used.
|
||||
func NewPriorityWriteScheduler(cfg *PriorityWriteSchedulerConfig) WriteScheduler {
|
||||
if cfg == nil {
|
||||
|
||||
6
vendor/golang.org/x/net/internal/iana/const.go
сгенерированный
поставляемый
6
vendor/golang.org/x/net/internal/iana/const.go
сгенерированный
поставляемый
@@ -4,7 +4,7 @@
|
||||
// Package iana provides protocol number resources managed by the Internet Assigned Numbers Authority (IANA).
|
||||
package iana // import "golang.org/x/net/internal/iana"
|
||||
|
||||
// Differentiated Services Field Codepoints (DSCP), Updated: 2013-06-25
|
||||
// Differentiated Services Field Codepoints (DSCP), Updated: 2017-05-12
|
||||
const (
|
||||
DiffServCS0 = 0x0 // CS0
|
||||
DiffServCS1 = 0x20 // CS1
|
||||
@@ -26,7 +26,7 @@ const (
|
||||
DiffServAF41 = 0x88 // AF41
|
||||
DiffServAF42 = 0x90 // AF42
|
||||
DiffServAF43 = 0x98 // AF43
|
||||
DiffServEFPHB = 0xb8 // EF PHB
|
||||
DiffServEF = 0xb8 // EF
|
||||
DiffServVOICEADMIT = 0xb0 // VOICE-ADMIT
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ const (
|
||||
CongestionExperienced = 0x3 // CE (Congestion Experienced)
|
||||
)
|
||||
|
||||
// Protocol Numbers, Updated: 2015-10-06
|
||||
// Protocol Numbers, Updated: 2016-06-22
|
||||
const (
|
||||
ProtocolIP = 0 // IPv4 encapsulation, pseudo protocol number
|
||||
ProtocolHOPOPT = 0 // IPv6 Hop-by-Hop Option
|
||||
|
||||
41
vendor/golang.org/x/net/internal/netreflect/socket.go
сгенерированный
поставляемый
41
vendor/golang.org/x/net/internal/netreflect/socket.go
сгенерированный
поставляемый
@@ -1,41 +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 !go1.9
|
||||
|
||||
// Package netreflect implements run-time reflection for the
|
||||
// facilities of net package.
|
||||
//
|
||||
// This package works only for Go 1.8 or below.
|
||||
package netreflect
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidType = errors.New("invalid type")
|
||||
errOpNoSupport = errors.New("operation not supported")
|
||||
)
|
||||
|
||||
// SocketOf returns the socket descriptor of c.
|
||||
func SocketOf(c net.Conn) (uintptr, error) {
|
||||
switch c.(type) {
|
||||
case *net.TCPConn, *net.UDPConn, *net.IPConn, *net.UnixConn:
|
||||
return socketOf(c)
|
||||
default:
|
||||
return 0, errInvalidType
|
||||
}
|
||||
}
|
||||
|
||||
// PacketSocketOf returns the socket descriptor of c.
|
||||
func PacketSocketOf(c net.PacketConn) (uintptr, error) {
|
||||
switch c.(type) {
|
||||
case *net.UDPConn, *net.IPConn, *net.UnixConn:
|
||||
return socketOf(c.(net.Conn))
|
||||
default:
|
||||
return 0, errInvalidType
|
||||
}
|
||||
}
|
||||
37
vendor/golang.org/x/net/internal/netreflect/socket_19.go
сгенерированный
поставляемый
37
vendor/golang.org/x/net/internal/netreflect/socket_19.go
сгенерированный
поставляемый
@@ -1,37 +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
|
||||
|
||||
package netreflect
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidType = errors.New("invalid type")
|
||||
errOpNoSupport = errors.New("operation not supported")
|
||||
)
|
||||
|
||||
// SocketOf returns the socket descriptor of c.
|
||||
func SocketOf(c net.Conn) (uintptr, error) {
|
||||
switch c.(type) {
|
||||
case *net.TCPConn, *net.UDPConn, *net.IPConn, *net.UnixConn:
|
||||
return 0, errOpNoSupport
|
||||
default:
|
||||
return 0, errInvalidType
|
||||
}
|
||||
}
|
||||
|
||||
// PacketSocketOf returns the socket descriptor of c.
|
||||
func PacketSocketOf(c net.PacketConn) (uintptr, error) {
|
||||
switch c.(type) {
|
||||
case *net.UDPConn, *net.IPConn, *net.UnixConn:
|
||||
return 0, errOpNoSupport
|
||||
default:
|
||||
return 0, errInvalidType
|
||||
}
|
||||
}
|
||||
31
vendor/golang.org/x/net/internal/netreflect/socket_posix.go
сгенерированный
поставляемый
31
vendor/golang.org/x/net/internal/netreflect/socket_posix.go
сгенерированный
поставляемый
@@ -1,31 +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 !go1.9
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
|
||||
|
||||
package netreflect
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func socketOf(c net.Conn) (uintptr, error) {
|
||||
v := reflect.ValueOf(c)
|
||||
switch e := v.Elem(); e.Kind() {
|
||||
case reflect.Struct:
|
||||
fd := e.FieldByName("conn").FieldByName("fd")
|
||||
switch e := fd.Elem(); e.Kind() {
|
||||
case reflect.Struct:
|
||||
sysfd := e.FieldByName("sysfd")
|
||||
if runtime.GOOS == "windows" {
|
||||
return uintptr(sysfd.Uint()), nil
|
||||
}
|
||||
return uintptr(sysfd.Int()), nil
|
||||
}
|
||||
}
|
||||
return 0, errInvalidType
|
||||
}
|
||||
12
vendor/golang.org/x/net/internal/netreflect/socket_stub.go
сгенерированный
поставляемый
12
vendor/golang.org/x/net/internal/netreflect/socket_stub.go
сгенерированный
поставляемый
@@ -1,12 +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 !go1.9
|
||||
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
|
||||
|
||||
package netreflect
|
||||
|
||||
import "net"
|
||||
|
||||
func socketOf(c net.Conn) (uintptr, error) { return 0, errOpNoSupport }
|
||||
65
vendor/golang.org/x/net/internal/netreflect/socket_test.go
сгенерированный
поставляемый
65
vendor/golang.org/x/net/internal/netreflect/socket_test.go
сгенерированный
поставляемый
@@ -1,65 +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 !go1.9
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
|
||||
|
||||
package netreflect_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/internal/netreflect"
|
||||
"golang.org/x/net/internal/nettest"
|
||||
)
|
||||
|
||||
func TestSocketOf(t *testing.T) {
|
||||
for _, network := range []string{"tcp", "unix", "unixpacket"} {
|
||||
if !nettest.TestableNetwork(network) {
|
||||
continue
|
||||
}
|
||||
ln, err := nettest.NewLocalListener(network)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
defer func() {
|
||||
path := ln.Addr().String()
|
||||
ln.Close()
|
||||
if network == "unix" || network == "unixpacket" {
|
||||
os.Remove(path)
|
||||
}
|
||||
}()
|
||||
c, err := net.Dial(ln.Addr().Network(), ln.Addr().String())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
defer c.Close()
|
||||
if _, err := netreflect.SocketOf(c); err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPacketSocketOf(t *testing.T) {
|
||||
for _, network := range []string{"udp", "unixgram"} {
|
||||
if !nettest.TestableNetwork(network) {
|
||||
continue
|
||||
}
|
||||
c, err := nettest.NewLocalPacketListener(network)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
defer c.Close()
|
||||
if _, err := netreflect.PacketSocketOf(c); err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
11
vendor/golang.org/x/net/internal/socket/cmsghdr.go
сгенерированный
поставляемый
Обычный файл
11
vendor/golang.org/x/net/internal/socket/cmsghdr.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
func (h *cmsghdr) len() int { return int(h.Len) }
|
||||
func (h *cmsghdr) lvl() int { return int(h.Level) }
|
||||
func (h *cmsghdr) typ() int { return int(h.Type) }
|
||||
13
vendor/golang.org/x/net/internal/socket/cmsghdr_bsd.go
сгенерированный
поставляемый
Обычный файл
13
vendor/golang.org/x/net/internal/socket/cmsghdr_bsd.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,13 @@
|
||||
// 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 netbsd openbsd
|
||||
|
||||
package socket
|
||||
|
||||
func (h *cmsghdr) set(l, lvl, typ int) {
|
||||
h.Len = uint32(l)
|
||||
h.Level = int32(lvl)
|
||||
h.Type = int32(typ)
|
||||
}
|
||||
14
vendor/golang.org/x/net/internal/socket/cmsghdr_linux_32bit.go
сгенерированный
поставляемый
Обычный файл
14
vendor/golang.org/x/net/internal/socket/cmsghdr_linux_32bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,14 @@
|
||||
// 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 arm mips mipsle 386
|
||||
// +build linux
|
||||
|
||||
package socket
|
||||
|
||||
func (h *cmsghdr) set(l, lvl, typ int) {
|
||||
h.Len = uint32(l)
|
||||
h.Level = int32(lvl)
|
||||
h.Type = int32(typ)
|
||||
}
|
||||
14
vendor/golang.org/x/net/internal/socket/cmsghdr_linux_64bit.go
сгенерированный
поставляемый
Обычный файл
14
vendor/golang.org/x/net/internal/socket/cmsghdr_linux_64bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,14 @@
|
||||
// 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 arm64 amd64 ppc64 ppc64le mips64 mips64le s390x
|
||||
// +build linux
|
||||
|
||||
package socket
|
||||
|
||||
func (h *cmsghdr) set(l, lvl, typ int) {
|
||||
h.Len = uint64(l)
|
||||
h.Level = int32(lvl)
|
||||
h.Type = int32(typ)
|
||||
}
|
||||
14
vendor/golang.org/x/net/internal/socket/cmsghdr_solaris_64bit.go
сгенерированный
поставляемый
Обычный файл
14
vendor/golang.org/x/net/internal/socket/cmsghdr_solaris_64bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,14 @@
|
||||
// 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 amd64
|
||||
// +build solaris
|
||||
|
||||
package socket
|
||||
|
||||
func (h *cmsghdr) set(l, lvl, typ int) {
|
||||
h.Len = uint32(l)
|
||||
h.Level = int32(lvl)
|
||||
h.Type = int32(typ)
|
||||
}
|
||||
17
vendor/golang.org/x/net/internal/socket/cmsghdr_stub.go
сгенерированный
поставляемый
Обычный файл
17
vendor/golang.org/x/net/internal/socket/cmsghdr_stub.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,17 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
type cmsghdr struct{}
|
||||
|
||||
const sizeofCmsghdr = 0
|
||||
|
||||
func (h *cmsghdr) len() int { return 0 }
|
||||
func (h *cmsghdr) lvl() int { return 0 }
|
||||
func (h *cmsghdr) typ() int { return 0 }
|
||||
|
||||
func (h *cmsghdr) set(l, lvl, typ int) {}
|
||||
44
vendor/golang.org/x/net/internal/socket/defs_darwin.go
сгенерированный
поставляемый
Обычный файл
44
vendor/golang.org/x/net/internal/socket/defs_darwin.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,44 @@
|
||||
// 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 ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
44
vendor/golang.org/x/net/internal/socket/defs_dragonfly.go
сгенерированный
поставляемый
Обычный файл
44
vendor/golang.org/x/net/internal/socket/defs_dragonfly.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,44 @@
|
||||
// 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 ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
44
vendor/golang.org/x/net/internal/socket/defs_freebsd.go
сгенерированный
поставляемый
Обычный файл
44
vendor/golang.org/x/net/internal/socket/defs_freebsd.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,44 @@
|
||||
// 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 ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
49
vendor/golang.org/x/net/internal/socket/defs_linux.go
сгенерированный
поставляемый
Обычный файл
49
vendor/golang.org/x/net/internal/socket/defs_linux.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,49 @@
|
||||
// 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 ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <linux/in.h>
|
||||
#include <linux/in6.h>
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <sys/socket.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type mmsghdr C.struct_mmsghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofMmsghdr = C.sizeof_struct_mmsghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
47
vendor/golang.org/x/net/internal/socket/defs_netbsd.go
сгенерированный
поставляемый
Обычный файл
47
vendor/golang.org/x/net/internal/socket/defs_netbsd.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,47 @@
|
||||
// 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 ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type mmsghdr C.struct_mmsghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofMmsghdr = C.sizeof_struct_mmsghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
44
vendor/golang.org/x/net/internal/socket/defs_openbsd.go
сгенерированный
поставляемый
Обычный файл
44
vendor/golang.org/x/net/internal/socket/defs_openbsd.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,44 @@
|
||||
// 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 ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
44
vendor/golang.org/x/net/internal/socket/defs_solaris.go
сгенерированный
поставляемый
Обычный файл
44
vendor/golang.org/x/net/internal/socket/defs_solaris.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,44 @@
|
||||
// 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 ignore
|
||||
|
||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
||||
|
||||
package socket
|
||||
|
||||
/*
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
sysAF_UNSPEC = C.AF_UNSPEC
|
||||
sysAF_INET = C.AF_INET
|
||||
sysAF_INET6 = C.AF_INET6
|
||||
|
||||
sysSOCK_RAW = C.SOCK_RAW
|
||||
)
|
||||
|
||||
type iovec C.struct_iovec
|
||||
|
||||
type msghdr C.struct_msghdr
|
||||
|
||||
type cmsghdr C.struct_cmsghdr
|
||||
|
||||
type sockaddrInet C.struct_sockaddr_in
|
||||
|
||||
type sockaddrInet6 C.struct_sockaddr_in6
|
||||
|
||||
const (
|
||||
sizeofIovec = C.sizeof_struct_iovec
|
||||
sizeofMsghdr = C.sizeof_struct_msghdr
|
||||
sizeofCmsghdr = C.sizeof_struct_cmsghdr
|
||||
|
||||
sizeofSockaddrInet = C.sizeof_struct_sockaddr_in
|
||||
sizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6
|
||||
)
|
||||
31
vendor/golang.org/x/net/internal/socket/error_unix.go
сгенерированный
поставляемый
Обычный файл
31
vendor/golang.org/x/net/internal/socket/error_unix.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
import "syscall"
|
||||
|
||||
var (
|
||||
errEAGAIN error = syscall.EAGAIN
|
||||
errEINVAL error = syscall.EINVAL
|
||||
errENOENT error = syscall.ENOENT
|
||||
)
|
||||
|
||||
// errnoErr returns common boxed Errno values, to prevent allocations
|
||||
// at runtime.
|
||||
func errnoErr(errno syscall.Errno) error {
|
||||
switch errno {
|
||||
case 0:
|
||||
return nil
|
||||
case syscall.EAGAIN:
|
||||
return errEAGAIN
|
||||
case syscall.EINVAL:
|
||||
return errEINVAL
|
||||
case syscall.ENOENT:
|
||||
return errENOENT
|
||||
}
|
||||
return errno
|
||||
}
|
||||
26
vendor/golang.org/x/net/internal/socket/error_windows.go
сгенерированный
поставляемый
Обычный файл
26
vendor/golang.org/x/net/internal/socket/error_windows.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,26 @@
|
||||
// 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.
|
||||
|
||||
package socket
|
||||
|
||||
import "syscall"
|
||||
|
||||
var (
|
||||
errERROR_IO_PENDING error = syscall.ERROR_IO_PENDING
|
||||
errEINVAL error = syscall.EINVAL
|
||||
)
|
||||
|
||||
// errnoErr returns common boxed Errno values, to prevent allocations
|
||||
// at runtime.
|
||||
func errnoErr(errno syscall.Errno) error {
|
||||
switch errno {
|
||||
case 0:
|
||||
return nil
|
||||
case syscall.ERROR_IO_PENDING:
|
||||
return errERROR_IO_PENDING
|
||||
case syscall.EINVAL:
|
||||
return errEINVAL
|
||||
}
|
||||
return errno
|
||||
}
|
||||
15
vendor/golang.org/x/net/internal/socket/iovec_32bit.go
сгенерированный
поставляемый
Обычный файл
15
vendor/golang.org/x/net/internal/socket/iovec_32bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,15 @@
|
||||
// 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 arm mips mipsle 386
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (v *iovec) set(b []byte) {
|
||||
v.Base = (*byte)(unsafe.Pointer(&b[0]))
|
||||
v.Len = uint32(len(b))
|
||||
}
|
||||
15
vendor/golang.org/x/net/internal/socket/iovec_64bit.go
сгенерированный
поставляемый
Обычный файл
15
vendor/golang.org/x/net/internal/socket/iovec_64bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,15 @@
|
||||
// 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 arm64 amd64 ppc64 ppc64le mips64 mips64le s390x
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (v *iovec) set(b []byte) {
|
||||
v.Base = (*byte)(unsafe.Pointer(&b[0]))
|
||||
v.Len = uint64(len(b))
|
||||
}
|
||||
15
vendor/golang.org/x/net/internal/socket/iovec_solaris_64bit.go
сгенерированный
поставляемый
Обычный файл
15
vendor/golang.org/x/net/internal/socket/iovec_solaris_64bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,15 @@
|
||||
// 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 amd64
|
||||
// +build solaris
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (v *iovec) set(b []byte) {
|
||||
v.Base = (*int8)(unsafe.Pointer(&b[0]))
|
||||
v.Len = uint64(len(b))
|
||||
}
|
||||
11
vendor/golang.org/x/net/internal/socket/iovec_stub.go
сгенерированный
поставляемый
Обычный файл
11
vendor/golang.org/x/net/internal/socket/iovec_stub.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
type iovec struct{}
|
||||
|
||||
func (v *iovec) set(b []byte) {}
|
||||
21
vendor/golang.org/x/net/internal/socket/mmsghdr_stub.go
сгенерированный
поставляемый
Обычный файл
21
vendor/golang.org/x/net/internal/socket/mmsghdr_stub.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,21 @@
|
||||
// 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 !linux,!netbsd
|
||||
|
||||
package socket
|
||||
|
||||
import "net"
|
||||
|
||||
type mmsghdr struct{}
|
||||
|
||||
type mmsghdrs []mmsghdr
|
||||
|
||||
func (hs mmsghdrs) pack(ms []Message, parseFn func([]byte, string) (net.Addr, error), marshalFn func(net.Addr) []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hs mmsghdrs) unpack(ms []Message, parseFn func([]byte, string) (net.Addr, error), hint string) error {
|
||||
return nil
|
||||
}
|
||||
42
vendor/golang.org/x/net/internal/socket/mmsghdr_unix.go
сгенерированный
поставляемый
Обычный файл
42
vendor/golang.org/x/net/internal/socket/mmsghdr_unix.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,42 @@
|
||||
// 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 linux netbsd
|
||||
|
||||
package socket
|
||||
|
||||
import "net"
|
||||
|
||||
type mmsghdrs []mmsghdr
|
||||
|
||||
func (hs mmsghdrs) pack(ms []Message, parseFn func([]byte, string) (net.Addr, error), marshalFn func(net.Addr) []byte) error {
|
||||
for i := range hs {
|
||||
vs := make([]iovec, len(ms[i].Buffers))
|
||||
var sa []byte
|
||||
if parseFn != nil {
|
||||
sa = make([]byte, sizeofSockaddrInet6)
|
||||
}
|
||||
if marshalFn != nil {
|
||||
sa = marshalFn(ms[i].Addr)
|
||||
}
|
||||
hs[i].Hdr.pack(vs, ms[i].Buffers, ms[i].OOB, sa)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hs mmsghdrs) unpack(ms []Message, parseFn func([]byte, string) (net.Addr, error), hint string) error {
|
||||
for i := range hs {
|
||||
ms[i].N = int(hs[i].Len)
|
||||
ms[i].NN = hs[i].Hdr.controllen()
|
||||
ms[i].Flags = hs[i].Hdr.flags()
|
||||
if parseFn != nil {
|
||||
var err error
|
||||
ms[i].Addr, err = parseFn(hs[i].Hdr.name(), hint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
39
vendor/golang.org/x/net/internal/socket/msghdr_bsd.go
сгенерированный
поставляемый
Обычный файл
39
vendor/golang.org/x/net/internal/socket/msghdr_bsd.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,39 @@
|
||||
// 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 netbsd openbsd
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {
|
||||
for i := range vs {
|
||||
vs[i].set(bs[i])
|
||||
}
|
||||
h.setIov(vs)
|
||||
if len(oob) > 0 {
|
||||
h.Control = (*byte)(unsafe.Pointer(&oob[0]))
|
||||
h.Controllen = uint32(len(oob))
|
||||
}
|
||||
if sa != nil {
|
||||
h.Name = (*byte)(unsafe.Pointer(&sa[0]))
|
||||
h.Namelen = uint32(len(sa))
|
||||
}
|
||||
}
|
||||
|
||||
func (h *msghdr) name() []byte {
|
||||
if h.Name != nil && h.Namelen > 0 {
|
||||
return (*[sizeofSockaddrInet6]byte)(unsafe.Pointer(h.Name))[:h.Namelen]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *msghdr) controllen() int {
|
||||
return int(h.Controllen)
|
||||
}
|
||||
|
||||
func (h *msghdr) flags() int {
|
||||
return int(h.Flags)
|
||||
}
|
||||
12
vendor/golang.org/x/net/internal/socket/msghdr_bsdvar.go
сгенерированный
поставляемый
Обычный файл
12
vendor/golang.org/x/net/internal/socket/msghdr_bsdvar.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,12 @@
|
||||
// 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 netbsd
|
||||
|
||||
package socket
|
||||
|
||||
func (h *msghdr) setIov(vs []iovec) {
|
||||
h.Iov = &vs[0]
|
||||
h.Iovlen = int32(len(vs))
|
||||
}
|
||||
36
vendor/golang.org/x/net/internal/socket/msghdr_linux.go
сгенерированный
поставляемый
Обычный файл
36
vendor/golang.org/x/net/internal/socket/msghdr_linux.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {
|
||||
for i := range vs {
|
||||
vs[i].set(bs[i])
|
||||
}
|
||||
h.setIov(vs)
|
||||
if len(oob) > 0 {
|
||||
h.setControl(oob)
|
||||
}
|
||||
if sa != nil {
|
||||
h.Name = (*byte)(unsafe.Pointer(&sa[0]))
|
||||
h.Namelen = uint32(len(sa))
|
||||
}
|
||||
}
|
||||
|
||||
func (h *msghdr) name() []byte {
|
||||
if h.Name != nil && h.Namelen > 0 {
|
||||
return (*[sizeofSockaddrInet6]byte)(unsafe.Pointer(h.Name))[:h.Namelen]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *msghdr) controllen() int {
|
||||
return int(h.Controllen)
|
||||
}
|
||||
|
||||
func (h *msghdr) flags() int {
|
||||
return int(h.Flags)
|
||||
}
|
||||
20
vendor/golang.org/x/net/internal/socket/msghdr_linux_32bit.go
сгенерированный
поставляемый
Обычный файл
20
vendor/golang.org/x/net/internal/socket/msghdr_linux_32bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,20 @@
|
||||
// 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 arm mips mipsle 386
|
||||
// +build linux
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (h *msghdr) setIov(vs []iovec) {
|
||||
h.Iov = &vs[0]
|
||||
h.Iovlen = uint32(len(vs))
|
||||
}
|
||||
|
||||
func (h *msghdr) setControl(b []byte) {
|
||||
h.Control = (*byte)(unsafe.Pointer(&b[0]))
|
||||
h.Controllen = uint32(len(b))
|
||||
}
|
||||
20
vendor/golang.org/x/net/internal/socket/msghdr_linux_64bit.go
сгенерированный
поставляемый
Обычный файл
20
vendor/golang.org/x/net/internal/socket/msghdr_linux_64bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,20 @@
|
||||
// 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 arm64 amd64 ppc64 ppc64le mips64 mips64le s390x
|
||||
// +build linux
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (h *msghdr) setIov(vs []iovec) {
|
||||
h.Iov = &vs[0]
|
||||
h.Iovlen = uint64(len(vs))
|
||||
}
|
||||
|
||||
func (h *msghdr) setControl(b []byte) {
|
||||
h.Control = (*byte)(unsafe.Pointer(&b[0]))
|
||||
h.Controllen = uint64(len(b))
|
||||
}
|
||||
10
vendor/golang.org/x/net/internal/socket/msghdr_openbsd.go
сгенерированный
поставляемый
Обычный файл
10
vendor/golang.org/x/net/internal/socket/msghdr_openbsd.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,10 @@
|
||||
// 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.
|
||||
|
||||
package socket
|
||||
|
||||
func (h *msghdr) setIov(vs []iovec) {
|
||||
h.Iov = &vs[0]
|
||||
h.Iovlen = uint32(len(vs))
|
||||
}
|
||||
34
vendor/golang.org/x/net/internal/socket/msghdr_solaris_64bit.go
сгенерированный
поставляемый
Обычный файл
34
vendor/golang.org/x/net/internal/socket/msghdr_solaris_64bit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,34 @@
|
||||
// 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 amd64
|
||||
// +build solaris
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {
|
||||
for i := range vs {
|
||||
vs[i].set(bs[i])
|
||||
}
|
||||
h.Iov = &vs[0]
|
||||
h.Iovlen = int32(len(vs))
|
||||
if len(oob) > 0 {
|
||||
h.Accrights = (*int8)(unsafe.Pointer(&oob[0]))
|
||||
h.Accrightslen = int32(len(oob))
|
||||
}
|
||||
if sa != nil {
|
||||
h.Name = (*byte)(unsafe.Pointer(&sa[0]))
|
||||
h.Namelen = uint32(len(sa))
|
||||
}
|
||||
}
|
||||
|
||||
func (h *msghdr) controllen() int {
|
||||
return int(h.Accrightslen)
|
||||
}
|
||||
|
||||
func (h *msghdr) flags() int {
|
||||
return int(NativeEndian.Uint32(h.Pad_cgo_2[:]))
|
||||
}
|
||||
14
vendor/golang.org/x/net/internal/socket/msghdr_stub.go
сгенерированный
поставляемый
Обычный файл
14
vendor/golang.org/x/net/internal/socket/msghdr_stub.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,14 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
type msghdr struct{}
|
||||
|
||||
func (h *msghdr) pack(vs []iovec, bs [][]byte, oob []byte, sa []byte) {}
|
||||
func (h *msghdr) name() []byte { return nil }
|
||||
func (h *msghdr) controllen() int { return 0 }
|
||||
func (h *msghdr) flags() int { return 0 }
|
||||
66
vendor/golang.org/x/net/internal/socket/rawconn.go
сгенерированный
поставляемый
Обычный файл
66
vendor/golang.org/x/net/internal/socket/rawconn.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,66 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// A Conn represents a raw connection.
|
||||
type Conn struct {
|
||||
network string
|
||||
c syscall.RawConn
|
||||
}
|
||||
|
||||
// NewConn returns a new raw connection.
|
||||
func NewConn(c net.Conn) (*Conn, error) {
|
||||
var err error
|
||||
var cc Conn
|
||||
switch c := c.(type) {
|
||||
case *net.TCPConn:
|
||||
cc.network = "tcp"
|
||||
cc.c, err = c.SyscallConn()
|
||||
case *net.UDPConn:
|
||||
cc.network = "udp"
|
||||
cc.c, err = c.SyscallConn()
|
||||
case *net.IPConn:
|
||||
cc.network = "ip"
|
||||
cc.c, err = c.SyscallConn()
|
||||
default:
|
||||
return nil, errors.New("unknown connection type")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cc, nil
|
||||
}
|
||||
|
||||
func (o *Option) get(c *Conn, b []byte) (int, error) {
|
||||
var operr error
|
||||
var n int
|
||||
fn := func(s uintptr) {
|
||||
n, operr = getsockopt(s, o.Level, o.Name, b)
|
||||
}
|
||||
if err := c.c.Control(fn); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return n, os.NewSyscallError("getsockopt", operr)
|
||||
}
|
||||
|
||||
func (o *Option) set(c *Conn, b []byte) error {
|
||||
var operr error
|
||||
fn := func(s uintptr) {
|
||||
operr = setsockopt(s, o.Level, o.Name, b)
|
||||
}
|
||||
if err := c.c.Control(fn); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", operr)
|
||||
}
|
||||
74
vendor/golang.org/x/net/internal/socket/rawconn_mmsg.go
сгенерированный
поставляемый
Обычный файл
74
vendor/golang.org/x/net/internal/socket/rawconn_mmsg.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,74 @@
|
||||
// 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 linux
|
||||
|
||||
package socket
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) {
|
||||
hs := make(mmsghdrs, len(ms))
|
||||
var parseFn func([]byte, string) (net.Addr, error)
|
||||
if c.network != "tcp" {
|
||||
parseFn = parseInetAddr
|
||||
}
|
||||
if err := hs.pack(ms, parseFn, nil); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var operr error
|
||||
var n int
|
||||
fn := func(s uintptr) bool {
|
||||
n, operr = recvmmsg(s, hs, flags)
|
||||
if operr == syscall.EAGAIN {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
if err := c.c.Read(fn); err != nil {
|
||||
return n, err
|
||||
}
|
||||
if operr != nil {
|
||||
return n, os.NewSyscallError("recvmmsg", operr)
|
||||
}
|
||||
if err := hs[:n].unpack(ms[:n], parseFn, c.network); err != nil {
|
||||
return n, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (c *Conn) sendMsgs(ms []Message, flags int) (int, error) {
|
||||
hs := make(mmsghdrs, len(ms))
|
||||
var marshalFn func(net.Addr) []byte
|
||||
if c.network != "tcp" {
|
||||
marshalFn = marshalInetAddr
|
||||
}
|
||||
if err := hs.pack(ms, nil, marshalFn); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var operr error
|
||||
var n int
|
||||
fn := func(s uintptr) bool {
|
||||
n, operr = sendmmsg(s, hs, flags)
|
||||
if operr == syscall.EAGAIN {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
if err := c.c.Write(fn); err != nil {
|
||||
return n, err
|
||||
}
|
||||
if operr != nil {
|
||||
return n, os.NewSyscallError("sendmmsg", operr)
|
||||
}
|
||||
if err := hs[:n].unpack(ms[:n], nil, ""); err != nil {
|
||||
return n, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
77
vendor/golang.org/x/net/internal/socket/rawconn_msg.go
сгенерированный
поставляемый
Обычный файл
77
vendor/golang.org/x/net/internal/socket/rawconn_msg.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,77 @@
|
||||
// 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 windows
|
||||
|
||||
package socket
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func (c *Conn) recvMsg(m *Message, flags int) error {
|
||||
var h msghdr
|
||||
vs := make([]iovec, len(m.Buffers))
|
||||
var sa []byte
|
||||
if c.network != "tcp" {
|
||||
sa = make([]byte, sizeofSockaddrInet6)
|
||||
}
|
||||
h.pack(vs, m.Buffers, m.OOB, sa)
|
||||
var operr error
|
||||
var n int
|
||||
fn := func(s uintptr) bool {
|
||||
n, operr = recvmsg(s, &h, flags)
|
||||
if operr == syscall.EAGAIN {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
if err := c.c.Read(fn); err != nil {
|
||||
return err
|
||||
}
|
||||
if operr != nil {
|
||||
return os.NewSyscallError("recvmsg", operr)
|
||||
}
|
||||
if c.network != "tcp" {
|
||||
var err error
|
||||
m.Addr, err = parseInetAddr(sa[:], c.network)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
m.N = n
|
||||
m.NN = h.controllen()
|
||||
m.Flags = h.flags()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Conn) sendMsg(m *Message, flags int) error {
|
||||
var h msghdr
|
||||
vs := make([]iovec, len(m.Buffers))
|
||||
var sa []byte
|
||||
if m.Addr != nil {
|
||||
sa = marshalInetAddr(m.Addr)
|
||||
}
|
||||
h.pack(vs, m.Buffers, m.OOB, sa)
|
||||
var operr error
|
||||
var n int
|
||||
fn := func(s uintptr) bool {
|
||||
n, operr = sendmsg(s, &h, flags)
|
||||
if operr == syscall.EAGAIN {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
if err := c.c.Write(fn); err != nil {
|
||||
return err
|
||||
}
|
||||
if operr != nil {
|
||||
return os.NewSyscallError("sendmsg", operr)
|
||||
}
|
||||
m.N = n
|
||||
m.NN = len(m.OOB)
|
||||
return nil
|
||||
}
|
||||
18
vendor/golang.org/x/net/internal/socket/rawconn_nommsg.go
сгенерированный
поставляемый
Обычный файл
18
vendor/golang.org/x/net/internal/socket/rawconn_nommsg.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,18 @@
|
||||
// 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 !linux
|
||||
|
||||
package socket
|
||||
|
||||
import "errors"
|
||||
|
||||
func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (c *Conn) sendMsgs(ms []Message, flags int) (int, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
18
vendor/golang.org/x/net/internal/socket/rawconn_nomsg.go
сгенерированный
поставляемый
Обычный файл
18
vendor/golang.org/x/net/internal/socket/rawconn_nomsg.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,18 @@
|
||||
// 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,!windows
|
||||
|
||||
package socket
|
||||
|
||||
import "errors"
|
||||
|
||||
func (c *Conn) recvMsg(m *Message, flags int) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (c *Conn) sendMsg(m *Message, flags int) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
25
vendor/golang.org/x/net/internal/socket/rawconn_stub.go
сгенерированный
поставляемый
Обычный файл
25
vendor/golang.org/x/net/internal/socket/rawconn_stub.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,25 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
import "errors"
|
||||
|
||||
func (c *Conn) recvMsg(m *Message, flags int) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (c *Conn) sendMsg(m *Message, flags int) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (c *Conn) recvMsgs(ms []Message, flags int) (int, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (c *Conn) sendMsgs(ms []Message, flags int) (int, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
62
vendor/golang.org/x/net/internal/socket/reflect.go
сгенерированный
поставляемый
Обычный файл
62
vendor/golang.org/x/net/internal/socket/reflect.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,62 @@
|
||||
// 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
|
||||
|
||||
package socket
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// A Conn represents a raw connection.
|
||||
type Conn struct {
|
||||
c net.Conn
|
||||
}
|
||||
|
||||
// NewConn returns a new raw connection.
|
||||
func NewConn(c net.Conn) (*Conn, error) {
|
||||
return &Conn{c: c}, nil
|
||||
}
|
||||
|
||||
func (o *Option) get(c *Conn, b []byte) (int, error) {
|
||||
s, err := socketOf(c.c)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n, err := getsockopt(s, o.Level, o.Name, b)
|
||||
return n, os.NewSyscallError("getsockopt", err)
|
||||
}
|
||||
|
||||
func (o *Option) set(c *Conn, b []byte) error {
|
||||
s, err := socketOf(c.c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.NewSyscallError("setsockopt", setsockopt(s, o.Level, o.Name, b))
|
||||
}
|
||||
|
||||
func socketOf(c net.Conn) (uintptr, error) {
|
||||
switch c.(type) {
|
||||
case *net.TCPConn, *net.UDPConn, *net.IPConn:
|
||||
v := reflect.ValueOf(c)
|
||||
switch e := v.Elem(); e.Kind() {
|
||||
case reflect.Struct:
|
||||
fd := e.FieldByName("conn").FieldByName("fd")
|
||||
switch e := fd.Elem(); e.Kind() {
|
||||
case reflect.Struct:
|
||||
sysfd := e.FieldByName("sysfd")
|
||||
if runtime.GOOS == "windows" {
|
||||
return uintptr(sysfd.Uint()), nil
|
||||
}
|
||||
return uintptr(sysfd.Int()), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, errors.New("invalid type")
|
||||
}
|
||||
285
vendor/golang.org/x/net/internal/socket/socket.go
сгенерированный
поставляемый
Обычный файл
285
vendor/golang.org/x/net/internal/socket/socket.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,285 @@
|
||||
// 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.
|
||||
|
||||
// Package socket provides a portable interface for socket system
|
||||
// calls.
|
||||
package socket // import "golang.org/x/net/internal/socket"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// An Option represents a sticky socket option.
|
||||
type Option struct {
|
||||
Level int // level
|
||||
Name int // name; must be equal or greater than 1
|
||||
Len int // length of value in bytes; must be equal or greater than 1
|
||||
}
|
||||
|
||||
// Get reads a value for the option from the kernel.
|
||||
// It returns the number of bytes written into b.
|
||||
func (o *Option) Get(c *Conn, b []byte) (int, error) {
|
||||
if o.Name < 1 || o.Len < 1 {
|
||||
return 0, errors.New("invalid option")
|
||||
}
|
||||
if len(b) < o.Len {
|
||||
return 0, errors.New("short buffer")
|
||||
}
|
||||
return o.get(c, b)
|
||||
}
|
||||
|
||||
// GetInt returns an integer value for the option.
|
||||
//
|
||||
// The Len field of Option must be either 1 or 4.
|
||||
func (o *Option) GetInt(c *Conn) (int, error) {
|
||||
if o.Len != 1 && o.Len != 4 {
|
||||
return 0, errors.New("invalid option")
|
||||
}
|
||||
var b []byte
|
||||
var bb [4]byte
|
||||
if o.Len == 1 {
|
||||
b = bb[:1]
|
||||
} else {
|
||||
b = bb[:4]
|
||||
}
|
||||
n, err := o.get(c, b)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if n != o.Len {
|
||||
return 0, errors.New("invalid option length")
|
||||
}
|
||||
if o.Len == 1 {
|
||||
return int(b[0]), nil
|
||||
}
|
||||
return int(NativeEndian.Uint32(b[:4])), nil
|
||||
}
|
||||
|
||||
// Set writes the option and value to the kernel.
|
||||
func (o *Option) Set(c *Conn, b []byte) error {
|
||||
if o.Name < 1 || o.Len < 1 {
|
||||
return errors.New("invalid option")
|
||||
}
|
||||
if len(b) < o.Len {
|
||||
return errors.New("short buffer")
|
||||
}
|
||||
return o.set(c, b)
|
||||
}
|
||||
|
||||
// SetInt writes the option and value to the kernel.
|
||||
//
|
||||
// The Len field of Option must be either 1 or 4.
|
||||
func (o *Option) SetInt(c *Conn, v int) error {
|
||||
if o.Len != 1 && o.Len != 4 {
|
||||
return errors.New("invalid option")
|
||||
}
|
||||
var b []byte
|
||||
if o.Len == 1 {
|
||||
b = []byte{byte(v)}
|
||||
} else {
|
||||
var bb [4]byte
|
||||
NativeEndian.PutUint32(bb[:o.Len], uint32(v))
|
||||
b = bb[:4]
|
||||
}
|
||||
return o.set(c, b)
|
||||
}
|
||||
|
||||
func controlHeaderLen() int {
|
||||
return roundup(sizeofCmsghdr)
|
||||
}
|
||||
|
||||
func controlMessageLen(dataLen int) int {
|
||||
return roundup(sizeofCmsghdr) + dataLen
|
||||
}
|
||||
|
||||
// ControlMessageSpace returns the whole length of control message.
|
||||
func ControlMessageSpace(dataLen int) int {
|
||||
return roundup(sizeofCmsghdr) + roundup(dataLen)
|
||||
}
|
||||
|
||||
// A ControlMessage represents the head message in a stream of control
|
||||
// messages.
|
||||
//
|
||||
// A control message comprises of a header, data and a few padding
|
||||
// fields to conform to the interface to the kernel.
|
||||
//
|
||||
// See RFC 3542 for further information.
|
||||
type ControlMessage []byte
|
||||
|
||||
// Data returns the data field of the control message at the head on
|
||||
// w.
|
||||
func (m ControlMessage) Data(dataLen int) []byte {
|
||||
l := controlHeaderLen()
|
||||
if len(m) < l || len(m) < l+dataLen {
|
||||
return nil
|
||||
}
|
||||
return m[l : l+dataLen]
|
||||
}
|
||||
|
||||
// Next returns the control message at the next on w.
|
||||
//
|
||||
// Next works only for standard control messages.
|
||||
func (m ControlMessage) Next(dataLen int) ControlMessage {
|
||||
l := ControlMessageSpace(dataLen)
|
||||
if len(m) < l {
|
||||
return nil
|
||||
}
|
||||
return m[l:]
|
||||
}
|
||||
|
||||
// MarshalHeader marshals the header fields of the control message at
|
||||
// the head on w.
|
||||
func (m ControlMessage) MarshalHeader(lvl, typ, dataLen int) error {
|
||||
if len(m) < controlHeaderLen() {
|
||||
return errors.New("short message")
|
||||
}
|
||||
h := (*cmsghdr)(unsafe.Pointer(&m[0]))
|
||||
h.set(controlMessageLen(dataLen), lvl, typ)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseHeader parses and returns the header fields of the control
|
||||
// message at the head on w.
|
||||
func (m ControlMessage) ParseHeader() (lvl, typ, dataLen int, err error) {
|
||||
l := controlHeaderLen()
|
||||
if len(m) < l {
|
||||
return 0, 0, 0, errors.New("short message")
|
||||
}
|
||||
h := (*cmsghdr)(unsafe.Pointer(&m[0]))
|
||||
return h.lvl(), h.typ(), int(uint64(h.len()) - uint64(l)), nil
|
||||
}
|
||||
|
||||
// Marshal marshals the control message at the head on w, and returns
|
||||
// the next control message.
|
||||
func (m ControlMessage) Marshal(lvl, typ int, data []byte) (ControlMessage, error) {
|
||||
l := len(data)
|
||||
if len(m) < ControlMessageSpace(l) {
|
||||
return nil, errors.New("short message")
|
||||
}
|
||||
h := (*cmsghdr)(unsafe.Pointer(&m[0]))
|
||||
h.set(controlMessageLen(l), lvl, typ)
|
||||
if l > 0 {
|
||||
copy(m.Data(l), data)
|
||||
}
|
||||
return m.Next(l), nil
|
||||
}
|
||||
|
||||
// Parse parses w as a single or multiple control messages.
|
||||
//
|
||||
// Parse works for both standard and compatible messages.
|
||||
func (m ControlMessage) Parse() ([]ControlMessage, error) {
|
||||
var ms []ControlMessage
|
||||
for len(m) >= controlHeaderLen() {
|
||||
h := (*cmsghdr)(unsafe.Pointer(&m[0]))
|
||||
l := h.len()
|
||||
if l <= 0 {
|
||||
return nil, errors.New("invalid header length")
|
||||
}
|
||||
if uint64(l) < uint64(controlHeaderLen()) {
|
||||
return nil, errors.New("invalid message length")
|
||||
}
|
||||
if uint64(l) > uint64(len(m)) {
|
||||
return nil, errors.New("short buffer")
|
||||
}
|
||||
// On message reception:
|
||||
//
|
||||
// |<- ControlMessageSpace --------------->|
|
||||
// |<- controlMessageLen ---------->| |
|
||||
// |<- controlHeaderLen ->| | |
|
||||
// +---------------+------+---------+------+
|
||||
// | Header | PadH | Data | PadD |
|
||||
// +---------------+------+---------+------+
|
||||
//
|
||||
// On compatible message reception:
|
||||
//
|
||||
// | ... |<- controlMessageLen ----------->|
|
||||
// | ... |<- controlHeaderLen ->| |
|
||||
// +-----+---------------+------+----------+
|
||||
// | ... | Header | PadH | Data |
|
||||
// +-----+---------------+------+----------+
|
||||
ms = append(ms, ControlMessage(m[:l]))
|
||||
ll := l - controlHeaderLen()
|
||||
if len(m) >= ControlMessageSpace(ll) {
|
||||
m = m[ControlMessageSpace(ll):]
|
||||
} else {
|
||||
m = m[controlMessageLen(ll):]
|
||||
}
|
||||
}
|
||||
return ms, nil
|
||||
}
|
||||
|
||||
// NewControlMessage returns a new stream of control messages.
|
||||
func NewControlMessage(dataLen []int) ControlMessage {
|
||||
var l int
|
||||
for i := range dataLen {
|
||||
l += ControlMessageSpace(dataLen[i])
|
||||
}
|
||||
return make([]byte, l)
|
||||
}
|
||||
|
||||
// A Message represents an IO message.
|
||||
type Message struct {
|
||||
// When writing, the Buffers field must contain at least one
|
||||
// byte to write.
|
||||
// When reading, the Buffers field will always contain a byte
|
||||
// to read.
|
||||
Buffers [][]byte
|
||||
|
||||
// OOB contains protocol-specific control or miscellaneous
|
||||
// ancillary data known as out-of-band data.
|
||||
OOB []byte
|
||||
|
||||
// Addr specifies a destination address when writing.
|
||||
// It can be nil when the underlying protocol of the raw
|
||||
// connection uses connection-oriented communication.
|
||||
// After a successful read, it may contain the source address
|
||||
// on the received packet.
|
||||
Addr net.Addr
|
||||
|
||||
N int // # of bytes read or written from/to Buffers
|
||||
NN int // # of bytes read or written from/to OOB
|
||||
Flags int // protocol-specific information on the received message
|
||||
}
|
||||
|
||||
// RecvMsg wraps recvmsg system call.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_PEEK.
|
||||
func (c *Conn) RecvMsg(m *Message, flags int) error {
|
||||
return c.recvMsg(m, flags)
|
||||
}
|
||||
|
||||
// SendMsg wraps sendmsg system call.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_DONTROUTE.
|
||||
func (c *Conn) SendMsg(m *Message, flags int) error {
|
||||
return c.sendMsg(m, flags)
|
||||
}
|
||||
|
||||
// RecvMsgs wraps recvmmsg system call.
|
||||
//
|
||||
// It returns the number of processed messages.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_PEEK.
|
||||
//
|
||||
// Only Linux supports this.
|
||||
func (c *Conn) RecvMsgs(ms []Message, flags int) (int, error) {
|
||||
return c.recvMsgs(ms, flags)
|
||||
}
|
||||
|
||||
// SendMsgs wraps sendmmsg system call.
|
||||
//
|
||||
// It returns the number of processed messages.
|
||||
//
|
||||
// The provided flags is a set of platform-dependent flags, such as
|
||||
// syscall.MSG_DONTROUTE.
|
||||
//
|
||||
// Only Linux supports this.
|
||||
func (c *Conn) SendMsgs(ms []Message, flags int) (int, error) {
|
||||
return c.sendMsgs(ms, flags)
|
||||
}
|
||||
256
vendor/golang.org/x/net/internal/socket/socket_go1_9_test.go
сгенерированный
поставляемый
Обычный файл
256
vendor/golang.org/x/net/internal/socket/socket_go1_9_test.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,256 @@
|
||||
// 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()
|
||||
|
||||
t.Run("Message", func(t *testing.T) {
|
||||
testUDPMessage(t, c.(net.Conn))
|
||||
})
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
t.Run("Messages", func(t *testing.T) {
|
||||
testUDPMessages(t, c.(net.Conn))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testUDPMessage(t *testing.T, c net.Conn) {
|
||||
cc, err := socket.NewConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func testUDPMessages(t *testing.T, c net.Conn) {
|
||||
cc, err := socket.NewConn(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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 "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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
46
vendor/golang.org/x/net/internal/socket/socket_test.go
сгенерированный
поставляемый
Обычный файл
46
vendor/golang.org/x/net/internal/socket/socket_test.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,46 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
33
vendor/golang.org/x/net/internal/socket/sys.go
сгенерированный
поставляемый
Обычный файл
33
vendor/golang.org/x/net/internal/socket/sys.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
|
||||
package socket
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
// NativeEndian is the machine native endian implementation of
|
||||
// ByteOrder.
|
||||
NativeEndian binary.ByteOrder
|
||||
|
||||
kernelAlign int
|
||||
)
|
||||
|
||||
func init() {
|
||||
i := uint32(1)
|
||||
b := (*[4]byte)(unsafe.Pointer(&i))
|
||||
if b[0] == 1 {
|
||||
NativeEndian = binary.LittleEndian
|
||||
} else {
|
||||
NativeEndian = binary.BigEndian
|
||||
}
|
||||
kernelAlign = probeProtocolStack()
|
||||
}
|
||||
|
||||
func roundup(l int) int {
|
||||
return (l + kernelAlign - 1) & ^(kernelAlign - 1)
|
||||
}
|
||||
17
vendor/golang.org/x/net/internal/socket/sys_bsd.go
сгенерированный
поставляемый
Обычный файл
17
vendor/golang.org/x/net/internal/socket/sys_bsd.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,17 @@
|
||||
// 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 openbsd
|
||||
|
||||
package socket
|
||||
|
||||
import "errors"
|
||||
|
||||
func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func sendmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
14
vendor/golang.org/x/net/internal/socket/sys_bsdvar.go
сгенерированный
поставляемый
Обычный файл
14
vendor/golang.org/x/net/internal/socket/sys_bsdvar.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,14 @@
|
||||
// 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 freebsd netbsd openbsd
|
||||
|
||||
package socket
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func probeProtocolStack() int {
|
||||
var p uintptr
|
||||
return int(unsafe.Sizeof(p))
|
||||
}
|
||||
8
vendor/golang.org/x/net/ipv4/go19_test.go → vendor/golang.org/x/net/internal/socket/sys_darwin.go
сгенерированный
поставляемый
8
vendor/golang.org/x/net/ipv4/go19_test.go → vendor/golang.org/x/net/internal/socket/sys_darwin.go
сгенерированный
поставляемый
@@ -2,10 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build go1.9
|
||||
package socket
|
||||
|
||||
package ipv4
|
||||
|
||||
func init() {
|
||||
disableTests = true
|
||||
}
|
||||
func probeProtocolStack() int { return 4 }
|
||||
8
vendor/golang.org/x/net/ipv6/go19_test.go → vendor/golang.org/x/net/internal/socket/sys_dragonfly.go
сгенерированный
поставляемый
8
vendor/golang.org/x/net/ipv6/go19_test.go → vendor/golang.org/x/net/internal/socket/sys_dragonfly.go
сгенерированный
поставляемый
@@ -2,10 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build go1.9
|
||||
package socket
|
||||
|
||||
package ipv6
|
||||
|
||||
func init() {
|
||||
disableTests = true
|
||||
}
|
||||
func probeProtocolStack() int { return 4 }
|
||||
27
vendor/golang.org/x/net/internal/socket/sys_linux.go
сгенерированный
поставляемый
Обычный файл
27
vendor/golang.org/x/net/internal/socket/sys_linux.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,27 @@
|
||||
// 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 linux,!s390x,!386
|
||||
|
||||
package socket
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func probeProtocolStack() int {
|
||||
var p uintptr
|
||||
return int(unsafe.Sizeof(p))
|
||||
}
|
||||
|
||||
func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
||||
n, _, errno := syscall.Syscall6(sysRECVMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
||||
return int(n), errnoErr(errno)
|
||||
}
|
||||
|
||||
func sendmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
||||
n, _, errno := syscall.Syscall6(sysSENDMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
||||
return int(n), errnoErr(errno)
|
||||
}
|
||||
55
vendor/golang.org/x/net/internal/socket/sys_linux_386.go
сгенерированный
поставляемый
Обычный файл
55
vendor/golang.org/x/net/internal/socket/sys_linux_386.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,55 @@
|
||||
// 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.
|
||||
|
||||
package socket
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func probeProtocolStack() int { return 4 }
|
||||
|
||||
const (
|
||||
sysSETSOCKOPT = 0xe
|
||||
sysGETSOCKOPT = 0xf
|
||||
sysSENDMSG = 0x10
|
||||
sysRECVMSG = 0x11
|
||||
sysRECVMMSG = 0x13
|
||||
sysSENDMMSG = 0x14
|
||||
)
|
||||
|
||||
func socketcall(call, a0, a1, a2, a3, a4, a5 uintptr) (uintptr, syscall.Errno)
|
||||
func rawsocketcall(call, a0, a1, a2, a3, a4, a5 uintptr) (uintptr, syscall.Errno)
|
||||
|
||||
func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
|
||||
l := uint32(len(b))
|
||||
_, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&l)), 0)
|
||||
return int(l), errnoErr(errno)
|
||||
}
|
||||
|
||||
func setsockopt(s uintptr, level, name int, b []byte) error {
|
||||
_, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), 0)
|
||||
return errnoErr(errno)
|
||||
}
|
||||
|
||||
func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
|
||||
n, errno := socketcall(sysRECVMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
|
||||
return int(n), errnoErr(errno)
|
||||
}
|
||||
|
||||
func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
|
||||
n, errno := socketcall(sysSENDMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
|
||||
return int(n), errnoErr(errno)
|
||||
}
|
||||
|
||||
func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
||||
n, errno := socketcall(sysRECVMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
||||
return int(n), errnoErr(errno)
|
||||
}
|
||||
|
||||
func sendmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
||||
n, errno := socketcall(sysSENDMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
||||
return int(n), errnoErr(errno)
|
||||
}
|
||||
3
vendor/golang.org/x/net/ipv6/sys_linux_386.s → vendor/golang.org/x/net/internal/socket/sys_linux_386.s
сгенерированный
поставляемый
3
vendor/golang.org/x/net/ipv6/sys_linux_386.s → vendor/golang.org/x/net/internal/socket/sys_linux_386.s
сгенерированный
поставляемый
@@ -6,3 +6,6 @@
|
||||
|
||||
TEXT ·socketcall(SB),NOSPLIT,$0-36
|
||||
JMP syscall·socketcall(SB)
|
||||
|
||||
TEXT ·rawsocketcall(SB),NOSPLIT,$0-36
|
||||
JMP syscall·rawsocketcall(SB)
|
||||
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Ссылка в новой задаче
Block a user