@@ -268,7 +268,6 @@ func (m *peerMap) deleteEndpoint(ep *endpoint) {
268
268
}
269
269
270
270
// A Conn routes UDP packets and actively manages a list of its endpoints.
271
- // It implements wireguard/conn.Bind.
272
271
type Conn struct {
273
272
// This block mirrors the contents and field order of the Options
274
273
// struct. Initialized once at construction, then constant.
@@ -1280,6 +1279,9 @@ var errNetworkDown = errors.New("magicsock: network down")
1280
1279
1281
1280
func (c * Conn ) networkDown () bool { return ! c .networkUp .Load () }
1282
1281
1282
+ // Send implements conn.Bind.
1283
+ //
1284
+ // See https://pkg.go.dev/golang.zx2c4.com/wireguard/conn#Bind.Send
1283
1285
func (c * Conn ) Send (buffs [][]byte , ep conn.Endpoint ) error {
1284
1286
n := int64 (len (buffs ))
1285
1287
metricSendData .Add (n )
@@ -1952,7 +1954,7 @@ func (c *connBind) receiveDERP(buffs [][]byte, sizes []int, eps []conn.Endpoint)
1952
1954
defer health .ReceiveDERP .Exit ()
1953
1955
1954
1956
for dm := range c .derpRecvCh {
1955
- if c .Closed () {
1957
+ if c .isClosed () {
1956
1958
break
1957
1959
}
1958
1960
n , ep := c .processDERPReadResult (dm , buffs [0 ])
@@ -2989,6 +2991,8 @@ func (c *Conn) DERPs() int {
2989
2991
}
2990
2992
2991
2993
// Bind returns the wireguard-go conn.Bind for c.
2994
+ //
2995
+ // See https://pkg.go.dev/golang.zx2c4.com/wireguard/conn#Bind
2992
2996
func (c * Conn ) Bind () conn.Bind {
2993
2997
return c .bind
2994
2998
}
@@ -3004,6 +3008,12 @@ type connBind struct {
3004
3008
closed bool
3005
3009
}
3006
3010
3011
+ var _ conn.Bind = (* connBind )(nil )
3012
+
3013
+ // BatchSize returns the number of buffers expected to be passed to
3014
+ // the ReceiveFuncs, and the maximum expected to be passed to SendBatch.
3015
+ //
3016
+ // See https://pkg.go.dev/golang.zx2c4.com/wireguard/conn#Bind.BatchSize
3007
3017
func (c * connBind ) BatchSize () int {
3008
3018
// TODO(raggi): determine by properties rather than hardcoding platform behavior
3009
3019
switch runtime .GOOS {
@@ -3017,6 +3027,8 @@ func (c *connBind) BatchSize() int {
3017
3027
// Open is called by WireGuard to create a UDP binding.
3018
3028
// The ignoredPort comes from wireguard-go, via the wgcfg config.
3019
3029
// We ignore that port value here, since we have the local port available easily.
3030
+ //
3031
+ // See https://pkg.go.dev/golang.zx2c4.com/wireguard/conn#Bind.Open
3020
3032
func (c * connBind ) Open (ignoredPort uint16 ) ([]conn.ReceiveFunc , uint16 , error ) {
3021
3033
c .mu .Lock ()
3022
3034
defer c .mu .Unlock ()
@@ -3035,11 +3047,15 @@ func (c *connBind) Open(ignoredPort uint16) ([]conn.ReceiveFunc, uint16, error)
3035
3047
3036
3048
// SetMark is used by wireguard-go to set a mark bit for packets to avoid routing loops.
3037
3049
// We handle that ourselves elsewhere.
3050
+ //
3051
+ // See https://pkg.go.dev/golang.zx2c4.com/wireguard/conn#Bind.SetMark
3038
3052
func (c * connBind ) SetMark (value uint32 ) error {
3039
3053
return nil
3040
3054
}
3041
3055
3042
3056
// Close closes the connBind, unless it is already closed.
3057
+ //
3058
+ // See https://pkg.go.dev/golang.zx2c4.com/wireguard/conn#Bind.Close
3043
3059
func (c * connBind ) Close () error {
3044
3060
c .mu .Lock ()
3045
3061
defer c .mu .Unlock ()
@@ -3063,8 +3079,8 @@ func (c *connBind) Close() error {
3063
3079
return nil
3064
3080
}
3065
3081
3066
- // Closed reports whether c is closed.
3067
- func (c * connBind ) Closed () bool {
3082
+ // isClosed reports whether c is closed.
3083
+ func (c * connBind ) isClosed () bool {
3068
3084
c .mu .Lock ()
3069
3085
defer c .mu .Unlock ()
3070
3086
return c .closed
@@ -3370,7 +3386,9 @@ func packIPPort(ua netip.AddrPort) []byte {
3370
3386
return b
3371
3387
}
3372
3388
3373
- // ParseEndpoint is called by WireGuard to connect to an endpoint.
3389
+ // ParseEndpoint implements conn.Bind; it's called by WireGuard to connect to an endpoint.
3390
+ //
3391
+ // See https://pkg.go.dev/golang.zx2c4.com/wireguard/conn#Bind.ParseEndpoint
3374
3392
func (c * Conn ) ParseEndpoint (nodeKeyStr string ) (conn.Endpoint , error ) {
3375
3393
k , err := key .ParseNodePublicUntyped (mem .S (nodeKeyStr ))
3376
3394
if err != nil {
0 commit comments