vless: added udp support

This commit is contained in:
nadoo committed 2020-10-02 19:09:12 +08:00
1 parent bc68535dcd
commit b323a62ce6
10 files changed
+97 -34

No files matched your search

+6
View File
@@ -28,6 +28,7 @@ func NewPktConn(c net.Conn, tgtAddr socks.Addr) *PktConn {
}
// ReadFrom implements the necessary function of net.PacketConn.
// TODO: we know that we use it in proxy.RelayUDP and the length of b is enough, check it later.
func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
// ATYP, DST.ADDR, DST.PORT
_, err := socks.ReadAddr(pc.Conn)
@@ -50,6 +51,10 @@ func (pc *PktConn) ReadFrom(b []byte) (int, net.Addr, error) {
return 0, nil, err
}
if len(b) < length {
return 0, nil, errors.New("buf size is not enough")
}
// Payload
n, err := io.ReadFull(pc.Conn, b[:length])
if err != nil {
@@ -69,5 +74,6 @@ func (pc *PktConn) WriteTo(b []byte, addr net.Addr) (int, error) {
binary.Write(buf, binary.BigEndian, uint16(len(b)))
buf.WriteString("\r\n")
buf.Write(b)
return pc.Write(buf.Bytes())
}