github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/transport/hysteria/wrap.go (about) 1 package hysteria 2 3 import ( 4 "net" 5 "os" 6 "syscall" 7 8 "github.com/inazumav/sing-box/common/baderror" 9 "github.com/sagernet/quic-go" 10 "github.com/sagernet/sing/common" 11 ) 12 13 type PacketConnWrapper struct { 14 net.PacketConn 15 } 16 17 func (c *PacketConnWrapper) SetReadBuffer(bytes int) error { 18 return common.MustCast[*net.UDPConn](c.PacketConn).SetReadBuffer(bytes) 19 } 20 21 func (c *PacketConnWrapper) SetWriteBuffer(bytes int) error { 22 return common.MustCast[*net.UDPConn](c.PacketConn).SetWriteBuffer(bytes) 23 } 24 25 func (c *PacketConnWrapper) SyscallConn() (syscall.RawConn, error) { 26 return common.MustCast[*net.UDPConn](c.PacketConn).SyscallConn() 27 } 28 29 func (c *PacketConnWrapper) File() (f *os.File, err error) { 30 return common.MustCast[*net.UDPConn](c.PacketConn).File() 31 } 32 33 func (c *PacketConnWrapper) Upstream() any { 34 return c.PacketConn 35 } 36 37 type StreamWrapper struct { 38 Conn quic.Connection 39 quic.Stream 40 } 41 42 func (s *StreamWrapper) Read(p []byte) (n int, err error) { 43 n, err = s.Stream.Read(p) 44 return n, baderror.WrapQUIC(err) 45 } 46 47 func (s *StreamWrapper) Write(p []byte) (n int, err error) { 48 n, err = s.Stream.Write(p) 49 return n, baderror.WrapQUIC(err) 50 } 51 52 func (s *StreamWrapper) LocalAddr() net.Addr { 53 return s.Conn.LocalAddr() 54 } 55 56 func (s *StreamWrapper) RemoteAddr() net.Addr { 57 return s.Conn.RemoteAddr() 58 } 59 60 func (s *StreamWrapper) Upstream() any { 61 return s.Stream 62 } 63 64 func (s *StreamWrapper) Close() error { 65 s.CancelRead(0) 66 s.Stream.Close() 67 return nil 68 }