Skip to content

Commit 29f7df9

Browse files
committed
wgengine/magicsock, etc: remove mostly unused WriteTo methods
Updates tailscale#2331 Updates tailscale#5162 Change-Id: I8291884425481eeaedde38a54adfd8ed7292a497 Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent 83c41f3 commit 29f7df9

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

net/netcheck/netcheck.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,14 @@ func nodeMight4(n *tailcfg.DERPNode) bool {
517517
return ip.Is4()
518518
}
519519

520+
type packetReaderFromCloser interface {
521+
ReadFrom([]byte) (int, net.Addr, error)
522+
io.Closer
523+
}
524+
520525
// readPackets reads STUN packets from pc until there's an error or ctx is done.
521526
// In either case, it closes pc.
522-
func (c *Client) readPackets(ctx context.Context, pc net.PacketConn) {
527+
func (c *Client) readPackets(ctx context.Context, pc packetReaderFromCloser) {
523528
done := make(chan struct{})
524529
defer close(done)
525530

@@ -902,7 +907,9 @@ func (c *Client) GetReport(ctx context.Context, dm *tailcfg.DERPMap) (_ *Report,
902907
// So do that for now. In the future we might want to classify networks
903908
// that do and don't require this separately. But for now help it.
904909
const documentationIP = "203.0.113.1"
905-
rs.pc4Hair.WriteTo([]byte("tailscale netcheck; see https://github.com/tailscale/tailscale/issues/188"), &net.UDPAddr{IP: net.ParseIP(documentationIP), Port: 12345})
910+
rs.pc4Hair.WriteToUDPAddrPort(
911+
[]byte("tailscale netcheck; see https://github.com/tailscale/tailscale/issues/188"),
912+
netip.AddrPortFrom(netip.MustParseAddr(documentationIP), 12345))
906913

907914
if f := c.GetSTUNConn4; f != nil {
908915
rs.pc4 = f()

types/nettype/nettype.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ package nettype
66

77
import (
88
"context"
9+
"io"
910
"net"
1011
"net/netip"
12+
"time"
1113
)
1214

1315
// PacketListener defines the ListenPacket method as implemented
@@ -28,9 +30,16 @@ func (Std) ListenPacket(ctx context.Context, network, address string) (net.Packe
2830
return conf.ListenPacket(ctx, network, address)
2931
}
3032

33+
// PacketConn is a net.PacketConn that's about halfway (as of 2023-04-15)
34+
// converted to use netip.AddrPort.
3135
type PacketConn interface {
32-
net.PacketConn
3336
WriteToUDPAddrPort([]byte, netip.AddrPort) (int, error)
37+
ReadFrom(p []byte) (int, net.Addr, error)
38+
io.Closer
39+
LocalAddr() net.Addr
40+
SetDeadline(time.Time) error
41+
SetReadDeadline(time.Time) error
42+
SetWriteDeadline(time.Time) error
3443
}
3544

3645
func MakePacketListenerWithNetIP(ln PacketListener) PacketListenerWithNetIP {

wgengine/magicsock/magicsock.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,10 +3433,6 @@ func (c *batchingUDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
34333433
return c.pc.ReadFrom(p)
34343434
}
34353435

3436-
func (c *batchingUDPConn) WriteTo(b []byte, addr net.Addr) (n int, err error) {
3437-
return c.pc.WriteTo(b, addr)
3438-
}
3439-
34403436
func (c *batchingUDPConn) SetDeadline(t time.Time) error {
34413437
return c.pc.SetDeadline(t)
34423438
}
@@ -3867,17 +3863,6 @@ func (c *RebindingUDPConn) writeToUDPAddrPortWithInitPconn(pconn nettype.PacketC
38673863
}
38683864
}
38693865

3870-
func (c *RebindingUDPConn) WriteTo(b []byte, addr net.Addr) (int, error) {
3871-
for {
3872-
pconn := *c.pconnAtomic.Load()
3873-
n, err := pconn.WriteTo(b, addr)
3874-
if err != nil && pconn != c.currentConn() {
3875-
continue
3876-
}
3877-
return n, err
3878-
}
3879-
}
3880-
38813866
func (c *RebindingUDPConn) WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (int, error) {
38823867
return c.writeToUDPAddrPortWithInitPconn(*c.pconnAtomic.Load(), b, addr)
38833868
}
@@ -3904,11 +3889,6 @@ func (c *blockForeverConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
39043889
return 0, nil, net.ErrClosed
39053890
}
39063891

3907-
func (c *blockForeverConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
3908-
// Silently drop writes.
3909-
return len(p), nil
3910-
}
3911-
39123892
func (c *blockForeverConn) WriteToUDPAddrPort(p []byte, addr netip.AddrPort) (int, error) {
39133893
// Silently drop writes.
39143894
return len(p), nil

0 commit comments

Comments
 (0)