Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterZhizhin committed Nov 13, 2024
1 parent 5d6424a commit b6aef3d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
7 changes: 4 additions & 3 deletions x/configurl/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ For more details, refer to [github.com/Jigsaw-Code/outline-sdk/transport/tlsfrag
tlsfrag:[LENGTH]
Disorder transport (streams only, package [github.com/Jigsaw-Code/outline-sdk/x/disorder])
Packet reordering (streams only, package [github.com/Jigsaw-Code/outline-sdk/x/disorder])
The disorder strategy sends TCP packets out of order by manipulating the
socket's Time To Live (TTL) or Hop Limit. It temporarily sets the TTL to a low
Expand All @@ -126,11 +126,12 @@ Packet splitting - To split outgoing streams on bytes 2 and 123, you can use:
split:2|split:123
Disorder transport - Send some of the packets out of order
Disorder transport - Send some of the packets out of order:
disorder:0|split:123
Split at position 123, then send packet 0 of 123 bytes (from splitting) out of order. The network filter will first receive packet 1, only then packet 0.
Split at position 123, then send packet 0 of 123 bytes (from splitting) out of order. The network filter will first receive packet 1, only then packet 0. This
is done by setting the hop limit for the write to 1, and then restoring it. It will be sent with its original hop limit on retransmission.
Evading DNS and SNI blocking - You can use Cloudflare's DNS-over-HTTPS to protect against DNS disruption.
The DoH resolver cloudflare-dns.com is accessible from any cloudflare.net IP, so you can specify the address to avoid blocking
Expand Down
14 changes: 7 additions & 7 deletions x/disorder/stream_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type disorderDialer struct {
var _ transport.StreamDialer = (*disorderDialer)(nil)

// NewStreamDialer creates a [transport.StreamDialer]
// It work almost the same as the other split dialer, however, it also manipulates socket TTL:
// * Before sending the first prefixBytes TTL is set to 1
// * This packet is dropped somewhere in the network and never reaches the server
// * TTL is restored
// * The next part of data is sent normally
// * Server notices the lost fragment and requests re-transmission
// Currently this only works with Linux kernel (for Windows/Mac a different implementation is required)
// It work like this:
// * Wait for disorderPacketN'th call to Write. All Write requests before and after the target packet are written normally.
// * Send the disorderPacketN'th packet with TTL == 1.
// * This packet is dropped somewhere in the network and never reaches the server.
// * TTL is restored.
// * The next part of data is sent normally.
// * Server notices the lost fragment and requests re-transmission of lost packet.
func NewStreamDialer(dialer transport.StreamDialer, disorderPacketN int) (transport.StreamDialer, error) {
if dialer == nil {
return nil, errors.New("argument dialer must not be nil")
Expand Down
18 changes: 10 additions & 8 deletions x/disorder/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type disorderWriter struct {

var _ io.Writer = (*disorderWriter)(nil)

// Setting number of hops to 1 will lead to data to get lost on host
// Setting number of hops to 1 will lead to data to get lost on host.
var disorderHopN = 1

func NewWriter(conn io.Writer, tcpOptions sockopt.TCPOptions, runAtPacketN int) io.Writer {
Expand All @@ -54,23 +54,25 @@ func (w *disorderWriter) Write(data []byte) (written int, err error) {
}

defer func() {
// The packet with low hop limit was sent
// Make next calls send data normally
// The packet with low hop limit was sent.
// Make next calls send data normally.
//
// The packet with the low hop limit will get resent by the kernel later
// The network filters will receive data out of order
// The packet with the low hop limit will get resent by the kernel later.
// The network filters will receive data out of order.
err = w.tcpOptions.SetHopLimit(defaultHopLimit)
if err != nil {
err = fmt.Errorf("failed to set the hop limit error %d: %w", defaultHopLimit, err)
}
}()
}

// The packet will get lost at the first send, since the hop limit is too low
// The packet will get lost at the first send, since the hop limit is too low.
n, err := w.conn.Write(data)

// TODO: Wait for queued data to be sent by the kernel to the socket
// TODO: Wait for queued data to be sent by the kernel to the socket.

w.writesToDisorder -= 1
if w.writesToDisorder > -1 {
w.writesToDisorder -= 1
}
return n, err
}

0 comments on commit b6aef3d

Please sign in to comment.