mirror of
https://github.com/fumiama/terasu-cloudflared.git
synced 2026-06-11 05:30:30 +08:00
The lucas-clemente/quic-go package moved namespaces and our branch went stale, this new fork provides support for the new quic-go repo and applies the max datagram frame size change. Until the max datagram frame size support gets upstreamed into quic-go, this can be used to unblock go 1.20 support as the old lucas-clemente/quic-go will not get go 1.20 support.
54 lines
929 B
Go
54 lines
929 B
Go
package quic
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
// A sendConn allows sending using a simple Write() on a non-connected packet conn.
|
|
type sendConn interface {
|
|
Write([]byte) error
|
|
Close() error
|
|
LocalAddr() net.Addr
|
|
RemoteAddr() net.Addr
|
|
}
|
|
|
|
type sconn struct {
|
|
rawConn
|
|
|
|
remoteAddr net.Addr
|
|
info *packetInfo
|
|
oob []byte
|
|
}
|
|
|
|
var _ sendConn = &sconn{}
|
|
|
|
func newSendConn(c rawConn, remote net.Addr, info *packetInfo) *sconn {
|
|
return &sconn{
|
|
rawConn: c,
|
|
remoteAddr: remote,
|
|
info: info,
|
|
oob: info.OOB(),
|
|
}
|
|
}
|
|
|
|
func (c *sconn) Write(p []byte) error {
|
|
_, err := c.WritePacket(p, c.remoteAddr, c.oob)
|
|
return err
|
|
}
|
|
|
|
func (c *sconn) RemoteAddr() net.Addr {
|
|
return c.remoteAddr
|
|
}
|
|
|
|
func (c *sconn) LocalAddr() net.Addr {
|
|
addr := c.rawConn.LocalAddr()
|
|
if c.info != nil {
|
|
if udpAddr, ok := addr.(*net.UDPAddr); ok {
|
|
addrCopy := *udpAddr
|
|
addrCopy.IP = c.info.addr
|
|
addr = &addrCopy
|
|
}
|
|
}
|
|
return addr
|
|
}
|