Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
siriusfreak committed Nov 13, 2024
1 parent 8b9fff0 commit afde648
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 75 deletions.
12 changes: 6 additions & 6 deletions x/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ require (
github.com/stretchr/testify v1.9.0
github.com/vishvananda/netlink v1.1.0
golang.org/x/mobile v0.0.0-20240520174638-fa72addaaa1b
golang.org/x/net v0.28.0
golang.org/x/sys v0.23.0
golang.org/x/term v0.23.0
golang.org/x/net v0.31.0
golang.org/x/sys v0.27.0
golang.org/x/term v0.26.0
)

require (
Expand Down Expand Up @@ -72,11 +72,11 @@ require (
github.com/wader/filtertransport v0.0.0-20200316221534-bdd9e61eee78 // indirect
gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.5.0 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 12 additions & 2 deletions x/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/AndreasBriese/bbloom v0.0.0-20170702084017-28f7e881ca57 h1:CVuXDbdzPW
github.com/AndreasBriese/bbloom v0.0.0-20170702084017-28f7e881ca57/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241106233708-faffebb12629 h1:sHi1X4vwtNNBUDCbxynGXe7cM/inwTbavowHziaxlbk=
github.com/Jigsaw-Code/outline-sdk v0.0.18-0.20241106233708-faffebb12629/go.mod h1:CFDKyGZA4zatKE4vMLe8TyQpZCyINOeRFbMAmYHxodw=
github.com/Psiphon-Inc/rotate-safe-writer v0.0.0-20210303140923-464a7a37606e h1:NPfqIbzmijrl0VclX2t8eO5EPBhqe47LLGKpRrcVjXk=
github.com/Psiphon-Inc/rotate-safe-writer v0.0.0-20210303140923-464a7a37606e/go.mod h1:ZdY5pBfat/WVzw3eXbIf7N1nZN0XD5H5+X8ZMDWbCs4=
github.com/Psiphon-Labs/bolt v0.0.0-20200624191537-23cedaef7ad7 h1:Hx/NCZTnvoKZuIBwSmxE58KKoNLXIGG6hBJYN7pj9Ag=
Expand Down Expand Up @@ -207,6 +205,8 @@ golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mobile v0.0.0-20240520174638-fa72addaaa1b h1:WX7nnnLfCEXg+FmdYZPai2XuP3VqCP1HZVMST0n9DF0=
Expand All @@ -226,12 +226,16 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -249,6 +253,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -258,6 +264,8 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand All @@ -266,6 +274,8 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
8 changes: 5 additions & 3 deletions x/oob/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"time"

"github.com/Jigsaw-Code/outline-sdk/transport"
"github.com/Jigsaw-Code/outline-sdk/x/sockopt"
)

// oobDialer is a dialer that applies the OOB and disOOB strategies.
type oobDialer struct {
dialer transport.StreamDialer
opts sockopt.TCPOptions
oobByte byte
oobPosition int64
disOOB bool
Expand Down Expand Up @@ -47,12 +49,12 @@ func (d *oobDialer) DialStream(ctx context.Context, remoteAddr string) (transpor
return nil, fmt.Errorf("oob: only works with direct TCP connections")
}

sd, err := getSocketDescriptor(tcpConn)
opts, err := sockopt.NewTCPOptions(tcpConn)
if err != nil {
return nil, fmt.Errorf("oob: unable to get conn sd: %w", err)
return nil, fmt.Errorf("oob: unable to get TCP options: %w", err)
}

dw := NewWriter(tcpConn, sd, d.oobPosition, d.oobByte, d.disOOB, d.delay)
dw := NewWriter(tcpConn, opts, d.oobPosition, d.oobByte, d.disOOB, d.delay)

return transport.WrapConn(innerConn, innerConn, dw), nil
}
39 changes: 0 additions & 39 deletions x/oob/ttl.go

This file was deleted.

5 changes: 4 additions & 1 deletion x/oob/unix_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
package oob

import (
"golang.org/x/sys/unix"
"net"
"syscall"
)

const MSG_OOB = unix.MSG_OOB

type SocketDescriptor int

func sendTo(fd SocketDescriptor, data []byte, flags int) (err error) {
return syscall.Sendto(int(fd), data, flags, nil)
return syscall.Sendmsg(int(fd), data, nil, nil, flags)
}

func getSocketDescriptor(conn *net.TCPConn) (SocketDescriptor, error) {
Expand Down
6 changes: 2 additions & 4 deletions x/oob/windows_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
"syscall"
)

type SocketDescriptor uintptr
const MSG_OOB = windows.MSG_OOB

func setsockoptInt(fd SocketDescriptor, level, opt int, value int) error {
return syscall.SetsockoptInt(syscall.Handle(fd), level, opt, value)
}
type SocketDescriptor uintptr

func sendTo(fd SocketDescriptor, data []byte, flags int) (err error) {
var wsaBuf [1]syscall.WSABuf
Expand Down
42 changes: 22 additions & 20 deletions x/oob/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oob

import (
"fmt"
"github.com/Jigsaw-Code/outline-sdk/x/sockopt"
"io"
"net"
"sync"
Expand All @@ -10,6 +11,7 @@ import (

type oobWriter struct {
conn *net.TCPConn
opts sockopt.TCPOptions
resetTTL sync.Once
setTTL sync.Once
oobPosition int64
Expand All @@ -26,34 +28,26 @@ type oobWriterReaderFrom struct {
rf io.ReaderFrom
}

var _ io.ReaderFrom = (*oobWriterReaderFrom)(nil)

// NewWriter creates an [io.Writer] that sends an OOB byte at the specified "oobPosition".
// If disOOB is enabled, it will apply the --disOOB strategy.
// "oobByte" specifies the value of the byte to send out-of-band.
func NewWriter(
conn *net.TCPConn,
sd SocketDescriptor,
opts sockopt.TCPOptions,
oobPosition int64,
oobByte byte,
disOOB bool,
delay time.Duration,
) io.Writer {
return &oobWriter{conn: conn, sd: sd, oobPosition: oobPosition, oobByte: oobByte, disOOB: disOOB, delay: delay}
}

func (w *oobWriterReaderFrom) ReadFrom(source io.Reader) (int64, error) {
reader := io.MultiReader(io.LimitReader(source, w.oobPosition), source)
written, err := w.rf.ReadFrom(reader)
w.oobPosition -= written
return written, err
return &oobWriter{conn: conn, opts: opts, oobPosition: oobPosition, oobByte: oobByte, disOOB: disOOB, delay: delay}
}

func (w *oobWriter) Write(data []byte) (int, error) {
var written int
var err error

if w.oobPosition > 0 && w.oobPosition < int64(len(data)) {
fmt.Println("oobWriter, total: ", len(data))
if w.oobPosition > 0 && w.oobPosition < int64(len(data))-1 {
firstPart := data[:w.oobPosition+1]
secondPart := data[w.oobPosition:]

Expand All @@ -64,36 +58,44 @@ func (w *oobWriter) Write(data []byte) (int, error) {
var oldTTL int
if w.disOOB {
w.setTTL.Do(func() {
oldTTL, err = setTtl(w.conn, 1)
oldTTL, err = w.opts.HopLimit()
if err != nil {
return
}
err = w.opts.SetHopLimit(0)
})
if err != nil {
return written, fmt.Errorf("oob: setsockopt IPPROTO_IP/IP_TTL error: %w", err)
return written, fmt.Errorf("oob: new hop limit set error: %w", err)
}
}

err = w.send(firstPart, 0x01)
err = w.send(firstPart, MSG_OOB)
if err != nil {
return written, err
}
written = int(w.oobPosition)
secondPart[0] = tmp

fmt.Printf("oobWriter: firstPart len: %d\n", len(firstPart))

if w.disOOB {
w.resetTTL.Do(func() {
_, err = setTtl(w.conn, oldTTL)
err = w.opts.SetHopLimit(oldTTL)
})
if err != nil {
return written, fmt.Errorf("oob: setsockopt IPPROTO_IP/IP_TTL error: %w", err)
return written, fmt.Errorf("oob: old hop limit set error: %w", err)
}
}

time.Sleep(w.delay)
data = secondPart

time.Sleep(w.delay)
}

// Write the remaining data
err = w.send(data, 0)
written += len(data)
n, err := w.conn.Write(data)
written += n
fmt.Printf("oobWriter: second part len: %d\n", len(data))
return written, err
}

Expand Down

0 comments on commit afde648

Please sign in to comment.