Skip to content

Commit

Permalink
WIP: disorder: review stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
derlaft committed Nov 3, 2024
1 parent db99e8a commit a910d10
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/configurl/disorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func registerDisorderDialer(r TypeRegistry[transport.StreamDialer], typeID strin
prefixBytesStr := config.URL.Opaque
prefixBytes, err := strconv.Atoi(prefixBytesStr)
if err != nil {
return nil, fmt.Errorf("prefixBytes is not a number: %v. Split config should be in split:<number> format", prefixBytesStr)
return nil, fmt.Errorf("disoder: could not parse splice position: %v", err)
}
return disorder.NewStreamDialer(sd, int64(prefixBytes))
})
Expand Down
10 changes: 6 additions & 4 deletions x/disorder/stream_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (d *disorderDialer) DialStream(ctx context.Context, remoteAddr string) (tra
return nil, err
}

oldTTL, err := setTtl(innerConn, 1)
oldTTL, err := setHopLimit(innerConn, 1)
if err != nil {
return nil, fmt.Errorf("disorder strategy: failed to change ttl: %w", err)
}
Expand All @@ -67,12 +67,12 @@ func (d *disorderDialer) DialStream(ctx context.Context, remoteAddr string) (tra
return transport.WrapConn(innerConn, innerConn, dw), nil
}

// setTtl changes the socket TTL and returns the old value
// setHopLimit changes the socket TTL for IPv4 (or HopLimit for IPv6) and returns the old value
// socket must be `*net.TCPConn`
func setTtl(conn net.Conn, ttl int) (oldTTL int, err error) {
func setHopLimit(conn net.Conn, ttl int) (oldTTL int, err error) {
addr, err := netip.ParseAddrPort(conn.RemoteAddr().String())
if err != nil {
return 0, err
return 0, fmt.Errorf("could not parse remote addr: %w", err)
}

switch {
Expand All @@ -84,6 +84,8 @@ func setTtl(conn net.Conn, ttl int) (oldTTL int, err error) {
conn := ipv6.NewConn(conn)
oldTTL, _ = conn.HopLimit()
err = conn.SetHopLimit(ttl)
default:
return 0, fmt.Errorf("unknown remote addr type (%v)", addr.Addr().String())
}
if err != nil {
return 0, fmt.Errorf("failed to change TTL: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion x/disorder/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (w *disorderWriter) Write(data []byte) (written int, err error) {
data = data[written:]
}
w.resetTTL.Do(func() {
_, err = setTtl(w.conn, w.oldTTL)
_, err = setHopLimit(w.conn, w.oldTTL)
})
if err != nil {
return written, fmt.Errorf("setsockopt IPPROTO_IP/IP_TTL error: %w", err)
Expand Down

0 comments on commit a910d10

Please sign in to comment.