mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
format using go-1.19
This commit is contained in:
parent
9ce1de4eee
commit
5ef5142bb0
11 changed files with 34 additions and 27 deletions
|
@ -22,7 +22,6 @@ The Dial function connects to a Snowflake server:
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package snowflake_client
|
package snowflake_client
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Package amp provides functions for working with the AMP (Accelerated Mobile
|
Package amp provides functions for working with the AMP (Accelerated Mobile
|
||||||
Pages) subset of HTML, and conveying binary data through an AMP cache.
|
Pages) subset of HTML, and conveying binary data through an AMP cache.
|
||||||
|
|
||||||
AMP cache
|
# AMP cache
|
||||||
|
|
||||||
The CacheURL function takes a plain URL and converts it to be accessed through a
|
The CacheURL function takes a plain URL and converts it to be accessed through a
|
||||||
given AMP cache.
|
given AMP cache.
|
||||||
|
@ -11,7 +11,9 @@ The EncodePath and DecodePath functions provide a way to encode data into the
|
||||||
suffix of a URL path. AMP caches do not support HTTP POST, but encoding data
|
suffix of a URL path. AMP caches do not support HTTP POST, but encoding data
|
||||||
into a URL path with GET is an alternative means of sending data to the server.
|
into a URL path with GET is an alternative means of sending data to the server.
|
||||||
The format of an encoded path is:
|
The format of an encoded path is:
|
||||||
|
|
||||||
0<0 or more bytes, including slash>/<base64 of data>
|
0<0 or more bytes, including slash>/<base64 of data>
|
||||||
|
|
||||||
That is:
|
That is:
|
||||||
* "0", a format version number, which controls the interpretation of the rest of
|
* "0", a format version number, which controls the interpretation of the rest of
|
||||||
the path. Only the first byte matters as a version indicator (not the whole
|
the path. Only the first byte matters as a version indicator (not the whole
|
||||||
|
@ -25,12 +27,13 @@ include slash).
|
||||||
For example, an encoding of the string "This is path-encoded data." is the
|
For example, an encoding of the string "This is path-encoded data." is the
|
||||||
following. The "lgWHcwhXFjUm" following the format version number is random
|
following. The "lgWHcwhXFjUm" following the format version number is random
|
||||||
padding that will be ignored on decoding.
|
padding that will be ignored on decoding.
|
||||||
|
|
||||||
0lgWHcwhXFjUm/VGhpcyBpcyBwYXRoLWVuY29kZWQgZGF0YS4
|
0lgWHcwhXFjUm/VGhpcyBpcyBwYXRoLWVuY29kZWQgZGF0YS4
|
||||||
|
|
||||||
It is the caller's responsibility to add or remove any directory path prefix
|
It is the caller's responsibility to add or remove any directory path prefix
|
||||||
before calling EncodePath or DecodePath.
|
before calling EncodePath or DecodePath.
|
||||||
|
|
||||||
AMP armor
|
# AMP armor
|
||||||
|
|
||||||
AMP armor is a data encoding scheme that that satisfies the requirements of the
|
AMP armor is a data encoding scheme that that satisfies the requirements of the
|
||||||
AMP (Accelerated Mobile Pages) subset of HTML, and survives modification by an
|
AMP (Accelerated Mobile Pages) subset of HTML, and survives modification by an
|
||||||
|
@ -63,7 +66,7 @@ limit the amount of text a decoder may have to buffer while parsing the HTML.
|
||||||
Each pre element may contain at most 64 KB of text. pre elements may not be
|
Each pre element may contain at most 64 KB of text. pre elements may not be
|
||||||
nested.
|
nested.
|
||||||
|
|
||||||
Example
|
# Example
|
||||||
|
|
||||||
The following is the result of encoding the string
|
The following is the result of encoding the string
|
||||||
"This was encoded with AMP armor.":
|
"This was encoded with AMP armor.":
|
||||||
|
|
|
@ -6,23 +6,29 @@
|
||||||
// represents data or padding (1=data, 0=padding). Another bit ("c" for
|
// represents data or padding (1=data, 0=padding). Another bit ("c" for
|
||||||
// "continuation") is the indicates whether there are more bytes in the length
|
// "continuation") is the indicates whether there are more bytes in the length
|
||||||
// prefix. The remaining 6 bits ("x") encode part of the length value.
|
// prefix. The remaining 6 bits ("x") encode part of the length value.
|
||||||
|
//
|
||||||
// dcxxxxxx
|
// dcxxxxxx
|
||||||
|
//
|
||||||
// If the continuation bit is set, then the next byte is also part of the length
|
// If the continuation bit is set, then the next byte is also part of the length
|
||||||
// prefix. It lacks the "d" bit, has its own "c" bit, and 7 value-carrying bits
|
// prefix. It lacks the "d" bit, has its own "c" bit, and 7 value-carrying bits
|
||||||
// ("y").
|
// ("y").
|
||||||
|
//
|
||||||
// cyyyyyyy
|
// cyyyyyyy
|
||||||
|
//
|
||||||
// The length is decoded by concatenating value-carrying bits, from left to
|
// The length is decoded by concatenating value-carrying bits, from left to
|
||||||
// right, of all value-carrying bits, up to and including the first byte whose
|
// right, of all value-carrying bits, up to and including the first byte whose
|
||||||
// "c" bit is 0. Although in principle this encoding would allow for length
|
// "c" bit is 0. Although in principle this encoding would allow for length
|
||||||
// prefixes of any size, length prefixes are arbitrarily limited to 3 bytes and
|
// prefixes of any size, length prefixes are arbitrarily limited to 3 bytes and
|
||||||
// any attempt to read or write a longer one is an error. These are therefore
|
// any attempt to read or write a longer one is an error. These are therefore
|
||||||
// the only valid formats:
|
// the only valid formats:
|
||||||
|
//
|
||||||
// 00xxxxxx xxxxxx₂ bytes of padding
|
// 00xxxxxx xxxxxx₂ bytes of padding
|
||||||
// 10xxxxxx xxxxxx₂ bytes of data
|
// 10xxxxxx xxxxxx₂ bytes of data
|
||||||
// 01xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of padding
|
// 01xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of padding
|
||||||
// 11xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of data
|
// 11xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of data
|
||||||
// 01xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of padding
|
// 01xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of padding
|
||||||
// 11xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of data
|
// 11xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of data
|
||||||
|
//
|
||||||
// The maximum encodable length is 11111111111111111111₂ = 0xfffff = 1048575.
|
// The maximum encodable length is 11111111111111111111₂ = 0xfffff = 1048575.
|
||||||
// There is no requirement to use a length prefix of minimum size; i.e. 00000100
|
// There is no requirement to use a length prefix of minimum size; i.e. 00000100
|
||||||
// and 01000000 00000100 are both valid encodings of the value 4.
|
// and 01000000 00000100 are both valid encodings of the value 4.
|
||||||
|
|
|
@ -146,6 +146,7 @@ func TestWrite(t *testing.T) {
|
||||||
|
|
||||||
// Test that multiple goroutines may call Read on a Conn simultaneously. Run
|
// Test that multiple goroutines may call Read on a Conn simultaneously. Run
|
||||||
// this with
|
// this with
|
||||||
|
//
|
||||||
// go test -race
|
// go test -race
|
||||||
func TestConcurrentRead(t *testing.T) {
|
func TestConcurrentRead(t *testing.T) {
|
||||||
s, c, err := connPair()
|
s, c, err := connPair()
|
||||||
|
@ -189,6 +190,7 @@ func TestConcurrentRead(t *testing.T) {
|
||||||
|
|
||||||
// Test that multiple goroutines may call Write on a Conn simultaneously. Run
|
// Test that multiple goroutines may call Write on a Conn simultaneously. Run
|
||||||
// this with
|
// this with
|
||||||
|
//
|
||||||
// go test -race
|
// go test -race
|
||||||
func TestConcurrentWrite(t *testing.T) {
|
func TestConcurrentWrite(t *testing.T) {
|
||||||
s, c, err := connPair()
|
s, c, err := connPair()
|
||||||
|
|
|
@ -17,7 +17,6 @@ Transport as follows:
|
||||||
|
|
||||||
transport := snowflake_server.NewSnowflakeServer(certManager.GetCertificate)
|
transport := snowflake_server.NewSnowflakeServer(certManager.GetCertificate)
|
||||||
|
|
||||||
|
|
||||||
The Listen function starts a new listener, and Accept will return incoming Snowflake connections:
|
The Listen function starts a new listener, and Accept will return incoming Snowflake connections:
|
||||||
|
|
||||||
ln, err := transport.Listen(addr)
|
ln, err := transport.Listen(addr)
|
||||||
|
@ -31,8 +30,6 @@ The Listen function starts a new listener, and Accept will return incoming Snowf
|
||||||
}
|
}
|
||||||
// handle conn
|
// handle conn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package snowflake_server
|
package snowflake_server
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue