code
stringlengths 11
335k
| docstring
stringlengths 20
11.8k
| func_name
stringlengths 1
100
| language
stringclasses 1
value | repo
stringclasses 245
values | path
stringlengths 4
144
| url
stringlengths 43
214
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func (c *genericOpt) SetTTL(ttl int) error {
if !c.ok() {
return errInvalidConn
}
so, ok := sockOpts[ssoTTL]
if !ok {
return errNotImplemented
}
return so.SetInt(c.Conn, ttl)
} | SetTTL sets the time-to-live field value for future outgoing
packets. | SetTTL | go | flynn/flynn | vendor/golang.org/x/net/ipv4/genericopt.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/ipv4/genericopt.go | BSD-3-Clause |
func isBadCipher(cipher uint16) bool {
switch cipher {
case cipher_TLS_NULL_WITH_NULL_NULL,
cipher_TLS_RSA_WITH_NULL_MD5,
cipher_TLS_RSA_WITH_NULL_SHA,
cipher_TLS_RSA_EXPORT_WITH_RC4_40_MD5,
cipher_TLS_RSA_WITH_RC4_128_MD5,
cipher_TLS_RSA_WITH_RC4_128_SHA,
cipher_TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5,
cipher_TLS_RSA_WITH_IDEA_CBC_SHA,
cipher_TLS_RSA_EXPORT_WITH_DES40_CBC_SHA,
cipher_TLS_RSA_WITH_DES_CBC_SHA,
cipher_TLS_RSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA,
cipher_TLS_DH_DSS_WITH_DES_CBC_SHA,
cipher_TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA,
cipher_TLS_DH_RSA_WITH_DES_CBC_SHA,
cipher_TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA,
cipher_TLS_DHE_DSS_WITH_DES_CBC_SHA,
cipher_TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_DES_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_DH_anon_EXPORT_WITH_RC4_40_MD5,
cipher_TLS_DH_anon_WITH_RC4_128_MD5,
cipher_TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA,
cipher_TLS_DH_anon_WITH_DES_CBC_SHA,
cipher_TLS_DH_anon_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_KRB5_WITH_DES_CBC_SHA,
cipher_TLS_KRB5_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_KRB5_WITH_RC4_128_SHA,
cipher_TLS_KRB5_WITH_IDEA_CBC_SHA,
cipher_TLS_KRB5_WITH_DES_CBC_MD5,
cipher_TLS_KRB5_WITH_3DES_EDE_CBC_MD5,
cipher_TLS_KRB5_WITH_RC4_128_MD5,
cipher_TLS_KRB5_WITH_IDEA_CBC_MD5,
cipher_TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA,
cipher_TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA,
cipher_TLS_KRB5_EXPORT_WITH_RC4_40_SHA,
cipher_TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5,
cipher_TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5,
cipher_TLS_KRB5_EXPORT_WITH_RC4_40_MD5,
cipher_TLS_PSK_WITH_NULL_SHA,
cipher_TLS_DHE_PSK_WITH_NULL_SHA,
cipher_TLS_RSA_PSK_WITH_NULL_SHA,
cipher_TLS_RSA_WITH_AES_128_CBC_SHA,
cipher_TLS_DH_DSS_WITH_AES_128_CBC_SHA,
cipher_TLS_DH_RSA_WITH_AES_128_CBC_SHA,
cipher_TLS_DHE_DSS_WITH_AES_128_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
cipher_TLS_DH_anon_WITH_AES_128_CBC_SHA,
cipher_TLS_RSA_WITH_AES_256_CBC_SHA,
cipher_TLS_DH_DSS_WITH_AES_256_CBC_SHA,
cipher_TLS_DH_RSA_WITH_AES_256_CBC_SHA,
cipher_TLS_DHE_DSS_WITH_AES_256_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
cipher_TLS_DH_anon_WITH_AES_256_CBC_SHA,
cipher_TLS_RSA_WITH_NULL_SHA256,
cipher_TLS_RSA_WITH_AES_128_CBC_SHA256,
cipher_TLS_RSA_WITH_AES_256_CBC_SHA256,
cipher_TLS_DH_DSS_WITH_AES_128_CBC_SHA256,
cipher_TLS_DH_RSA_WITH_AES_128_CBC_SHA256,
cipher_TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,
cipher_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA,
cipher_TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA,
cipher_TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA,
cipher_TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA,
cipher_TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
cipher_TLS_DH_DSS_WITH_AES_256_CBC_SHA256,
cipher_TLS_DH_RSA_WITH_AES_256_CBC_SHA256,
cipher_TLS_DHE_DSS_WITH_AES_256_CBC_SHA256,
cipher_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
cipher_TLS_DH_anon_WITH_AES_128_CBC_SHA256,
cipher_TLS_DH_anon_WITH_AES_256_CBC_SHA256,
cipher_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA,
cipher_TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA,
cipher_TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA,
cipher_TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA,
cipher_TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA,
cipher_TLS_PSK_WITH_RC4_128_SHA,
cipher_TLS_PSK_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_PSK_WITH_AES_128_CBC_SHA,
cipher_TLS_PSK_WITH_AES_256_CBC_SHA,
cipher_TLS_DHE_PSK_WITH_RC4_128_SHA,
cipher_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_DHE_PSK_WITH_AES_128_CBC_SHA,
cipher_TLS_DHE_PSK_WITH_AES_256_CBC_SHA,
cipher_TLS_RSA_PSK_WITH_RC4_128_SHA,
cipher_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_RSA_PSK_WITH_AES_128_CBC_SHA,
cipher_TLS_RSA_PSK_WITH_AES_256_CBC_SHA,
cipher_TLS_RSA_WITH_SEED_CBC_SHA,
cipher_TLS_DH_DSS_WITH_SEED_CBC_SHA,
cipher_TLS_DH_RSA_WITH_SEED_CBC_SHA,
cipher_TLS_DHE_DSS_WITH_SEED_CBC_SHA,
cipher_TLS_DHE_RSA_WITH_SEED_CBC_SHA,
cipher_TLS_DH_anon_WITH_SEED_CBC_SHA,
cipher_TLS_RSA_WITH_AES_128_GCM_SHA256,
cipher_TLS_RSA_WITH_AES_256_GCM_SHA384,
cipher_TLS_DH_RSA_WITH_AES_128_GCM_SHA256,
cipher_TLS_DH_RSA_WITH_AES_256_GCM_SHA384,
cipher_TLS_DH_DSS_WITH_AES_128_GCM_SHA256,
cipher_TLS_DH_DSS_WITH_AES_256_GCM_SHA384,
cipher_TLS_DH_anon_WITH_AES_128_GCM_SHA256,
cipher_TLS_DH_anon_WITH_AES_256_GCM_SHA384,
cipher_TLS_PSK_WITH_AES_128_GCM_SHA256,
cipher_TLS_PSK_WITH_AES_256_GCM_SHA384,
cipher_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256,
cipher_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384,
cipher_TLS_PSK_WITH_AES_128_CBC_SHA256,
cipher_TLS_PSK_WITH_AES_256_CBC_SHA384,
cipher_TLS_PSK_WITH_NULL_SHA256,
cipher_TLS_PSK_WITH_NULL_SHA384,
cipher_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256,
cipher_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384,
cipher_TLS_DHE_PSK_WITH_NULL_SHA256,
cipher_TLS_DHE_PSK_WITH_NULL_SHA384,
cipher_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256,
cipher_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384,
cipher_TLS_RSA_PSK_WITH_NULL_SHA256,
cipher_TLS_RSA_PSK_WITH_NULL_SHA384,
cipher_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256,
cipher_TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256,
cipher_TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256,
cipher_TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256,
cipher_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256,
cipher_TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256,
cipher_TLS_EMPTY_RENEGOTIATION_INFO_SCSV,
cipher_TLS_ECDH_ECDSA_WITH_NULL_SHA,
cipher_TLS_ECDH_ECDSA_WITH_RC4_128_SHA,
cipher_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
cipher_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
cipher_TLS_ECDHE_ECDSA_WITH_NULL_SHA,
cipher_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
cipher_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
cipher_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
cipher_TLS_ECDH_RSA_WITH_NULL_SHA,
cipher_TLS_ECDH_RSA_WITH_RC4_128_SHA,
cipher_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,
cipher_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA,
cipher_TLS_ECDHE_RSA_WITH_NULL_SHA,
cipher_TLS_ECDHE_RSA_WITH_RC4_128_SHA,
cipher_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
cipher_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
cipher_TLS_ECDH_anon_WITH_NULL_SHA,
cipher_TLS_ECDH_anon_WITH_RC4_128_SHA,
cipher_TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_ECDH_anon_WITH_AES_128_CBC_SHA,
cipher_TLS_ECDH_anon_WITH_AES_256_CBC_SHA,
cipher_TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_SRP_SHA_WITH_AES_128_CBC_SHA,
cipher_TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA,
cipher_TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA,
cipher_TLS_SRP_SHA_WITH_AES_256_CBC_SHA,
cipher_TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA,
cipher_TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA,
cipher_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
cipher_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
cipher_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256,
cipher_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384,
cipher_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
cipher_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
cipher_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256,
cipher_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384,
cipher_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,
cipher_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
cipher_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,
cipher_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
cipher_TLS_ECDHE_PSK_WITH_RC4_128_SHA,
cipher_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA,
cipher_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
cipher_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA,
cipher_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256,
cipher_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384,
cipher_TLS_ECDHE_PSK_WITH_NULL_SHA,
cipher_TLS_ECDHE_PSK_WITH_NULL_SHA256,
cipher_TLS_ECDHE_PSK_WITH_NULL_SHA384,
cipher_TLS_RSA_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_RSA_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_DH_anon_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_DH_anon_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_RSA_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_RSA_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_DH_anon_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_DH_anon_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_PSK_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_PSK_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_PSK_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_PSK_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256,
cipher_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384,
cipher_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256,
cipher_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384,
cipher_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256,
cipher_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384,
cipher_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256,
cipher_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384,
cipher_TLS_RSA_WITH_AES_128_CCM,
cipher_TLS_RSA_WITH_AES_256_CCM,
cipher_TLS_RSA_WITH_AES_128_CCM_8,
cipher_TLS_RSA_WITH_AES_256_CCM_8,
cipher_TLS_PSK_WITH_AES_128_CCM,
cipher_TLS_PSK_WITH_AES_256_CCM,
cipher_TLS_PSK_WITH_AES_128_CCM_8,
cipher_TLS_PSK_WITH_AES_256_CCM_8:
return true
default:
return false
}
} | isBadCipher reports whether the cipher is blacklisted by the HTTP/2 spec.
References:
https://tools.ietf.org/html/rfc7540#appendix-A
Reject cipher suites from Appendix A.
"This list includes those cipher suites that do not
offer an ephemeral key exchange and those that are
based on the TLS null, stream or block cipher type" | isBadCipher | go | flynn/flynn | vendor/golang.org/x/net/http2/ciphers.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/ciphers.go | BSD-3-Clause |
func NewRandomWriteScheduler() WriteScheduler {
return &randomWriteScheduler{sq: make(map[uint32]*writeQueue)}
} | NewRandomWriteScheduler constructs a WriteScheduler that ignores HTTP/2
priorities. Control frames like SETTINGS and PING are written before DATA
frames, but if no control frames are queued and multiple streams have queued
HEADERS or DATA frames, Pop selects a ready stream arbitrarily. | NewRandomWriteScheduler | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched_random.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched_random.go | BSD-3-Clause |
func writeEndsStream(w writeFramer) bool {
switch v := w.(type) {
case *writeData:
return v.endStream
case *writeResHeaders:
return v.endStream
case nil:
// This can only happen if the caller reuses w after it's
// been intentionally nil'ed out to prevent use. Keep this
// here to catch future refactoring breaking it.
panic("writeEndsStream called on nil writeFramer")
} | writeEndsStream reports whether w writes a frame that will transition
the stream to a half-closed local state. This returns false for RST_STREAM,
which closes the entire stream (not just the local half). | writeEndsStream | go | flynn/flynn | vendor/golang.org/x/net/http2/write.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/write.go | BSD-3-Clause |
func splitHeaderBlock(ctx writeContext, headerBlock []byte, fn func(ctx writeContext, frag []byte, firstFrag, lastFrag bool) error) error {
// For now we're lazy and just pick the minimum MAX_FRAME_SIZE
// that all peers must support (16KB). Later we could care
// more and send larger frames if the peer advertised it, but
// there's little point. Most headers are small anyway (so we
// generally won't have CONTINUATION frames), and extra frames
// only waste 9 bytes anyway.
const maxFrameSize = 16384
first := true
for len(headerBlock) > 0 {
frag := headerBlock
if len(frag) > maxFrameSize {
frag = frag[:maxFrameSize]
}
headerBlock = headerBlock[len(frag):]
if err := fn(ctx, frag, first, len(headerBlock) == 0); err != nil {
return err
}
first = false
}
return nil
} | splitHeaderBlock splits headerBlock into fragments so that each fragment fits
in a single frame, then calls fn for each fragment. firstFrag/lastFrag are true
for the first/last fragment, respectively. | splitHeaderBlock | go | flynn/flynn | vendor/golang.org/x/net/http2/write.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/write.go | BSD-3-Clause |
func encodeHeaders(enc *hpack.Encoder, h http.Header, keys []string) {
if keys == nil {
sorter := sorterPool.Get().(*sorter)
// Using defer here, since the returned keys from the
// sorter.Keys method is only valid until the sorter
// is returned:
defer sorterPool.Put(sorter)
keys = sorter.Keys(h)
}
for _, k := range keys {
vv := h[k]
k = lowerHeader(k)
if !validWireHeaderFieldName(k) {
// Skip it as backup paranoia. Per
// golang.org/issue/14048, these should
// already be rejected at a higher level.
continue
}
isTE := k == "transfer-encoding"
for _, v := range vv {
if !httpguts.ValidHeaderFieldValue(v) {
// TODO: return an error? golang.org/issue/14048
// For now just omit it.
continue
}
// TODO: more of "8.1.2.2 Connection-Specific Header Fields"
if isTE && v != "trailers" {
continue
}
encKV(enc, k, v)
}
}
} | encodeHeaders encodes an http.Header. If keys is not nil, then (k, h[k])
is encoded only if k is in keys. | encodeHeaders | go | flynn/flynn | vendor/golang.org/x/net/http2/write.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/write.go | BSD-3-Clause |
func (p *pipe) Read(d []byte) (n int, err error) {
p.mu.Lock()
defer p.mu.Unlock()
if p.c.L == nil {
p.c.L = &p.mu
}
for {
if p.breakErr != nil {
return 0, p.breakErr
}
if p.b != nil && p.b.Len() > 0 {
return p.b.Read(d)
}
if p.err != nil {
if p.readFn != nil {
p.readFn() // e.g. copy trailers
p.readFn = nil // not sticky like p.err
}
p.b = nil
return 0, p.err
}
p.c.Wait()
}
} | Read waits until data is available and copies bytes
from the buffer into p. | Read | go | flynn/flynn | vendor/golang.org/x/net/http2/pipe.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/pipe.go | BSD-3-Clause |
func (p *pipe) Write(d []byte) (n int, err error) {
p.mu.Lock()
defer p.mu.Unlock()
if p.c.L == nil {
p.c.L = &p.mu
}
defer p.c.Signal()
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)
} | Write copies bytes from p into the buffer and wakes a reader.
It is an error to write more data than the buffer can hold. | Write | go | flynn/flynn | vendor/golang.org/x/net/http2/pipe.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/pipe.go | BSD-3-Clause |
func (p *pipe) CloseWithError(err error) { p.closeWithError(&p.err, err, nil) } | CloseWithError causes the next Read (waking up a current blocked
Read if needed) to return the provided err after all data has been
read.
The error must be non-nil. | CloseWithError | go | flynn/flynn | vendor/golang.org/x/net/http2/pipe.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/pipe.go | BSD-3-Clause |
func (p *pipe) BreakWithError(err error) { p.closeWithError(&p.breakErr, err, nil) } | BreakWithError causes the next Read (waking up a current blocked
Read if needed) to return the provided err immediately, without
waiting for unread data. | BreakWithError | go | flynn/flynn | vendor/golang.org/x/net/http2/pipe.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/pipe.go | BSD-3-Clause |
func (p *pipe) closeWithErrorAndCode(err error, fn func()) { p.closeWithError(&p.err, err, fn) } | closeWithErrorAndCode is like CloseWithError but also sets some code to run
in the caller's goroutine before returning the error. | closeWithErrorAndCode | go | flynn/flynn | vendor/golang.org/x/net/http2/pipe.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/pipe.go | BSD-3-Clause |
func (p *pipe) closeDoneLocked() {
if p.donec == nil {
return
}
// Close if unclosed. This isn't racy since we always
// hold p.mu while closing.
select {
case <-p.donec:
default:
close(p.donec)
}
} | requires p.mu be held. | closeDoneLocked | go | flynn/flynn | vendor/golang.org/x/net/http2/pipe.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/pipe.go | BSD-3-Clause |
func (p *pipe) Err() error {
p.mu.Lock()
defer p.mu.Unlock()
if p.breakErr != nil {
return p.breakErr
}
return p.err
} | Err returns the error (if any) first set by BreakWithError or CloseWithError. | Err | go | flynn/flynn | vendor/golang.org/x/net/http2/pipe.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/pipe.go | BSD-3-Clause |
func parseUintBytes(s []byte, base int, bitSize int) (n uint64, err error) {
var cutoff, maxVal uint64
if bitSize == 0 {
bitSize = int(strconv.IntSize)
}
s0 := s
switch {
case len(s) < 1:
err = strconv.ErrSyntax
goto Error
case 2 <= base && base <= 36:
// valid base; nothing to do
case base == 0:
// Look for octal, hex prefix.
switch {
case s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X'):
base = 16
s = s[2:]
if len(s) < 1 {
err = strconv.ErrSyntax
goto Error
}
case s[0] == '0':
base = 8
default:
base = 10
}
default:
err = errors.New("invalid base " + strconv.Itoa(base))
goto Error
}
n = 0
cutoff = cutoff64(base)
maxVal = 1<<uint(bitSize) - 1
for i := 0; i < len(s); i++ {
var v byte
d := s[i]
switch {
case '0' <= d && d <= '9':
v = d - '0'
case 'a' <= d && d <= 'z':
v = d - 'a' + 10
case 'A' <= d && d <= 'Z':
v = d - 'A' + 10
default:
n = 0
err = strconv.ErrSyntax
goto Error
}
if int(v) >= base {
n = 0
err = strconv.ErrSyntax
goto Error
}
if n >= cutoff {
// n*base overflows
n = 1<<64 - 1
err = strconv.ErrRange
goto Error
}
n *= uint64(base)
n1 := n + uint64(v)
if n1 < n || n1 > maxVal {
// n+v overflows
n = 1<<64 - 1
err = strconv.ErrRange
goto Error
}
n = n1
}
return n, nil
Error:
return n, &strconv.NumError{Func: "ParseUint", Num: string(s0), Err: err}
} | parseUintBytes is like strconv.ParseUint, but using a []byte. | parseUintBytes | go | flynn/flynn | vendor/golang.org/x/net/http2/gotrack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/gotrack.go | BSD-3-Clause |
func cutoff64(base int) uint64 {
if base < 2 {
return 0
}
return (1<<64-1)/uint64(base) + 1
} | Return the first number n such that n*base >= 1<<64. | cutoff64 | go | flynn/flynn | vendor/golang.org/x/net/http2/gotrack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/gotrack.go | BSD-3-Clause |
func NewPriorityWriteScheduler(cfg *PriorityWriteSchedulerConfig) WriteScheduler {
if cfg == nil {
// For justification of these defaults, see:
// https://docs.google.com/document/d/1oLhNg1skaWD4_DtaoCxdSRN5erEXrH-KnLrMwEpOtFY
cfg = &PriorityWriteSchedulerConfig{
MaxClosedNodesInTree: 10,
MaxIdleNodesInTree: 10,
ThrottleOutOfOrderWrites: false,
}
}
ws := &priorityWriteScheduler{
nodes: make(map[uint32]*priorityNode),
maxClosedNodesInTree: cfg.MaxClosedNodesInTree,
maxIdleNodesInTree: cfg.MaxIdleNodesInTree,
enableWriteThrottle: cfg.ThrottleOutOfOrderWrites,
}
ws.nodes[0] = &ws.root
if cfg.ThrottleOutOfOrderWrites {
ws.writeThrottleLimit = 1024
} else {
ws.writeThrottleLimit = math.MaxInt32
}
return ws
} | NewPriorityWriteScheduler constructs a WriteScheduler that schedules
frames by following HTTP/2 priorities as described in RFC 7540 Section 5.3.
If cfg is nil, default options are used. | NewPriorityWriteScheduler | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched_priority.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched_priority.go | BSD-3-Clause |
func (n *priorityNode) walkReadyInOrder(openParent bool, tmp *[]*priorityNode, f func(*priorityNode, bool) bool) bool {
if !n.q.empty() && f(n, openParent) {
return true
}
if n.kids == nil {
return false
}
// Don't consider the root "open" when updating openParent since
// we can't send data frames on the root stream (only control frames).
if n.id != 0 {
openParent = openParent || (n.state == priorityNodeOpen)
}
// Common case: only one kid or all kids have the same weight.
// Some clients don't use weights; other clients (like web browsers)
// use mostly-linear priority trees.
w := n.kids.weight
needSort := false
for k := n.kids.next; k != nil; k = k.next {
if k.weight != w {
needSort = true
break
}
}
if !needSort {
for k := n.kids; k != nil; k = k.next {
if k.walkReadyInOrder(openParent, tmp, f) {
return true
}
}
return false
}
// Uncommon case: sort the child nodes. We remove the kids from the parent,
// then re-insert after sorting so we can reuse tmp for future sort calls.
*tmp = (*tmp)[:0]
for n.kids != nil {
*tmp = append(*tmp, n.kids)
n.kids.setParent(nil)
}
sort.Sort(sortPriorityNodeSiblings(*tmp))
for i := len(*tmp) - 1; i >= 0; i-- {
(*tmp)[i].setParent(n) // setParent inserts at the head of n.kids
}
for k := n.kids; k != nil; k = k.next {
if k.walkReadyInOrder(openParent, tmp, f) {
return true
}
}
return false
} | walkReadyInOrder iterates over the tree in priority order, calling f for each node
with a non-empty write queue. When f returns true, this function returns true and the
walk halts. tmp is used as scratch space for sorting.
f(n, openParent) takes two arguments: the node to visit, n, and a bool that is true
if any ancestor p of n is still open (ignoring the root node). | walkReadyInOrder | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched_priority.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched_priority.go | BSD-3-Clause |
func ConfigureTransport(t1 *http.Transport) error {
_, err := configureTransport(t1)
return err
} | ConfigureTransport configures a net/http HTTP/1 Transport to use HTTP/2.
It returns an error if t1 has already been HTTP/2-enabled. | ConfigureTransport | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func awaitRequestCancel(req *http.Request, done <-chan struct{}) error {
ctx := req.Context()
if req.Cancel == nil && ctx.Done() == nil {
return nil
}
select {
case <-req.Cancel:
return errRequestCanceled
case <-ctx.Done():
return ctx.Err()
case <-done:
return nil
}
} | awaitRequestCancel waits for the user to cancel a request or for the done
channel to be signaled. A non-nil error is returned only if the request was
canceled. | awaitRequestCancel | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func isNoCachedConnError(err error) bool {
_, ok := err.(interface{ IsHTTP2NoCachedConnError() })
return ok
} | isNoCachedConnError reports whether err is of type noCachedConnError
or its equivalent renamed type in net/http2's h2_bundle.go. Both types
may coexist in the same running program. | isNoCachedConnError | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func authorityAddr(scheme string, authority string) (addr string) {
host, port, err := net.SplitHostPort(authority)
if err != nil { // authority didn't have a port
port = "443"
if scheme == "http" {
port = "80"
}
host = authority
}
if a, err := idna.ToASCII(host); err == nil {
host = a
}
// IPv6 address literal, without a port:
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
return host + ":" + port
}
return net.JoinHostPort(host, port)
} | authorityAddr returns a given authority (a host/IP, or host:port / ip:port)
and returns a host:port. The port 443 is added if needed. | authorityAddr | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func shouldRetryRequest(req *http.Request, err error, afterBodyWrite bool) (*http.Request, error) {
if !canRetryError(err) {
return nil, err
}
// If the Body is nil (or http.NoBody), it's safe to reuse
// this request and its Body.
if req.Body == nil || req.Body == http.NoBody {
return req, nil
}
// If the request body can be reset back to its original
// state via the optional req.GetBody, do that.
if req.GetBody != nil {
// TODO: consider a req.Body.Close here? or audit that all caller paths do?
body, err := req.GetBody()
if err != nil {
return nil, err
}
newReq := *req
newReq.Body = body
return &newReq, nil
}
// The Request.Body can't reset back to the beginning, but we
// don't seem to have started to read from it yet, so reuse
// the request directly. The "afterBodyWrite" means the
// bodyWrite process has started, which becomes true before
// the first Read.
if !afterBodyWrite {
return req, nil
}
return nil, fmt.Errorf("http2: Transport: cannot retry err [%v] after Request.Body was written; define Request.GetBody to avoid this error", err)
} | shouldRetryRequest is called by RoundTrip when a request fails to get
response headers. It is always called with a non-nil error.
It returns either a request to retry (either the same request, or a
modified clone), or an error if the request can't be replayed. | shouldRetryRequest | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func checkConnHeaders(req *http.Request) error {
if v := req.Header.Get("Upgrade"); v != "" {
return fmt.Errorf("http2: invalid Upgrade request header: %q", req.Header["Upgrade"])
}
if vv := req.Header["Transfer-Encoding"]; len(vv) > 0 && (len(vv) > 1 || vv[0] != "" && vv[0] != "chunked") {
return fmt.Errorf("http2: invalid Transfer-Encoding request header: %q", vv)
}
if vv := req.Header["Connection"]; len(vv) > 0 && (len(vv) > 1 || vv[0] != "" && !strings.EqualFold(vv[0], "close") && !strings.EqualFold(vv[0], "keep-alive")) {
return fmt.Errorf("http2: invalid Connection request header: %q", vv)
}
return nil
} | checkConnHeaders checks whether req has any invalid connection-level headers.
per RFC 7540 section 8.1.2.2: Connection-Specific Header Fields.
Certain headers are special-cased as okay but not transmitted later. | checkConnHeaders | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func actualContentLength(req *http.Request) int64 {
if req.Body == nil || req.Body == http.NoBody {
return 0
}
if req.ContentLength != 0 {
return req.ContentLength
}
return -1
} | actualContentLength returns a sanitized version of
req.ContentLength, where 0 actually means zero (not unknown) and -1
means unknown. | actualContentLength | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func shouldSendReqContentLength(method string, contentLength int64) bool {
if contentLength > 0 {
return true
}
if contentLength < 0 {
return false
}
// For zero bodies, whether we send a content-length depends on the method.
// It also kinda doesn't matter for http2 either way, with END_STREAM.
switch method {
case "POST", "PUT", "PATCH":
return true
default:
return false
}
} | shouldSendReqContentLength reports whether the http2.Transport should send
a "content-length" request header. This logic is basically a copy of the net/http
transferWriter.shouldSendContentLength.
The contentLength is the corrected contentLength (so 0 means actually 0, not unknown).
-1 means unknown. | shouldSendReqContentLength | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func isConnectionCloseRequest(req *http.Request) bool {
return req.Close || httpguts.HeaderValuesContainsToken(req.Header["Connection"], "close")
} | isConnectionCloseRequest reports whether req should use its own
connection for a single request and then close the connection. | isConnectionCloseRequest | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func registerHTTPSProtocol(t *http.Transport, rt noDialH2RoundTripper) (err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("%v", e)
}
}()
t.RegisterProtocol("https", rt)
return nil
} | registerHTTPSProtocol calls Transport.RegisterProtocol but
converting panics into errors. | registerHTTPSProtocol | go | flynn/flynn | vendor/golang.org/x/net/http2/transport.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/transport.go | BSD-3-Clause |
func (p *clientConnPool) shouldTraceGetConn(st clientConnIdleState) bool {
// If our Transport wasn't made via ConfigureTransport, always
// trace the GetConn hook if provided, because that means the
// http2 package is being used directly and it's the one
// dialing, as opposed to net/http.
if _, ok := p.t.ConnPool.(noDialClientConnPool); !ok {
return true
}
// Otherwise, only use the GetConn hook if this connection has
// been used previously for other requests. For fresh
// connections, the net/http package does the dialing.
return !st.freshConn
} | shouldTraceGetConn reports whether getClientConn should call any
ClientTrace.GetConn hook associated with the http.Request.
This complexity is needed to avoid double calls of the GetConn hook
during the back-and-forth between net/http and x/net/http2 (when the
net/http.Transport is upgraded to also speak http2), as well as support
the case where x/net/http2 is being used directly. | shouldTraceGetConn | go | flynn/flynn | vendor/golang.org/x/net/http2/client_conn_pool.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/client_conn_pool.go | BSD-3-Clause |
func (p *clientConnPool) getStartDialLocked(addr string) *dialCall {
if call, ok := p.dialing[addr]; ok {
// A dial is already in-flight. Don't start another.
return call
}
call := &dialCall{p: p, done: make(chan struct{})}
if p.dialing == nil {
p.dialing = make(map[string]*dialCall)
}
p.dialing[addr] = call
go call.dial(addr)
return call
} | requires p.mu is held. | getStartDialLocked | go | flynn/flynn | vendor/golang.org/x/net/http2/client_conn_pool.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/client_conn_pool.go | BSD-3-Clause |
func (c *dialCall) dial(addr string) {
const singleUse = false // shared conn
c.res, c.err = c.p.t.dialClientConn(addr, singleUse)
close(c.done)
c.p.mu.Lock()
delete(c.p.dialing, addr)
if c.err == nil {
c.p.addConnLocked(addr, c.res)
}
c.p.mu.Unlock()
} | run in its own goroutine. | dial | go | flynn/flynn | vendor/golang.org/x/net/http2/client_conn_pool.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/client_conn_pool.go | BSD-3-Clause |
func (p *clientConnPool) addConnIfNeeded(key string, t *Transport, c *tls.Conn) (used bool, err error) {
p.mu.Lock()
for _, cc := range p.conns[key] {
if cc.CanTakeNewRequest() {
p.mu.Unlock()
return false, nil
}
}
call, dup := p.addConnCalls[key]
if !dup {
if p.addConnCalls == nil {
p.addConnCalls = make(map[string]*addConnCall)
}
call = &addConnCall{
p: p,
done: make(chan struct{}),
}
p.addConnCalls[key] = call
go call.run(t, key, c)
}
p.mu.Unlock()
<-call.done
if call.err != nil {
return false, call.err
}
return !dup, nil
} | addConnIfNeeded makes a NewClientConn out of c if a connection for key doesn't
already exist. It coalesces concurrent calls with the same key.
This is used by the http1 Transport code when it creates a new connection. Because
the http1 Transport doesn't de-dup TCP dials to outbound hosts (because it doesn't know
the protocol), it can get into a situation where it has multiple TLS connections.
This code decides which ones live or die.
The return value used is whether c was used.
c is never closed. | addConnIfNeeded | go | flynn/flynn | vendor/golang.org/x/net/http2/client_conn_pool.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/client_conn_pool.go | BSD-3-Clause |
func (wr FrameWriteRequest) StreamID() uint32 {
if wr.stream == nil {
if se, ok := wr.write.(StreamError); ok {
// (*serverConn).resetStream doesn't set
// stream because it doesn't necessarily have
// one. So special case this type of write
// message.
return se.StreamID
}
return 0
}
return wr.stream.id
} | StreamID returns the id of the stream this frame will be written to.
0 is used for non-stream frames such as PING and SETTINGS. | StreamID | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (wr FrameWriteRequest) isControl() bool {
return wr.stream == nil
} | isControl reports whether wr is a control frame for MaxQueuedControlFrames
purposes. That includes non-stream frames and RST_STREAM frames. | isControl | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (wr FrameWriteRequest) DataSize() int {
if wd, ok := wr.write.(*writeData); ok {
return len(wd.p)
}
return 0
} | DataSize returns the number of flow control bytes that must be consumed
to write this entire frame. This is 0 for non-DATA frames. | DataSize | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (wr FrameWriteRequest) Consume(n int32) (FrameWriteRequest, FrameWriteRequest, int) {
var empty FrameWriteRequest
// Non-DATA frames are always consumed whole.
wd, ok := wr.write.(*writeData)
if !ok || len(wd.p) == 0 {
return wr, empty, 1
}
// Might need to split after applying limits.
allowed := wr.stream.flow.available()
if n < allowed {
allowed = n
}
if wr.stream.sc.maxFrameSize < allowed {
allowed = wr.stream.sc.maxFrameSize
}
if allowed <= 0 {
return empty, empty, 0
}
if len(wd.p) > int(allowed) {
wr.stream.flow.take(allowed)
consumed := FrameWriteRequest{
stream: wr.stream,
write: &writeData{
streamID: wd.streamID,
p: wd.p[:allowed],
// Even if the original had endStream set, there
// are bytes remaining because len(wd.p) > allowed,
// so we know endStream is false.
endStream: false,
},
// Our caller is blocking on the final DATA frame, not
// this intermediate frame, so no need to wait.
done: nil,
}
rest := FrameWriteRequest{
stream: wr.stream,
write: &writeData{
streamID: wd.streamID,
p: wd.p[allowed:],
endStream: wd.endStream,
},
done: wr.done,
}
return consumed, rest, 2
}
// The frame is consumed whole.
// NB: This cast cannot overflow because allowed is <= math.MaxInt32.
wr.stream.flow.take(int32(len(wd.p)))
return wr, empty, 1
} | Consume consumes min(n, available) bytes from this frame, where available
is the number of flow control bytes available on the stream. Consume returns
0, 1, or 2 frames, where the integer return value gives the number of frames
returned.
If flow control prevents consuming any bytes, this returns (_, _, 0). If
the entire frame was consumed, this returns (wr, _, 1). Otherwise, this
returns (consumed, rest, 2), where 'consumed' contains the consumed bytes and
'rest' contains the remaining bytes. The consumed bytes are deducted from the
underlying stream's flow control budget. | Consume | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (wr FrameWriteRequest) String() string {
var des string
if s, ok := wr.write.(fmt.Stringer); ok {
des = s.String()
} else {
des = fmt.Sprintf("%T", wr.write)
}
return fmt.Sprintf("[FrameWriteRequest stream=%d, ch=%v, writer=%v]", wr.StreamID(), wr.done != nil, des)
} | String is for debugging only. | String | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (wr *FrameWriteRequest) replyToWriter(err error) {
if wr.done == nil {
return
}
select {
case wr.done <- err:
default:
panic(fmt.Sprintf("unbuffered done channel passed in for type %T", wr.write))
}
wr.write = nil // prevent use (assume it's tainted after wr.done send)
} | replyToWriter sends err to wr.done and panics if the send must block
This does nothing if wr.done is nil. | replyToWriter | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (q *writeQueue) consume(n int32) (FrameWriteRequest, bool) {
if len(q.s) == 0 {
return FrameWriteRequest{}, false
}
consumed, rest, numresult := q.s[0].Consume(n)
switch numresult {
case 0:
return FrameWriteRequest{}, false
case 1:
q.shift()
case 2:
q.s[0] = rest
}
return consumed, true
} | consume consumes up to n bytes from q.s[0]. If the frame is
entirely consumed, it is removed from the queue. If the frame
is partially consumed, the frame is kept with the consumed
bytes removed. Returns true iff any bytes were consumed. | consume | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (p *writeQueuePool) put(q *writeQueue) {
for i := range q.s {
q.s[i] = FrameWriteRequest{}
}
q.s = q.s[:0]
*p = append(*p, q)
} | put inserts an unused writeQueue into the pool. | put | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (p *writeQueuePool) get() *writeQueue {
ln := len(*p)
if ln == 0 {
return new(writeQueue)
}
x := ln - 1
q := (*p)[x]
(*p)[x] = nil
*p = (*p)[:x]
return q
} | get returns an empty writeQueue. | get | go | flynn/flynn | vendor/golang.org/x/net/http2/writesched.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/writesched.go | BSD-3-Clause |
func (f Flags) Has(v Flags) bool {
return (f & v) == v
} | Has reports whether f contains all (0 or more) flags in v. | Has | go | flynn/flynn | vendor/golang.org/x/net/http2/frame.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/frame.go | BSD-3-Clause |
func (h FrameHeader) Header() FrameHeader { return h } | Header returns h. It exists so FrameHeaders can be embedded in other
specific frame types and implement the Frame interface. | Header | go | flynn/flynn | vendor/golang.org/x/net/http2/frame.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/frame.go | BSD-3-Clause |
func ReadFrameHeader(r io.Reader) (FrameHeader, error) {
bufp := fhBytes.Get().(*[]byte)
defer fhBytes.Put(bufp)
return readFrameHeader(*bufp, r)
} | ReadFrameHeader reads 9 bytes from r and returns a FrameHeader.
Most users should use Framer.ReadFrame instead. | ReadFrameHeader | go | flynn/flynn | vendor/golang.org/x/net/http2/frame.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/frame.go | BSD-3-Clause |
func NewFramer(w io.Writer, r io.Reader) *Framer {
fr := &Framer{
w: w,
r: r,
logReads: logFrameReads,
logWrites: logFrameWrites,
debugReadLoggerf: log.Printf,
debugWriteLoggerf: log.Printf,
}
fr.getReadBuf = func(size uint32) []byte {
if cap(fr.readBuf) >= int(size) {
return fr.readBuf[:size]
}
fr.readBuf = make([]byte, size)
return fr.readBuf
}
fr.SetMaxReadFrameSize(maxFrameSize)
return fr
} | NewFramer returns a Framer that writes frames to w and reads them from r. | NewFramer | go | flynn/flynn | vendor/golang.org/x/net/http2/frame.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/frame.go | BSD-3-Clause |
func terminalReadFrameError(err error) bool {
if _, ok := err.(StreamError); ok {
return false
}
return err != nil
} | terminalReadFrameError reports whether err is an unrecoverable
error from ReadFrame and no other frames should be read. | terminalReadFrameError | go | flynn/flynn | vendor/golang.org/x/net/http2/frame.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/frame.go | BSD-3-Clause |
func (s Setting) Valid() error {
// Limits and error codes from 6.5.2 Defined SETTINGS Parameters
switch s.ID {
case SettingEnablePush:
if s.Val != 1 && s.Val != 0 {
return ConnectionError(ErrCodeProtocol)
}
case SettingInitialWindowSize:
if s.Val > 1<<31-1 {
return ConnectionError(ErrCodeFlowControl)
}
case SettingMaxFrameSize:
if s.Val < 16384 || s.Val > 1<<24-1 {
return ConnectionError(ErrCodeProtocol)
}
}
return nil
} | Valid reports whether the setting is valid. | Valid | go | flynn/flynn | vendor/golang.org/x/net/http2/http2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/http2.go | BSD-3-Clause |
func validWireHeaderFieldName(v string) bool {
if len(v) == 0 {
return false
}
for _, r := range v {
if !httpguts.IsTokenRune(r) {
return false
}
if 'A' <= r && r <= 'Z' {
return false
}
}
return true
} | validWireHeaderFieldName reports whether v is a valid header field
name (key). See httpguts.ValidHeaderName for the base rules.
Further, http2 says:
"Just as in HTTP/1.x, header field names are strings of ASCII
characters that are compared in a case-insensitive
fashion. However, header field names MUST be converted to
lowercase prior to their encoding in HTTP/2. " | validWireHeaderFieldName | go | flynn/flynn | vendor/golang.org/x/net/http2/http2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/http2.go | BSD-3-Clause |
func (cw *closeWaiter) Init() {
*cw = make(chan struct{})
} | Init makes a closeWaiter usable.
It exists because so a closeWaiter value can be placed inside a
larger struct and have the Mutex and Cond's memory in the same
allocation. | Init | go | flynn/flynn | vendor/golang.org/x/net/http2/http2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/http2.go | BSD-3-Clause |
func (cw closeWaiter) Close() {
close(cw)
} | Close marks the closeWaiter as closed and unblocks any waiters. | Close | go | flynn/flynn | vendor/golang.org/x/net/http2/http2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/http2.go | BSD-3-Clause |
func (cw closeWaiter) Wait() {
<-cw
} | Wait waits for the closeWaiter to become closed. | Wait | go | flynn/flynn | vendor/golang.org/x/net/http2/http2.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/http2.go | BSD-3-Clause |
func (f *flow) add(n int32) bool {
sum := f.n + n
if (sum > n) == (f.n > 0) {
f.n = sum
return true
}
return false
} | add adds n bytes (positive or negative) to the flow control window.
It returns false if the sum would exceed 2^31-1. | add | go | flynn/flynn | vendor/golang.org/x/net/http2/flow.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/flow.go | BSD-3-Clause |
func NewEncoder(w io.Writer) *Encoder {
e := &Encoder{
minSize: uint32Max,
maxSizeLimit: initialHeaderTableSize,
tableSizeUpdate: false,
w: w,
}
e.dynTab.table.init()
e.dynTab.setMaxSize(initialHeaderTableSize)
return e
} | NewEncoder returns a new Encoder which performs HPACK encoding. An
encoded data is written to w. | NewEncoder | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func (e *Encoder) WriteField(f HeaderField) error {
e.buf = e.buf[:0]
if e.tableSizeUpdate {
e.tableSizeUpdate = false
if e.minSize < e.dynTab.maxSize {
e.buf = appendTableSize(e.buf, e.minSize)
}
e.minSize = uint32Max
e.buf = appendTableSize(e.buf, e.dynTab.maxSize)
}
idx, nameValueMatch := e.searchTable(f)
if nameValueMatch {
e.buf = appendIndexed(e.buf, idx)
} else {
indexing := e.shouldIndex(f)
if indexing {
e.dynTab.add(f)
}
if idx == 0 {
e.buf = appendNewName(e.buf, f, indexing)
} else {
e.buf = appendIndexedName(e.buf, f, idx, indexing)
}
}
n, err := e.w.Write(e.buf)
if err == nil && n != len(e.buf) {
err = io.ErrShortWrite
}
return err
} | WriteField encodes f into a single Write to e's underlying Writer.
This function may also produce bytes for "Header Table Size Update"
if necessary. If produced, it is done before encoding f. | WriteField | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func (e *Encoder) searchTable(f HeaderField) (i uint64, nameValueMatch bool) {
i, nameValueMatch = staticTable.search(f)
if nameValueMatch {
return i, true
}
j, nameValueMatch := e.dynTab.table.search(f)
if nameValueMatch || (i == 0 && j != 0) {
return j + uint64(staticTable.len()), nameValueMatch
}
return i, false
} | searchTable searches f in both stable and dynamic header tables.
The static header table is searched first. Only when there is no
exact match for both name and value, the dynamic header table is
then searched. If there is no match, i is 0. If both name and value
match, i is the matched index and nameValueMatch becomes true. If
only name matches, i points to that index and nameValueMatch
becomes false. | searchTable | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func (e *Encoder) SetMaxDynamicTableSize(v uint32) {
if v > e.maxSizeLimit {
v = e.maxSizeLimit
}
if v < e.minSize {
e.minSize = v
}
e.tableSizeUpdate = true
e.dynTab.setMaxSize(v)
} | SetMaxDynamicTableSize changes the dynamic header table size to v.
The actual size is bounded by the value passed to
SetMaxDynamicTableSizeLimit. | SetMaxDynamicTableSize | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func (e *Encoder) SetMaxDynamicTableSizeLimit(v uint32) {
e.maxSizeLimit = v
if e.dynTab.maxSize > v {
e.tableSizeUpdate = true
e.dynTab.setMaxSize(v)
}
} | SetMaxDynamicTableSizeLimit changes the maximum value that can be
specified in SetMaxDynamicTableSize to v. By default, it is set to
4096, which is the same size of the default dynamic header table
size described in HPACK specification. If the current maximum
dynamic header table size is strictly greater than v, "Header Table
Size Update" will be done in the next WriteField call and the
maximum dynamic header table size is truncated to v. | SetMaxDynamicTableSizeLimit | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func (e *Encoder) shouldIndex(f HeaderField) bool {
return !f.Sensitive && f.Size() <= e.dynTab.maxSize
} | shouldIndex reports whether f should be indexed. | shouldIndex | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func appendIndexed(dst []byte, i uint64) []byte {
first := len(dst)
dst = appendVarInt(dst, 7, i)
dst[first] |= 0x80
return dst
} | appendIndexed appends index i, as encoded in "Indexed Header Field"
representation, to dst and returns the extended buffer. | appendIndexed | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func appendNewName(dst []byte, f HeaderField, indexing bool) []byte {
dst = append(dst, encodeTypeByte(indexing, f.Sensitive))
dst = appendHpackString(dst, f.Name)
return appendHpackString(dst, f.Value)
} | appendNewName appends f, as encoded in one of "Literal Header field
- New Name" representation variants, to dst and returns the
extended buffer.
If f.Sensitive is true, "Never Indexed" representation is used. If
f.Sensitive is false and indexing is true, "Incremental Indexing"
representation is used. | appendNewName | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func appendIndexedName(dst []byte, f HeaderField, i uint64, indexing bool) []byte {
first := len(dst)
var n byte
if indexing {
n = 6
} else {
n = 4
}
dst = appendVarInt(dst, n, i)
dst[first] |= encodeTypeByte(indexing, f.Sensitive)
return appendHpackString(dst, f.Value)
} | appendIndexedName appends f and index i referring indexed name
entry, as encoded in one of "Literal Header field - Indexed Name"
representation variants, to dst and returns the extended buffer.
If f.Sensitive is true, "Never Indexed" representation is used. If
f.Sensitive is false and indexing is true, "Incremental Indexing"
representation is used. | appendIndexedName | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func appendTableSize(dst []byte, v uint32) []byte {
first := len(dst)
dst = appendVarInt(dst, 5, uint64(v))
dst[first] |= 0x20
return dst
} | appendTableSize appends v, as encoded in "Header Table Size Update"
representation, to dst and returns the extended buffer. | appendTableSize | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func appendVarInt(dst []byte, n byte, i uint64) []byte {
k := uint64((1 << n) - 1)
if i < k {
return append(dst, byte(i))
}
dst = append(dst, byte(k))
i -= k
for ; i >= 128; i >>= 7 {
dst = append(dst, byte(0x80|(i&0x7f)))
}
return append(dst, byte(i))
} | appendVarInt appends i, as encoded in variable integer form using n
bit prefix, to dst and returns the extended buffer.
See
http://http2.github.io/http2-spec/compression.html#integer.representation | appendVarInt | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func appendHpackString(dst []byte, s string) []byte {
huffmanLength := HuffmanEncodeLength(s)
if huffmanLength < uint64(len(s)) {
first := len(dst)
dst = appendVarInt(dst, 7, huffmanLength)
dst = AppendHuffmanString(dst, s)
dst[first] |= 0x80
} else {
dst = appendVarInt(dst, 7, uint64(len(s)))
dst = append(dst, s...)
}
return dst
} | appendHpackString appends s, as encoded in "String Literal"
representation, to dst and returns the extended buffer.
s will be encoded in Huffman codes only when it produces strictly
shorter byte string. | appendHpackString | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func encodeTypeByte(indexing, sensitive bool) byte {
if sensitive {
return 0x10
}
if indexing {
return 0x40
}
return 0
} | encodeTypeByte returns type byte. If sensitive is true, type byte
for "Never Indexed" representation is returned. If sensitive is
false and indexing is true, type byte for "Incremental Indexing"
representation is returned. Otherwise, type byte for "Without
Indexing" is returned. | encodeTypeByte | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/encode.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/encode.go | BSD-3-Clause |
func (t *headerFieldTable) len() int {
return len(t.ents)
} | len reports the number of entries in the table. | len | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/tables.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/tables.go | BSD-3-Clause |
func (t *headerFieldTable) addEntry(f HeaderField) {
id := uint64(t.len()) + t.evictCount + 1
t.byName[f.Name] = id
t.byNameValue[pairNameValue{f.Name, f.Value}] = id
t.ents = append(t.ents, f)
} | addEntry adds a new entry. | addEntry | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/tables.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/tables.go | BSD-3-Clause |
func (t *headerFieldTable) evictOldest(n int) {
if n > t.len() {
panic(fmt.Sprintf("evictOldest(%v) on table with %v entries", n, t.len()))
}
for k := 0; k < n; k++ {
f := t.ents[k]
id := t.evictCount + uint64(k) + 1
if t.byName[f.Name] == id {
delete(t.byName, f.Name)
}
if p := (pairNameValue{f.Name, f.Value}); t.byNameValue[p] == id {
delete(t.byNameValue, p)
}
}
copy(t.ents, t.ents[n:])
for k := t.len() - n; k < t.len(); k++ {
t.ents[k] = HeaderField{} // so strings can be garbage collected
}
t.ents = t.ents[:t.len()-n]
if t.evictCount+uint64(n) < t.evictCount {
panic("evictCount overflow")
}
t.evictCount += uint64(n)
} | evictOldest evicts the n oldest entries in the table. | evictOldest | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/tables.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/tables.go | BSD-3-Clause |
func (t *headerFieldTable) search(f HeaderField) (i uint64, nameValueMatch bool) {
if !f.Sensitive {
if id := t.byNameValue[pairNameValue{f.Name, f.Value}]; id != 0 {
return t.idToIndex(id), true
}
}
if id := t.byName[f.Name]; id != 0 {
return t.idToIndex(id), false
}
return 0, false
} | search finds f in the table. If there is no match, i is 0.
If both name and value match, i is the matched index and nameValueMatch
becomes true. If only name matches, i points to that index and
nameValueMatch becomes false.
The returned index is a 1-based HPACK index. For dynamic tables, HPACK says
that index 1 should be the newest entry, but t.ents[0] is the oldest entry,
meaning t.ents is reversed for dynamic tables. Hence, when t is a dynamic
table, the return value i actually refers to the entry t.ents[t.len()-i].
All tables are assumed to be a dynamic tables except for the global
staticTable pointer.
See Section 2.3.3. | search | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/tables.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/tables.go | BSD-3-Clause |
func (t *headerFieldTable) idToIndex(id uint64) uint64 {
if id <= t.evictCount {
panic(fmt.Sprintf("id (%v) <= evictCount (%v)", id, t.evictCount))
}
k := id - t.evictCount - 1 // convert id to an index t.ents[k]
if t != staticTable {
return uint64(t.len()) - k // dynamic table
}
return k + 1
} | idToIndex converts a unique id to an HPACK index.
See Section 2.3.3. | idToIndex | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/tables.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/tables.go | BSD-3-Clause |
func (hf HeaderField) IsPseudo() bool {
return len(hf.Name) != 0 && hf.Name[0] == ':'
} | IsPseudo reports whether the header field is an http2 pseudo header.
That is, it reports whether it starts with a colon.
It is not otherwise guaranteed to be a valid pseudo header field,
though. | IsPseudo | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (hf HeaderField) Size() uint32 {
// http://http2.github.io/http2-spec/compression.html#rfc.section.4.1
// "The size of the dynamic table is the sum of the size of
// its entries. The size of an entry is the sum of its name's
// length in octets (as defined in Section 5.2), its value's
// length in octets (see Section 5.2), plus 32. The size of
// an entry is calculated using the length of the name and
// value without any Huffman encoding applied."
// This can overflow if somebody makes a large HeaderField
// Name and/or Value by hand, but we don't care, because that
// won't happen on the wire because the encoding doesn't allow
// it.
return uint32(len(hf.Name) + len(hf.Value) + 32)
} | Size returns the size of an entry per RFC 7541 section 4.1. | Size | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func NewDecoder(maxDynamicTableSize uint32, emitFunc func(f HeaderField)) *Decoder {
d := &Decoder{
emit: emitFunc,
emitEnabled: true,
firstField: true,
}
d.dynTab.table.init()
d.dynTab.allowedMaxSize = maxDynamicTableSize
d.dynTab.setMaxSize(maxDynamicTableSize)
return d
} | NewDecoder returns a new decoder with the provided maximum dynamic
table size. The emitFunc will be called for each valid field
parsed, in the same goroutine as calls to Write, before Write returns. | NewDecoder | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) SetMaxStringLength(n int) {
d.maxStrLen = n
} | SetMaxStringLength sets the maximum size of a HeaderField name or
value string. If a string exceeds this length (even after any
decompression), Write will return ErrStringLength.
A value of 0 means unlimited and is the default from NewDecoder. | SetMaxStringLength | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) SetEmitFunc(emitFunc func(f HeaderField)) {
d.emit = emitFunc
} | SetEmitFunc changes the callback used when new header fields
are decoded.
It must be non-nil. It does not affect EmitEnabled. | SetEmitFunc | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) SetEmitEnabled(v bool) { d.emitEnabled = v } | SetEmitEnabled controls whether the emitFunc provided to NewDecoder
should be called. The default is true.
This facility exists to let servers enforce MAX_HEADER_LIST_SIZE
while still decoding and keeping in-sync with decoder state, but
without doing unnecessary decompression or generating unnecessary
garbage for header fields past the limit. | SetEmitEnabled | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) EmitEnabled() bool { return d.emitEnabled } | EmitEnabled reports whether calls to the emitFunc provided to NewDecoder
are currently enabled. The default is true. | EmitEnabled | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) SetAllowedMaxDynamicTableSize(v uint32) {
d.dynTab.allowedMaxSize = v
} | SetAllowedMaxDynamicTableSize sets the upper bound that the encoded
stream (via dynamic table size updates) may set the maximum size
to. | SetAllowedMaxDynamicTableSize | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (dt *dynamicTable) evict() {
var n int
for dt.size > dt.maxSize && n < dt.table.len() {
dt.size -= dt.table.ents[n].Size()
n++
}
dt.table.evictOldest(n)
} | If we're too big, evict old stuff. | evict | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) DecodeFull(p []byte) ([]HeaderField, error) {
var hf []HeaderField
saveFunc := d.emit
defer func() { d.emit = saveFunc }()
d.emit = func(f HeaderField) { hf = append(hf, f) }
if _, err := d.Write(p); err != nil {
return nil, err
}
if err := d.Close(); err != nil {
return nil, err
}
return hf, nil
} | Decode decodes an entire block.
TODO: remove this method and make it incremental later? This is
easier for debugging now. | DecodeFull | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) Close() error {
if d.saveBuf.Len() > 0 {
d.saveBuf.Reset()
return DecodingError{errors.New("truncated headers")}
}
d.firstField = true
return nil
} | Close declares that the decoding is complete and resets the Decoder
to be reused again for a new header block. If there is any remaining
data in the decoder's buffer, Close returns an error. | Close | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) parseHeaderFieldRepr() error {
b := d.buf[0]
switch {
case b&128 != 0:
// Indexed representation.
// High bit set?
// http://http2.github.io/http2-spec/compression.html#rfc.section.6.1
return d.parseFieldIndexed()
case b&192 == 64:
// 6.2.1 Literal Header Field with Incremental Indexing
// 0b10xxxxxx: top two bits are 10
// http://http2.github.io/http2-spec/compression.html#rfc.section.6.2.1
return d.parseFieldLiteral(6, indexedTrue)
case b&240 == 0:
// 6.2.2 Literal Header Field without Indexing
// 0b0000xxxx: top four bits are 0000
// http://http2.github.io/http2-spec/compression.html#rfc.section.6.2.2
return d.parseFieldLiteral(4, indexedFalse)
case b&240 == 16:
// 6.2.3 Literal Header Field never Indexed
// 0b0001xxxx: top four bits are 0001
// http://http2.github.io/http2-spec/compression.html#rfc.section.6.2.3
return d.parseFieldLiteral(4, indexedNever)
case b&224 == 32:
// 6.3 Dynamic Table Size Update
// Top three bits are '001'.
// http://http2.github.io/http2-spec/compression.html#rfc.section.6.3
return d.parseDynamicTableSizeUpdate()
}
return DecodingError{errors.New("invalid encoding")}
} | returns errNeedMore if there isn't enough data available.
any other error is fatal.
consumes d.buf iff it returns nil.
precondition: must be called with len(d.buf) > 0 | parseHeaderFieldRepr | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) parseFieldIndexed() error {
buf := d.buf
idx, buf, err := readVarInt(7, buf)
if err != nil {
return err
}
hf, ok := d.at(idx)
if !ok {
return DecodingError{InvalidIndexError(idx)}
}
d.buf = buf
return d.callEmit(HeaderField{Name: hf.Name, Value: hf.Value})
} | (same invariants and behavior as parseHeaderFieldRepr) | parseFieldIndexed | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) parseFieldLiteral(n uint8, it indexType) error {
buf := d.buf
nameIdx, buf, err := readVarInt(n, buf)
if err != nil {
return err
}
var hf HeaderField
wantStr := d.emitEnabled || it.indexed()
if nameIdx > 0 {
ihf, ok := d.at(nameIdx)
if !ok {
return DecodingError{InvalidIndexError(nameIdx)}
}
hf.Name = ihf.Name
} else {
hf.Name, buf, err = d.readString(buf, wantStr)
if err != nil {
return err
}
}
hf.Value, buf, err = d.readString(buf, wantStr)
if err != nil {
return err
}
d.buf = buf
if it.indexed() {
d.dynTab.add(hf)
}
hf.Sensitive = it.sensitive()
return d.callEmit(hf)
} | (same invariants and behavior as parseHeaderFieldRepr) | parseFieldLiteral | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) parseDynamicTableSizeUpdate() error {
// RFC 7541, sec 4.2: This dynamic table size update MUST occur at the
// beginning of the first header block following the change to the dynamic table size.
if !d.firstField && d.dynTab.size > 0 {
return DecodingError{errors.New("dynamic table size update MUST occur at the beginning of a header block")}
}
buf := d.buf
size, buf, err := readVarInt(5, buf)
if err != nil {
return err
}
if size > uint64(d.dynTab.allowedMaxSize) {
return DecodingError{errors.New("dynamic table size update too large")}
}
d.dynTab.setMaxSize(uint32(size))
d.buf = buf
return nil
} | (same invariants and behavior as parseHeaderFieldRepr) | parseDynamicTableSizeUpdate | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func readVarInt(n byte, p []byte) (i uint64, remain []byte, err error) {
if n < 1 || n > 8 {
panic("bad n")
}
if len(p) == 0 {
return 0, p, errNeedMore
}
i = uint64(p[0])
if n < 8 {
i &= (1 << uint64(n)) - 1
}
if i < (1<<uint64(n))-1 {
return i, p[1:], nil
}
origP := p
p = p[1:]
var m uint64
for len(p) > 0 {
b := p[0]
p = p[1:]
i += uint64(b&127) << m
if b&128 == 0 {
return i, p, nil
}
m += 7
if m >= 63 { // TODO: proper overflow check. making this up.
return 0, origP, errVarintOverflow
}
}
return 0, origP, errNeedMore
} | readVarInt reads an unsigned variable length integer off the
beginning of p. n is the parameter as described in
http://http2.github.io/http2-spec/compression.html#rfc.section.5.1.
n must always be between 1 and 8.
The returned remain buffer is either a smaller suffix of p, or err != nil.
The error is errNeedMore if p doesn't contain a complete integer. | readVarInt | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func (d *Decoder) readString(p []byte, wantStr bool) (s string, remain []byte, err error) {
if len(p) == 0 {
return "", p, errNeedMore
}
isHuff := p[0]&128 != 0
strLen, p, err := readVarInt(7, p)
if err != nil {
return "", p, err
}
if d.maxStrLen != 0 && strLen > uint64(d.maxStrLen) {
return "", nil, ErrStringLength
}
if uint64(len(p)) < strLen {
return "", p, errNeedMore
}
if !isHuff {
if wantStr {
s = string(p[:strLen])
}
return s, p[strLen:], nil
}
if wantStr {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset() // don't trust others
defer bufPool.Put(buf)
if err := huffmanDecode(buf, d.maxStrLen, p[:strLen]); err != nil {
buf.Reset()
return "", nil, err
}
s = buf.String()
buf.Reset() // be nice to GC
}
return s, p[strLen:], nil
} | readString decodes an hpack string from p.
wantStr is whether s will be used. If false, decompression and
[]byte->string garbage are skipped if s will be ignored
anyway. This does mean that huffman decoding errors for non-indexed
strings past the MAX_HEADER_LIST_SIZE are ignored, but the server
is returning an error anyway, and because they're not indexed, the error
won't affect the decoding state. | readString | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/hpack.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/hpack.go | BSD-3-Clause |
func HuffmanDecode(w io.Writer, v []byte) (int, error) {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
defer bufPool.Put(buf)
if err := huffmanDecode(buf, 0, v); err != nil {
return 0, err
}
return w.Write(buf.Bytes())
} | HuffmanDecode decodes the string in v and writes the expanded
result to w, returning the number of bytes written to w and the
Write call's return value. At most one Write call is made. | HuffmanDecode | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/huffman.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/huffman.go | BSD-3-Clause |
func HuffmanDecodeToString(v []byte) (string, error) {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
defer bufPool.Put(buf)
if err := huffmanDecode(buf, 0, v); err != nil {
return "", err
}
return buf.String(), nil
} | HuffmanDecodeToString decodes the string in v. | HuffmanDecodeToString | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/huffman.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/huffman.go | BSD-3-Clause |
func huffmanDecode(buf *bytes.Buffer, maxLen int, v []byte) error {
rootHuffmanNode := getRootHuffmanNode()
n := rootHuffmanNode
// cur is the bit buffer that has not been fed into n.
// cbits is the number of low order bits in cur that are valid.
// sbits is the number of bits of the symbol prefix being decoded.
cur, cbits, sbits := uint(0), uint8(0), uint8(0)
for _, b := range v {
cur = cur<<8 | uint(b)
cbits += 8
sbits += 8
for cbits >= 8 {
idx := byte(cur >> (cbits - 8))
n = n.children[idx]
if n == nil {
return ErrInvalidHuffman
}
if n.children == nil {
if maxLen != 0 && buf.Len() == maxLen {
return ErrStringLength
}
buf.WriteByte(n.sym)
cbits -= n.codeLen
n = rootHuffmanNode
sbits = cbits
} else {
cbits -= 8
}
}
}
for cbits > 0 {
n = n.children[byte(cur<<(8-cbits))]
if n == nil {
return ErrInvalidHuffman
}
if n.children != nil || n.codeLen > cbits {
break
}
if maxLen != 0 && buf.Len() == maxLen {
return ErrStringLength
}
buf.WriteByte(n.sym)
cbits -= n.codeLen
n = rootHuffmanNode
sbits = cbits
}
if sbits > 7 {
// Either there was an incomplete symbol, or overlong padding.
// Both are decoding errors per RFC 7541 section 5.2.
return ErrInvalidHuffman
}
if mask := uint(1<<cbits - 1); cur&mask != mask {
// Trailing bits must be a prefix of EOS per RFC 7541 section 5.2.
return ErrInvalidHuffman
}
return nil
} | huffmanDecode decodes v to buf.
If maxLen is greater than 0, attempts to write more to buf than
maxLen bytes will return ErrStringLength. | huffmanDecode | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/huffman.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/huffman.go | BSD-3-Clause |
func AppendHuffmanString(dst []byte, s string) []byte {
rembits := uint8(8)
for i := 0; i < len(s); i++ {
if rembits == 8 {
dst = append(dst, 0)
}
dst, rembits = appendByteToHuffmanCode(dst, rembits, s[i])
}
if rembits < 8 {
// special EOS symbol
code := uint32(0x3fffffff)
nbits := uint8(30)
t := uint8(code >> (nbits - rembits))
dst[len(dst)-1] |= t
}
return dst
} | AppendHuffmanString appends s, as encoded in Huffman codes, to dst
and returns the extended buffer. | AppendHuffmanString | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/huffman.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/huffman.go | BSD-3-Clause |
func HuffmanEncodeLength(s string) uint64 {
n := uint64(0)
for i := 0; i < len(s); i++ {
n += uint64(huffmanCodeLen[s[i]])
}
return (n + 7) / 8
} | HuffmanEncodeLength returns the number of bytes required to encode
s in Huffman codes. The result is round up to byte boundary. | HuffmanEncodeLength | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/huffman.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/huffman.go | BSD-3-Clause |
func appendByteToHuffmanCode(dst []byte, rembits uint8, c byte) ([]byte, uint8) {
code := huffmanCodes[c]
nbits := huffmanCodeLen[c]
for {
if rembits > nbits {
t := uint8(code << (rembits - nbits))
dst[len(dst)-1] |= t
rembits -= nbits
break
}
t := uint8(code >> (nbits - rembits))
dst[len(dst)-1] |= t
nbits -= rembits
rembits = 8
if nbits == 0 {
break
}
dst = append(dst, 0)
}
return dst, rembits
} | appendByteToHuffmanCode appends Huffman code for c to dst and
returns the extended buffer and the remaining bits in the last
element. The appending is not byte aligned and the remaining bits
in the last element of dst is given in rembits. | appendByteToHuffmanCode | go | flynn/flynn | vendor/golang.org/x/net/http2/hpack/huffman.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/net/http2/hpack/huffman.go | BSD-3-Clause |
func (ft *Filetime) Nanoseconds() int64 {
// 100-nanosecond intervals since January 1, 1601
nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
// change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
nsec -= 116444736000000000
// convert into nanoseconds
nsec *= 100
return nsec
} | Nanoseconds returns Filetime ft in nanoseconds
since Epoch (00:00:00 UTC, January 1, 1970). | Nanoseconds | go | flynn/flynn | vendor/golang.org/x/sys/windows/types_windows.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/types_windows.go | BSD-3-Clause |
func (addr *SocketAddress) IP() net.IP {
if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(RawSockaddrInet4{}) && addr.Sockaddr.Addr.Family == AF_INET {
return (*RawSockaddrInet4)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
} else if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(RawSockaddrInet6{}) && addr.Sockaddr.Addr.Family == AF_INET6 {
return (*RawSockaddrInet6)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
}
return nil
} | IP returns an IPv4 or IPv6 address, or nil if the underlying SocketAddress is neither. | IP | go | flynn/flynn | vendor/golang.org/x/sys/windows/types_windows.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/types_windows.go | BSD-3-Clause |
func (token Token) Environ(inheritExisting bool) (env []string, err error) {
var block *uint16
err = CreateEnvironmentBlock(&block, token, inheritExisting)
if err != nil {
return nil, err
}
defer DestroyEnvironmentBlock(block)
blockp := uintptr(unsafe.Pointer(block))
for {
entry := (*[(1 << 30) - 1]uint16)(unsafe.Pointer(blockp))[:]
for i, v := range entry {
if v == 0 {
entry = entry[:i]
break
}
}
if len(entry) == 0 {
break
}
env = append(env, string(utf16.Decode(entry)))
blockp += 2 * (uintptr(len(entry)) + 1)
}
return env, nil
} | Returns a default environment associated with the token, rather than the current
process. If inheritExisting is true, then this environment also inherits the
environment of the current process. | Environ | go | flynn/flynn | vendor/golang.org/x/sys/windows/env_windows.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/env_windows.go | BSD-3-Clause |
func ByteSliceFromString(s string) ([]byte, error) {
for i := 0; i < len(s); i++ {
if s[i] == 0 {
return nil, syscall.EINVAL
}
}
a := make([]byte, len(s)+1)
copy(a, s)
return a, nil
} | ByteSliceFromString returns a NUL-terminated slice of bytes
containing the text of s. If s contains a NUL byte at any
location, it returns (nil, syscall.EINVAL). | ByteSliceFromString | go | flynn/flynn | vendor/golang.org/x/sys/windows/syscall.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/syscall.go | BSD-3-Clause |
func BytePtrFromString(s string) (*byte, error) {
a, err := ByteSliceFromString(s)
if err != nil {
return nil, err
}
return &a[0], nil
} | BytePtrFromString returns a pointer to a NUL-terminated array of
bytes containing the text of s. If s contains a NUL byte at any
location, it returns (nil, syscall.EINVAL). | BytePtrFromString | go | flynn/flynn | vendor/golang.org/x/sys/windows/syscall.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/syscall.go | BSD-3-Clause |
func errnoErr(e syscall.Errno) error {
switch e {
case 0:
return nil
case errnoERROR_IO_PENDING:
return errERROR_IO_PENDING
}
// TODO: add more here, after collecting data on the common
// error values see on Windows. (perhaps when running
// all.bat?)
return e
} | errnoErr returns common boxed Errno values, to prevent
allocations at runtime. | errnoErr | go | flynn/flynn | vendor/golang.org/x/sys/windows/zsyscall_windows.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/zsyscall_windows.go | BSD-3-Clause |
func TranslateAccountName(username string, from, to uint32, initSize int) (string, error) {
u, e := UTF16PtrFromString(username)
if e != nil {
return "", e
}
n := uint32(50)
for {
b := make([]uint16, n)
e = TranslateName(u, from, to, &b[0], &n)
if e == nil {
return UTF16ToString(b[:n]), nil
}
if e != ERROR_INSUFFICIENT_BUFFER {
return "", e
}
if n <= uint32(len(b)) {
return "", e
}
}
} | TranslateAccountName converts a directory service
object name from one format to another. | TranslateAccountName | go | flynn/flynn | vendor/golang.org/x/sys/windows/security_windows.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/security_windows.go | BSD-3-Clause |
func StringToSid(s string) (*SID, error) {
var sid *SID
p, e := UTF16PtrFromString(s)
if e != nil {
return nil, e
}
e = ConvertStringSidToSid(p, &sid)
if e != nil {
return nil, e
}
defer LocalFree((Handle)(unsafe.Pointer(sid)))
return sid.Copy()
} | StringToSid converts a string-format security identifier
SID into a valid, functional SID. | StringToSid | go | flynn/flynn | vendor/golang.org/x/sys/windows/security_windows.go | https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/sys/windows/security_windows.go | BSD-3-Clause |
go Code Dataset (go-codesearch-dataset-open)
Dataset Description
This dataset contains go methods (functions) along with their documentation comments (typically #
comments preceding the def
line), extracted from various GitHub repositories. It follows a format similar to CodeSearchNet.
Features
The dataset includes the following features for each sample:
code
: The go method's source code (fromdef
toend
).docstring
: The documentation comment associated with the method.func_name
: The name of the method (function).language
: The programming language (always"go"
).repo
: The full name of the source GitHub repository (e.g.,rails/rails
).path
: The relative file path within the source repository.url
: A GitHub URL pointing to the source file (usually on the master/main branch).license
: The SPDX identifier of the license declared for the source repository (e.g.,MIT
,Apache-2.0
,go
, orNO LICENSE
).
Dataset Structure
The dataset is divided into the following splits:
train
: 388,495 examplesvalidation
: 43,941 examplestest
: 1,736 examples
Total Examples: 434,172
Usage
You can load and use this dataset using the datasets
library:
from datasets import load_dataset
# Load the dataset from the Hugging Face Hub
dataset = load_dataset("Shuu12121/go-codesearch-dataset-open")
# Access a specific split (e.g., training split)
train_data = dataset["train"]
# Explore the data
print(f"Number of training samples: {len(train_data):,}")
print("\nFirst training sample:")
print(train_data[0])
# Example: Access code and docstring of the first sample
first_sample = train_data[0]
print("\nMethod Name:", first_sample['func_name'])
print("\nDocstring:\n", first_sample['docstring'])
# print("\nCode Snippet:\n", first_sample['code'][:500] + "...") # Print first 500 chars of code
Licensing
The code snippets included in this dataset are sourced from various GitHub repositories under different licenses (MIT, Apache-2.0, go License, BSD clauses, etc.). Each data sample contains a license
field indicating the license of the source repository. Users of this dataset should be aware of and respect the original licenses when using the code snippets. The dataset itself (the collection and organization) is provided under a permissive license, but the underlying code snippets retain their original licenses.
Disclaimer
This dataset was generated through an automated process. While efforts were made to accurately extract methods and documentation, there might be errors or inaccuracies.
- Downloads last month
- 55