Commit graph

156 commits

Author SHA1 Message Date
David Fifield
590d158df8 Comment typo. 2023-04-04 18:46:35 -06:00
David Fifield
36d5d2dd83 Fix comment typo on NewRedialPacketConn. 2023-03-13 15:10:35 -06:00
David Fifield
d2858aeb7e Revert "Take ownership of buffer in QueuePacketConn QueueIncoming/WriteTo."
This reverts commit 839d221883. (Except for
the added benchmarks in queuepacketconn_test.go.) This change
corresponds to the issues #40187 and #40199.

The analysis in https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40199
was wrong; kcp-go does reuse the buffers it passes to
QueuePacketConn.WriteTo. This led to unsynchronized reuse of packet
buffers and mangled packets observable at the client:
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40260.

Undoing the change in QueuePacketConn.QueueIncoming as well, for
symmetry, even though it is not implicated in any correctness problems.
2023-03-13 12:57:35 -06:00
David Fifield
b63d2272bf Test for data race with QueuePacketConn.WriteTo and kcp-go.
For #40260.
2023-03-13 11:42:44 -06:00
Shelikhoo
7b77001eaa
Update version to v2.5.1 2023-01-18 14:37:05 +00:00
Shelikhoo
daa9b535c8
Update Version to v2.5.0 2023-01-18 11:27:31 +00:00
Cecylia Bocovich
4895a32fd3
Bump version to v2.4.3 2023-01-16 11:55:31 -05:00
Flo418
11c3333856 add some more test for URL encoded IPs (safelog) 2022-12-12 19:56:59 +01:00
David Fifield
839d221883 Take ownership of buffer in QueuePacketConn QueueIncoming/WriteTo.
This design is easier to misuse, because it allows the caller to modify
the contents of the slice after queueing it, but it avoids an extra
allocation + memmove per incoming packet.

Before:
	$ go test -bench='Benchmark(QueueIncoming|WriteTo)' -benchtime=2s -benchmem
	BenchmarkQueueIncoming-4         7001494               342.4 ns/op          1024 B/op          2 allocs/op
	BenchmarkWriteTo-4               3777459               627 ns/op            1024 B/op          2 allocs/op
After:
	$ go test -bench=BenchmarkWriteTo -benchtime 2s -benchmem
	BenchmarkQueueIncoming-4        13361600               170.1 ns/op           512 B/op          1 allocs/op
	BenchmarkWriteTo-4               6702324               373 ns/op             512 B/op          1 allocs/op

Despite the benchmark results, the change in QueueIncoming turns out not
to have an effect in practice. It appears that the compiler had already
been optimizing out the allocation and copy in QueueIncoming.
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40187

The WriteTo change, on the other hand, in practice reduces the frequency
of garbage collection.
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40199
2022-12-08 08:03:54 -07:00
David Fifield
d4749d2c1d Reduce turbotunnel queueSize from 2048 to 512.
This is to reduce heap usage.

https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40179

Past discussion of queueSize:
https://lists.torproject.org/pipermail/anti-censorship-team/2021-July/000188.html
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/48#note_2744619
2022-12-08 08:03:54 -07:00
David Fifield
64491466ce Manually unlock the mutex in ClientMap.SendQueue.
Rather than use defer. It is only a tiny amount faster, but this
function is frequently called.

Before:
	$ go test -bench=BenchmarkSendQueue -benchtime=2s
	BenchmarkSendQueue-4    15901834               151 ns/op
After:
	$ go test -bench=BenchmarkSendQueue -benchtime=2s
	BenchmarkSendQueue-4    15859948               147 ns/op

https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40177
2022-12-08 08:03:54 -07:00
Cecylia Bocovich
7c154e5fd0
Bump version to v2.4.1 2022-12-01 11:38:22 -05:00
Shelikhoo
788e3ae956
Refactor utls roundtripper_test to deduplicate 2022-11-29 15:41:49 +00:00
Shelikhoo
d8d3e538f1
Fix uTLS RoundTripper Inconsistent Key for host:port
This commit fixes an issue described at:
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40224

This bug has been fixed, with test case describing this bug added.
2022-11-29 15:41:49 +00:00
luciole
90d1a56719
change regexes for ipv6 addresses to catch url-encoded addresses 2022-11-28 15:56:35 -05:00
Shelikhoo
33248f3dec
Add Version Output Support to Snowflake
From now on, there will be a file at common/version/version.go that includes current version number.
2022-11-23 12:29:51 +00:00
luciole
2c599f8827
change bandwidth type from int to int64 to prevent overflow 2022-11-21 10:33:21 -05:00
David Fifield
e851861e68 Benchmark for encapsulation.ReadData. 2022-11-16 13:48:34 -07:00
David Fifield
a579c969e6 encapsulation.paddingBuffer can be statically allocated. 2022-11-16 13:48:34 -07:00
David Fifield
4ae63eccab Benchmark websocket.Conn Upgrade creation.
I had thought to set a buffer size of 2048, half the websocket package
default of 4096. But it turns out when you don't set a buffer size, the
websocket package reuses the HTTP server's read/write buffers, which
empirically already have a size of 2048.

	$ go test -bench=BenchmarkUpgradeBufferSize -benchmem -benchtime=5s
	BenchmarkUpgradeBufferSize/0-4                     25669            234566 ns/op           32604 B/op        113 allocs/op
	BenchmarkUpgradeBufferSize/128-4                   24739            238283 ns/op           24325 B/op        117 allocs/op
	BenchmarkUpgradeBufferSize/1024-4                  25352            238885 ns/op           28087 B/op        116 allocs/op
	BenchmarkUpgradeBufferSize/2048-4                  22660            234890 ns/op           32444 B/op        116 allocs/op
	BenchmarkUpgradeBufferSize/4096-4                  25668            232591 ns/op           41672 B/op        116 allocs/op
	BenchmarkUpgradeBufferSize/8192-4                  24908            240755 ns/op           59103 B/op        116 allocs/op
2022-11-16 13:48:34 -07:00
David Fifield
2321642f3c Hoist temporary buffers outside the loop.
Otherwise the buffers are re-allocated on every iteration, which is a
surprise to me. I thought the compiler would do this transformation
itself.

Now there is just one allocation per client←server read (one
messageReader) and two allocations per server←client read (one
messageReader and one messageWriter).

	$ go test -bench=BenchmarkReadWrite -benchmem -benchtime=5s
	BenchmarkReadWrite/c←s_150-4              481054             12849 ns/op          11.67 MB/s           8 B/op          1 allocs/op
	BenchmarkReadWrite/s←c_150-4              421809             14095 ns/op          10.64 MB/s          56 B/op          2 allocs/op
	BenchmarkReadWrite/c←s_3000-4             208564             28003 ns/op         107.13 MB/s          16 B/op          2 allocs/op
	BenchmarkReadWrite/s←c_3000-4             186320             30576 ns/op          98.12 MB/s         112 B/op          4 allocs/op
2022-11-16 13:48:34 -07:00
David Fifield
264425a488 Use io.CopyBuffer in websocketconn.readLoop.
This avoids io.Copy allocating a 32 KB buffer on every call.
https://cs.opensource.google/go/go/+/refs/tags/go1.19.1:src/io/io.go;l=416

	$ go test -bench=BenchmarkReadWrite -benchmem -benchtime=5s
	BenchmarkReadWrite/c←s_150-4              385740             15114 ns/op           9.92 MB/s        4104 B/op          3 allocs/op
	BenchmarkReadWrite/s←c_150-4              347070             16824 ns/op           8.92 MB/s        4152 B/op          4 allocs/op
	BenchmarkReadWrite/c←s_3000-4             190257             31581 ns/op          94.99 MB/s        8208 B/op          6 allocs/op
	BenchmarkReadWrite/s←c_3000-4             163233             34821 ns/op          86.16 MB/s        8304 B/op          8 allocs/op
2022-11-16 13:48:34 -07:00
David Fifield
3df514ae29 Call WriteMessage directly in websocketconn.Conn.Write.
In the client←server direction, this hits a fast path that avoids
allocating a messageWriter.
https://github.com/gorilla/websocket/blob/v1.5.0/conn.go#L760

Cuts the number of allocations in half in the client←server direction:

	$ go test -bench=BenchmarkReadWrite -benchmem -benchtime=5s
	BenchmarkReadWrite/c←s_150-4              597511             13358 ns/op          11.23 MB/s       33709 B/op          2 allocs/op
	BenchmarkReadWrite/s←c_150-4              474176             13756 ns/op          10.90 MB/s       34968 B/op          4 allocs/op
	BenchmarkReadWrite/c←s_3000-4             156488             36290 ns/op          82.67 MB/s       68673 B/op          5 allocs/op
	BenchmarkReadWrite/s←c_3000-4             190897             34719 ns/op          86.41 MB/s       69730 B/op          8 allocs/op
2022-11-16 13:48:34 -07:00
David Fifield
8cadcaee70 Benchmark for websocketconn.Conn read/write.
Current output:
	$ go test -bench=BenchmarkReadWrite -benchmem -benchtime=5s
	BenchmarkReadWrite/c←s_150-4              451840             13904 ns/op          10.79 MB/s       34954 B/op          4 allocs/op
	BenchmarkReadWrite/s←c_150-4              452560             16134 ns/op           9.30 MB/s       36378 B/op          4 allocs/op
	BenchmarkReadWrite/c←s_3000-4             202950             40846 ns/op          73.45 MB/s       69833 B/op          8 allocs/op
	BenchmarkReadWrite/s←c_3000-4             189262             37930 ns/op          79.09 MB/s       69768 B/op          8 allocs/op
2022-11-16 13:48:34 -07:00
itchyonion
768b80dbdf
Use event logger for proxy starting message and NAT info 2022-11-16 10:08:10 -08:00
trinity-1686a
5ef5142bb0 format using go-1.19 2022-10-09 21:15:50 +02:00
Shelikhoo
35e9ab8c0b
Use truncated hash instead crc64 for counted hash 2022-06-16 15:00:12 +01:00
Shelikhoo
b18e6fcfe4
Add document for Distinct IP file 2022-06-16 15:00:12 +01:00
Shelikhoo
211254fa98
Add distinct IP counter 2022-06-16 14:58:12 +01:00
Shelikhoo
97dea533da
Update Relay Pattern format to include dollar sign 2022-06-16 14:06:58 +01:00
Shelikhoo
e5b799d618
Update documents for broker messages 2022-06-16 14:06:58 +01:00
Shelikhoo
0ae4d821f0
Move ErrExtraInfo to ipc.go 2022-06-16 14:06:58 +01:00
Shelikhoo
c5e5b45b06
Update message protocol version to 1.3 for RelayURL 2022-06-16 14:06:58 +01:00
Shelikhoo
f789dce6d2
Represent Bridge Fingerprint As String 2022-06-16 14:06:58 +01:00
Shelikhoo
1b48ee14f4
Add test for proxy poll with Relay URL 2022-06-16 14:06:57 +01:00
Shelikhoo
6e8fbe54ee
Rejection reason feedback 2022-06-16 14:06:57 +01:00
Shelikhoo
2ebdc89c42
Add Allowed Relay Hostname Pattern Indication 2022-06-16 14:06:57 +01:00
Shelikhoo
613ceaf970
Add RelayURL and AllowedRelayPattern to snowflake signaling 2022-06-16 13:57:33 +01:00
Shelikhoo
38f0e00e5d
Add Domain Name Matcher
Design difference from original vision: Skipped FQDN step to make it more generalized
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/28651#note_2787394
2022-06-16 13:57:33 +01:00
meskio
f38c91f906
Don't use entropy for test
Use math/rand instead of crypto/rand, so entropy is not a blocker when
running the tests.
2022-06-02 17:24:54 +02:00
itchyonion
e4c01f0595 Wrap client NAT log 2022-05-31 08:52:23 -07:00
meskio
1d592b06e5
Implement String() method on events
To make it safe for logging safelog.Scrub function is now public.

Closes: #40141
2022-05-25 18:09:06 +02:00
itchyonion
9757784c5a
Wait some time before displaying the proxy usage log 2022-05-25 11:01:01 -04:00
Arlo Breault
2f89fbc2ed Represent fingerprint internally as byte array 2022-03-31 11:28:00 -04:00
Arlo Breault
fa2f6824d9 Add some test cases for client poll requests 2022-03-21 15:31:02 -04:00
Arlo Breault
b563141c6a Forward bridge fingerprint
gitlab 28651
2022-03-21 15:06:05 -04:00
Arlo Breault
281d917beb Stop storing version in ClientPollRequest
This continues to asserts the known version while decoding.  The client
will only ever generate the latest version while encoding and if the
response needs to change, the impetus will be a new feature, set in the
deserialized request, which can be used as a distinguisher.
2022-03-21 15:06:05 -04:00
meskio
b265bd3092
Make easier to extend the list of known proxy types
And include iptproxy as a valid proxy type.
2022-03-21 19:23:49 +01:00
Arlo Breault
829cacac5f Parse ClientPollRequest version in DecodeClientPollRequest
Instead of IPC.ClientOffers.  This makes things consistent with
EncodeClientPollRequest which adds the version while serializing.
2022-03-16 15:43:10 -04:00
Arlo Breault
6fd0f1ae5d Rename *PollRequest methods to distinguish client/proxy 2022-03-16 15:43:10 -04:00