mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -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
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
*/
|
||||
package snowflake_client
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Package amp provides functions for working with the AMP (Accelerated Mobile
|
||||
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
|
||||
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
|
||||
into a URL path with GET is an alternative means of sending data to the server.
|
||||
The format of an encoded path is:
|
||||
|
||||
0<0 or more bytes, including slash>/<base64 of data>
|
||||
|
||||
That is:
|
||||
* "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
|
||||
|
@ -25,12 +27,13 @@ include slash).
|
|||
For example, an encoding of the string "This is path-encoded data." is the
|
||||
following. The "lgWHcwhXFjUm" following the format version number is random
|
||||
padding that will be ignored on decoding.
|
||||
|
||||
0lgWHcwhXFjUm/VGhpcyBpcyBwYXRoLWVuY29kZWQgZGF0YS4
|
||||
|
||||
It is the caller's responsibility to add or remove any directory path prefix
|
||||
before calling EncodePath or DecodePath.
|
||||
|
||||
AMP armor
|
||||
# AMP armor
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
nested.
|
||||
|
||||
Example
|
||||
# Example
|
||||
|
||||
The following is the result of encoding the string
|
||||
"This was encoded with AMP armor.":
|
||||
|
|
|
@ -6,23 +6,29 @@
|
|||
// represents data or padding (1=data, 0=padding). Another bit ("c" for
|
||||
// "continuation") is the indicates whether there are more bytes in the length
|
||||
// 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
|
||||
// prefix. It lacks the "d" bit, has its own "c" bit, and 7 value-carrying bits
|
||||
// ("y").
|
||||
// cyyyyyyy
|
||||
//
|
||||
// cyyyyyyy
|
||||
//
|
||||
// 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
|
||||
// "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
|
||||
// any attempt to read or write a longer one is an error. These are therefore
|
||||
// the only valid formats:
|
||||
// 00xxxxxx xxxxxx₂ bytes of padding
|
||||
// 10xxxxxx xxxxxx₂ bytes of data
|
||||
// 01xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of padding
|
||||
// 11xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of data
|
||||
// 01xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of padding
|
||||
// 11xxxxxx 1yyyyyyy 0zzzzzzz xxxxxxyyyyyyyzzzzzzz₂ bytes of data
|
||||
//
|
||||
// 00xxxxxx xxxxxx₂ bytes of padding
|
||||
// 10xxxxxx xxxxxx₂ bytes of data
|
||||
// 01xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ bytes of padding
|
||||
// 11xxxxxx 0yyyyyyy xxxxxxyyyyyyy₂ 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.
|
||||
// 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.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//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
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//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
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//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
|
||||
|
||||
import (
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"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) {
|
||||
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) {
|
||||
for _, test := range []struct {
|
||||
input, expected string
|
||||
|
|
|
@ -146,7 +146,8 @@ func TestWrite(t *testing.T) {
|
|||
|
||||
// Test that multiple goroutines may call Read on a Conn simultaneously. Run
|
||||
// this with
|
||||
// go test -race
|
||||
//
|
||||
// go test -race
|
||||
func TestConcurrentRead(t *testing.T) {
|
||||
s, c, err := connPair()
|
||||
if err != nil {
|
||||
|
@ -189,7 +190,8 @@ func TestConcurrentRead(t *testing.T) {
|
|||
|
||||
// Test that multiple goroutines may call Write on a Conn simultaneously. Run
|
||||
// this with
|
||||
// go test -race
|
||||
//
|
||||
// go test -race
|
||||
func TestConcurrentWrite(t *testing.T) {
|
||||
s, c, err := connPair()
|
||||
if err != nil {
|
||||
|
|
|
@ -70,8 +70,8 @@ const (
|
|||
NATUnrestricted = "unrestricted"
|
||||
)
|
||||
|
||||
//amount of time after sending an SDP answer before the proxy assumes the
|
||||
//client is not going to connect
|
||||
// amount of time after sending an SDP answer before the proxy assumes the
|
||||
// client is not going to connect
|
||||
const dataChannelTimeout = 20 * time.Second
|
||||
|
||||
const readLimit = 100000 //Maximum number of bytes to be read from an HTTP request
|
||||
|
|
|
@ -17,7 +17,6 @@ Transport as follows:
|
|||
|
||||
transport := snowflake_server.NewSnowflakeServer(certManager.GetCertificate)
|
||||
|
||||
|
||||
The Listen function starts a new listener, and Accept will return incoming Snowflake connections:
|
||||
|
||||
ln, err := transport.Listen(addr)
|
||||
|
@ -31,8 +30,6 @@ The Listen function starts a new listener, and Accept will return incoming Snowf
|
|||
}
|
||||
// handle conn
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
package snowflake_server
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ additional HTTP listener on port 80 to work with ACME.
|
|||
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) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
|
@ -67,7 +67,7 @@ func proxy(local *net.TCPConn, conn net.Conn) {
|
|||
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 {
|
||||
addr := conn.RemoteAddr().String()
|
||||
statsChannel <- addr != ""
|
||||
|
@ -80,7 +80,7 @@ func handleConn(conn net.Conn) error {
|
|||
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) {
|
||||
for {
|
||||
conn, err := ln.Accept()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue