quic

package
v0.3.1-rc.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

Types

type Client

type Client struct {
	proxy.EmptyDispatch
	// contains filtered or unexported fields
}

func (*Client) Conn

func (c *Client) Conn(ctx context.Context, s proxy.Address) (net.Conn, error)

func (*Client) PacketConn

func (c *Client) PacketConn(ctx context.Context, host proxy.Address) (net.PacketConn, error)

type QuicAddr

type QuicAddr struct {
	Addr net.Addr
	ID   quic.StreamID
}
func (s *Server) handleQuicDatagram(b []byte, session quic.Connection) error {
	if len(b) <= 5 {
		return fmt.Errorf("invalid datagram")
	}

	id := binary.BigEndian.Uint16(b[:2])
	addr, err := s5c.ResolveAddr(bytes.NewBuffer(b[2:]))
	if err != nil {
		return err
	}

	log.Println("new udp from", session.RemoteAddr(), "id", id, "to", addr.Address(statistic.Type_udp))

	return c.nat.Write(&nat.Packet{
		SourceAddress: &QuicAddr{
			addr: session.RemoteAddr(),
			id:   quic.StreamID(id),
		},
		DestinationAddress: addr.Address(statistic.Type_udp),
		Payload:            b[2+len(addr):],
		WriteBack: func(b []byte, addr net.Addr) (int, error) {
			add, err := proxy.ParseSysAddr(addr)
			if err != nil {
				return 0, err
			}

			buf := pool.GetBuffer()
			defer pool.PutBuffer(buf)

			binary.Write(buf, binary.BigEndian, id)
			s5c.ParseAddrWriter(add, buf)
			buf.Write(b)

			// log.Println("write back to", session.RemoteAddr(), "id", id)
			if err = session.SendMessage(buf.Bytes()); err != nil {
				return 0, err
			}

			return len(b), nil
		},
	})
}

func (*QuicAddr) Network

func (q *QuicAddr) Network() string

func (*QuicAddr) String

func (q *QuicAddr) String() string

type Server

type Server struct {
	quic.EarlyListener
	// contains filtered or unexported fields
}

func NewServer

func NewServer(packetConn net.PacketConn, tlsConfig *tls.Config) (*Server, error)

func (*Server) Accept

func (s *Server) Accept() (net.Conn, error)

func (*Server) Close

func (s *Server) Close() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL