format using go-1.19

This commit is contained in:
trinity-1686a 2022-10-09 16:36:22 +02:00
parent 9ce1de4eee
commit 5ef5142bb0
11 changed files with 34 additions and 27 deletions

View file

@ -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

View file

@ -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.":

View file

@ -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 //
// 10xxxxxx xxxxxx₂ bytes of data // 00xxxxxx xxxxxx₂ bytes of padding
// 01xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of padding // 10xxxxxx xxxxxx₂ bytes of data
// 11xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of data // 01xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of padding
// 01xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of padding // 11xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of data
// 11xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of data // 01xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of padding
// 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.

View file

@ -1,6 +1,6 @@
//Package for communication with the snowflake broker //Package for communication with the snowflake broker
//import "git.torproject.org/pluggable-transports/snowflake.git/v2/common/messages" // import "git.torproject.org/pluggable-transports/snowflake.git/v2/common/messages"
package messages package messages
import ( import (

View file

@ -1,6 +1,6 @@
//Package for communication with the snowflake broker //Package for communication with the snowflake broker
//import "git.torproject.org/pluggable-transports/snowflake.git/v2/common/messages" // import "git.torproject.org/pluggable-transports/snowflake.git/v2/common/messages"
package messages package messages
import ( import (

View file

@ -1,6 +1,6 @@
//Package for a safer logging wrapper around the standard logging package //Package for a safer logging wrapper around the standard logging package
//import "git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog" // import "git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog"
package safelog package safelog
import ( import (

View file

@ -6,7 +6,7 @@ import (
"testing" "testing"
) )
//Check to make sure that addresses split across calls to write are still scrubbed // Check to make sure that addresses split across calls to write are still scrubbed
func TestLogScrubberSplit(t *testing.T) { func TestLogScrubberSplit(t *testing.T) {
input := []byte("test\nhttp2: panic serving [2620:101:f000:780:9097:75b1:519f:dbb8]:58344: interface conversion: *http2.responseWriter is not http.Hijacker: missing method Hijack\n") input := []byte("test\nhttp2: panic serving [2620:101:f000:780:9097:75b1:519f:dbb8]:58344: interface conversion: *http2.responseWriter is not http.Hijacker: missing method Hijack\n")
@ -49,7 +49,7 @@ func TestLogScrubberSplit(t *testing.T) {
} }
//Test the log scrubber on known problematic log messages // Test the log scrubber on known problematic log messages
func TestLogScrubberMessages(t *testing.T) { func TestLogScrubberMessages(t *testing.T) {
for _, test := range []struct { for _, test := range []struct {
input, expected string input, expected string

View file

@ -146,7 +146,8 @@ 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()
if err != nil { if err != nil {
@ -189,7 +190,8 @@ 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()
if err != nil { if err != nil {

View file

@ -70,8 +70,8 @@ const (
NATUnrestricted = "unrestricted" NATUnrestricted = "unrestricted"
) )
//amount of time after sending an SDP answer before the proxy assumes the // amount of time after sending an SDP answer before the proxy assumes the
//client is not going to connect // client is not going to connect
const dataChannelTimeout = 20 * time.Second const dataChannelTimeout = 20 * time.Second
const readLimit = 100000 //Maximum number of bytes to be read from an HTTP request const readLimit = 100000 //Maximum number of bytes to be read from an HTTP request

View file

@ -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

View file

@ -42,7 +42,7 @@ additional HTTP listener on port 80 to work with ACME.
flag.PrintDefaults() flag.PrintDefaults()
} }
//proxy copies data bidirectionally from one connection to another. // proxy copies data bidirectionally from one connection to another.
func proxy(local *net.TCPConn, conn net.Conn) { func proxy(local *net.TCPConn, conn net.Conn) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
@ -67,7 +67,7 @@ func proxy(local *net.TCPConn, conn net.Conn) {
wg.Wait() wg.Wait()
} }
//handleConn bidirectionally connects a client snowflake connection with an ORPort. // handleConn bidirectionally connects a client snowflake connection with an ORPort.
func handleConn(conn net.Conn) error { func handleConn(conn net.Conn) error {
addr := conn.RemoteAddr().String() addr := conn.RemoteAddr().String()
statsChannel <- addr != "" statsChannel <- addr != ""
@ -80,7 +80,7 @@ func handleConn(conn net.Conn) error {
return nil return nil
} }
//acceptLoop accepts incoming client snowflake connection and passes them to a handler function. // acceptLoop accepts incoming client snowflake connection and passes them to a handler function.
func acceptLoop(ln net.Listener) { func acceptLoop(ln net.Listener) {
for { for {
conn, err := ln.Accept() conn, err := ln.Accept()