repo
stringlengths
6
47
file_url
stringlengths
77
269
file_path
stringlengths
5
186
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-07 08:35:43
2026-01-07 08:55:24
truncated
bool
2 classes
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/system_dialer.go
transport/internet/system_dialer.go
package internet import ( "context" "syscall" "time" "v2ray.com/core/common/net" "v2ray.com/core/common/session" ) var ( effectiveSystemDialer SystemDialer = &DefaultSystemDialer{} ) type SystemDialer interface { Dial(ctx context.Context, source net.Address, destination net.Destination, sockopt *SocketConfig) (net.Conn, error) } type DefaultSystemDialer struct { controllers []controller } func resolveSrcAddr(network net.Network, src net.Address) net.Addr { if src == nil || src == net.AnyIP { return nil } if network == net.Network_TCP { return &net.TCPAddr{ IP: src.IP(), Port: 0, } } return &net.UDPAddr{ IP: src.IP(), Port: 0, } } func hasBindAddr(sockopt *SocketConfig) bool { return sockopt != nil && len(sockopt.BindAddress) > 0 && sockopt.BindPort > 0 } func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest net.Destination, sockopt *SocketConfig) (net.Conn, error) { if dest.Network == net.Network_UDP && !hasBindAddr(sockopt) { srcAddr := resolveSrcAddr(net.Network_UDP, src) if srcAddr == nil { srcAddr = &net.UDPAddr{ IP: []byte{0, 0, 0, 0}, Port: 0, } } packetConn, err := ListenSystemPacket(ctx, srcAddr, sockopt) if err != nil { return nil, err } destAddr, err := net.ResolveUDPAddr("udp", dest.NetAddr()) if err != nil { return nil, err } return &packetConnWrapper{ conn: packetConn, dest: destAddr, }, nil } dialer := &net.Dialer{ Timeout: time.Second * 16, DualStack: true, LocalAddr: resolveSrcAddr(dest.Network, src), } if sockopt != nil || len(d.controllers) > 0 { dialer.Control = func(network, address string, c syscall.RawConn) error { return c.Control(func(fd uintptr) { if sockopt != nil { if err := applyOutboundSocketOptions(network, address, fd, sockopt); err != nil { newError("failed to apply socket options").Base(err).WriteToLog(session.ExportIDToError(ctx)) } if dest.Network == net.Network_UDP && hasBindAddr(sockopt) { if err := bindAddr(fd, sockopt.BindAddress, sockopt.BindPort); err != nil { newError("failed to bind source address to ", sockopt.BindAddress).Base(err).WriteToLog(session.ExportIDToError(ctx)) } } } for _, ctl := range d.controllers { if err := ctl(network, address, fd); err != nil { newError("failed to apply external controller").Base(err).WriteToLog(session.ExportIDToError(ctx)) } } }) } } return dialer.DialContext(ctx, dest.Network.SystemString(), dest.NetAddr()) } type packetConnWrapper struct { conn net.PacketConn dest net.Addr } func (c *packetConnWrapper) Close() error { return c.conn.Close() } func (c *packetConnWrapper) LocalAddr() net.Addr { return c.conn.LocalAddr() } func (c *packetConnWrapper) RemoteAddr() net.Addr { return c.dest } func (c *packetConnWrapper) Write(p []byte) (int, error) { return c.conn.WriteTo(p, c.dest) } func (c *packetConnWrapper) Read(p []byte) (int, error) { n, _, err := c.conn.ReadFrom(p) return n, err } func (c *packetConnWrapper) SetDeadline(t time.Time) error { return c.conn.SetDeadline(t) } func (c *packetConnWrapper) SetReadDeadline(t time.Time) error { return c.conn.SetReadDeadline(t) } func (c *packetConnWrapper) SetWriteDeadline(t time.Time) error { return c.conn.SetWriteDeadline(t) } type SystemDialerAdapter interface { Dial(network string, address string) (net.Conn, error) } type SimpleSystemDialer struct { adapter SystemDialerAdapter } func WithAdapter(dialer SystemDialerAdapter) SystemDialer { return &SimpleSystemDialer{ adapter: dialer, } } func (v *SimpleSystemDialer) Dial(ctx context.Context, src net.Address, dest net.Destination, sockopt *SocketConfig) (net.Conn, error) { return v.adapter.Dial(dest.Network.SystemString(), dest.NetAddr()) } // UseAlternativeSystemDialer replaces the current system dialer with a given one. // Caller must ensure there is no race condition. // // v2ray:api:stable func UseAlternativeSystemDialer(dialer SystemDialer) { if dialer == nil { effectiveSystemDialer = &DefaultSystemDialer{} } effectiveSystemDialer = dialer } // RegisterDialerController adds a controller to the effective system dialer. // The controller can be used to operate on file descriptors before they are put into use. // It only works when effective dialer is the default dialer. // // v2ray:api:beta func RegisterDialerController(ctl func(network, address string, fd uintptr) error) error { if ctl == nil { return newError("nil listener controller") } dialer, ok := effectiveSystemDialer.(*DefaultSystemDialer) if !ok { return newError("RegisterListenerController not supported in custom dialer") } dialer.controllers = append(dialer.controllers, ctl) return nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/sockopt_freebsd.go
transport/internet/sockopt_freebsd.go
package internet import ( "encoding/binary" "net" "os" "syscall" "unsafe" "golang.org/x/sys/unix" ) const ( sysPFINOUT = 0x0 sysPFIN = 0x1 sysPFOUT = 0x2 sysPFFWD = 0x3 sysDIOCNATLOOK = 0xc04c4417 ) type pfiocNatlook struct { Saddr [16]byte /* pf_addr */ Daddr [16]byte /* pf_addr */ Rsaddr [16]byte /* pf_addr */ Rdaddr [16]byte /* pf_addr */ Sport uint16 Dport uint16 Rsport uint16 Rdport uint16 Af uint8 Proto uint8 Direction uint8 Pad [1]byte } const ( sizeofPfiocNatlook = 0x4c soReUsePort = 0x00000200 soReUsePortLB = 0x00010000 ) func ioctl(s uintptr, ioc int, b []byte) error { if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, s, uintptr(ioc), uintptr(unsafe.Pointer(&b[0]))); errno != 0 { return error(errno) } return nil } func (nl *pfiocNatlook) rdPort() int { return int(binary.BigEndian.Uint16((*[2]byte)(unsafe.Pointer(&nl.Rdport))[:])) } func (nl *pfiocNatlook) setPort(remote, local int) { binary.BigEndian.PutUint16((*[2]byte)(unsafe.Pointer(&nl.Sport))[:], uint16(remote)) binary.BigEndian.PutUint16((*[2]byte)(unsafe.Pointer(&nl.Dport))[:], uint16(local)) } // OriginalDst uses ioctl to read original destination from /dev/pf func OriginalDst(la, ra net.Addr) (net.IP, int, error) { f, err := os.Open("/dev/pf") if err != nil { return net.IP{}, -1, newError("failed to open device /dev/pf").Base(err) } defer f.Close() fd := f.Fd() b := make([]byte, sizeofPfiocNatlook) nl := (*pfiocNatlook)(unsafe.Pointer(&b[0])) var raIP, laIP net.IP var raPort, laPort int switch la.(type) { case *net.TCPAddr: raIP = ra.(*net.TCPAddr).IP laIP = la.(*net.TCPAddr).IP raPort = ra.(*net.TCPAddr).Port laPort = la.(*net.TCPAddr).Port nl.Proto = syscall.IPPROTO_TCP case *net.UDPAddr: raIP = ra.(*net.UDPAddr).IP laIP = la.(*net.UDPAddr).IP raPort = ra.(*net.UDPAddr).Port laPort = la.(*net.UDPAddr).Port nl.Proto = syscall.IPPROTO_UDP } if raIP.To4() != nil { if laIP.IsUnspecified() { laIP = net.ParseIP("127.0.0.1") } copy(nl.Saddr[:net.IPv4len], raIP.To4()) copy(nl.Daddr[:net.IPv4len], laIP.To4()) nl.Af = syscall.AF_INET } if raIP.To16() != nil && raIP.To4() == nil { if laIP.IsUnspecified() { laIP = net.ParseIP("::1") } copy(nl.Saddr[:], raIP) copy(nl.Daddr[:], laIP) nl.Af = syscall.AF_INET6 } nl.setPort(raPort, laPort) ioc := uintptr(sysDIOCNATLOOK) for _, dir := range []byte{sysPFOUT, sysPFIN} { nl.Direction = dir err = ioctl(fd, int(ioc), b) if err == nil || err != syscall.ENOENT { break } } if err != nil { return net.IP{}, -1, os.NewSyscallError("ioctl", err) } odPort := nl.rdPort() var odIP net.IP switch nl.Af { case syscall.AF_INET: odIP = make(net.IP, net.IPv4len) copy(odIP, nl.Rdaddr[:net.IPv4len]) case syscall.AF_INET6: odIP = make(net.IP, net.IPv6len) copy(odIP, nl.Rdaddr[:]) } return odIP, odPort, nil } func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error { if config.Mark != 0 { if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_USER_COOKIE, int(config.Mark)); err != nil { return newError("failed to set SO_USER_COOKIE").Base(err) } } if isTCPSocket(network) { switch config.Tfo { case SocketConfig_Enable: if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 1); err != nil { return newError("failed to set TCP_FASTOPEN_CONNECT=1").Base(err) } case SocketConfig_Disable: if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 0); err != nil { return newError("failed to set TCP_FASTOPEN_CONNECT=0").Base(err) } } } if config.Tproxy.IsEnabled() { ip, _, _ := net.SplitHostPort(address) if net.ParseIP(ip).To4() != nil { if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_BINDANY, 1); err != nil { return newError("failed to set outbound IP_BINDANY").Base(err) } } else { if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_BINDANY, 1); err != nil { return newError("failed to set outbound IPV6_BINDANY").Base(err) } } } return nil } func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error { if config.Mark != 0 { if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_USER_COOKIE, int(config.Mark)); err != nil { return newError("failed to set SO_USER_COOKIE").Base(err) } } if isTCPSocket(network) { switch config.Tfo { case SocketConfig_Enable: if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 1); err != nil { return newError("failed to set TCP_FASTOPEN=1").Base(err) } case SocketConfig_Disable: if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, 0); err != nil { return newError("failed to set TCP_FASTOPEN=0").Base(err) } } } if config.Tproxy.IsEnabled() { if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_BINDANY, 1); err != nil { if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_BINDANY, 1); err != nil { return newError("failed to set inbound IP_BINDANY").Base(err) } } } return nil } func bindAddr(fd uintptr, ip []byte, port uint32) error { setReuseAddr(fd) setReusePort(fd) var sockaddr syscall.Sockaddr switch len(ip) { case net.IPv4len: a4 := &syscall.SockaddrInet4{ Port: int(port), } copy(a4.Addr[:], ip) sockaddr = a4 case net.IPv6len: a6 := &syscall.SockaddrInet6{ Port: int(port), } copy(a6.Addr[:], ip) sockaddr = a6 default: return newError("unexpected length of ip") } return syscall.Bind(int(fd), sockaddr) } func setReuseAddr(fd uintptr) error { if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { return newError("failed to set SO_REUSEADDR").Base(err).AtWarning() } return nil } func setReusePort(fd uintptr) error { if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, soReUsePortLB, 1); err != nil { if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, soReUsePort, 1); err != nil { return newError("failed to set SO_REUSEPORT").Base(err).AtWarning() } } return nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/hub.go
transport/internet/quic/hub.go
// +build !confonly package quic import ( "context" "time" "github.com/lucas-clemente/quic-go" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol/tls/cert" "v2ray.com/core/common/signal/done" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" ) // Listener is an internet.Listener that listens for TCP connections. type Listener struct { rawConn *sysConn listener quic.Listener done *done.Instance addConn internet.ConnHandler } func (l *Listener) acceptStreams(session quic.Session) { for { stream, err := session.AcceptStream(context.Background()) if err != nil { newError("failed to accept stream").Base(err).WriteToLog() select { case <-session.Context().Done(): return case <-l.done.Wait(): if err := session.CloseWithError(0, ""); err != nil { newError("failed to close session").Base(err).WriteToLog() } return default: time.Sleep(time.Second) continue } } conn := &interConn{ stream: stream, local: session.LocalAddr(), remote: session.RemoteAddr(), } l.addConn(conn) } } func (l *Listener) keepAccepting() { for { conn, err := l.listener.Accept(context.Background()) if err != nil { newError("failed to accept QUIC sessions").Base(err).WriteToLog() if l.done.Done() { break } time.Sleep(time.Second) continue } go l.acceptStreams(conn) } } // Addr implements internet.Listener.Addr. func (l *Listener) Addr() net.Addr { return l.listener.Addr() } // Close implements internet.Listener.Close. func (l *Listener) Close() error { l.done.Close() l.listener.Close() l.rawConn.Close() return nil } // Listen creates a new Listener based on configurations. func Listen(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, handler internet.ConnHandler) (internet.Listener, error) { if address.Family().IsDomain() { return nil, newError("domain address is not allows for listening quic") } tlsConfig := tls.ConfigFromStreamSettings(streamSettings) if tlsConfig == nil { tlsConfig = &tls.Config{ Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.DNSNames(internalDomain), cert.CommonName(internalDomain)))}, } } config := streamSettings.ProtocolSettings.(*Config) rawConn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{ IP: address.IP(), Port: int(port), }, streamSettings.SocketSettings) if err != nil { return nil, err } quicConfig := &quic.Config{ ConnectionIDLength: 12, HandshakeTimeout: time.Second * 8, MaxIdleTimeout: time.Second * 45, MaxIncomingStreams: 32, MaxIncomingUniStreams: -1, } conn, err := wrapSysConn(rawConn, config) if err != nil { conn.Close() return nil, err } qListener, err := quic.Listen(conn, tlsConfig.GetTLSConfig(), quicConfig) if err != nil { conn.Close() return nil, err } listener := &Listener{ done: done.New(), rawConn: conn, listener: qListener, addConn: handler, } go listener.keepAccepting() return listener, nil } func init() { common.Must(internet.RegisterTransportListener(protocolName, Listen)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/dialer.go
transport/internet/quic/dialer.go
// +build !confonly package quic import ( "context" "sync" "time" "github.com/lucas-clemente/quic-go" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/task" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" ) type sessionContext struct { rawConn *sysConn session quic.Session } var errSessionClosed = newError("session closed") func (c *sessionContext) openStream(destAddr net.Addr) (*interConn, error) { if !isActive(c.session) { return nil, errSessionClosed } stream, err := c.session.OpenStream() if err != nil { return nil, err } conn := &interConn{ stream: stream, local: c.session.LocalAddr(), remote: destAddr, } return conn, nil } type clientSessions struct { access sync.Mutex sessions map[net.Destination][]*sessionContext cleanup *task.Periodic } func isActive(s quic.Session) bool { select { case <-s.Context().Done(): return false default: return true } } func removeInactiveSessions(sessions []*sessionContext) []*sessionContext { activeSessions := make([]*sessionContext, 0, len(sessions)) for _, s := range sessions { if isActive(s.session) { activeSessions = append(activeSessions, s) continue } if err := s.session.CloseWithError(0, ""); err != nil { newError("failed to close session").Base(err).WriteToLog() } if err := s.rawConn.Close(); err != nil { newError("failed to close raw connection").Base(err).WriteToLog() } } if len(activeSessions) < len(sessions) { return activeSessions } return sessions } func openStream(sessions []*sessionContext, destAddr net.Addr) *interConn { for _, s := range sessions { if !isActive(s.session) { continue } conn, err := s.openStream(destAddr) if err != nil { continue } return conn } return nil } func (s *clientSessions) cleanSessions() error { s.access.Lock() defer s.access.Unlock() if len(s.sessions) == 0 { return nil } newSessionMap := make(map[net.Destination][]*sessionContext) for dest, sessions := range s.sessions { sessions = removeInactiveSessions(sessions) if len(sessions) > 0 { newSessionMap[dest] = sessions } } s.sessions = newSessionMap return nil } func (s *clientSessions) openConnection(destAddr net.Addr, config *Config, tlsConfig *tls.Config, sockopt *internet.SocketConfig) (internet.Connection, error) { s.access.Lock() defer s.access.Unlock() if s.sessions == nil { s.sessions = make(map[net.Destination][]*sessionContext) } dest := net.DestinationFromAddr(destAddr) var sessions []*sessionContext if s, found := s.sessions[dest]; found { sessions = s } if true { conn := openStream(sessions, destAddr) if conn != nil { return conn, nil } } sessions = removeInactiveSessions(sessions) rawConn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{ IP: []byte{0, 0, 0, 0}, Port: 0, }, sockopt) if err != nil { return nil, err } quicConfig := &quic.Config{ ConnectionIDLength: 12, HandshakeTimeout: time.Second * 8, MaxIdleTimeout: time.Second * 30, } conn, err := wrapSysConn(rawConn, config) if err != nil { rawConn.Close() return nil, err } session, err := quic.DialContext(context.Background(), conn, destAddr, "", tlsConfig.GetTLSConfig(tls.WithDestination(dest)), quicConfig) if err != nil { conn.Close() return nil, err } context := &sessionContext{ session: session, rawConn: conn, } s.sessions[dest] = append(sessions, context) return context.openStream(destAddr) } var client clientSessions func init() { client.sessions = make(map[net.Destination][]*sessionContext) client.cleanup = &task.Periodic{ Interval: time.Minute, Execute: client.cleanSessions, } common.Must(client.cleanup.Start()) } func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { tlsConfig := tls.ConfigFromStreamSettings(streamSettings) if tlsConfig == nil { tlsConfig = &tls.Config{ ServerName: internalDomain, AllowInsecure: true, } } var destAddr *net.UDPAddr if dest.Address.Family().IsIP() { destAddr = &net.UDPAddr{ IP: dest.Address.IP(), Port: int(dest.Port), } } else { addr, err := net.ResolveUDPAddr("udp", dest.NetAddr()) if err != nil { return nil, err } destAddr = addr } config := streamSettings.ProtocolSettings.(*Config) return client.openConnection(destAddr, config, tlsConfig, streamSettings.SocketSettings) } func init() { common.Must(internet.RegisterTransportDialer(protocolName, Dial)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/errors.generated.go
transport/internet/quic/errors.generated.go
package quic import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/config.go
transport/internet/quic/config.go
// +build !confonly package quic import ( "crypto/aes" "crypto/cipher" "crypto/sha256" "golang.org/x/crypto/chacha20poly1305" "v2ray.com/core/common" "v2ray.com/core/common/protocol" "v2ray.com/core/transport/internet" ) func getAuth(config *Config) (cipher.AEAD, error) { security := config.Security.GetSecurityType() if security == protocol.SecurityType_NONE { return nil, nil } salted := []byte(config.Key + "v2ray-quic-salt") key := sha256.Sum256(salted) if security == protocol.SecurityType_AES128_GCM { block, err := aes.NewCipher(key[:16]) common.Must(err) return cipher.NewGCM(block) } if security == protocol.SecurityType_CHACHA20_POLY1305 { return chacha20poly1305.New(key[:]) } return nil, newError("unsupported security type") } func getHeader(config *Config) (internet.PacketHeader, error) { if config.Header == nil { return nil, nil } msg, err := config.Header.GetInstance() if err != nil { return nil, err } return internet.CreatePacketHeader(msg) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/conn.go
transport/internet/quic/conn.go
// +build !confonly package quic import ( "crypto/cipher" "crypto/rand" "errors" "time" "github.com/lucas-clemente/quic-go" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) type sysConn struct { conn net.PacketConn header internet.PacketHeader auth cipher.AEAD } func wrapSysConn(rawConn net.PacketConn, config *Config) (*sysConn, error) { header, err := getHeader(config) if err != nil { return nil, err } auth, err := getAuth(config) if err != nil { return nil, err } return &sysConn{ conn: rawConn, header: header, auth: auth, }, nil } var errInvalidPacket = errors.New("invalid packet") func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) { buffer := getBuffer() defer putBuffer(buffer) nBytes, addr, err := c.conn.ReadFrom(buffer) if err != nil { return 0, nil, err } payload := buffer[:nBytes] if c.header != nil { if len(payload) <= int(c.header.Size()) { return 0, nil, errInvalidPacket } payload = payload[c.header.Size():] } if c.auth == nil { n := copy(p, payload) return n, addr, nil } if len(payload) <= c.auth.NonceSize() { return 0, nil, errInvalidPacket } nonce := payload[:c.auth.NonceSize()] payload = payload[c.auth.NonceSize():] p, err = c.auth.Open(p[:0], nonce, payload, nil) if err != nil { return 0, nil, errInvalidPacket } return len(p), addr, nil } func (c *sysConn) ReadFrom(p []byte) (int, net.Addr, error) { if c.header == nil && c.auth == nil { return c.conn.ReadFrom(p) } for { n, addr, err := c.readFromInternal(p) if err != nil && err != errInvalidPacket { return 0, nil, err } if err == nil { return n, addr, nil } } } func (c *sysConn) WriteTo(p []byte, addr net.Addr) (int, error) { if c.header == nil && c.auth == nil { return c.conn.WriteTo(p, addr) } buffer := getBuffer() defer putBuffer(buffer) payload := buffer n := 0 if c.header != nil { c.header.Serialize(payload) n = int(c.header.Size()) } if c.auth == nil { nBytes := copy(payload[n:], p) n += nBytes } else { nounce := payload[n : n+c.auth.NonceSize()] common.Must2(rand.Read(nounce)) n += c.auth.NonceSize() pp := c.auth.Seal(payload[:n], nounce, p, nil) n = len(pp) } return c.conn.WriteTo(payload[:n], addr) } func (c *sysConn) Close() error { return c.conn.Close() } func (c *sysConn) LocalAddr() net.Addr { return c.conn.LocalAddr() } func (c *sysConn) SetDeadline(t time.Time) error { return c.conn.SetDeadline(t) } func (c *sysConn) SetReadDeadline(t time.Time) error { return c.conn.SetReadDeadline(t) } func (c *sysConn) SetWriteDeadline(t time.Time) error { return c.conn.SetWriteDeadline(t) } type interConn struct { stream quic.Stream local net.Addr remote net.Addr } func (c *interConn) Read(b []byte) (int, error) { return c.stream.Read(b) } func (c *interConn) WriteMultiBuffer(mb buf.MultiBuffer) error { mb = buf.Compact(mb) mb, err := buf.WriteMultiBuffer(c, mb) buf.ReleaseMulti(mb) return err } func (c *interConn) Write(b []byte) (int, error) { return c.stream.Write(b) } func (c *interConn) Close() error { return c.stream.Close() } func (c *interConn) LocalAddr() net.Addr { return c.local } func (c *interConn) RemoteAddr() net.Addr { return c.remote } func (c *interConn) SetDeadline(t time.Time) error { return c.stream.SetDeadline(t) } func (c *interConn) SetReadDeadline(t time.Time) error { return c.stream.SetReadDeadline(t) } func (c *interConn) SetWriteDeadline(t time.Time) error { return c.stream.SetWriteDeadline(t) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/pool.go
transport/internet/quic/pool.go
// +build !confonly package quic import ( "sync" "v2ray.com/core/common/bytespool" ) var pool *sync.Pool func init() { pool = bytespool.GetPool(2048) } func getBuffer() []byte { return pool.Get().([]byte) } func putBuffer(p []byte) { pool.Put(p) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/quic.go
transport/internet/quic/quic.go
// +build !confonly package quic import ( "v2ray.com/core/common" "v2ray.com/core/transport/internet" ) //go:generate go run v2ray.com/core/common/errors/errorgen // Here is some modification needs to be done before update quic vendor. // * use bytespool in buffer_pool.go // * set MaxReceivePacketSize to 1452 - 32 (16 bytes auth, 16 bytes head) // // const protocolName = "quic" const internalDomain = "quic.internal.v2ray.com" func init() { common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { return new(Config) })) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/config.pb.go
transport/internet/quic/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/quic/config.proto package quic import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" protocol "v2ray.com/core/common/protocol" serial "v2ray.com/core/common/serial" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Security *protocol.SecurityConfig `protobuf:"bytes,2,opt,name=security,proto3" json:"security,omitempty"` Header *serial.TypedMessage `protobuf:"bytes,3,opt,name=header,proto3" json:"header,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_quic_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_quic_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_quic_config_proto_rawDescGZIP(), []int{0} } func (x *Config) GetKey() string { if x != nil { return x.Key } return "" } func (x *Config) GetSecurity() *protocol.SecurityConfig { if x != nil { return x.Security } return nil } func (x *Config) GetHeader() *serial.TypedMessage { if x != nil { return x.Header } return nil } var File_transport_internet_quic_config_proto protoreflect.FileDescriptor var file_transport_internet_quic_config_proto_rawDesc = []byte{ 0x0a, 0x24, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x71, 0x75, 0x69, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x22, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x1a, 0x21, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x64, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa2, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x46, 0x0a, 0x08, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x08, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x12, 0x3e, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x42, 0x77, 0x0a, 0x26, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x50, 0x01, 0x5a, 0x26, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x71, 0x75, 0x69, 0x63, 0xaa, 0x02, 0x22, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_quic_config_proto_rawDescOnce sync.Once file_transport_internet_quic_config_proto_rawDescData = file_transport_internet_quic_config_proto_rawDesc ) func file_transport_internet_quic_config_proto_rawDescGZIP() []byte { file_transport_internet_quic_config_proto_rawDescOnce.Do(func() { file_transport_internet_quic_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_quic_config_proto_rawDescData) }) return file_transport_internet_quic_config_proto_rawDescData } var file_transport_internet_quic_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_quic_config_proto_goTypes = []interface{}{ (*Config)(nil), // 0: v2ray.core.transport.internet.quic.Config (*protocol.SecurityConfig)(nil), // 1: v2ray.core.common.protocol.SecurityConfig (*serial.TypedMessage)(nil), // 2: v2ray.core.common.serial.TypedMessage } var file_transport_internet_quic_config_proto_depIdxs = []int32{ 1, // 0: v2ray.core.transport.internet.quic.Config.security:type_name -> v2ray.core.common.protocol.SecurityConfig 2, // 1: v2ray.core.transport.internet.quic.Config.header:type_name -> v2ray.core.common.serial.TypedMessage 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name } func init() { file_transport_internet_quic_config_proto_init() } func file_transport_internet_quic_config_proto_init() { if File_transport_internet_quic_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_quic_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_quic_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_quic_config_proto_goTypes, DependencyIndexes: file_transport_internet_quic_config_proto_depIdxs, MessageInfos: file_transport_internet_quic_config_proto_msgTypes, }.Build() File_transport_internet_quic_config_proto = out.File file_transport_internet_quic_config_proto_rawDesc = nil file_transport_internet_quic_config_proto_goTypes = nil file_transport_internet_quic_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/quic/quic_test.go
transport/internet/quic/quic_test.go
package quic_test import ( "context" "crypto/rand" "testing" "time" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/common/protocol/tls/cert" "v2ray.com/core/common/serial" "v2ray.com/core/testing/servers/udp" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/headers/wireguard" "v2ray.com/core/transport/internet/quic" "v2ray.com/core/transport/internet/tls" ) func TestQuicConnection(t *testing.T) { port := udp.PickPort() listener, err := quic.Listen(context.Background(), net.LocalHostIP, port, &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{}, SecurityType: "tls", SecuritySettings: &tls.Config{ Certificate: []*tls.Certificate{ tls.ParseCertificate( cert.MustGenerate(nil, cert.DNSNames("www.v2fly.org"), ), ), }, }, }, func(conn internet.Connection) { go func() { defer conn.Close() b := buf.New() defer b.Release() for { b.Clear() if _, err := b.ReadFrom(conn); err != nil { return } common.Must2(conn.Write(b.Bytes())) } }() }) common.Must(err) defer listener.Close() time.Sleep(time.Second) dctx := context.Background() conn, err := quic.Dial(dctx, net.TCPDestination(net.LocalHostIP, port), &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{}, SecurityType: "tls", SecuritySettings: &tls.Config{ ServerName: "www.v2fly.org", AllowInsecure: true, }, }) common.Must(err) defer conn.Close() const N = 1024 b1 := make([]byte, N) common.Must2(rand.Read(b1)) b2 := buf.New() common.Must2(conn.Write(b1)) b2.Clear() common.Must2(b2.ReadFullFrom(conn, N)) if r := cmp.Diff(b2.Bytes(), b1); r != "" { t.Error(r) } common.Must2(conn.Write(b1)) b2.Clear() common.Must2(b2.ReadFullFrom(conn, N)) if r := cmp.Diff(b2.Bytes(), b1); r != "" { t.Error(r) } } func TestQuicConnectionWithoutTLS(t *testing.T) { port := udp.PickPort() listener, err := quic.Listen(context.Background(), net.LocalHostIP, port, &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{}, }, func(conn internet.Connection) { go func() { defer conn.Close() b := buf.New() defer b.Release() for { b.Clear() if _, err := b.ReadFrom(conn); err != nil { return } common.Must2(conn.Write(b.Bytes())) } }() }) common.Must(err) defer listener.Close() time.Sleep(time.Second) dctx := context.Background() conn, err := quic.Dial(dctx, net.TCPDestination(net.LocalHostIP, port), &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{}, }) common.Must(err) defer conn.Close() const N = 1024 b1 := make([]byte, N) common.Must2(rand.Read(b1)) b2 := buf.New() common.Must2(conn.Write(b1)) b2.Clear() common.Must2(b2.ReadFullFrom(conn, N)) if r := cmp.Diff(b2.Bytes(), b1); r != "" { t.Error(r) } common.Must2(conn.Write(b1)) b2.Clear() common.Must2(b2.ReadFullFrom(conn, N)) if r := cmp.Diff(b2.Bytes(), b1); r != "" { t.Error(r) } } func TestQuicConnectionAuthHeader(t *testing.T) { port := udp.PickPort() listener, err := quic.Listen(context.Background(), net.LocalHostIP, port, &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{ Header: serial.ToTypedMessage(&wireguard.WireguardConfig{}), Key: "abcd", Security: &protocol.SecurityConfig{ Type: protocol.SecurityType_AES128_GCM, }, }, }, func(conn internet.Connection) { go func() { defer conn.Close() b := buf.New() defer b.Release() for { b.Clear() if _, err := b.ReadFrom(conn); err != nil { return } common.Must2(conn.Write(b.Bytes())) } }() }) common.Must(err) defer listener.Close() time.Sleep(time.Second) dctx := context.Background() conn, err := quic.Dial(dctx, net.TCPDestination(net.LocalHostIP, port), &internet.MemoryStreamConfig{ ProtocolName: "quic", ProtocolSettings: &quic.Config{ Header: serial.ToTypedMessage(&wireguard.WireguardConfig{}), Key: "abcd", Security: &protocol.SecurityConfig{ Type: protocol.SecurityType_AES128_GCM, }, }, }) common.Must(err) defer conn.Close() const N = 1024 b1 := make([]byte, N) common.Must2(rand.Read(b1)) b2 := buf.New() common.Must2(conn.Write(b1)) b2.Clear() common.Must2(b2.ReadFullFrom(conn, N)) if r := cmp.Diff(b2.Bytes(), b1); r != "" { t.Error(r) } common.Must2(conn.Write(b1)) b2.Clear() common.Must2(b2.ReadFullFrom(conn, N)) if r := cmp.Diff(b2.Bytes(), b1); r != "" { t.Error(r) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tls/config_windows.go
transport/internet/tls/config_windows.go
// +build windows // +build !confonly package tls import "crypto/x509" func (c *Config) getCertPool() (*x509.CertPool, error) { if c.DisableSystemRoot { return c.loadSelfCertPool() } return nil, nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tls/errors.generated.go
transport/internet/tls/errors.generated.go
package tls import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tls/config_other.go
transport/internet/tls/config_other.go
// +build !windows // +build !confonly package tls import ( "crypto/x509" "sync" ) type rootCertsCache struct { sync.Mutex pool *x509.CertPool } func (c *rootCertsCache) load() (*x509.CertPool, error) { c.Lock() defer c.Unlock() if c.pool != nil { return c.pool, nil } pool, err := x509.SystemCertPool() if err != nil { return nil, err } c.pool = pool return pool, nil } var rootCerts rootCertsCache func (c *Config) getCertPool() (*x509.CertPool, error) { if c.DisableSystemRoot { return c.loadSelfCertPool() } if len(c.Certificate) == 0 { return rootCerts.load() } pool, err := x509.SystemCertPool() if err != nil { return nil, newError("system root").AtWarning().Base(err) } for _, cert := range c.Certificate { if !pool.AppendCertsFromPEM(cert.Certificate) { return nil, newError("append cert to root").AtWarning().Base(err) } } return pool, err }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tls/config.go
transport/internet/tls/config.go
// +build !confonly package tls import ( "crypto/tls" "crypto/x509" "strings" "sync" "time" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol/tls/cert" "v2ray.com/core/transport/internet" ) var ( globalSessionCache = tls.NewLRUClientSessionCache(128) ) const exp8357 = "experiment:8357" // ParseCertificate converts a cert.Certificate to Certificate. func ParseCertificate(c *cert.Certificate) *Certificate { certPEM, keyPEM := c.ToPEM() return &Certificate{ Certificate: certPEM, Key: keyPEM, } } func (c *Config) loadSelfCertPool() (*x509.CertPool, error) { root := x509.NewCertPool() for _, cert := range c.Certificate { if !root.AppendCertsFromPEM(cert.Certificate) { return nil, newError("failed to append cert").AtWarning() } } return root, nil } // BuildCertificates builds a list of TLS certificates from proto definition. func (c *Config) BuildCertificates() []tls.Certificate { certs := make([]tls.Certificate, 0, len(c.Certificate)) for _, entry := range c.Certificate { if entry.Usage != Certificate_ENCIPHERMENT { continue } keyPair, err := tls.X509KeyPair(entry.Certificate, entry.Key) if err != nil { newError("ignoring invalid X509 key pair").Base(err).AtWarning().WriteToLog() continue } certs = append(certs, keyPair) } return certs } func isCertificateExpired(c *tls.Certificate) bool { if c.Leaf == nil && len(c.Certificate) > 0 { if pc, err := x509.ParseCertificate(c.Certificate[0]); err == nil { c.Leaf = pc } } // If leaf is not there, the certificate is probably not used yet. We trust user to provide a valid certificate. return c.Leaf != nil && c.Leaf.NotAfter.Before(time.Now().Add(-time.Minute)) } func issueCertificate(rawCA *Certificate, domain string) (*tls.Certificate, error) { parent, err := cert.ParseCertificate(rawCA.Certificate, rawCA.Key) if err != nil { return nil, newError("failed to parse raw certificate").Base(err) } newCert, err := cert.Generate(parent, cert.CommonName(domain), cert.DNSNames(domain)) if err != nil { return nil, newError("failed to generate new certificate for ", domain).Base(err) } newCertPEM, newKeyPEM := newCert.ToPEM() cert, err := tls.X509KeyPair(newCertPEM, newKeyPEM) return &cert, err } func (c *Config) getCustomCA() []*Certificate { certs := make([]*Certificate, 0, len(c.Certificate)) for _, certificate := range c.Certificate { if certificate.Usage == Certificate_AUTHORITY_ISSUE { certs = append(certs, certificate) } } return certs } func getGetCertificateFunc(c *tls.Config, ca []*Certificate) func(hello *tls.ClientHelloInfo) (*tls.Certificate, error) { var access sync.RWMutex return func(hello *tls.ClientHelloInfo) (*tls.Certificate, error) { domain := hello.ServerName certExpired := false access.RLock() certificate, found := c.NameToCertificate[domain] access.RUnlock() if found { if !isCertificateExpired(certificate) { return certificate, nil } certExpired = true } if certExpired { newCerts := make([]tls.Certificate, 0, len(c.Certificates)) access.Lock() for _, certificate := range c.Certificates { if !isCertificateExpired(&certificate) { newCerts = append(newCerts, certificate) } } c.Certificates = newCerts access.Unlock() } var issuedCertificate *tls.Certificate // Create a new certificate from existing CA if possible for _, rawCert := range ca { if rawCert.Usage == Certificate_AUTHORITY_ISSUE { newCert, err := issueCertificate(rawCert, domain) if err != nil { newError("failed to issue new certificate for ", domain).Base(err).WriteToLog() continue } access.Lock() c.Certificates = append(c.Certificates, *newCert) issuedCertificate = &c.Certificates[len(c.Certificates)-1] access.Unlock() break } } if issuedCertificate == nil { return nil, newError("failed to create a new certificate for ", domain) } access.Lock() c.BuildNameToCertificate() access.Unlock() return issuedCertificate, nil } } func (c *Config) IsExperiment8357() bool { return strings.HasPrefix(c.ServerName, exp8357) } func (c *Config) parseServerName() string { if c.IsExperiment8357() { return c.ServerName[len(exp8357):] } return c.ServerName } // GetTLSConfig converts this Config into tls.Config. func (c *Config) GetTLSConfig(opts ...Option) *tls.Config { root, err := c.getCertPool() if err != nil { newError("failed to load system root certificate").AtError().Base(err).WriteToLog() } config := &tls.Config{ ClientSessionCache: globalSessionCache, RootCAs: root, InsecureSkipVerify: c.AllowInsecure, NextProtos: c.NextProtocol, SessionTicketsDisabled: c.DisableSessionResumption, } if c == nil { return config } for _, opt := range opts { opt(config) } config.Certificates = c.BuildCertificates() config.BuildNameToCertificate() caCerts := c.getCustomCA() if len(caCerts) > 0 { config.GetCertificate = getGetCertificateFunc(config, caCerts) } if sn := c.parseServerName(); len(sn) > 0 { config.ServerName = sn } if len(config.NextProtos) == 0 { config.NextProtos = []string{"h2", "http/1.1"} } return config } // Option for building TLS config. type Option func(*tls.Config) // WithDestination sets the server name in TLS config. func WithDestination(dest net.Destination) Option { return func(config *tls.Config) { if dest.Address.Family().IsDomain() && config.ServerName == "" { config.ServerName = dest.Address.Domain() } } } // WithNextProto sets the ALPN values in TLS config. func WithNextProto(protocol ...string) Option { return func(config *tls.Config) { if len(config.NextProtos) == 0 { config.NextProtos = protocol } } } // ConfigFromStreamSettings fetches Config from stream settings. Nil if not found. func ConfigFromStreamSettings(settings *internet.MemoryStreamConfig) *Config { if settings == nil { return nil } config, ok := settings.SecuritySettings.(*Config) if !ok { return nil } return config }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tls/config_test.go
transport/internet/tls/config_test.go
package tls_test import ( gotls "crypto/tls" "crypto/x509" "testing" "time" "v2ray.com/core/common" "v2ray.com/core/common/protocol/tls/cert" . "v2ray.com/core/transport/internet/tls" ) func TestCertificateIssuing(t *testing.T) { certificate := ParseCertificate(cert.MustGenerate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageCertSign))) certificate.Usage = Certificate_AUTHORITY_ISSUE c := &Config{ Certificate: []*Certificate{ certificate, }, } tlsConfig := c.GetTLSConfig() v2rayCert, err := tlsConfig.GetCertificate(&gotls.ClientHelloInfo{ ServerName: "www.v2ray.com", }) common.Must(err) x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0]) common.Must(err) if !x509Cert.NotAfter.After(time.Now()) { t.Error("NotAfter: ", x509Cert.NotAfter) } } func TestExpiredCertificate(t *testing.T) { caCert := cert.MustGenerate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageCertSign)) expiredCert := cert.MustGenerate(caCert, cert.NotAfter(time.Now().Add(time.Minute*-2)), cert.CommonName("www.v2ray.com"), cert.DNSNames("www.v2ray.com")) certificate := ParseCertificate(caCert) certificate.Usage = Certificate_AUTHORITY_ISSUE certificate2 := ParseCertificate(expiredCert) c := &Config{ Certificate: []*Certificate{ certificate, certificate2, }, } tlsConfig := c.GetTLSConfig() v2rayCert, err := tlsConfig.GetCertificate(&gotls.ClientHelloInfo{ ServerName: "www.v2ray.com", }) common.Must(err) x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0]) common.Must(err) if !x509Cert.NotAfter.After(time.Now()) { t.Error("NotAfter: ", x509Cert.NotAfter) } } func TestInsecureCertificates(t *testing.T) { c := &Config{ AllowInsecureCiphers: true, } tlsConfig := c.GetTLSConfig() if len(tlsConfig.CipherSuites) > 0 { t.Fatal("Unexpected tls cipher suites list: ", tlsConfig.CipherSuites) } } func BenchmarkCertificateIssuing(b *testing.B) { certificate := ParseCertificate(cert.MustGenerate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageCertSign))) certificate.Usage = Certificate_AUTHORITY_ISSUE c := &Config{ Certificate: []*Certificate{ certificate, }, } tlsConfig := c.GetTLSConfig() lenCerts := len(tlsConfig.Certificates) b.ResetTimer() for i := 0; i < b.N; i++ { _, _ = tlsConfig.GetCertificate(&gotls.ClientHelloInfo{ ServerName: "www.v2ray.com", }) delete(tlsConfig.NameToCertificate, "www.v2ray.com") tlsConfig.Certificates = tlsConfig.Certificates[:lenCerts] } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tls/config.pb.go
transport/internet/tls/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/tls/config.proto package tls import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Certificate_Usage int32 const ( Certificate_ENCIPHERMENT Certificate_Usage = 0 Certificate_AUTHORITY_VERIFY Certificate_Usage = 1 Certificate_AUTHORITY_ISSUE Certificate_Usage = 2 ) // Enum value maps for Certificate_Usage. var ( Certificate_Usage_name = map[int32]string{ 0: "ENCIPHERMENT", 1: "AUTHORITY_VERIFY", 2: "AUTHORITY_ISSUE", } Certificate_Usage_value = map[string]int32{ "ENCIPHERMENT": 0, "AUTHORITY_VERIFY": 1, "AUTHORITY_ISSUE": 2, } ) func (x Certificate_Usage) Enum() *Certificate_Usage { p := new(Certificate_Usage) *p = x return p } func (x Certificate_Usage) String() string { return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) } func (Certificate_Usage) Descriptor() protoreflect.EnumDescriptor { return file_transport_internet_tls_config_proto_enumTypes[0].Descriptor() } func (Certificate_Usage) Type() protoreflect.EnumType { return &file_transport_internet_tls_config_proto_enumTypes[0] } func (x Certificate_Usage) Number() protoreflect.EnumNumber { return protoreflect.EnumNumber(x) } // Deprecated: Use Certificate_Usage.Descriptor instead. func (Certificate_Usage) EnumDescriptor() ([]byte, []int) { return file_transport_internet_tls_config_proto_rawDescGZIP(), []int{0, 0} } type Certificate struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // TLS certificate in x509 format. Certificate []byte `protobuf:"bytes,1,opt,name=Certificate,proto3" json:"Certificate,omitempty"` // TLS key in x509 format. Key []byte `protobuf:"bytes,2,opt,name=Key,proto3" json:"Key,omitempty"` Usage Certificate_Usage `protobuf:"varint,3,opt,name=usage,proto3,enum=v2ray.core.transport.internet.tls.Certificate_Usage" json:"usage,omitempty"` } func (x *Certificate) Reset() { *x = Certificate{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_tls_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Certificate) String() string { return protoimpl.X.MessageStringOf(x) } func (*Certificate) ProtoMessage() {} func (x *Certificate) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_tls_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Certificate.ProtoReflect.Descriptor instead. func (*Certificate) Descriptor() ([]byte, []int) { return file_transport_internet_tls_config_proto_rawDescGZIP(), []int{0} } func (x *Certificate) GetCertificate() []byte { if x != nil { return x.Certificate } return nil } func (x *Certificate) GetKey() []byte { if x != nil { return x.Key } return nil } func (x *Certificate) GetUsage() Certificate_Usage { if x != nil { return x.Usage } return Certificate_ENCIPHERMENT } type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Whether or not to allow self-signed certificates. AllowInsecure bool `protobuf:"varint,1,opt,name=allow_insecure,json=allowInsecure,proto3" json:"allow_insecure,omitempty"` // Whether or not to allow insecure cipher suites. AllowInsecureCiphers bool `protobuf:"varint,5,opt,name=allow_insecure_ciphers,json=allowInsecureCiphers,proto3" json:"allow_insecure_ciphers,omitempty"` // List of certificates to be served on server. Certificate []*Certificate `protobuf:"bytes,2,rep,name=certificate,proto3" json:"certificate,omitempty"` // Override server name. ServerName string `protobuf:"bytes,3,opt,name=server_name,json=serverName,proto3" json:"server_name,omitempty"` // Lists of string as ALPN values. NextProtocol []string `protobuf:"bytes,4,rep,name=next_protocol,json=nextProtocol,proto3" json:"next_protocol,omitempty"` // Whether or not to disable session (ticket) resumption. DisableSessionResumption bool `protobuf:"varint,6,opt,name=disable_session_resumption,json=disableSessionResumption,proto3" json:"disable_session_resumption,omitempty"` // If true, root certificates on the system will not be loaded for // verification. DisableSystemRoot bool `protobuf:"varint,7,opt,name=disable_system_root,json=disableSystemRoot,proto3" json:"disable_system_root,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_tls_config_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_tls_config_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_tls_config_proto_rawDescGZIP(), []int{1} } func (x *Config) GetAllowInsecure() bool { if x != nil { return x.AllowInsecure } return false } func (x *Config) GetAllowInsecureCiphers() bool { if x != nil { return x.AllowInsecureCiphers } return false } func (x *Config) GetCertificate() []*Certificate { if x != nil { return x.Certificate } return nil } func (x *Config) GetServerName() string { if x != nil { return x.ServerName } return "" } func (x *Config) GetNextProtocol() []string { if x != nil { return x.NextProtocol } return nil } func (x *Config) GetDisableSessionResumption() bool { if x != nil { return x.DisableSessionResumption } return false } func (x *Config) GetDisableSystemRoot() bool { if x != nil { return x.DisableSystemRoot } return false } var File_transport_internet_tls_config_proto protoreflect.FileDescriptor var file_transport_internet_tls_config_proto_rawDesc = []byte{ 0x0a, 0x23, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x74, 0x6c, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x74, 0x6c, 0x73, 0x22, 0xd3, 0x01, 0x0a, 0x0b, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x4b, 0x65, 0x79, 0x12, 0x4a, 0x0a, 0x05, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x34, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x74, 0x6c, 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x2e, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x05, 0x75, 0x73, 0x61, 0x67, 0x65, 0x22, 0x44, 0x0a, 0x05, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x45, 0x4e, 0x43, 0x49, 0x50, 0x48, 0x45, 0x52, 0x4d, 0x45, 0x4e, 0x54, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x41, 0x55, 0x54, 0x48, 0x4f, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x56, 0x45, 0x52, 0x49, 0x46, 0x59, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x41, 0x55, 0x54, 0x48, 0x4f, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x49, 0x53, 0x53, 0x55, 0x45, 0x10, 0x02, 0x22, 0xeb, 0x02, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x49, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x12, 0x34, 0x0a, 0x16, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x5f, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x14, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x49, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x43, 0x69, 0x70, 0x68, 0x65, 0x72, 0x73, 0x12, 0x50, 0x0a, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x74, 0x6c, 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x6e, 0x65, 0x78, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x3c, 0x0a, 0x1a, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x65, 0x73, 0x75, 0x6d, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x18, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6d, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2e, 0x0a, 0x13, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x52, 0x6f, 0x6f, 0x74, 0x42, 0x74, 0x0a, 0x25, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x74, 0x6c, 0x73, 0x50, 0x01, 0x5a, 0x25, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x74, 0x6c, 0x73, 0xaa, 0x02, 0x21, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x54, 0x6c, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_tls_config_proto_rawDescOnce sync.Once file_transport_internet_tls_config_proto_rawDescData = file_transport_internet_tls_config_proto_rawDesc ) func file_transport_internet_tls_config_proto_rawDescGZIP() []byte { file_transport_internet_tls_config_proto_rawDescOnce.Do(func() { file_transport_internet_tls_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_tls_config_proto_rawDescData) }) return file_transport_internet_tls_config_proto_rawDescData } var file_transport_internet_tls_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_transport_internet_tls_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_transport_internet_tls_config_proto_goTypes = []interface{}{ (Certificate_Usage)(0), // 0: v2ray.core.transport.internet.tls.Certificate.Usage (*Certificate)(nil), // 1: v2ray.core.transport.internet.tls.Certificate (*Config)(nil), // 2: v2ray.core.transport.internet.tls.Config } var file_transport_internet_tls_config_proto_depIdxs = []int32{ 0, // 0: v2ray.core.transport.internet.tls.Certificate.usage:type_name -> v2ray.core.transport.internet.tls.Certificate.Usage 1, // 1: v2ray.core.transport.internet.tls.Config.certificate:type_name -> v2ray.core.transport.internet.tls.Certificate 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name } func init() { file_transport_internet_tls_config_proto_init() } func file_transport_internet_tls_config_proto_init() { if File_transport_internet_tls_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_tls_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Certificate); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_tls_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_tls_config_proto_rawDesc, NumEnums: 1, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_tls_config_proto_goTypes, DependencyIndexes: file_transport_internet_tls_config_proto_depIdxs, EnumInfos: file_transport_internet_tls_config_proto_enumTypes, MessageInfos: file_transport_internet_tls_config_proto_msgTypes, }.Build() File_transport_internet_tls_config_proto = out.File file_transport_internet_tls_config_proto_rawDesc = nil file_transport_internet_tls_config_proto_goTypes = nil file_transport_internet_tls_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tls/tls.go
transport/internet/tls/tls.go
// +build !confonly package tls import ( "crypto/tls" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" ) //go:generate go run v2ray.com/core/common/errors/errorgen var ( _ buf.Writer = (*Conn)(nil) ) type Conn struct { *tls.Conn } func (c *Conn) WriteMultiBuffer(mb buf.MultiBuffer) error { mb = buf.Compact(mb) mb, err := buf.WriteMultiBuffer(c, mb) buf.ReleaseMulti(mb) return err } func (c *Conn) HandshakeAddress() net.Address { if err := c.Handshake(); err != nil { return nil } state := c.ConnectionState() if state.ServerName == "" { return nil } return net.ParseAddress(state.ServerName) } // Client initiates a TLS client handshake on the given connection. func Client(c net.Conn, config *tls.Config) net.Conn { tlsConn := tls.Client(c, config) return &Conn{Conn: tlsConn} } /* func copyConfig(c *tls.Config) *utls.Config { return &utls.Config{ NextProtos: c.NextProtos, ServerName: c.ServerName, InsecureSkipVerify: c.InsecureSkipVerify, MinVersion: utls.VersionTLS12, MaxVersion: utls.VersionTLS12, } } func UClient(c net.Conn, config *tls.Config) net.Conn { uConfig := copyConfig(config) return utls.Client(c, uConfig) } */ // Server initiates a TLS server handshake on the given connection. func Server(c net.Conn, config *tls.Config) net.Conn { tlsConn := tls.Server(c, config) return &Conn{Conn: tlsConn} }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/hub.go
transport/internet/tcp/hub.go
// +build !confonly package tcp import ( "context" gotls "crypto/tls" "strings" "time" "github.com/pires/go-proxyproto" goxtls "github.com/xtls/go" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" "v2ray.com/core/transport/internet/xtls" ) // Listener is an internet.Listener that listens for TCP connections. type Listener struct { listener net.Listener tlsConfig *gotls.Config xtlsConfig *goxtls.Config authConfig internet.ConnectionAuthenticator config *Config addConn internet.ConnHandler } // ListenTCP creates a new Listener based on configurations. func ListenTCP(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, handler internet.ConnHandler) (internet.Listener, error) { listener, err := internet.ListenSystem(ctx, &net.TCPAddr{ IP: address.IP(), Port: int(port), }, streamSettings.SocketSettings) if err != nil { return nil, newError("failed to listen TCP on", address, ":", port).Base(err) } newError("listening TCP on ", address, ":", port).WriteToLog(session.ExportIDToError(ctx)) tcpSettings := streamSettings.ProtocolSettings.(*Config) var l *Listener if tcpSettings.AcceptProxyProtocol { policyFunc := func(upstream net.Addr) (proxyproto.Policy, error) { return proxyproto.REQUIRE, nil } l = &Listener{ listener: &proxyproto.Listener{Listener: listener, Policy: policyFunc}, config: tcpSettings, addConn: handler, } newError("accepting PROXY protocol").AtWarning().WriteToLog(session.ExportIDToError(ctx)) } else { l = &Listener{ listener: listener, config: tcpSettings, addConn: handler, } } if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { l.tlsConfig = config.GetTLSConfig(tls.WithNextProto("h2")) } if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil { l.xtlsConfig = config.GetXTLSConfig(xtls.WithNextProto("h2")) } if tcpSettings.HeaderSettings != nil { headerConfig, err := tcpSettings.HeaderSettings.GetInstance() if err != nil { return nil, newError("invalid header settings").Base(err).AtError() } auth, err := internet.CreateConnectionAuthenticator(headerConfig) if err != nil { return nil, newError("invalid header settings.").Base(err).AtError() } l.authConfig = auth } go l.keepAccepting() return l, nil } func (v *Listener) keepAccepting() { for { conn, err := v.listener.Accept() if err != nil { errStr := err.Error() if strings.Contains(errStr, "closed") { break } newError("failed to accepted raw connections").Base(err).AtWarning().WriteToLog() if strings.Contains(errStr, "too many") { time.Sleep(time.Millisecond * 500) } continue } if v.tlsConfig != nil { conn = tls.Server(conn, v.tlsConfig) } else if v.xtlsConfig != nil { conn = xtls.Server(conn, v.xtlsConfig) } if v.authConfig != nil { conn = v.authConfig.Server(conn) } v.addConn(internet.Connection(conn)) } } // Addr implements internet.Listener.Addr. func (v *Listener) Addr() net.Addr { return v.listener.Addr() } // Close implements internet.Listener.Close. func (v *Listener) Close() error { return v.listener.Close() } func init() { common.Must(internet.RegisterTransportListener(protocolName, ListenTCP)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/dialer.go
transport/internet/tcp/dialer.go
// +build !confonly package tcp import ( "context" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" "v2ray.com/core/transport/internet/xtls" ) // Dial dials a new TCP connection to the given destination. func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { newError("dialing TCP to ", dest).WriteToLog(session.ExportIDToError(ctx)) conn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings) if err != nil { return nil, err } if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { tlsConfig := config.GetTLSConfig(tls.WithDestination(dest)) /* if config.IsExperiment8357() { conn = tls.UClient(conn, tlsConfig) } else { conn = tls.Client(conn, tlsConfig) } */ conn = tls.Client(conn, tlsConfig) } else if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil { xtlsConfig := config.GetXTLSConfig(xtls.WithDestination(dest)) conn = xtls.Client(conn, xtlsConfig) } tcpSettings := streamSettings.ProtocolSettings.(*Config) if tcpSettings.HeaderSettings != nil { headerConfig, err := tcpSettings.HeaderSettings.GetInstance() if err != nil { return nil, newError("failed to get header settings").Base(err).AtError() } auth, err := internet.CreateConnectionAuthenticator(headerConfig) if err != nil { return nil, newError("failed to create header authenticator").Base(err).AtError() } conn = auth.Client(conn) } return internet.Connection(conn), nil } func init() { common.Must(internet.RegisterTransportDialer(protocolName, Dial)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/errors.generated.go
transport/internet/tcp/errors.generated.go
package tcp import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/tcp.go
transport/internet/tcp/tcp.go
package tcp //go:generate go run v2ray.com/core/common/errors/errorgen
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/sockopt_other.go
transport/internet/tcp/sockopt_other.go
// +build !linux,!freebsd // +build !confonly package tcp import ( "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) func GetOriginalDestination(conn internet.Connection) (net.Destination, error) { return net.Destination{}, nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/config.go
transport/internet/tcp/config.go
// +build !confonly package tcp import ( "v2ray.com/core/common" "v2ray.com/core/transport/internet" ) const protocolName = "tcp" func init() { common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { return new(Config) })) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/sockopt_linux.go
transport/internet/tcp/sockopt_linux.go
// +build linux // +build !confonly package tcp import ( "syscall" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) const SO_ORIGINAL_DST = 80 func GetOriginalDestination(conn internet.Connection) (net.Destination, error) { sysrawconn, f := conn.(syscall.Conn) if !f { return net.Destination{}, newError("unable to get syscall.Conn") } rawConn, err := sysrawconn.SyscallConn() if err != nil { return net.Destination{}, newError("failed to get sys fd").Base(err) } var dest net.Destination err = rawConn.Control(func(fd uintptr) { addr, err := syscall.GetsockoptIPv6Mreq(int(fd), syscall.IPPROTO_IP, SO_ORIGINAL_DST) if err != nil { newError("failed to call getsockopt").Base(err).WriteToLog() return } ip := net.IPAddress(addr.Multiaddr[4:8]) port := uint16(addr.Multiaddr[2])<<8 + uint16(addr.Multiaddr[3]) dest = net.TCPDestination(ip, net.Port(port)) }) if err != nil { return net.Destination{}, newError("failed to control connection").Base(err) } if !dest.IsValid() { return net.Destination{}, newError("failed to call getsockopt") } return dest, nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/sockopt_linux_test.go
transport/internet/tcp/sockopt_linux_test.go
// +build linux package tcp_test import ( "context" "strings" "testing" "v2ray.com/core/common" "v2ray.com/core/testing/servers/tcp" "v2ray.com/core/transport/internet" . "v2ray.com/core/transport/internet/tcp" ) func TestGetOriginalDestination(t *testing.T) { tcpServer := tcp.Server{} dest, err := tcpServer.Start() common.Must(err) defer tcpServer.Close() config, err := internet.ToMemoryStreamConfig(nil) common.Must(err) conn, err := Dial(context.Background(), dest, config) common.Must(err) defer conn.Close() originalDest, err := GetOriginalDestination(conn) if !(dest == originalDest || strings.Contains(err.Error(), "failed to call getsockopt")) { t.Error("unexpected state") } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/config.pb.go
transport/internet/tcp/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/tcp/config.proto package tcp import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" serial "v2ray.com/core/common/serial" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields HeaderSettings *serial.TypedMessage `protobuf:"bytes,2,opt,name=header_settings,json=headerSettings,proto3" json:"header_settings,omitempty"` AcceptProxyProtocol bool `protobuf:"varint,3,opt,name=accept_proxy_protocol,json=acceptProxyProtocol,proto3" json:"accept_proxy_protocol,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_tcp_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_tcp_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_tcp_config_proto_rawDescGZIP(), []int{0} } func (x *Config) GetHeaderSettings() *serial.TypedMessage { if x != nil { return x.HeaderSettings } return nil } func (x *Config) GetAcceptProxyProtocol() bool { if x != nil { return x.AcceptProxyProtocol } return false } var File_transport_internet_tcp_config_proto protoreflect.FileDescriptor var file_transport_internet_tcp_config_proto_rawDesc = []byte{ 0x0a, 0x23, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x74, 0x63, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x74, 0x63, 0x70, 0x1a, 0x21, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x64, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x93, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x4f, 0x0a, 0x0f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x0e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x32, 0x0a, 0x15, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x13, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x42, 0x74, 0x0a, 0x25, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x74, 0x63, 0x70, 0x50, 0x01, 0x5a, 0x25, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x74, 0x63, 0x70, 0xaa, 0x02, 0x21, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x54, 0x63, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_tcp_config_proto_rawDescOnce sync.Once file_transport_internet_tcp_config_proto_rawDescData = file_transport_internet_tcp_config_proto_rawDesc ) func file_transport_internet_tcp_config_proto_rawDescGZIP() []byte { file_transport_internet_tcp_config_proto_rawDescOnce.Do(func() { file_transport_internet_tcp_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_tcp_config_proto_rawDescData) }) return file_transport_internet_tcp_config_proto_rawDescData } var file_transport_internet_tcp_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_tcp_config_proto_goTypes = []interface{}{ (*Config)(nil), // 0: v2ray.core.transport.internet.tcp.Config (*serial.TypedMessage)(nil), // 1: v2ray.core.common.serial.TypedMessage } var file_transport_internet_tcp_config_proto_depIdxs = []int32{ 1, // 0: v2ray.core.transport.internet.tcp.Config.header_settings:type_name -> v2ray.core.common.serial.TypedMessage 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name } func init() { file_transport_internet_tcp_config_proto_init() } func file_transport_internet_tcp_config_proto_init() { if File_transport_internet_tcp_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_tcp_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_tcp_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_tcp_config_proto_goTypes, DependencyIndexes: file_transport_internet_tcp_config_proto_depIdxs, MessageInfos: file_transport_internet_tcp_config_proto_msgTypes, }.Build() File_transport_internet_tcp_config_proto = out.File file_transport_internet_tcp_config_proto_rawDesc = nil file_transport_internet_tcp_config_proto_goTypes = nil file_transport_internet_tcp_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/tcp/sockopt_freebsd.go
transport/internet/tcp/sockopt_freebsd.go
// +build freebsd // +build !confonly package tcp import ( "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) // GetOriginalDestination from tcp conn func GetOriginalDestination(conn internet.Connection) (net.Destination, error) { la := conn.LocalAddr() ra := conn.RemoteAddr() ip, port, err := internet.OriginalDst(la, ra) if err != nil { return net.Destination{}, newError("failed to get destination").Base(err) } dest := net.TCPDestination(net.IPAddress(ip), net.Port(port)) if !dest.IsValid() { return net.Destination{}, newError("failed to parse destination.") } return dest, nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/hub.go
transport/internet/udp/hub.go
package udp import ( "context" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol/udp" "v2ray.com/core/transport/internet" ) type HubOption func(h *Hub) func HubCapacity(capacity int) HubOption { return func(h *Hub) { h.capacity = capacity } } func HubReceiveOriginalDestination(r bool) HubOption { return func(h *Hub) { h.recvOrigDest = r } } type Hub struct { conn *net.UDPConn cache chan *udp.Packet capacity int recvOrigDest bool } func ListenUDP(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, options ...HubOption) (*Hub, error) { hub := &Hub{ capacity: 256, recvOrigDest: false, } for _, opt := range options { opt(hub) } var sockopt *internet.SocketConfig if streamSettings != nil { sockopt = streamSettings.SocketSettings } if sockopt != nil && sockopt.ReceiveOriginalDestAddress { hub.recvOrigDest = true } udpConn, err := internet.ListenSystemPacket(ctx, &net.UDPAddr{ IP: address.IP(), Port: int(port), }, sockopt) if err != nil { return nil, err } newError("listening UDP on ", address, ":", port).WriteToLog() hub.conn = udpConn.(*net.UDPConn) hub.cache = make(chan *udp.Packet, hub.capacity) go hub.start() return hub, nil } // Close implements net.Listener. func (h *Hub) Close() error { h.conn.Close() return nil } func (h *Hub) WriteTo(payload []byte, dest net.Destination) (int, error) { return h.conn.WriteToUDP(payload, &net.UDPAddr{ IP: dest.Address.IP(), Port: int(dest.Port), }) } func (h *Hub) start() { c := h.cache defer close(c) oobBytes := make([]byte, 256) for { buffer := buf.New() var noob int var addr *net.UDPAddr rawBytes := buffer.Extend(buf.Size) n, noob, _, addr, err := ReadUDPMsg(h.conn, rawBytes, oobBytes) if err != nil { newError("failed to read UDP msg").Base(err).WriteToLog() buffer.Release() break } buffer.Resize(0, int32(n)) if buffer.IsEmpty() { buffer.Release() continue } payload := &udp.Packet{ Payload: buffer, Source: net.UDPDestination(net.IPAddress(addr.IP), net.Port(addr.Port)), } if h.recvOrigDest && noob > 0 { payload.Target = RetrieveOriginalDest(oobBytes[:noob]) if payload.Target.IsValid() { newError("UDP original destination: ", payload.Target).AtDebug().WriteToLog() } else { newError("failed to read UDP original destination").WriteToLog() } } select { case c <- payload: default: buffer.Release() payload.Payload = nil } } } // Addr implements net.Listener. func (h *Hub) Addr() net.Addr { return h.conn.LocalAddr() } func (h *Hub) Receive() <-chan *udp.Packet { return h.cache }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/dialer.go
transport/internet/udp/dialer.go
package udp import ( "context" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) func init() { common.Must(internet.RegisterTransportDialer(protocolName, func(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { var sockopt *internet.SocketConfig if streamSettings != nil { sockopt = streamSettings.SocketSettings } conn, err := internet.DialSystem(ctx, dest, sockopt) if err != nil { return nil, err } // TODO: handle dialer options return internet.Connection(conn), nil })) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/errors.generated.go
transport/internet/udp/errors.generated.go
package udp import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/hub_freebsd.go
transport/internet/udp/hub_freebsd.go
// +build freebsd package udp import ( "bytes" "encoding/gob" "io" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) // RetrieveOriginalDest from stored laddr, caddr func RetrieveOriginalDest(oob []byte) net.Destination { dec := gob.NewDecoder(bytes.NewBuffer(oob)) var la, ra net.UDPAddr dec.Decode(&la) dec.Decode(&ra) ip, port, err := internet.OriginalDst(&la, &ra) if err != nil { return net.Destination{} } return net.UDPDestination(net.IPAddress(ip), net.Port(port)) } // ReadUDPMsg stores laddr, caddr for later use func ReadUDPMsg(conn *net.UDPConn, payload []byte, oob []byte) (int, int, int, *net.UDPAddr, error) { nBytes, addr, err := conn.ReadFromUDP(payload) var buf bytes.Buffer enc := gob.NewEncoder(&buf) enc.Encode(conn.LocalAddr().(*net.UDPAddr)) enc.Encode(addr) var reader io.Reader = &buf noob, _ := reader.Read(oob) return nBytes, noob, 0, addr, err }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/hub_linux.go
transport/internet/udp/hub_linux.go
// +build linux package udp import ( "syscall" "golang.org/x/sys/unix" "v2ray.com/core/common/net" ) func RetrieveOriginalDest(oob []byte) net.Destination { msgs, err := syscall.ParseSocketControlMessage(oob) if err != nil { return net.Destination{} } for _, msg := range msgs { if msg.Header.Level == syscall.SOL_IP && msg.Header.Type == syscall.IP_RECVORIGDSTADDR { ip := net.IPAddress(msg.Data[4:8]) port := net.PortFromBytes(msg.Data[2:4]) return net.UDPDestination(ip, port) } else if msg.Header.Level == syscall.SOL_IPV6 && msg.Header.Type == unix.IPV6_RECVORIGDSTADDR { ip := net.IPAddress(msg.Data[8:24]) port := net.PortFromBytes(msg.Data[2:4]) return net.UDPDestination(ip, port) } } return net.Destination{} } func ReadUDPMsg(conn *net.UDPConn, payload []byte, oob []byte) (int, int, int, *net.UDPAddr, error) { return conn.ReadMsgUDP(payload, oob) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/config.go
transport/internet/udp/config.go
package udp import ( "v2ray.com/core/common" "v2ray.com/core/transport/internet" ) func init() { common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { return new(Config) })) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/dispatcher.go
transport/internet/udp/dispatcher.go
package udp import ( "context" "io" "sync" "time" "v2ray.com/core/common/signal/done" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol/udp" "v2ray.com/core/common/session" "v2ray.com/core/common/signal" "v2ray.com/core/features/routing" "v2ray.com/core/transport" ) type ResponseCallback func(ctx context.Context, packet *udp.Packet) type connEntry struct { link *transport.Link timer signal.ActivityUpdater cancel context.CancelFunc } type Dispatcher struct { sync.RWMutex conns map[net.Destination]*connEntry dispatcher routing.Dispatcher callback ResponseCallback } func NewDispatcher(dispatcher routing.Dispatcher, callback ResponseCallback) *Dispatcher { return &Dispatcher{ conns: make(map[net.Destination]*connEntry), dispatcher: dispatcher, callback: callback, } } func (v *Dispatcher) RemoveRay(dest net.Destination) { v.Lock() defer v.Unlock() if conn, found := v.conns[dest]; found { common.Close(conn.link.Reader) common.Close(conn.link.Writer) delete(v.conns, dest) } } func (v *Dispatcher) getInboundRay(ctx context.Context, dest net.Destination) *connEntry { v.Lock() defer v.Unlock() if entry, found := v.conns[dest]; found { return entry } newError("establishing new connection for ", dest).WriteToLog() ctx, cancel := context.WithCancel(ctx) removeRay := func() { cancel() v.RemoveRay(dest) } timer := signal.CancelAfterInactivity(ctx, removeRay, time.Second*4) link, _ := v.dispatcher.Dispatch(ctx, dest) entry := &connEntry{ link: link, timer: timer, cancel: removeRay, } v.conns[dest] = entry go handleInput(ctx, entry, dest, v.callback) return entry } func (v *Dispatcher) Dispatch(ctx context.Context, destination net.Destination, payload *buf.Buffer) { // TODO: Add user to destString newError("dispatch request to: ", destination).AtDebug().WriteToLog(session.ExportIDToError(ctx)) conn := v.getInboundRay(ctx, destination) outputStream := conn.link.Writer if outputStream != nil { if err := outputStream.WriteMultiBuffer(buf.MultiBuffer{payload}); err != nil { newError("failed to write first UDP payload").Base(err).WriteToLog(session.ExportIDToError(ctx)) conn.cancel() return } } } func handleInput(ctx context.Context, conn *connEntry, dest net.Destination, callback ResponseCallback) { defer conn.cancel() input := conn.link.Reader timer := conn.timer for { select { case <-ctx.Done(): return default: } mb, err := input.ReadMultiBuffer() if err != nil { newError("failed to handle UDP input").Base(err).WriteToLog(session.ExportIDToError(ctx)) return } timer.Update() for _, b := range mb { callback(ctx, &udp.Packet{ Payload: b, Source: dest, }) } } } type dispatcherConn struct { dispatcher *Dispatcher cache chan *udp.Packet done *done.Instance } func DialDispatcher(ctx context.Context, dispatcher routing.Dispatcher) (net.PacketConn, error) { c := &dispatcherConn{ cache: make(chan *udp.Packet, 16), done: done.New(), } d := NewDispatcher(dispatcher, c.callback) c.dispatcher = d return c, nil } func (c *dispatcherConn) callback(ctx context.Context, packet *udp.Packet) { select { case <-c.done.Wait(): packet.Payload.Release() return case c.cache <- packet: default: packet.Payload.Release() return } } func (c *dispatcherConn) ReadFrom(p []byte) (int, net.Addr, error) { select { case <-c.done.Wait(): return 0, nil, io.EOF case packet := <-c.cache: n := copy(p, packet.Payload.Bytes()) return n, &net.UDPAddr{ IP: packet.Source.Address.IP(), Port: int(packet.Source.Port), }, nil } } func (c *dispatcherConn) WriteTo(p []byte, addr net.Addr) (int, error) { buffer := buf.New() raw := buffer.Extend(buf.Size) n := copy(raw, p) buffer.Resize(0, int32(n)) ctx := context.Background() c.dispatcher.Dispatch(ctx, net.DestinationFromAddr(addr), buffer) return n, nil } func (c *dispatcherConn) Close() error { return c.done.Close() } func (c *dispatcherConn) LocalAddr() net.Addr { return &net.UDPAddr{ IP: []byte{0, 0, 0, 0}, Port: 0, } } func (c *dispatcherConn) SetDeadline(t time.Time) error { return nil } func (c *dispatcherConn) SetReadDeadline(t time.Time) error { return nil } func (c *dispatcherConn) SetWriteDeadline(t time.Time) error { return nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/udp.go
transport/internet/udp/udp.go
package udp //go:generate go run v2ray.com/core/common/errors/errorgen const protocolName = "udp"
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/hub_other.go
transport/internet/udp/hub_other.go
// +build !linux,!freebsd package udp import ( "v2ray.com/core/common/net" ) func RetrieveOriginalDest(oob []byte) net.Destination { return net.Destination{} } func ReadUDPMsg(conn *net.UDPConn, payload []byte, oob []byte) (int, int, int, *net.UDPAddr, error) { nBytes, addr, err := conn.ReadFromUDP(payload) return nBytes, 0, 0, addr, err }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/dispatcher_test.go
transport/internet/udp/dispatcher_test.go
package udp_test import ( "context" "sync/atomic" "testing" "time" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol/udp" "v2ray.com/core/features/routing" "v2ray.com/core/transport" . "v2ray.com/core/transport/internet/udp" "v2ray.com/core/transport/pipe" ) type TestDispatcher struct { OnDispatch func(ctx context.Context, dest net.Destination) (*transport.Link, error) } func (d *TestDispatcher) Dispatch(ctx context.Context, dest net.Destination) (*transport.Link, error) { return d.OnDispatch(ctx, dest) } func (d *TestDispatcher) Start() error { return nil } func (d *TestDispatcher) Close() error { return nil } func (*TestDispatcher) Type() interface{} { return routing.DispatcherType() } func TestSameDestinationDispatching(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) uplinkReader, uplinkWriter := pipe.New(pipe.WithSizeLimit(1024)) downlinkReader, downlinkWriter := pipe.New(pipe.WithSizeLimit(1024)) go func() { for { data, err := uplinkReader.ReadMultiBuffer() if err != nil { break } err = downlinkWriter.WriteMultiBuffer(data) common.Must(err) } }() var count uint32 td := &TestDispatcher{ OnDispatch: func(ctx context.Context, dest net.Destination) (*transport.Link, error) { atomic.AddUint32(&count, 1) return &transport.Link{Reader: downlinkReader, Writer: uplinkWriter}, nil }, } dest := net.UDPDestination(net.LocalHostIP, 53) b := buf.New() b.WriteString("abcd") var msgCount uint32 dispatcher := NewDispatcher(td, func(ctx context.Context, packet *udp.Packet) { atomic.AddUint32(&msgCount, 1) }) dispatcher.Dispatch(ctx, dest, b) for i := 0; i < 5; i++ { dispatcher.Dispatch(ctx, dest, b) } time.Sleep(time.Second) cancel() if count != 1 { t.Error("count: ", count) } if v := atomic.LoadUint32(&msgCount); v != 6 { t.Error("msgCount: ", v) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/udp/config.pb.go
transport/internet/udp/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/udp/config.proto package udp import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_udp_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_udp_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_udp_config_proto_rawDescGZIP(), []int{0} } var File_transport_internet_udp_config_proto protoreflect.FileDescriptor var file_transport_internet_udp_config_proto_rawDesc = []byte{ 0x0a, 0x23, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x75, 0x64, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x75, 0x64, 0x70, 0x22, 0x08, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x74, 0x0a, 0x25, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x75, 0x64, 0x70, 0x50, 0x01, 0x5a, 0x25, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x75, 0x64, 0x70, 0xaa, 0x02, 0x21, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x55, 0x64, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_udp_config_proto_rawDescOnce sync.Once file_transport_internet_udp_config_proto_rawDescData = file_transport_internet_udp_config_proto_rawDesc ) func file_transport_internet_udp_config_proto_rawDescGZIP() []byte { file_transport_internet_udp_config_proto_rawDescOnce.Do(func() { file_transport_internet_udp_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_udp_config_proto_rawDescData) }) return file_transport_internet_udp_config_proto_rawDescData } var file_transport_internet_udp_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_udp_config_proto_goTypes = []interface{}{ (*Config)(nil), // 0: v2ray.core.transport.internet.udp.Config } var file_transport_internet_udp_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_udp_config_proto_init() } func file_transport_internet_udp_config_proto_init() { if File_transport_internet_udp_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_udp_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_udp_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_udp_config_proto_goTypes, DependencyIndexes: file_transport_internet_udp_config_proto_depIdxs, MessageInfos: file_transport_internet_udp_config_proto_msgTypes, }.Build() File_transport_internet_udp_config_proto = out.File file_transport_internet_udp_config_proto_rawDesc = nil file_transport_internet_udp_config_proto_goTypes = nil file_transport_internet_udp_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/xtls/config_windows.go
transport/internet/xtls/config_windows.go
// +build windows // +build !confonly package xtls import "crypto/x509" func (c *Config) getCertPool() (*x509.CertPool, error) { if c.DisableSystemRoot { return c.loadSelfCertPool() } return nil, nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/xtls/errors.generated.go
transport/internet/xtls/errors.generated.go
package xtls import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/xtls/xtls.go
transport/internet/xtls/xtls.go
// +build !confonly package xtls import ( xtls "github.com/xtls/go" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" ) //go:generate go run v2ray.com/core/common/errors/errorgen var ( _ buf.Writer = (*Conn)(nil) ) type Conn struct { *xtls.Conn } func (c *Conn) WriteMultiBuffer(mb buf.MultiBuffer) error { mb = buf.Compact(mb) mb, err := buf.WriteMultiBuffer(c, mb) buf.ReleaseMulti(mb) return err } func (c *Conn) HandshakeAddress() net.Address { if err := c.Handshake(); err != nil { return nil } state := c.ConnectionState() if state.ServerName == "" { return nil } return net.ParseAddress(state.ServerName) } // Client initiates a XTLS client handshake on the given connection. func Client(c net.Conn, config *xtls.Config) net.Conn { xtlsConn := xtls.Client(c, config) return &Conn{Conn: xtlsConn} } // Server initiates a XTLS server handshake on the given connection. func Server(c net.Conn, config *xtls.Config) net.Conn { xtlsConn := xtls.Server(c, config) return &Conn{Conn: xtlsConn} }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/xtls/config_other.go
transport/internet/xtls/config_other.go
// +build !windows // +build !confonly package xtls import ( "crypto/x509" "sync" ) type rootCertsCache struct { sync.Mutex pool *x509.CertPool } func (c *rootCertsCache) load() (*x509.CertPool, error) { c.Lock() defer c.Unlock() if c.pool != nil { return c.pool, nil } pool, err := x509.SystemCertPool() if err != nil { return nil, err } c.pool = pool return pool, nil } var rootCerts rootCertsCache func (c *Config) getCertPool() (*x509.CertPool, error) { if c.DisableSystemRoot { return c.loadSelfCertPool() } if len(c.Certificate) == 0 { return rootCerts.load() } pool, err := x509.SystemCertPool() if err != nil { return nil, newError("system root").AtWarning().Base(err) } for _, cert := range c.Certificate { if !pool.AppendCertsFromPEM(cert.Certificate) { return nil, newError("append cert to root").AtWarning().Base(err) } } return pool, err }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/xtls/config.go
transport/internet/xtls/config.go
// +build !confonly package xtls import ( "crypto/x509" "sync" "time" xtls "github.com/xtls/go" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol/tls/cert" "v2ray.com/core/transport/internet" ) var ( globalSessionCache = xtls.NewLRUClientSessionCache(128) ) // ParseCertificate converts a cert.Certificate to Certificate. func ParseCertificate(c *cert.Certificate) *Certificate { certPEM, keyPEM := c.ToPEM() return &Certificate{ Certificate: certPEM, Key: keyPEM, } } func (c *Config) loadSelfCertPool() (*x509.CertPool, error) { root := x509.NewCertPool() for _, cert := range c.Certificate { if !root.AppendCertsFromPEM(cert.Certificate) { return nil, newError("failed to append cert").AtWarning() } } return root, nil } // BuildCertificates builds a list of TLS certificates from proto definition. func (c *Config) BuildCertificates() []xtls.Certificate { certs := make([]xtls.Certificate, 0, len(c.Certificate)) for _, entry := range c.Certificate { if entry.Usage != Certificate_ENCIPHERMENT { continue } keyPair, err := xtls.X509KeyPair(entry.Certificate, entry.Key) if err != nil { newError("ignoring invalid X509 key pair").Base(err).AtWarning().WriteToLog() continue } certs = append(certs, keyPair) } return certs } func isCertificateExpired(c *xtls.Certificate) bool { if c.Leaf == nil && len(c.Certificate) > 0 { if pc, err := x509.ParseCertificate(c.Certificate[0]); err == nil { c.Leaf = pc } } // If leaf is not there, the certificate is probably not used yet. We trust user to provide a valid certificate. return c.Leaf != nil && c.Leaf.NotAfter.Before(time.Now().Add(-time.Minute)) } func issueCertificate(rawCA *Certificate, domain string) (*xtls.Certificate, error) { parent, err := cert.ParseCertificate(rawCA.Certificate, rawCA.Key) if err != nil { return nil, newError("failed to parse raw certificate").Base(err) } newCert, err := cert.Generate(parent, cert.CommonName(domain), cert.DNSNames(domain)) if err != nil { return nil, newError("failed to generate new certificate for ", domain).Base(err) } newCertPEM, newKeyPEM := newCert.ToPEM() cert, err := xtls.X509KeyPair(newCertPEM, newKeyPEM) return &cert, err } func (c *Config) getCustomCA() []*Certificate { certs := make([]*Certificate, 0, len(c.Certificate)) for _, certificate := range c.Certificate { if certificate.Usage == Certificate_AUTHORITY_ISSUE { certs = append(certs, certificate) } } return certs } func getGetCertificateFunc(c *xtls.Config, ca []*Certificate) func(hello *xtls.ClientHelloInfo) (*xtls.Certificate, error) { var access sync.RWMutex return func(hello *xtls.ClientHelloInfo) (*xtls.Certificate, error) { domain := hello.ServerName certExpired := false access.RLock() certificate, found := c.NameToCertificate[domain] access.RUnlock() if found { if !isCertificateExpired(certificate) { return certificate, nil } certExpired = true } if certExpired { newCerts := make([]xtls.Certificate, 0, len(c.Certificates)) access.Lock() for _, certificate := range c.Certificates { if !isCertificateExpired(&certificate) { newCerts = append(newCerts, certificate) } } c.Certificates = newCerts access.Unlock() } var issuedCertificate *xtls.Certificate // Create a new certificate from existing CA if possible for _, rawCert := range ca { if rawCert.Usage == Certificate_AUTHORITY_ISSUE { newCert, err := issueCertificate(rawCert, domain) if err != nil { newError("failed to issue new certificate for ", domain).Base(err).WriteToLog() continue } access.Lock() c.Certificates = append(c.Certificates, *newCert) issuedCertificate = &c.Certificates[len(c.Certificates)-1] access.Unlock() break } } if issuedCertificate == nil { return nil, newError("failed to create a new certificate for ", domain) } access.Lock() c.BuildNameToCertificate() access.Unlock() return issuedCertificate, nil } } func (c *Config) parseServerName() string { return c.ServerName } // GetXTLSConfig converts this Config into xtls.Config. func (c *Config) GetXTLSConfig(opts ...Option) *xtls.Config { root, err := c.getCertPool() if err != nil { newError("failed to load system root certificate").AtError().Base(err).WriteToLog() } config := &xtls.Config{ ClientSessionCache: globalSessionCache, RootCAs: root, InsecureSkipVerify: c.AllowInsecure, NextProtos: c.NextProtocol, SessionTicketsDisabled: c.DisableSessionResumption, } if c == nil { return config } for _, opt := range opts { opt(config) } config.Certificates = c.BuildCertificates() config.BuildNameToCertificate() caCerts := c.getCustomCA() if len(caCerts) > 0 { config.GetCertificate = getGetCertificateFunc(config, caCerts) } if sn := c.parseServerName(); len(sn) > 0 { config.ServerName = sn } if len(config.NextProtos) == 0 { config.NextProtos = []string{"h2", "http/1.1"} } return config } // Option for building XTLS config. type Option func(*xtls.Config) // WithDestination sets the server name in XTLS config. func WithDestination(dest net.Destination) Option { return func(config *xtls.Config) { if dest.Address.Family().IsDomain() && config.ServerName == "" { config.ServerName = dest.Address.Domain() } } } // WithNextProto sets the ALPN values in XTLS config. func WithNextProto(protocol ...string) Option { return func(config *xtls.Config) { if len(config.NextProtos) == 0 { config.NextProtos = protocol } } } // ConfigFromStreamSettings fetches Config from stream settings. Nil if not found. func ConfigFromStreamSettings(settings *internet.MemoryStreamConfig) *Config { if settings == nil { return nil } config, ok := settings.SecuritySettings.(*Config) if !ok { return nil } return config }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/xtls/config_test.go
transport/internet/xtls/config_test.go
package xtls_test import ( "crypto/x509" "testing" "time" xtls "github.com/xtls/go" "v2ray.com/core/common" "v2ray.com/core/common/protocol/tls/cert" . "v2ray.com/core/transport/internet/xtls" ) func TestCertificateIssuing(t *testing.T) { certificate := ParseCertificate(cert.MustGenerate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageCertSign))) certificate.Usage = Certificate_AUTHORITY_ISSUE c := &Config{ Certificate: []*Certificate{ certificate, }, } xtlsConfig := c.GetXTLSConfig() v2rayCert, err := xtlsConfig.GetCertificate(&xtls.ClientHelloInfo{ ServerName: "www.v2fly.org", }) common.Must(err) x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0]) common.Must(err) if !x509Cert.NotAfter.After(time.Now()) { t.Error("NotAfter: ", x509Cert.NotAfter) } } func TestExpiredCertificate(t *testing.T) { caCert := cert.MustGenerate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageCertSign)) expiredCert := cert.MustGenerate(caCert, cert.NotAfter(time.Now().Add(time.Minute*-2)), cert.CommonName("www.v2fly.org"), cert.DNSNames("www.v2fly.org")) certificate := ParseCertificate(caCert) certificate.Usage = Certificate_AUTHORITY_ISSUE certificate2 := ParseCertificate(expiredCert) c := &Config{ Certificate: []*Certificate{ certificate, certificate2, }, } xtlsConfig := c.GetXTLSConfig() v2rayCert, err := xtlsConfig.GetCertificate(&xtls.ClientHelloInfo{ ServerName: "www.v2fly.org", }) common.Must(err) x509Cert, err := x509.ParseCertificate(v2rayCert.Certificate[0]) common.Must(err) if !x509Cert.NotAfter.After(time.Now()) { t.Error("NotAfter: ", x509Cert.NotAfter) } } func TestInsecureCertificates(t *testing.T) { c := &Config{ AllowInsecureCiphers: true, } xtlsConfig := c.GetXTLSConfig() if len(xtlsConfig.CipherSuites) > 0 { t.Fatal("Unexpected tls cipher suites list: ", xtlsConfig.CipherSuites) } } func BenchmarkCertificateIssuing(b *testing.B) { certificate := ParseCertificate(cert.MustGenerate(nil, cert.Authority(true), cert.KeyUsage(x509.KeyUsageCertSign))) certificate.Usage = Certificate_AUTHORITY_ISSUE c := &Config{ Certificate: []*Certificate{ certificate, }, } xtlsConfig := c.GetXTLSConfig() lenCerts := len(xtlsConfig.Certificates) b.ResetTimer() for i := 0; i < b.N; i++ { _, _ = xtlsConfig.GetCertificate(&xtls.ClientHelloInfo{ ServerName: "www.v2fly.org", }) delete(xtlsConfig.NameToCertificate, "www.v2fly.org") xtlsConfig.Certificates = xtlsConfig.Certificates[:lenCerts] } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/xtls/config.pb.go
transport/internet/xtls/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/xtls/config.proto package xtls import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Certificate_Usage int32 const ( Certificate_ENCIPHERMENT Certificate_Usage = 0 Certificate_AUTHORITY_VERIFY Certificate_Usage = 1 Certificate_AUTHORITY_ISSUE Certificate_Usage = 2 ) // Enum value maps for Certificate_Usage. var ( Certificate_Usage_name = map[int32]string{ 0: "ENCIPHERMENT", 1: "AUTHORITY_VERIFY", 2: "AUTHORITY_ISSUE", } Certificate_Usage_value = map[string]int32{ "ENCIPHERMENT": 0, "AUTHORITY_VERIFY": 1, "AUTHORITY_ISSUE": 2, } ) func (x Certificate_Usage) Enum() *Certificate_Usage { p := new(Certificate_Usage) *p = x return p } func (x Certificate_Usage) String() string { return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) } func (Certificate_Usage) Descriptor() protoreflect.EnumDescriptor { return file_transport_internet_xtls_config_proto_enumTypes[0].Descriptor() } func (Certificate_Usage) Type() protoreflect.EnumType { return &file_transport_internet_xtls_config_proto_enumTypes[0] } func (x Certificate_Usage) Number() protoreflect.EnumNumber { return protoreflect.EnumNumber(x) } // Deprecated: Use Certificate_Usage.Descriptor instead. func (Certificate_Usage) EnumDescriptor() ([]byte, []int) { return file_transport_internet_xtls_config_proto_rawDescGZIP(), []int{0, 0} } type Certificate struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // XTLS certificate in x509 format. Certificate []byte `protobuf:"bytes,1,opt,name=Certificate,proto3" json:"Certificate,omitempty"` // XTLS key in x509 format. Key []byte `protobuf:"bytes,2,opt,name=Key,proto3" json:"Key,omitempty"` Usage Certificate_Usage `protobuf:"varint,3,opt,name=usage,proto3,enum=v2ray.core.transport.internet.xtls.Certificate_Usage" json:"usage,omitempty"` } func (x *Certificate) Reset() { *x = Certificate{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_xtls_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Certificate) String() string { return protoimpl.X.MessageStringOf(x) } func (*Certificate) ProtoMessage() {} func (x *Certificate) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_xtls_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Certificate.ProtoReflect.Descriptor instead. func (*Certificate) Descriptor() ([]byte, []int) { return file_transport_internet_xtls_config_proto_rawDescGZIP(), []int{0} } func (x *Certificate) GetCertificate() []byte { if x != nil { return x.Certificate } return nil } func (x *Certificate) GetKey() []byte { if x != nil { return x.Key } return nil } func (x *Certificate) GetUsage() Certificate_Usage { if x != nil { return x.Usage } return Certificate_ENCIPHERMENT } type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Whether or not to allow self-signed certificates. AllowInsecure bool `protobuf:"varint,1,opt,name=allow_insecure,json=allowInsecure,proto3" json:"allow_insecure,omitempty"` // Whether or not to allow insecure cipher suites. AllowInsecureCiphers bool `protobuf:"varint,5,opt,name=allow_insecure_ciphers,json=allowInsecureCiphers,proto3" json:"allow_insecure_ciphers,omitempty"` // List of certificates to be served on server. Certificate []*Certificate `protobuf:"bytes,2,rep,name=certificate,proto3" json:"certificate,omitempty"` // Override server name. ServerName string `protobuf:"bytes,3,opt,name=server_name,json=serverName,proto3" json:"server_name,omitempty"` // Lists of string as ALPN values. NextProtocol []string `protobuf:"bytes,4,rep,name=next_protocol,json=nextProtocol,proto3" json:"next_protocol,omitempty"` // Whether or not to disable session (ticket) resumption. DisableSessionResumption bool `protobuf:"varint,6,opt,name=disable_session_resumption,json=disableSessionResumption,proto3" json:"disable_session_resumption,omitempty"` // If true, root certificates on the system will not be loaded for // verification. DisableSystemRoot bool `protobuf:"varint,7,opt,name=disable_system_root,json=disableSystemRoot,proto3" json:"disable_system_root,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_xtls_config_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_xtls_config_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_xtls_config_proto_rawDescGZIP(), []int{1} } func (x *Config) GetAllowInsecure() bool { if x != nil { return x.AllowInsecure } return false } func (x *Config) GetAllowInsecureCiphers() bool { if x != nil { return x.AllowInsecureCiphers } return false } func (x *Config) GetCertificate() []*Certificate { if x != nil { return x.Certificate } return nil } func (x *Config) GetServerName() string { if x != nil { return x.ServerName } return "" } func (x *Config) GetNextProtocol() []string { if x != nil { return x.NextProtocol } return nil } func (x *Config) GetDisableSessionResumption() bool { if x != nil { return x.DisableSessionResumption } return false } func (x *Config) GetDisableSystemRoot() bool { if x != nil { return x.DisableSystemRoot } return false } var File_transport_internet_xtls_config_proto protoreflect.FileDescriptor var file_transport_internet_xtls_config_proto_rawDesc = []byte{ 0x0a, 0x24, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x22, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x78, 0x74, 0x6c, 0x73, 0x22, 0xd4, 0x01, 0x0a, 0x0b, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x4b, 0x65, 0x79, 0x12, 0x4b, 0x0a, 0x05, 0x75, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x35, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x78, 0x74, 0x6c, 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x2e, 0x55, 0x73, 0x61, 0x67, 0x65, 0x52, 0x05, 0x75, 0x73, 0x61, 0x67, 0x65, 0x22, 0x44, 0x0a, 0x05, 0x55, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x45, 0x4e, 0x43, 0x49, 0x50, 0x48, 0x45, 0x52, 0x4d, 0x45, 0x4e, 0x54, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x41, 0x55, 0x54, 0x48, 0x4f, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x56, 0x45, 0x52, 0x49, 0x46, 0x59, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x41, 0x55, 0x54, 0x48, 0x4f, 0x52, 0x49, 0x54, 0x59, 0x5f, 0x49, 0x53, 0x53, 0x55, 0x45, 0x10, 0x02, 0x22, 0xec, 0x02, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x49, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x12, 0x34, 0x0a, 0x16, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x5f, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x14, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x49, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x43, 0x69, 0x70, 0x68, 0x65, 0x72, 0x73, 0x12, 0x51, 0x0a, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2f, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x78, 0x74, 0x6c, 0x73, 0x2e, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x52, 0x0b, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x6e, 0x65, 0x78, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x3c, 0x0a, 0x1a, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x65, 0x73, 0x75, 0x6d, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x18, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6d, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2e, 0x0a, 0x13, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x52, 0x6f, 0x6f, 0x74, 0x42, 0x77, 0x0a, 0x26, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x78, 0x74, 0x6c, 0x73, 0x50, 0x01, 0x5a, 0x26, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0xaa, 0x02, 0x22, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x58, 0x74, 0x6c, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_xtls_config_proto_rawDescOnce sync.Once file_transport_internet_xtls_config_proto_rawDescData = file_transport_internet_xtls_config_proto_rawDesc ) func file_transport_internet_xtls_config_proto_rawDescGZIP() []byte { file_transport_internet_xtls_config_proto_rawDescOnce.Do(func() { file_transport_internet_xtls_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_xtls_config_proto_rawDescData) }) return file_transport_internet_xtls_config_proto_rawDescData } var file_transport_internet_xtls_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_transport_internet_xtls_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_transport_internet_xtls_config_proto_goTypes = []interface{}{ (Certificate_Usage)(0), // 0: v2ray.core.transport.internet.xtls.Certificate.Usage (*Certificate)(nil), // 1: v2ray.core.transport.internet.xtls.Certificate (*Config)(nil), // 2: v2ray.core.transport.internet.xtls.Config } var file_transport_internet_xtls_config_proto_depIdxs = []int32{ 0, // 0: v2ray.core.transport.internet.xtls.Certificate.usage:type_name -> v2ray.core.transport.internet.xtls.Certificate.Usage 1, // 1: v2ray.core.transport.internet.xtls.Config.certificate:type_name -> v2ray.core.transport.internet.xtls.Certificate 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name } func init() { file_transport_internet_xtls_config_proto_init() } func file_transport_internet_xtls_config_proto_init() { if File_transport_internet_xtls_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_xtls_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Certificate); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_xtls_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_xtls_config_proto_rawDesc, NumEnums: 1, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_xtls_config_proto_goTypes, DependencyIndexes: file_transport_internet_xtls_config_proto_depIdxs, EnumInfos: file_transport_internet_xtls_config_proto_enumTypes, MessageInfos: file_transport_internet_xtls_config_proto_msgTypes, }.Build() File_transport_internet_xtls_config_proto = out.File file_transport_internet_xtls_config_proto_rawDesc = nil file_transport_internet_xtls_config_proto_goTypes = nil file_transport_internet_xtls_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/tls/dtls_test.go
transport/internet/headers/tls/dtls_test.go
package tls_test import ( "context" "testing" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/transport/internet/headers/tls" ) func TestDTLSWrite(t *testing.T) { content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} dtlsRaw, err := New(context.Background(), &PacketConfig{}) common.Must(err) dtls := dtlsRaw.(*DTLS) payload := buf.New() dtls.Serialize(payload.Extend(dtls.Size())) payload.Write(content) if payload.Len() != int32(len(content))+dtls.Size() { t.Error("payload len: ", payload.Len(), " want ", int32(len(content))+dtls.Size()) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/tls/config.pb.go
transport/internet/headers/tls/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/headers/tls/config.proto package tls import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type PacketConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } func (x *PacketConfig) Reset() { *x = PacketConfig{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_tls_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *PacketConfig) String() string { return protoimpl.X.MessageStringOf(x) } func (*PacketConfig) ProtoMessage() {} func (x *PacketConfig) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_tls_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use PacketConfig.ProtoReflect.Descriptor instead. func (*PacketConfig) Descriptor() ([]byte, []int) { return file_transport_internet_headers_tls_config_proto_rawDescGZIP(), []int{0} } var File_transport_internet_headers_tls_config_proto protoreflect.FileDescriptor var file_transport_internet_headers_tls_config_proto_rawDesc = []byte{ 0x0a, 0x2b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x74, 0x6c, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x29, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x74, 0x6c, 0x73, 0x22, 0x0e, 0x0a, 0x0c, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x8c, 0x01, 0x0a, 0x2d, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x74, 0x6c, 0x73, 0x50, 0x01, 0x5a, 0x2d, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x74, 0x6c, 0x73, 0xaa, 0x02, 0x29, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x54, 0x6c, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_headers_tls_config_proto_rawDescOnce sync.Once file_transport_internet_headers_tls_config_proto_rawDescData = file_transport_internet_headers_tls_config_proto_rawDesc ) func file_transport_internet_headers_tls_config_proto_rawDescGZIP() []byte { file_transport_internet_headers_tls_config_proto_rawDescOnce.Do(func() { file_transport_internet_headers_tls_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_tls_config_proto_rawDescData) }) return file_transport_internet_headers_tls_config_proto_rawDescData } var file_transport_internet_headers_tls_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_headers_tls_config_proto_goTypes = []interface{}{ (*PacketConfig)(nil), // 0: v2ray.core.transport.internet.headers.tls.PacketConfig } var file_transport_internet_headers_tls_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_headers_tls_config_proto_init() } func file_transport_internet_headers_tls_config_proto_init() { if File_transport_internet_headers_tls_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_headers_tls_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PacketConfig); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_headers_tls_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_headers_tls_config_proto_goTypes, DependencyIndexes: file_transport_internet_headers_tls_config_proto_depIdxs, MessageInfos: file_transport_internet_headers_tls_config_proto_msgTypes, }.Build() File_transport_internet_headers_tls_config_proto = out.File file_transport_internet_headers_tls_config_proto_rawDesc = nil file_transport_internet_headers_tls_config_proto_goTypes = nil file_transport_internet_headers_tls_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/tls/dtls.go
transport/internet/headers/tls/dtls.go
package tls import ( "context" "v2ray.com/core/common" "v2ray.com/core/common/dice" ) // DTLS writes header as DTLS. See https://tools.ietf.org/html/rfc6347 type DTLS struct { epoch uint16 length uint16 sequence uint32 } // Size implements PacketHeader. func (*DTLS) Size() int32 { return 1 + 2 + 2 + 6 + 2 } // Serialize implements PacketHeader. func (d *DTLS) Serialize(b []byte) { b[0] = 23 // application data b[1] = 254 b[2] = 253 b[3] = byte(d.epoch >> 8) b[4] = byte(d.epoch) b[5] = 0 b[6] = 0 b[7] = byte(d.sequence >> 24) b[8] = byte(d.sequence >> 16) b[9] = byte(d.sequence >> 8) b[10] = byte(d.sequence) d.sequence++ b[11] = byte(d.length >> 8) b[12] = byte(d.length) d.length += 17 if d.length > 100 { d.length -= 50 } } // New creates a new UTP header for the given config. func New(ctx context.Context, config interface{}) (interface{}, error) { return &DTLS{ epoch: dice.RollUint16(), sequence: 0, length: 17, }, nil } func init() { common.Must(common.RegisterConfig((*PacketConfig)(nil), New)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/noop/noop.go
transport/internet/headers/noop/noop.go
package noop import ( "context" "net" "v2ray.com/core/common" ) type NoOpHeader struct{} func (NoOpHeader) Size() int32 { return 0 } // Serialize implements PacketHeader. func (NoOpHeader) Serialize([]byte) {} func NewNoOpHeader(context.Context, interface{}) (interface{}, error) { return NoOpHeader{}, nil } type NoOpConnectionHeader struct{} func (NoOpConnectionHeader) Client(conn net.Conn) net.Conn { return conn } func (NoOpConnectionHeader) Server(conn net.Conn) net.Conn { return conn } func NewNoOpConnectionHeader(context.Context, interface{}) (interface{}, error) { return NoOpConnectionHeader{}, nil } func init() { common.Must(common.RegisterConfig((*Config)(nil), NewNoOpHeader)) common.Must(common.RegisterConfig((*ConnectionConfig)(nil), NewNoOpConnectionHeader)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/noop/config.pb.go
transport/internet/headers/noop/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/headers/noop/config.proto package noop import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_noop_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_noop_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_headers_noop_config_proto_rawDescGZIP(), []int{0} } type ConnectionConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } func (x *ConnectionConfig) Reset() { *x = ConnectionConfig{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_noop_config_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *ConnectionConfig) String() string { return protoimpl.X.MessageStringOf(x) } func (*ConnectionConfig) ProtoMessage() {} func (x *ConnectionConfig) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_noop_config_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use ConnectionConfig.ProtoReflect.Descriptor instead. func (*ConnectionConfig) Descriptor() ([]byte, []int) { return file_transport_internet_headers_noop_config_proto_rawDescGZIP(), []int{1} } var File_transport_internet_headers_noop_config_proto protoreflect.FileDescriptor var file_transport_internet_headers_noop_config_proto_rawDesc = []byte{ 0x0a, 0x2c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x6e, 0x6f, 0x6f, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2a, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x6e, 0x6f, 0x6f, 0x70, 0x22, 0x08, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0x12, 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x8f, 0x01, 0x0a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x6e, 0x6f, 0x6f, 0x70, 0x50, 0x01, 0x5a, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x6e, 0x6f, 0x6f, 0x70, 0xaa, 0x02, 0x2a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x4e, 0x6f, 0x6f, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_headers_noop_config_proto_rawDescOnce sync.Once file_transport_internet_headers_noop_config_proto_rawDescData = file_transport_internet_headers_noop_config_proto_rawDesc ) func file_transport_internet_headers_noop_config_proto_rawDescGZIP() []byte { file_transport_internet_headers_noop_config_proto_rawDescOnce.Do(func() { file_transport_internet_headers_noop_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_noop_config_proto_rawDescData) }) return file_transport_internet_headers_noop_config_proto_rawDescData } var file_transport_internet_headers_noop_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_transport_internet_headers_noop_config_proto_goTypes = []interface{}{ (*Config)(nil), // 0: v2ray.core.transport.internet.headers.noop.Config (*ConnectionConfig)(nil), // 1: v2ray.core.transport.internet.headers.noop.ConnectionConfig } var file_transport_internet_headers_noop_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_headers_noop_config_proto_init() } func file_transport_internet_headers_noop_config_proto_init() { if File_transport_internet_headers_noop_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_headers_noop_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_headers_noop_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ConnectionConfig); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_headers_noop_config_proto_rawDesc, NumEnums: 0, NumMessages: 2, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_headers_noop_config_proto_goTypes, DependencyIndexes: file_transport_internet_headers_noop_config_proto_depIdxs, MessageInfos: file_transport_internet_headers_noop_config_proto_msgTypes, }.Build() File_transport_internet_headers_noop_config_proto = out.File file_transport_internet_headers_noop_config_proto_rawDesc = nil file_transport_internet_headers_noop_config_proto_goTypes = nil file_transport_internet_headers_noop_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/wechat/wechat_test.go
transport/internet/headers/wechat/wechat_test.go
package wechat_test import ( "context" "testing" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/transport/internet/headers/wechat" ) func TestUTPWrite(t *testing.T) { videoRaw, err := NewVideoChat(context.Background(), &VideoConfig{}) common.Must(err) video := videoRaw.(*VideoChat) payload := buf.New() video.Serialize(payload.Extend(video.Size())) if payload.Len() != video.Size() { t.Error("expected payload size ", video.Size(), " but got ", payload.Len()) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/wechat/wechat.go
transport/internet/headers/wechat/wechat.go
package wechat import ( "context" "encoding/binary" "v2ray.com/core/common" "v2ray.com/core/common/dice" ) type VideoChat struct { sn uint32 } func (vc *VideoChat) Size() int32 { return 13 } // Serialize implements PacketHeader. func (vc *VideoChat) Serialize(b []byte) { vc.sn++ b[0] = 0xa1 b[1] = 0x08 binary.BigEndian.PutUint32(b[2:], vc.sn) // b[2:6] b[6] = 0x00 b[7] = 0x10 b[8] = 0x11 b[9] = 0x18 b[10] = 0x30 b[11] = 0x22 b[12] = 0x30 } // NewVideoChat returns a new VideoChat instance based on given config. func NewVideoChat(ctx context.Context, config interface{}) (interface{}, error) { return &VideoChat{ sn: uint32(dice.RollUint16()), }, nil } func init() { common.Must(common.RegisterConfig((*VideoConfig)(nil), NewVideoChat)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/wechat/config.pb.go
transport/internet/headers/wechat/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/headers/wechat/config.proto package wechat import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type VideoConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } func (x *VideoConfig) Reset() { *x = VideoConfig{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_wechat_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *VideoConfig) String() string { return protoimpl.X.MessageStringOf(x) } func (*VideoConfig) ProtoMessage() {} func (x *VideoConfig) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_wechat_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use VideoConfig.ProtoReflect.Descriptor instead. func (*VideoConfig) Descriptor() ([]byte, []int) { return file_transport_internet_headers_wechat_config_proto_rawDescGZIP(), []int{0} } var File_transport_internet_headers_wechat_config_proto protoreflect.FileDescriptor var file_transport_internet_headers_wechat_config_proto_rawDesc = []byte{ 0x0a, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x77, 0x65, 0x63, 0x68, 0x61, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2c, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x77, 0x65, 0x63, 0x68, 0x61, 0x74, 0x22, 0x0d, 0x0a, 0x0b, 0x56, 0x69, 0x64, 0x65, 0x6f, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x95, 0x01, 0x0a, 0x30, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x77, 0x65, 0x63, 0x68, 0x61, 0x74, 0x50, 0x01, 0x5a, 0x30, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x77, 0x65, 0x63, 0x68, 0x61, 0x74, 0xaa, 0x02, 0x2c, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x57, 0x65, 0x63, 0x68, 0x61, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_headers_wechat_config_proto_rawDescOnce sync.Once file_transport_internet_headers_wechat_config_proto_rawDescData = file_transport_internet_headers_wechat_config_proto_rawDesc ) func file_transport_internet_headers_wechat_config_proto_rawDescGZIP() []byte { file_transport_internet_headers_wechat_config_proto_rawDescOnce.Do(func() { file_transport_internet_headers_wechat_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_wechat_config_proto_rawDescData) }) return file_transport_internet_headers_wechat_config_proto_rawDescData } var file_transport_internet_headers_wechat_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_headers_wechat_config_proto_goTypes = []interface{}{ (*VideoConfig)(nil), // 0: v2ray.core.transport.internet.headers.wechat.VideoConfig } var file_transport_internet_headers_wechat_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_headers_wechat_config_proto_init() } func file_transport_internet_headers_wechat_config_proto_init() { if File_transport_internet_headers_wechat_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_headers_wechat_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*VideoConfig); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_headers_wechat_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_headers_wechat_config_proto_goTypes, DependencyIndexes: file_transport_internet_headers_wechat_config_proto_depIdxs, MessageInfos: file_transport_internet_headers_wechat_config_proto_msgTypes, }.Build() File_transport_internet_headers_wechat_config_proto = out.File file_transport_internet_headers_wechat_config_proto_rawDesc = nil file_transport_internet_headers_wechat_config_proto_goTypes = nil file_transport_internet_headers_wechat_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/wireguard/wireguard.go
transport/internet/headers/wireguard/wireguard.go
package wireguard import ( "context" "v2ray.com/core/common" ) type Wireguard struct{} func (Wireguard) Size() int32 { return 4 } // Serialize implements PacketHeader. func (Wireguard) Serialize(b []byte) { b[0] = 0x04 b[1] = 0x00 b[2] = 0x00 b[3] = 0x00 } // NewWireguard returns a new VideoChat instance based on given config. func NewWireguard(ctx context.Context, config interface{}) (interface{}, error) { return Wireguard{}, nil } func init() { common.Must(common.RegisterConfig((*WireguardConfig)(nil), NewWireguard)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/wireguard/config.pb.go
transport/internet/headers/wireguard/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/headers/wireguard/config.proto package wireguard import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type WireguardConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields } func (x *WireguardConfig) Reset() { *x = WireguardConfig{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_wireguard_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *WireguardConfig) String() string { return protoimpl.X.MessageStringOf(x) } func (*WireguardConfig) ProtoMessage() {} func (x *WireguardConfig) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_wireguard_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use WireguardConfig.ProtoReflect.Descriptor instead. func (*WireguardConfig) Descriptor() ([]byte, []int) { return file_transport_internet_headers_wireguard_config_proto_rawDescGZIP(), []int{0} } var File_transport_internet_headers_wireguard_config_proto protoreflect.FileDescriptor var file_transport_internet_headers_wireguard_config_proto_rawDesc = []byte{ 0x0a, 0x31, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x77, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x77, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x22, 0x11, 0x0a, 0x0f, 0x57, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x42, 0x9e, 0x01, 0x0a, 0x33, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x77, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x50, 0x01, 0x5a, 0x33, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x77, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0xaa, 0x02, 0x2f, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x57, 0x69, 0x72, 0x65, 0x67, 0x75, 0x61, 0x72, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_headers_wireguard_config_proto_rawDescOnce sync.Once file_transport_internet_headers_wireguard_config_proto_rawDescData = file_transport_internet_headers_wireguard_config_proto_rawDesc ) func file_transport_internet_headers_wireguard_config_proto_rawDescGZIP() []byte { file_transport_internet_headers_wireguard_config_proto_rawDescOnce.Do(func() { file_transport_internet_headers_wireguard_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_wireguard_config_proto_rawDescData) }) return file_transport_internet_headers_wireguard_config_proto_rawDescData } var file_transport_internet_headers_wireguard_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_headers_wireguard_config_proto_goTypes = []interface{}{ (*WireguardConfig)(nil), // 0: v2ray.core.transport.internet.headers.wireguard.WireguardConfig } var file_transport_internet_headers_wireguard_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_headers_wireguard_config_proto_init() } func file_transport_internet_headers_wireguard_config_proto_init() { if File_transport_internet_headers_wireguard_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_headers_wireguard_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*WireguardConfig); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_headers_wireguard_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_headers_wireguard_config_proto_goTypes, DependencyIndexes: file_transport_internet_headers_wireguard_config_proto_depIdxs, MessageInfos: file_transport_internet_headers_wireguard_config_proto_msgTypes, }.Build() File_transport_internet_headers_wireguard_config_proto = out.File file_transport_internet_headers_wireguard_config_proto_rawDesc = nil file_transport_internet_headers_wireguard_config_proto_goTypes = nil file_transport_internet_headers_wireguard_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/utp/utp_test.go
transport/internet/headers/utp/utp_test.go
package utp_test import ( "context" "testing" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/transport/internet/headers/utp" ) func TestUTPWrite(t *testing.T) { content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} utpRaw, err := New(context.Background(), &Config{}) common.Must(err) utp := utpRaw.(*UTP) payload := buf.New() utp.Serialize(payload.Extend(utp.Size())) payload.Write(content) if payload.Len() != int32(len(content))+utp.Size() { t.Error("unexpected payload length: ", payload.Len()) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/utp/utp.go
transport/internet/headers/utp/utp.go
package utp import ( "context" "encoding/binary" "v2ray.com/core/common" "v2ray.com/core/common/dice" ) type UTP struct { header byte extension byte connectionId uint16 } func (*UTP) Size() int32 { return 4 } // Serialize implements PacketHeader. func (u *UTP) Serialize(b []byte) { binary.BigEndian.PutUint16(b, u.connectionId) b[2] = u.header b[3] = u.extension } // New creates a new UTP header for the given config. func New(ctx context.Context, config interface{}) (interface{}, error) { return &UTP{ header: 1, extension: 0, connectionId: dice.RollUint16(), }, nil } func init() { common.Must(common.RegisterConfig((*Config)(nil), New)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/utp/config.pb.go
transport/internet/headers/utp/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/headers/utp/config.proto package utp import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Version uint32 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_utp_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_utp_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_headers_utp_config_proto_rawDescGZIP(), []int{0} } func (x *Config) GetVersion() uint32 { if x != nil { return x.Version } return 0 } var File_transport_internet_headers_utp_config_proto protoreflect.FileDescriptor var file_transport_internet_headers_utp_config_proto_rawDesc = []byte{ 0x0a, 0x2b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x75, 0x74, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x29, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x75, 0x74, 0x70, 0x22, 0x22, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x8c, 0x01, 0x0a, 0x2d, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x75, 0x74, 0x70, 0x50, 0x01, 0x5a, 0x2d, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x75, 0x74, 0x70, 0xaa, 0x02, 0x29, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x55, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_headers_utp_config_proto_rawDescOnce sync.Once file_transport_internet_headers_utp_config_proto_rawDescData = file_transport_internet_headers_utp_config_proto_rawDesc ) func file_transport_internet_headers_utp_config_proto_rawDescGZIP() []byte { file_transport_internet_headers_utp_config_proto_rawDescOnce.Do(func() { file_transport_internet_headers_utp_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_utp_config_proto_rawDescData) }) return file_transport_internet_headers_utp_config_proto_rawDescData } var file_transport_internet_headers_utp_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_headers_utp_config_proto_goTypes = []interface{}{ (*Config)(nil), // 0: v2ray.core.transport.internet.headers.utp.Config } var file_transport_internet_headers_utp_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_headers_utp_config_proto_init() } func file_transport_internet_headers_utp_config_proto_init() { if File_transport_internet_headers_utp_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_headers_utp_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_headers_utp_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_headers_utp_config_proto_goTypes, DependencyIndexes: file_transport_internet_headers_utp_config_proto_depIdxs, MessageInfos: file_transport_internet_headers_utp_config_proto_msgTypes, }.Build() File_transport_internet_headers_utp_config_proto = out.File file_transport_internet_headers_utp_config_proto_rawDesc = nil file_transport_internet_headers_utp_config_proto_goTypes = nil file_transport_internet_headers_utp_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/srtp/srtp_test.go
transport/internet/headers/srtp/srtp_test.go
package srtp_test import ( "context" "testing" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/transport/internet/headers/srtp" ) func TestSRTPWrite(t *testing.T) { content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} srtpRaw, err := New(context.Background(), &Config{}) common.Must(err) srtp := srtpRaw.(*SRTP) payload := buf.New() srtp.Serialize(payload.Extend(srtp.Size())) payload.Write(content) expectedLen := int32(len(content)) + srtp.Size() if payload.Len() != expectedLen { t.Error("expected ", expectedLen, " of bytes, but got ", payload.Len()) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/srtp/srtp.go
transport/internet/headers/srtp/srtp.go
package srtp import ( "context" "encoding/binary" "v2ray.com/core/common" "v2ray.com/core/common/dice" ) type SRTP struct { header uint16 number uint16 } func (*SRTP) Size() int32 { return 4 } // Serialize implements PacketHeader. func (s *SRTP) Serialize(b []byte) { s.number++ binary.BigEndian.PutUint16(b, s.header) binary.BigEndian.PutUint16(b[2:], s.number) } // New returns a new SRTP instance based on the given config. func New(ctx context.Context, config interface{}) (interface{}, error) { return &SRTP{ header: 0xB5E8, number: dice.RollUint16(), }, nil } func init() { common.Must(common.RegisterConfig((*Config)(nil), New)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/srtp/config.pb.go
transport/internet/headers/srtp/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/headers/srtp/config.proto package srtp import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Version uint32 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` Padding bool `protobuf:"varint,2,opt,name=padding,proto3" json:"padding,omitempty"` Extension bool `protobuf:"varint,3,opt,name=extension,proto3" json:"extension,omitempty"` CsrcCount uint32 `protobuf:"varint,4,opt,name=csrc_count,json=csrcCount,proto3" json:"csrc_count,omitempty"` Marker bool `protobuf:"varint,5,opt,name=marker,proto3" json:"marker,omitempty"` PayloadType uint32 `protobuf:"varint,6,opt,name=payload_type,json=payloadType,proto3" json:"payload_type,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_srtp_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_srtp_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_headers_srtp_config_proto_rawDescGZIP(), []int{0} } func (x *Config) GetVersion() uint32 { if x != nil { return x.Version } return 0 } func (x *Config) GetPadding() bool { if x != nil { return x.Padding } return false } func (x *Config) GetExtension() bool { if x != nil { return x.Extension } return false } func (x *Config) GetCsrcCount() uint32 { if x != nil { return x.CsrcCount } return 0 } func (x *Config) GetMarker() bool { if x != nil { return x.Marker } return false } func (x *Config) GetPayloadType() uint32 { if x != nil { return x.PayloadType } return 0 } var File_transport_internet_headers_srtp_config_proto protoreflect.FileDescriptor var file_transport_internet_headers_srtp_config_proto_rawDesc = []byte{ 0x0a, 0x2c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x73, 0x72, 0x74, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2a, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x73, 0x72, 0x74, 0x70, 0x22, 0xb4, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x73, 0x72, 0x63, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x63, 0x73, 0x72, 0x63, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6d, 0x61, 0x72, 0x6b, 0x65, 0x72, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0b, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x54, 0x79, 0x70, 0x65, 0x42, 0x8f, 0x01, 0x0a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x73, 0x72, 0x74, 0x70, 0x50, 0x01, 0x5a, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x73, 0x72, 0x74, 0x70, 0xaa, 0x02, 0x2a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x53, 0x72, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_headers_srtp_config_proto_rawDescOnce sync.Once file_transport_internet_headers_srtp_config_proto_rawDescData = file_transport_internet_headers_srtp_config_proto_rawDesc ) func file_transport_internet_headers_srtp_config_proto_rawDescGZIP() []byte { file_transport_internet_headers_srtp_config_proto_rawDescOnce.Do(func() { file_transport_internet_headers_srtp_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_srtp_config_proto_rawDescData) }) return file_transport_internet_headers_srtp_config_proto_rawDescData } var file_transport_internet_headers_srtp_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_headers_srtp_config_proto_goTypes = []interface{}{ (*Config)(nil), // 0: v2ray.core.transport.internet.headers.srtp.Config } var file_transport_internet_headers_srtp_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_headers_srtp_config_proto_init() } func file_transport_internet_headers_srtp_config_proto_init() { if File_transport_internet_headers_srtp_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_headers_srtp_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_headers_srtp_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_headers_srtp_config_proto_goTypes, DependencyIndexes: file_transport_internet_headers_srtp_config_proto_depIdxs, MessageInfos: file_transport_internet_headers_srtp_config_proto_msgTypes, }.Build() File_transport_internet_headers_srtp_config_proto = out.File file_transport_internet_headers_srtp_config_proto_rawDesc = nil file_transport_internet_headers_srtp_config_proto_goTypes = nil file_transport_internet_headers_srtp_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/http/errors.generated.go
transport/internet/headers/http/errors.generated.go
package http import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/http/config.go
transport/internet/headers/http/config.go
package http import ( "strings" "v2ray.com/core/common/dice" ) func pickString(arr []string) string { n := len(arr) switch n { case 0: return "" case 1: return arr[0] default: return arr[dice.Roll(n)] } } func (v *RequestConfig) PickUri() string { return pickString(v.Uri) } func (v *RequestConfig) PickHeaders() []string { n := len(v.Header) if n == 0 { return nil } headers := make([]string, n) for idx, headerConfig := range v.Header { headerName := headerConfig.Name headerValue := pickString(headerConfig.Value) headers[idx] = headerName + ": " + headerValue } return headers } func (v *RequestConfig) GetVersionValue() string { if v == nil || v.Version == nil { return "1.1" } return v.Version.Value } func (v *RequestConfig) GetMethodValue() string { if v == nil || v.Method == nil { return "GET" } return v.Method.Value } func (v *RequestConfig) GetFullVersion() string { return "HTTP/" + v.GetVersionValue() } func (v *ResponseConfig) HasHeader(header string) bool { cHeader := strings.ToLower(header) for _, tHeader := range v.Header { if strings.EqualFold(tHeader.Name, cHeader) { return true } } return false } func (v *ResponseConfig) PickHeaders() []string { n := len(v.Header) if n == 0 { return nil } headers := make([]string, n) for idx, headerConfig := range v.Header { headerName := headerConfig.Name headerValue := pickString(headerConfig.Value) headers[idx] = headerName + ": " + headerValue } return headers } func (v *ResponseConfig) GetVersionValue() string { if v == nil || v.Version == nil { return "1.1" } return v.Version.Value } func (v *ResponseConfig) GetFullVersion() string { return "HTTP/" + v.GetVersionValue() } func (v *ResponseConfig) GetStatusValue() *Status { if v == nil || v.Status == nil { return &Status{ Code: "200", Reason: "OK", } } return v.Status }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/http/linkedreadRequest.go
transport/internet/headers/http/linkedreadRequest.go
package http import ( "bufio" "net/http" _ "unsafe" // required to use //go:linkname ) //go:linkname readRequest net/http.readRequest func readRequest(b *bufio.Reader, deleteHostHeader bool) (req *http.Request, err error)
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/http/http_test.go
transport/internet/headers/http/http_test.go
package http_test import ( "bufio" "bytes" "context" "crypto/rand" "strings" "testing" "time" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" . "v2ray.com/core/transport/internet/headers/http" ) func TestReaderWriter(t *testing.T) { cache := buf.New() b := buf.New() common.Must2(b.WriteString("abcd" + ENDING)) writer := NewHeaderWriter(b) err := writer.Write(cache) common.Must(err) if v := cache.Len(); v != 8 { t.Error("cache len: ", v) } _, err = cache.Write([]byte{'e', 'f', 'g'}) common.Must(err) reader := &HeaderReader{} buffer, err := reader.Read(cache) if err != nil && !strings.HasPrefix(err.Error(), "malformed HTTP request") { t.Error("unknown error ", err) } _ = buffer /* if buffer.String() != "efg" { t.Error("buffer: ", buffer.String()) }*/ } func TestRequestHeader(t *testing.T) { auth, err := NewHttpAuthenticator(context.Background(), &Config{ Request: &RequestConfig{ Uri: []string{"/"}, Header: []*Header{ { Name: "Test", Value: []string{"Value"}, }, }, }, }) common.Must(err) cache := buf.New() err = auth.GetClientWriter().Write(cache) common.Must(err) if cache.String() != "GET / HTTP/1.1\r\nTest: Value\r\n\r\n" { t.Error("cache: ", cache.String()) } } func TestLongRequestHeader(t *testing.T) { payload := make([]byte, buf.Size+2) common.Must2(rand.Read(payload[:buf.Size-2])) copy(payload[buf.Size-2:], []byte(ENDING)) payload = append(payload, []byte("abcd")...) reader := HeaderReader{} b, err := reader.Read(bytes.NewReader(payload)) if err != nil && !(strings.HasPrefix(err.Error(), "invalid") || strings.HasPrefix(err.Error(), "malformed")) { t.Error("unknown error ", err) } _ = b /* common.Must(err) if b.String() != "abcd" { t.Error("expect content abcd, but actually ", b.String()) }*/ } func TestConnection(t *testing.T) { auth, err := NewHttpAuthenticator(context.Background(), &Config{ Request: &RequestConfig{ Method: &Method{Value: "Post"}, Uri: []string{"/testpath"}, Header: []*Header{ { Name: "Host", Value: []string{"www.v2ray.com", "www.google.com"}, }, { Name: "User-Agent", Value: []string{"Test-Agent"}, }, }, }, Response: &ResponseConfig{ Version: &Version{ Value: "1.1", }, Status: &Status{ Code: "404", Reason: "Not Found", }, }, }) common.Must(err) listener, err := net.Listen("tcp", "127.0.0.1:0") common.Must(err) go func() { conn, err := listener.Accept() common.Must(err) authConn := auth.Server(conn) b := make([]byte, 256) for { n, err := authConn.Read(b) if err != nil { break } _, err = authConn.Write(b[:n]) common.Must(err) } }() conn, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr)) common.Must(err) authConn := auth.Client(conn) defer authConn.Close() authConn.Write([]byte("Test payload")) authConn.Write([]byte("Test payload 2")) expectedResponse := "Test payloadTest payload 2" actualResponse := make([]byte, 256) deadline := time.Now().Add(time.Second * 5) totalBytes := 0 for { n, err := authConn.Read(actualResponse[totalBytes:]) common.Must(err) totalBytes += n if totalBytes >= len(expectedResponse) || time.Now().After(deadline) { break } } if string(actualResponse[:totalBytes]) != expectedResponse { t.Error("response: ", string(actualResponse[:totalBytes])) } } func TestConnectionInvPath(t *testing.T) { auth, err := NewHttpAuthenticator(context.Background(), &Config{ Request: &RequestConfig{ Method: &Method{Value: "Post"}, Uri: []string{"/testpath"}, Header: []*Header{ { Name: "Host", Value: []string{"www.v2ray.com", "www.google.com"}, }, { Name: "User-Agent", Value: []string{"Test-Agent"}, }, }, }, Response: &ResponseConfig{ Version: &Version{ Value: "1.1", }, Status: &Status{ Code: "404", Reason: "Not Found", }, }, }) common.Must(err) authR, err := NewHttpAuthenticator(context.Background(), &Config{ Request: &RequestConfig{ Method: &Method{Value: "Post"}, Uri: []string{"/testpathErr"}, Header: []*Header{ { Name: "Host", Value: []string{"www.v2ray.com", "www.google.com"}, }, { Name: "User-Agent", Value: []string{"Test-Agent"}, }, }, }, Response: &ResponseConfig{ Version: &Version{ Value: "1.1", }, Status: &Status{ Code: "404", Reason: "Not Found", }, }, }) common.Must(err) listener, err := net.Listen("tcp", "127.0.0.1:0") common.Must(err) go func() { conn, err := listener.Accept() common.Must(err) authConn := auth.Server(conn) b := make([]byte, 256) for { n, err := authConn.Read(b) if err != nil { authConn.Close() break } _, err = authConn.Write(b[:n]) common.Must(err) } }() conn, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr)) common.Must(err) authConn := authR.Client(conn) defer authConn.Close() authConn.Write([]byte("Test payload")) authConn.Write([]byte("Test payload 2")) expectedResponse := "Test payloadTest payload 2" actualResponse := make([]byte, 256) deadline := time.Now().Add(time.Second * 5) totalBytes := 0 for { n, err := authConn.Read(actualResponse[totalBytes:]) if err == nil { t.Error("Error Expected", err) } else { return } totalBytes += n if totalBytes >= len(expectedResponse) || time.Now().After(deadline) { break } } } func TestConnectionInvReq(t *testing.T) { auth, err := NewHttpAuthenticator(context.Background(), &Config{ Request: &RequestConfig{ Method: &Method{Value: "Post"}, Uri: []string{"/testpath"}, Header: []*Header{ { Name: "Host", Value: []string{"www.v2ray.com", "www.google.com"}, }, { Name: "User-Agent", Value: []string{"Test-Agent"}, }, }, }, Response: &ResponseConfig{ Version: &Version{ Value: "1.1", }, Status: &Status{ Code: "404", Reason: "Not Found", }, }, }) common.Must(err) listener, err := net.Listen("tcp", "127.0.0.1:0") common.Must(err) go func() { conn, err := listener.Accept() common.Must(err) authConn := auth.Server(conn) b := make([]byte, 256) for { n, err := authConn.Read(b) if err != nil { authConn.Close() break } _, err = authConn.Write(b[:n]) common.Must(err) } }() conn, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr)) common.Must(err) conn.Write([]byte("ABCDEFGHIJKMLN\r\n\r\n")) l, _, err := bufio.NewReader(conn).ReadLine() common.Must(err) if !strings.HasPrefix(string(l), "HTTP/1.1 400 Bad Request") { t.Error("Resp to non http conn", string(l)) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/http/http.go
transport/internet/headers/http/http.go
package http //go:generate go run v2ray.com/core/common/errors/errorgen import ( "bufio" "bytes" "context" "io" "net" "net/http" "strings" "time" "v2ray.com/core/common" "v2ray.com/core/common/buf" ) const ( // CRLF is the line ending in HTTP header CRLF = "\r\n" // ENDING is the double line ending between HTTP header and body. ENDING = CRLF + CRLF // max length of HTTP header. Safety precaution for DDoS attack. maxHeaderLength = 8192 ) var ( ErrHeaderToLong = newError("Header too long.") ErrHeaderMisMatch = newError("Header Mismatch.") ) type Reader interface { Read(io.Reader) (*buf.Buffer, error) } type Writer interface { Write(io.Writer) error } type NoOpReader struct{} func (NoOpReader) Read(io.Reader) (*buf.Buffer, error) { return nil, nil } type NoOpWriter struct{} func (NoOpWriter) Write(io.Writer) error { return nil } type HeaderReader struct { req *http.Request expectedHeader *RequestConfig } func (h *HeaderReader) ExpectThisRequest(expectedHeader *RequestConfig) *HeaderReader { h.expectedHeader = expectedHeader return h } func (h *HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) { buffer := buf.New() totalBytes := int32(0) endingDetected := false var headerBuf bytes.Buffer for totalBytes < maxHeaderLength { _, err := buffer.ReadFrom(reader) if err != nil { buffer.Release() return nil, err } if n := bytes.Index(buffer.Bytes(), []byte(ENDING)); n != -1 { headerBuf.Write(buffer.BytesRange(0, int32(n+len(ENDING)))) buffer.Advance(int32(n + len(ENDING))) endingDetected = true break } lenEnding := int32(len(ENDING)) if buffer.Len() >= lenEnding { totalBytes += buffer.Len() - lenEnding headerBuf.Write(buffer.BytesRange(0, buffer.Len()-lenEnding)) leftover := buffer.BytesFrom(-lenEnding) buffer.Clear() copy(buffer.Extend(lenEnding), leftover) if _, err := readRequest(bufio.NewReader(bytes.NewReader(headerBuf.Bytes())), false); err != io.ErrUnexpectedEOF { return nil, err } } } if !endingDetected { buffer.Release() return nil, ErrHeaderToLong } if h.expectedHeader == nil { if buffer.IsEmpty() { buffer.Release() return nil, nil } return buffer, nil } //Parse the request if req, err := readRequest(bufio.NewReader(bytes.NewReader(headerBuf.Bytes())), false); err != nil { return nil, err } else { h.req = req } //Check req path := h.req.URL.Path hasThisUri := false for _, u := range h.expectedHeader.Uri { if u == path { hasThisUri = true } } if !hasThisUri { return nil, ErrHeaderMisMatch } if buffer.IsEmpty() { buffer.Release() return nil, nil } return buffer, nil } type HeaderWriter struct { header *buf.Buffer } func NewHeaderWriter(header *buf.Buffer) *HeaderWriter { return &HeaderWriter{ header: header, } } func (w *HeaderWriter) Write(writer io.Writer) error { if w.header == nil { return nil } err := buf.WriteAllBytes(writer, w.header.Bytes()) w.header.Release() w.header = nil return err } type HttpConn struct { net.Conn readBuffer *buf.Buffer oneTimeReader Reader oneTimeWriter Writer errorWriter Writer errorMismatchWriter Writer errorTooLongWriter Writer errReason error } func NewHttpConn(conn net.Conn, reader Reader, writer Writer, errorWriter Writer, errorMismatchWriter Writer, errorTooLongWriter Writer) *HttpConn { return &HttpConn{ Conn: conn, oneTimeReader: reader, oneTimeWriter: writer, errorWriter: errorWriter, errorMismatchWriter: errorMismatchWriter, errorTooLongWriter: errorTooLongWriter, } } func (c *HttpConn) Read(b []byte) (int, error) { if c.oneTimeReader != nil { buffer, err := c.oneTimeReader.Read(c.Conn) if err != nil { c.errReason = err return 0, err } c.readBuffer = buffer c.oneTimeReader = nil } if !c.readBuffer.IsEmpty() { nBytes, _ := c.readBuffer.Read(b) if c.readBuffer.IsEmpty() { c.readBuffer.Release() c.readBuffer = nil } return nBytes, nil } return c.Conn.Read(b) } // Write implements io.Writer. func (c *HttpConn) Write(b []byte) (int, error) { if c.oneTimeWriter != nil { err := c.oneTimeWriter.Write(c.Conn) c.oneTimeWriter = nil if err != nil { return 0, err } } return c.Conn.Write(b) } // Close implements net.Conn.Close(). func (c *HttpConn) Close() error { if c.oneTimeWriter != nil && c.errorWriter != nil { // Connection is being closed but header wasn't sent. This means the client request // is probably not valid. Sending back a server error header in this case. //Write response based on error reason if c.errReason == ErrHeaderMisMatch { c.errorMismatchWriter.Write(c.Conn) } else if c.errReason == ErrHeaderToLong { c.errorTooLongWriter.Write(c.Conn) } else { c.errorWriter.Write(c.Conn) } } return c.Conn.Close() } func formResponseHeader(config *ResponseConfig) *HeaderWriter { header := buf.New() common.Must2(header.WriteString(strings.Join([]string{config.GetFullVersion(), config.GetStatusValue().Code, config.GetStatusValue().Reason}, " "))) common.Must2(header.WriteString(CRLF)) headers := config.PickHeaders() for _, h := range headers { common.Must2(header.WriteString(h)) common.Must2(header.WriteString(CRLF)) } if !config.HasHeader("Date") { common.Must2(header.WriteString("Date: ")) common.Must2(header.WriteString(time.Now().Format(http.TimeFormat))) common.Must2(header.WriteString(CRLF)) } common.Must2(header.WriteString(CRLF)) return &HeaderWriter{ header: header, } } type HttpAuthenticator struct { config *Config } func (a HttpAuthenticator) GetClientWriter() *HeaderWriter { header := buf.New() config := a.config.Request common.Must2(header.WriteString(strings.Join([]string{config.GetMethodValue(), config.PickUri(), config.GetFullVersion()}, " "))) common.Must2(header.WriteString(CRLF)) headers := config.PickHeaders() for _, h := range headers { common.Must2(header.WriteString(h)) common.Must2(header.WriteString(CRLF)) } common.Must2(header.WriteString(CRLF)) return &HeaderWriter{ header: header, } } func (a HttpAuthenticator) GetServerWriter() *HeaderWriter { return formResponseHeader(a.config.Response) } func (a HttpAuthenticator) Client(conn net.Conn) net.Conn { if a.config.Request == nil && a.config.Response == nil { return conn } var reader Reader = NoOpReader{} if a.config.Request != nil { reader = new(HeaderReader) } var writer Writer = NoOpWriter{} if a.config.Response != nil { writer = a.GetClientWriter() } return NewHttpConn(conn, reader, writer, NoOpWriter{}, NoOpWriter{}, NoOpWriter{}) } func (a HttpAuthenticator) Server(conn net.Conn) net.Conn { if a.config.Request == nil && a.config.Response == nil { return conn } return NewHttpConn(conn, new(HeaderReader).ExpectThisRequest(a.config.Request), a.GetServerWriter(), formResponseHeader(resp400), formResponseHeader(resp404), formResponseHeader(resp400)) } func NewHttpAuthenticator(ctx context.Context, config *Config) (HttpAuthenticator, error) { return HttpAuthenticator{ config: config, }, nil } func init() { common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { return NewHttpAuthenticator(ctx, config.(*Config)) })) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/http/resp.go
transport/internet/headers/http/resp.go
package http var resp400 = &ResponseConfig{ Version: &Version{ Value: "1.1", }, Status: &Status{ Code: "400", Reason: "Bad Request", }, Header: []*Header{ { Name: "Connection", Value: []string{"close"}, }, { Name: "Cache-Control", Value: []string{"private"}, }, { Name: "Content-Length", Value: []string{"0"}, }, }, } var resp404 = &ResponseConfig{ Version: &Version{ Value: "1.1", }, Status: &Status{ Code: "404", Reason: "Not Found", }, Header: []*Header{ { Name: "Connection", Value: []string{"close"}, }, { Name: "Cache-Control", Value: []string{"private"}, }, { Name: "Content-Length", Value: []string{"0"}, }, }, }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/headers/http/config.pb.go
transport/internet/headers/http/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/headers/http/config.proto package http import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Header struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // "Accept", "Cookie", etc Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // Each entry must be valid in one piece. Random entry will be chosen if // multiple entries present. Value []string `protobuf:"bytes,2,rep,name=value,proto3" json:"value,omitempty"` } func (x *Header) Reset() { *x = Header{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_http_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Header) String() string { return protoimpl.X.MessageStringOf(x) } func (*Header) ProtoMessage() {} func (x *Header) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_http_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Header.ProtoReflect.Descriptor instead. func (*Header) Descriptor() ([]byte, []int) { return file_transport_internet_headers_http_config_proto_rawDescGZIP(), []int{0} } func (x *Header) GetName() string { if x != nil { return x.Name } return "" } func (x *Header) GetValue() []string { if x != nil { return x.Value } return nil } // HTTP version. Default value "1.1". type Version struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` } func (x *Version) Reset() { *x = Version{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_http_config_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Version) String() string { return protoimpl.X.MessageStringOf(x) } func (*Version) ProtoMessage() {} func (x *Version) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_http_config_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Version.ProtoReflect.Descriptor instead. func (*Version) Descriptor() ([]byte, []int) { return file_transport_internet_headers_http_config_proto_rawDescGZIP(), []int{1} } func (x *Version) GetValue() string { if x != nil { return x.Value } return "" } // HTTP method. Default value "GET". type Method struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` } func (x *Method) Reset() { *x = Method{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_http_config_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Method) String() string { return protoimpl.X.MessageStringOf(x) } func (*Method) ProtoMessage() {} func (x *Method) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_http_config_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Method.ProtoReflect.Descriptor instead. func (*Method) Descriptor() ([]byte, []int) { return file_transport_internet_headers_http_config_proto_rawDescGZIP(), []int{2} } func (x *Method) GetValue() string { if x != nil { return x.Value } return "" } type RequestConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Full HTTP version like "1.1". Version *Version `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` // GET, POST, CONNECT etc Method *Method `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` // URI like "/login.php" Uri []string `protobuf:"bytes,3,rep,name=uri,proto3" json:"uri,omitempty"` Header []*Header `protobuf:"bytes,4,rep,name=header,proto3" json:"header,omitempty"` } func (x *RequestConfig) Reset() { *x = RequestConfig{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_http_config_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *RequestConfig) String() string { return protoimpl.X.MessageStringOf(x) } func (*RequestConfig) ProtoMessage() {} func (x *RequestConfig) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_http_config_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use RequestConfig.ProtoReflect.Descriptor instead. func (*RequestConfig) Descriptor() ([]byte, []int) { return file_transport_internet_headers_http_config_proto_rawDescGZIP(), []int{3} } func (x *RequestConfig) GetVersion() *Version { if x != nil { return x.Version } return nil } func (x *RequestConfig) GetMethod() *Method { if x != nil { return x.Method } return nil } func (x *RequestConfig) GetUri() []string { if x != nil { return x.Uri } return nil } func (x *RequestConfig) GetHeader() []*Header { if x != nil { return x.Header } return nil } type Status struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Status code. Default "200". Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` // Statue reason. Default "OK". Reason string `protobuf:"bytes,2,opt,name=reason,proto3" json:"reason,omitempty"` } func (x *Status) Reset() { *x = Status{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_http_config_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Status) String() string { return protoimpl.X.MessageStringOf(x) } func (*Status) ProtoMessage() {} func (x *Status) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_http_config_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Status.ProtoReflect.Descriptor instead. func (*Status) Descriptor() ([]byte, []int) { return file_transport_internet_headers_http_config_proto_rawDescGZIP(), []int{4} } func (x *Status) GetCode() string { if x != nil { return x.Code } return "" } func (x *Status) GetReason() string { if x != nil { return x.Reason } return "" } type ResponseConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Version *Version `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` Status *Status `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"` Header []*Header `protobuf:"bytes,3,rep,name=header,proto3" json:"header,omitempty"` } func (x *ResponseConfig) Reset() { *x = ResponseConfig{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_http_config_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *ResponseConfig) String() string { return protoimpl.X.MessageStringOf(x) } func (*ResponseConfig) ProtoMessage() {} func (x *ResponseConfig) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_http_config_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use ResponseConfig.ProtoReflect.Descriptor instead. func (*ResponseConfig) Descriptor() ([]byte, []int) { return file_transport_internet_headers_http_config_proto_rawDescGZIP(), []int{5} } func (x *ResponseConfig) GetVersion() *Version { if x != nil { return x.Version } return nil } func (x *ResponseConfig) GetStatus() *Status { if x != nil { return x.Status } return nil } func (x *ResponseConfig) GetHeader() []*Header { if x != nil { return x.Header } return nil } type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Settings for authenticating requests. If not set, client side will not send // authenication header, and server side will bypass authentication. Request *RequestConfig `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` // Settings for authenticating responses. If not set, client side will bypass // authentication, and server side will not send authentication header. Response *ResponseConfig `protobuf:"bytes,2,opt,name=response,proto3" json:"response,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_headers_http_config_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_headers_http_config_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_headers_http_config_proto_rawDescGZIP(), []int{6} } func (x *Config) GetRequest() *RequestConfig { if x != nil { return x.Request } return nil } func (x *Config) GetResponse() *ResponseConfig { if x != nil { return x.Response } return nil } var File_transport_internet_headers_http_config_proto protoreflect.FileDescriptor var file_transport_internet_headers_http_config_proto_rawDesc = []byte{ 0x0a, 0x2c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2a, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x22, 0x32, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x1f, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x1e, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x88, 0x02, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x4d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x33, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x4a, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, 0x12, 0x4a, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0x34, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0xf7, 0x01, 0x0a, 0x0e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x4d, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x33, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x4a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x4a, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0xb5, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x53, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x39, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x56, 0x0a, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x3a, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x08, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x8f, 0x01, 0x0a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x50, 0x01, 0x5a, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x68, 0x74, 0x74, 0x70, 0xaa, 0x02, 0x2a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_headers_http_config_proto_rawDescOnce sync.Once file_transport_internet_headers_http_config_proto_rawDescData = file_transport_internet_headers_http_config_proto_rawDesc ) func file_transport_internet_headers_http_config_proto_rawDescGZIP() []byte { file_transport_internet_headers_http_config_proto_rawDescOnce.Do(func() { file_transport_internet_headers_http_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_headers_http_config_proto_rawDescData) }) return file_transport_internet_headers_http_config_proto_rawDescData } var file_transport_internet_headers_http_config_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_transport_internet_headers_http_config_proto_goTypes = []interface{}{ (*Header)(nil), // 0: v2ray.core.transport.internet.headers.http.Header (*Version)(nil), // 1: v2ray.core.transport.internet.headers.http.Version (*Method)(nil), // 2: v2ray.core.transport.internet.headers.http.Method (*RequestConfig)(nil), // 3: v2ray.core.transport.internet.headers.http.RequestConfig (*Status)(nil), // 4: v2ray.core.transport.internet.headers.http.Status (*ResponseConfig)(nil), // 5: v2ray.core.transport.internet.headers.http.ResponseConfig (*Config)(nil), // 6: v2ray.core.transport.internet.headers.http.Config } var file_transport_internet_headers_http_config_proto_depIdxs = []int32{ 1, // 0: v2ray.core.transport.internet.headers.http.RequestConfig.version:type_name -> v2ray.core.transport.internet.headers.http.Version 2, // 1: v2ray.core.transport.internet.headers.http.RequestConfig.method:type_name -> v2ray.core.transport.internet.headers.http.Method 0, // 2: v2ray.core.transport.internet.headers.http.RequestConfig.header:type_name -> v2ray.core.transport.internet.headers.http.Header 1, // 3: v2ray.core.transport.internet.headers.http.ResponseConfig.version:type_name -> v2ray.core.transport.internet.headers.http.Version 4, // 4: v2ray.core.transport.internet.headers.http.ResponseConfig.status:type_name -> v2ray.core.transport.internet.headers.http.Status 0, // 5: v2ray.core.transport.internet.headers.http.ResponseConfig.header:type_name -> v2ray.core.transport.internet.headers.http.Header 3, // 6: v2ray.core.transport.internet.headers.http.Config.request:type_name -> v2ray.core.transport.internet.headers.http.RequestConfig 5, // 7: v2ray.core.transport.internet.headers.http.Config.response:type_name -> v2ray.core.transport.internet.headers.http.ResponseConfig 8, // [8:8] is the sub-list for method output_type 8, // [8:8] is the sub-list for method input_type 8, // [8:8] is the sub-list for extension type_name 8, // [8:8] is the sub-list for extension extendee 0, // [0:8] is the sub-list for field type_name } func init() { file_transport_internet_headers_http_config_proto_init() } func file_transport_internet_headers_http_config_proto_init() { if File_transport_internet_headers_http_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_headers_http_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Header); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_headers_http_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Version); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_headers_http_config_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Method); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_headers_http_config_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RequestConfig); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_headers_http_config_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Status); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_headers_http_config_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ResponseConfig); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_headers_http_config_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_headers_http_config_proto_rawDesc, NumEnums: 0, NumMessages: 7, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_headers_http_config_proto_goTypes, DependencyIndexes: file_transport_internet_headers_http_config_proto_depIdxs, MessageInfos: file_transport_internet_headers_http_config_proto_msgTypes, }.Build() File_transport_internet_headers_http_config_proto = out.File file_transport_internet_headers_http_config_proto_rawDesc = nil file_transport_internet_headers_http_config_proto_goTypes = nil file_transport_internet_headers_http_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/domainsocket/listener.go
transport/internet/domainsocket/listener.go
// +build !windows // +build !wasm // +build !confonly package domainsocket import ( "context" gotls "crypto/tls" "os" "strings" "github.com/pires/go-proxyproto" goxtls "github.com/xtls/go" "golang.org/x/sys/unix" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" "v2ray.com/core/transport/internet/xtls" ) type Listener struct { addr *net.UnixAddr ln net.Listener tlsConfig *gotls.Config xtlsConfig *goxtls.Config config *Config addConn internet.ConnHandler locker *fileLocker } func Listen(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, handler internet.ConnHandler) (internet.Listener, error) { settings := streamSettings.ProtocolSettings.(*Config) addr, err := settings.GetUnixAddr() if err != nil { return nil, err } unixListener, err := net.ListenUnix("unix", addr) if err != nil { return nil, newError("failed to listen domain socket").Base(err).AtWarning() } var ln *Listener if settings.AcceptProxyProtocol { policyFunc := func(upstream net.Addr) (proxyproto.Policy, error) { return proxyproto.REQUIRE, nil } ln = &Listener{ addr: addr, ln: &proxyproto.Listener{Listener: unixListener, Policy: policyFunc}, config: settings, addConn: handler, } newError("accepting PROXY protocol").AtWarning().WriteToLog(session.ExportIDToError(ctx)) } else { ln = &Listener{ addr: addr, ln: unixListener, config: settings, addConn: handler, } } if !settings.Abstract { ln.locker = &fileLocker{ path: settings.Path + ".lock", } if err := ln.locker.Acquire(); err != nil { unixListener.Close() return nil, err } } if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { ln.tlsConfig = config.GetTLSConfig() } if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil { ln.xtlsConfig = config.GetXTLSConfig() } go ln.run() return ln, nil } func (ln *Listener) Addr() net.Addr { return ln.addr } func (ln *Listener) Close() error { if ln.locker != nil { ln.locker.Release() } return ln.ln.Close() } func (ln *Listener) run() { for { conn, err := ln.ln.Accept() if err != nil { if strings.Contains(err.Error(), "closed") { break } newError("failed to accepted raw connections").Base(err).AtWarning().WriteToLog() continue } if ln.tlsConfig != nil { conn = tls.Server(conn, ln.tlsConfig) } else if ln.xtlsConfig != nil { conn = xtls.Server(conn, ln.xtlsConfig) } ln.addConn(internet.Connection(conn)) } } type fileLocker struct { path string file *os.File } func (fl *fileLocker) Acquire() error { f, err := os.Create(fl.path) if err != nil { return err } if err := unix.Flock(int(f.Fd()), unix.LOCK_EX); err != nil { f.Close() return newError("failed to lock file: ", fl.path).Base(err) } fl.file = f return nil } func (fl *fileLocker) Release() { if err := unix.Flock(int(fl.file.Fd()), unix.LOCK_UN); err != nil { newError("failed to unlock file: ", fl.path).Base(err).WriteToLog() } if err := fl.file.Close(); err != nil { newError("failed to close file: ", fl.path).Base(err).WriteToLog() } if err := os.Remove(fl.path); err != nil { newError("failed to remove file: ", fl.path).Base(err).WriteToLog() } } func init() { common.Must(internet.RegisterTransportListener(protocolName, Listen)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/domainsocket/errors.generated.go
transport/internet/domainsocket/errors.generated.go
package domainsocket import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/domainsocket/config.go
transport/internet/domainsocket/config.go
// +build !confonly package domainsocket import ( "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) const protocolName = "domainsocket" const sizeofSunPath = 108 func (c *Config) GetUnixAddr() (*net.UnixAddr, error) { path := c.Path if path == "" { return nil, newError("empty domain socket path") } if c.Abstract && path[0] != '@' { path = "@" + path } if c.Abstract && c.Padding { raw := []byte(path) addr := make([]byte, sizeofSunPath) for i, c := range raw { addr[i] = c } path = string(addr) } return &net.UnixAddr{ Name: path, Net: "unix", }, nil } func init() { common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { return new(Config) })) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/domainsocket/errgen.go
transport/internet/domainsocket/errgen.go
package domainsocket //go:generate go run v2ray.com/core/common/errors/errorgen
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/domainsocket/config.pb.go
transport/internet/domainsocket/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/domainsocket/config.proto package domainsocket import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Path of the domain socket. This overrides the IP/Port parameter from // upstream caller. Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` // Abstract speicifies whether to use abstract namespace or not. // Traditionally Unix domain socket is file system based. Abstract domain // socket can be used without acquiring file lock. Abstract bool `protobuf:"varint,2,opt,name=abstract,proto3" json:"abstract,omitempty"` // Some apps, eg. haproxy, use the full length of sockaddr_un.sun_path to // connect(2) or bind(2) when using abstract UDS. Padding bool `protobuf:"varint,3,opt,name=padding,proto3" json:"padding,omitempty"` AcceptProxyProtocol bool `protobuf:"varint,4,opt,name=acceptProxyProtocol,proto3" json:"acceptProxyProtocol,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_domainsocket_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_domainsocket_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_domainsocket_config_proto_rawDescGZIP(), []int{0} } func (x *Config) GetPath() string { if x != nil { return x.Path } return "" } func (x *Config) GetAbstract() bool { if x != nil { return x.Abstract } return false } func (x *Config) GetPadding() bool { if x != nil { return x.Padding } return false } func (x *Config) GetAcceptProxyProtocol() bool { if x != nil { return x.AcceptProxyProtocol } return false } var File_transport_internet_domainsocket_config_proto protoreflect.FileDescriptor var file_transport_internet_domainsocket_config_proto_rawDesc = []byte{ 0x0a, 0x2c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x2a, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x22, 0x84, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x62, 0x73, 0x74, 0x72, 0x61, 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x61, 0x62, 0x73, 0x74, 0x72, 0x61, 0x63, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x30, 0x0a, 0x13, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x13, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x42, 0x8f, 0x01, 0x0a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x50, 0x01, 0x5a, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0xaa, 0x02, 0x2a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x44, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_domainsocket_config_proto_rawDescOnce sync.Once file_transport_internet_domainsocket_config_proto_rawDescData = file_transport_internet_domainsocket_config_proto_rawDesc ) func file_transport_internet_domainsocket_config_proto_rawDescGZIP() []byte { file_transport_internet_domainsocket_config_proto_rawDescOnce.Do(func() { file_transport_internet_domainsocket_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_domainsocket_config_proto_rawDescData) }) return file_transport_internet_domainsocket_config_proto_rawDescData } var file_transport_internet_domainsocket_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_transport_internet_domainsocket_config_proto_goTypes = []interface{}{ (*Config)(nil), // 0: v2ray.core.transport.internet.domainsocket.Config } var file_transport_internet_domainsocket_config_proto_depIdxs = []int32{ 0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name } func init() { file_transport_internet_domainsocket_config_proto_init() } func file_transport_internet_domainsocket_config_proto_init() { if File_transport_internet_domainsocket_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_domainsocket_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_domainsocket_config_proto_rawDesc, NumEnums: 0, NumMessages: 1, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_domainsocket_config_proto_goTypes, DependencyIndexes: file_transport_internet_domainsocket_config_proto_depIdxs, MessageInfos: file_transport_internet_domainsocket_config_proto_msgTypes, }.Build() File_transport_internet_domainsocket_config_proto = out.File file_transport_internet_domainsocket_config_proto_rawDesc = nil file_transport_internet_domainsocket_config_proto_goTypes = nil file_transport_internet_domainsocket_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/domainsocket/listener_test.go
transport/internet/domainsocket/listener_test.go
// +build !windows package domainsocket_test import ( "context" "runtime" "testing" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" . "v2ray.com/core/transport/internet/domainsocket" ) func TestListen(t *testing.T) { ctx := context.Background() streamSettings := &internet.MemoryStreamConfig{ ProtocolName: "domainsocket", ProtocolSettings: &Config{ Path: "/tmp/ts3", }, } listener, err := Listen(ctx, nil, net.Port(0), streamSettings, func(conn internet.Connection) { defer conn.Close() b := buf.New() defer b.Release() common.Must2(b.ReadFrom(conn)) b.WriteString("Response") common.Must2(conn.Write(b.Bytes())) }) common.Must(err) defer listener.Close() conn, err := Dial(ctx, net.Destination{}, streamSettings) common.Must(err) defer conn.Close() common.Must2(conn.Write([]byte("Request"))) b := buf.New() defer b.Release() common.Must2(b.ReadFrom(conn)) if b.String() != "RequestResponse" { t.Error("expected response as 'RequestResponse' but got ", b.String()) } } func TestListenAbstract(t *testing.T) { if runtime.GOOS != "linux" { return } ctx := context.Background() streamSettings := &internet.MemoryStreamConfig{ ProtocolName: "domainsocket", ProtocolSettings: &Config{ Path: "/tmp/ts3", Abstract: true, }, } listener, err := Listen(ctx, nil, net.Port(0), streamSettings, func(conn internet.Connection) { defer conn.Close() b := buf.New() defer b.Release() common.Must2(b.ReadFrom(conn)) b.WriteString("Response") common.Must2(conn.Write(b.Bytes())) }) common.Must(err) defer listener.Close() conn, err := Dial(ctx, net.Destination{}, streamSettings) common.Must(err) defer conn.Close() common.Must2(conn.Write([]byte("Request"))) b := buf.New() defer b.Release() common.Must2(b.ReadFrom(conn)) if b.String() != "RequestResponse" { t.Error("expected response as 'RequestResponse' but got ", b.String()) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/domainsocket/dial.go
transport/internet/domainsocket/dial.go
// +build !windows // +build !wasm // +build !confonly package domainsocket import ( "context" "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" "v2ray.com/core/transport/internet/xtls" ) func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { settings := streamSettings.ProtocolSettings.(*Config) addr, err := settings.GetUnixAddr() if err != nil { return nil, err } conn, err := net.DialUnix("unix", nil, addr) if err != nil { return nil, newError("failed to dial unix: ", settings.Path).Base(err).AtWarning() } if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil } else if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil { return xtls.Client(conn, config.GetXTLSConfig(xtls.WithDestination(dest))), nil } return conn, nil } func init() { common.Must(internet.RegisterTransportDialer(protocolName, Dial)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/crypt.go
transport/internet/kcp/crypt.go
// +build !confonly package kcp import ( "crypto/cipher" "encoding/binary" "hash/fnv" "v2ray.com/core/common" ) // SimpleAuthenticator is a legacy AEAD used for KCP encryption. type SimpleAuthenticator struct{} // NewSimpleAuthenticator creates a new SimpleAuthenticator func NewSimpleAuthenticator() cipher.AEAD { return &SimpleAuthenticator{} } // NonceSize implements cipher.AEAD.NonceSize(). func (*SimpleAuthenticator) NonceSize() int { return 0 } // Overhead implements cipher.AEAD.NonceSize(). func (*SimpleAuthenticator) Overhead() int { return 6 } // Seal implements cipher.AEAD.Seal(). func (a *SimpleAuthenticator) Seal(dst, nonce, plain, extra []byte) []byte { dst = append(dst, 0, 0, 0, 0, 0, 0) // 4 bytes for hash, and then 2 bytes for length binary.BigEndian.PutUint16(dst[4:], uint16(len(plain))) dst = append(dst, plain...) fnvHash := fnv.New32a() common.Must2(fnvHash.Write(dst[4:])) fnvHash.Sum(dst[:0]) dstLen := len(dst) xtra := 4 - dstLen%4 if xtra != 4 { dst = append(dst, make([]byte, xtra)...) } xorfwd(dst) if xtra != 4 { dst = dst[:dstLen] } return dst } // Open implements cipher.AEAD.Open(). func (a *SimpleAuthenticator) Open(dst, nonce, cipherText, extra []byte) ([]byte, error) { dst = append(dst, cipherText...) dstLen := len(dst) xtra := 4 - dstLen%4 if xtra != 4 { dst = append(dst, make([]byte, xtra)...) } xorbkd(dst) if xtra != 4 { dst = dst[:dstLen] } fnvHash := fnv.New32a() common.Must2(fnvHash.Write(dst[4:])) if binary.BigEndian.Uint32(dst[:4]) != fnvHash.Sum32() { return nil, newError("invalid auth") } length := binary.BigEndian.Uint16(dst[4:6]) if len(dst)-6 != int(length) { return nil, newError("invalid auth") } return dst[6:], nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/listener.go
transport/internet/kcp/listener.go
// +build !confonly package kcp import ( "context" "crypto/cipher" gotls "crypto/tls" "sync" goxtls "github.com/xtls/go" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" "v2ray.com/core/transport/internet/udp" "v2ray.com/core/transport/internet/xtls" ) type ConnectionID struct { Remote net.Address Port net.Port Conv uint16 } // Listener defines a server listening for connections type Listener struct { sync.Mutex sessions map[ConnectionID]*Connection hub *udp.Hub tlsConfig *gotls.Config xtlsConfig *goxtls.Config config *Config reader PacketReader header internet.PacketHeader security cipher.AEAD addConn internet.ConnHandler } func NewListener(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, addConn internet.ConnHandler) (*Listener, error) { kcpSettings := streamSettings.ProtocolSettings.(*Config) header, err := kcpSettings.GetPackerHeader() if err != nil { return nil, newError("failed to create packet header").Base(err).AtError() } security, err := kcpSettings.GetSecurity() if err != nil { return nil, newError("failed to create security").Base(err).AtError() } l := &Listener{ header: header, security: security, reader: &KCPPacketReader{ Header: header, Security: security, }, sessions: make(map[ConnectionID]*Connection), config: kcpSettings, addConn: addConn, } if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { l.tlsConfig = config.GetTLSConfig() } if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil { l.xtlsConfig = config.GetXTLSConfig() } hub, err := udp.ListenUDP(ctx, address, port, streamSettings, udp.HubCapacity(1024)) if err != nil { return nil, err } l.Lock() l.hub = hub l.Unlock() newError("listening on ", address, ":", port).WriteToLog() go l.handlePackets() return l, nil } func (l *Listener) handlePackets() { receive := l.hub.Receive() for payload := range receive { l.OnReceive(payload.Payload, payload.Source) } } func (l *Listener) OnReceive(payload *buf.Buffer, src net.Destination) { segments := l.reader.Read(payload.Bytes()) payload.Release() if len(segments) == 0 { newError("discarding invalid payload from ", src).WriteToLog() return } conv := segments[0].Conversation() cmd := segments[0].Command() id := ConnectionID{ Remote: src.Address, Port: src.Port, Conv: conv, } l.Lock() defer l.Unlock() conn, found := l.sessions[id] if !found { if cmd == CommandTerminate { return } writer := &Writer{ id: id, hub: l.hub, dest: src, listener: l, } remoteAddr := &net.UDPAddr{ IP: src.Address.IP(), Port: int(src.Port), } localAddr := l.hub.Addr() conn = NewConnection(ConnMetadata{ LocalAddr: localAddr, RemoteAddr: remoteAddr, Conversation: conv, }, &KCPPacketWriter{ Header: l.header, Security: l.security, Writer: writer, }, writer, l.config) var netConn internet.Connection = conn if l.tlsConfig != nil { netConn = gotls.Server(conn, l.tlsConfig) } else if l.xtlsConfig != nil { netConn = goxtls.Server(conn, l.xtlsConfig) } l.addConn(netConn) l.sessions[id] = conn } conn.Input(segments) } func (l *Listener) Remove(id ConnectionID) { l.Lock() delete(l.sessions, id) l.Unlock() } // Close stops listening on the UDP address. Already Accepted connections are not closed. func (l *Listener) Close() error { l.hub.Close() l.Lock() defer l.Unlock() for _, conn := range l.sessions { go conn.Terminate() } return nil } func (l *Listener) ActiveConnections() int { l.Lock() defer l.Unlock() return len(l.sessions) } // Addr returns the listener's network address, The Addr returned is shared by all invocations of Addr, so do not modify it. func (l *Listener) Addr() net.Addr { return l.hub.Addr() } type Writer struct { id ConnectionID dest net.Destination hub *udp.Hub listener *Listener } func (w *Writer) Write(payload []byte) (int, error) { return w.hub.WriteTo(payload, w.dest) } func (w *Writer) Close() error { w.listener.Remove(w.id) return nil } func ListenKCP(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, addConn internet.ConnHandler) (internet.Listener, error) { return NewListener(ctx, address, port, streamSettings, addConn) } func init() { common.Must(internet.RegisterTransportListener(protocolName, ListenKCP)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/dialer.go
transport/internet/kcp/dialer.go
// +build !confonly package kcp import ( "context" "io" "sync/atomic" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/dice" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" "v2ray.com/core/transport/internet/xtls" ) var ( globalConv = uint32(dice.RollUint16()) ) func fetchInput(ctx context.Context, input io.Reader, reader PacketReader, conn *Connection) { cache := make(chan *buf.Buffer, 1024) go func() { for { payload := buf.New() if _, err := payload.ReadFrom(input); err != nil { payload.Release() close(cache) return } select { case cache <- payload: default: payload.Release() } } }() for payload := range cache { segments := reader.Read(payload.Bytes()) payload.Release() if len(segments) > 0 { conn.Input(segments) } } } // DialKCP dials a new KCP connections to the specific destination. func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { dest.Network = net.Network_UDP newError("dialing mKCP to ", dest).WriteToLog() rawConn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings) if err != nil { return nil, newError("failed to dial to dest: ", err).AtWarning().Base(err) } kcpSettings := streamSettings.ProtocolSettings.(*Config) header, err := kcpSettings.GetPackerHeader() if err != nil { return nil, newError("failed to create packet header").Base(err) } security, err := kcpSettings.GetSecurity() if err != nil { return nil, newError("failed to create security").Base(err) } reader := &KCPPacketReader{ Header: header, Security: security, } writer := &KCPPacketWriter{ Header: header, Security: security, Writer: rawConn, } conv := uint16(atomic.AddUint32(&globalConv, 1)) session := NewConnection(ConnMetadata{ LocalAddr: rawConn.LocalAddr(), RemoteAddr: rawConn.RemoteAddr(), Conversation: conv, }, writer, rawConn, kcpSettings) go fetchInput(ctx, rawConn, reader, session) var iConn internet.Connection = session if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { iConn = tls.Client(iConn, config.GetTLSConfig(tls.WithDestination(dest))) } else if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil { iConn = xtls.Client(iConn, config.GetXTLSConfig(xtls.WithDestination(dest))) } return iConn, nil } func init() { common.Must(internet.RegisterTransportDialer(protocolName, DialKCP)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/errors.generated.go
transport/internet/kcp/errors.generated.go
package kcp import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/receiving.go
transport/internet/kcp/receiving.go
// +build !confonly package kcp import ( "sync" "v2ray.com/core/common/buf" ) type ReceivingWindow struct { cache map[uint32]*DataSegment } func NewReceivingWindow() *ReceivingWindow { return &ReceivingWindow{ cache: make(map[uint32]*DataSegment), } } func (w *ReceivingWindow) Set(id uint32, value *DataSegment) bool { _, f := w.cache[id] if f { return false } w.cache[id] = value return true } func (w *ReceivingWindow) Has(id uint32) bool { _, f := w.cache[id] return f } func (w *ReceivingWindow) Remove(id uint32) *DataSegment { v, f := w.cache[id] if !f { return nil } delete(w.cache, id) return v } type AckList struct { writer SegmentWriter timestamps []uint32 numbers []uint32 nextFlush []uint32 flushCandidates []uint32 dirty bool } func NewAckList(writer SegmentWriter) *AckList { return &AckList{ writer: writer, timestamps: make([]uint32, 0, 128), numbers: make([]uint32, 0, 128), nextFlush: make([]uint32, 0, 128), flushCandidates: make([]uint32, 0, 128), } } func (l *AckList) Add(number uint32, timestamp uint32) { l.timestamps = append(l.timestamps, timestamp) l.numbers = append(l.numbers, number) l.nextFlush = append(l.nextFlush, 0) l.dirty = true } func (l *AckList) Clear(una uint32) { count := 0 for i := 0; i < len(l.numbers); i++ { if l.numbers[i] < una { continue } if i != count { l.numbers[count] = l.numbers[i] l.timestamps[count] = l.timestamps[i] l.nextFlush[count] = l.nextFlush[i] } count++ } if count < len(l.numbers) { l.numbers = l.numbers[:count] l.timestamps = l.timestamps[:count] l.nextFlush = l.nextFlush[:count] l.dirty = true } } func (l *AckList) Flush(current uint32, rto uint32) { l.flushCandidates = l.flushCandidates[:0] seg := NewAckSegment() for i := 0; i < len(l.numbers); i++ { if l.nextFlush[i] > current { if len(l.flushCandidates) < cap(l.flushCandidates) { l.flushCandidates = append(l.flushCandidates, l.numbers[i]) } continue } seg.PutNumber(l.numbers[i]) seg.PutTimestamp(l.timestamps[i]) timeout := rto / 2 if timeout < 20 { timeout = 20 } l.nextFlush[i] = current + timeout if seg.IsFull() { l.writer.Write(seg) seg.Release() seg = NewAckSegment() l.dirty = false } } if l.dirty || !seg.IsEmpty() { for _, number := range l.flushCandidates { if seg.IsFull() { break } seg.PutNumber(number) } l.writer.Write(seg) l.dirty = false } seg.Release() } type ReceivingWorker struct { sync.RWMutex conn *Connection leftOver buf.MultiBuffer window *ReceivingWindow acklist *AckList nextNumber uint32 windowSize uint32 } func NewReceivingWorker(kcp *Connection) *ReceivingWorker { worker := &ReceivingWorker{ conn: kcp, window: NewReceivingWindow(), windowSize: kcp.Config.GetReceivingInFlightSize(), } worker.acklist = NewAckList(worker) return worker } func (w *ReceivingWorker) Release() { w.Lock() buf.ReleaseMulti(w.leftOver) w.leftOver = nil w.Unlock() } func (w *ReceivingWorker) ProcessSendingNext(number uint32) { w.Lock() defer w.Unlock() w.acklist.Clear(number) } func (w *ReceivingWorker) ProcessSegment(seg *DataSegment) { w.Lock() defer w.Unlock() number := seg.Number idx := number - w.nextNumber if idx >= w.windowSize { return } w.acklist.Clear(seg.SendingNext) w.acklist.Add(number, seg.Timestamp) if !w.window.Set(seg.Number, seg) { seg.Release() } } func (w *ReceivingWorker) ReadMultiBuffer() buf.MultiBuffer { if w.leftOver != nil { mb := w.leftOver w.leftOver = nil return mb } mb := make(buf.MultiBuffer, 0, 32) w.Lock() defer w.Unlock() for { seg := w.window.Remove(w.nextNumber) if seg == nil { break } w.nextNumber++ mb = append(mb, seg.Detach()) seg.Release() } return mb } func (w *ReceivingWorker) Read(b []byte) int { mb := w.ReadMultiBuffer() if mb.IsEmpty() { return 0 } mb, nBytes := buf.SplitBytes(mb, b) if !mb.IsEmpty() { w.leftOver = mb } return nBytes } func (w *ReceivingWorker) IsDataAvailable() bool { w.RLock() defer w.RUnlock() return w.window.Has(w.nextNumber) } func (w *ReceivingWorker) NextNumber() uint32 { w.RLock() defer w.RUnlock() return w.nextNumber } func (w *ReceivingWorker) Flush(current uint32) { w.Lock() defer w.Unlock() w.acklist.Flush(current, w.conn.roundTrip.Timeout()) } func (w *ReceivingWorker) Write(seg Segment) error { ackSeg := seg.(*AckSegment) ackSeg.Conv = w.conn.meta.Conversation ackSeg.ReceivingNext = w.nextNumber ackSeg.ReceivingWindow = w.nextNumber + w.windowSize ackSeg.Option = 0 if w.conn.State() == StateReadyToClose { ackSeg.Option = SegmentOptionClose } return w.conn.output.Write(ackSeg) } func (*ReceivingWorker) CloseRead() { } func (w *ReceivingWorker) UpdateNecessary() bool { w.RLock() defer w.RUnlock() return len(w.acklist.numbers) > 0 }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/sending.go
transport/internet/kcp/sending.go
// +build !confonly package kcp import ( "container/list" "sync" "v2ray.com/core/common/buf" ) type SendingWindow struct { cache *list.List totalInFlightSize uint32 writer SegmentWriter onPacketLoss func(uint32) } func NewSendingWindow(writer SegmentWriter, onPacketLoss func(uint32)) *SendingWindow { window := &SendingWindow{ cache: list.New(), writer: writer, onPacketLoss: onPacketLoss, } return window } func (sw *SendingWindow) Release() { if sw == nil { return } for sw.cache.Len() > 0 { seg := sw.cache.Front().Value.(*DataSegment) seg.Release() sw.cache.Remove(sw.cache.Front()) } } func (sw *SendingWindow) Len() uint32 { return uint32(sw.cache.Len()) } func (sw *SendingWindow) IsEmpty() bool { return sw.cache.Len() == 0 } func (sw *SendingWindow) Push(number uint32, b *buf.Buffer) { seg := NewDataSegment() seg.Number = number seg.payload = b sw.cache.PushBack(seg) } func (sw *SendingWindow) FirstNumber() uint32 { return sw.cache.Front().Value.(*DataSegment).Number } func (sw *SendingWindow) Clear(una uint32) { for !sw.IsEmpty() { seg := sw.cache.Front().Value.(*DataSegment) if seg.Number >= una { break } seg.Release() sw.cache.Remove(sw.cache.Front()) } } func (sw *SendingWindow) HandleFastAck(number uint32, rto uint32) { if sw.IsEmpty() { return } sw.Visit(func(seg *DataSegment) bool { if number == seg.Number || number-seg.Number > 0x7FFFFFFF { return false } if seg.transmit > 0 && seg.timeout > rto/3 { seg.timeout -= rto / 3 } return true }) } func (sw *SendingWindow) Visit(visitor func(seg *DataSegment) bool) { if sw.IsEmpty() { return } for e := sw.cache.Front(); e != nil; e = e.Next() { seg := e.Value.(*DataSegment) if !visitor(seg) { break } } } func (sw *SendingWindow) Flush(current uint32, rto uint32, maxInFlightSize uint32) { if sw.IsEmpty() { return } var lost uint32 var inFlightSize uint32 sw.Visit(func(segment *DataSegment) bool { if current-segment.timeout >= 0x7FFFFFFF { return true } if segment.transmit == 0 { // First time sw.totalInFlightSize++ } else { lost++ } segment.timeout = current + rto segment.Timestamp = current segment.transmit++ sw.writer.Write(segment) inFlightSize++ return inFlightSize < maxInFlightSize }) if sw.onPacketLoss != nil && inFlightSize > 0 && sw.totalInFlightSize != 0 { rate := lost * 100 / sw.totalInFlightSize sw.onPacketLoss(rate) } } func (sw *SendingWindow) Remove(number uint32) bool { if sw.IsEmpty() { return false } for e := sw.cache.Front(); e != nil; e = e.Next() { seg := e.Value.(*DataSegment) if seg.Number > number { return false } else if seg.Number == number { if sw.totalInFlightSize > 0 { sw.totalInFlightSize-- } seg.Release() sw.cache.Remove(e) return true } } return false } type SendingWorker struct { sync.RWMutex conn *Connection window *SendingWindow firstUnacknowledged uint32 nextNumber uint32 remoteNextNumber uint32 controlWindow uint32 fastResend uint32 windowSize uint32 firstUnacknowledgedUpdated bool closed bool } func NewSendingWorker(kcp *Connection) *SendingWorker { worker := &SendingWorker{ conn: kcp, fastResend: 2, remoteNextNumber: 32, controlWindow: kcp.Config.GetSendingInFlightSize(), windowSize: kcp.Config.GetSendingBufferSize(), } worker.window = NewSendingWindow(worker, worker.OnPacketLoss) return worker } func (w *SendingWorker) Release() { w.Lock() w.window.Release() w.closed = true w.Unlock() } func (w *SendingWorker) ProcessReceivingNext(nextNumber uint32) { w.Lock() defer w.Unlock() w.ProcessReceivingNextWithoutLock(nextNumber) } func (w *SendingWorker) ProcessReceivingNextWithoutLock(nextNumber uint32) { w.window.Clear(nextNumber) w.FindFirstUnacknowledged() } func (w *SendingWorker) FindFirstUnacknowledged() { first := w.firstUnacknowledged if !w.window.IsEmpty() { w.firstUnacknowledged = w.window.FirstNumber() } else { w.firstUnacknowledged = w.nextNumber } if first != w.firstUnacknowledged { w.firstUnacknowledgedUpdated = true } } func (w *SendingWorker) processAck(number uint32) bool { // number < v.firstUnacknowledged || number >= v.nextNumber if number-w.firstUnacknowledged > 0x7FFFFFFF || number-w.nextNumber < 0x7FFFFFFF { return false } removed := w.window.Remove(number) if removed { w.FindFirstUnacknowledged() } return removed } func (w *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto uint32) { defer seg.Release() w.Lock() defer w.Unlock() if w.closed { return } if w.remoteNextNumber < seg.ReceivingWindow { w.remoteNextNumber = seg.ReceivingWindow } w.ProcessReceivingNextWithoutLock(seg.ReceivingNext) if seg.IsEmpty() { return } var maxack uint32 var maxackRemoved bool for _, number := range seg.NumberList { removed := w.processAck(number) if maxack < number { maxack = number maxackRemoved = removed } } if maxackRemoved { w.window.HandleFastAck(maxack, rto) if current-seg.Timestamp < 10000 { w.conn.roundTrip.Update(current-seg.Timestamp, current) } } } func (w *SendingWorker) Push(b *buf.Buffer) bool { w.Lock() defer w.Unlock() if w.closed { return false } if w.window.Len() > w.windowSize { return false } w.window.Push(w.nextNumber, b) w.nextNumber++ return true } func (w *SendingWorker) Write(seg Segment) error { dataSeg := seg.(*DataSegment) dataSeg.Conv = w.conn.meta.Conversation dataSeg.SendingNext = w.firstUnacknowledged dataSeg.Option = 0 if w.conn.State() == StateReadyToClose { dataSeg.Option = SegmentOptionClose } return w.conn.output.Write(dataSeg) } func (w *SendingWorker) OnPacketLoss(lossRate uint32) { if !w.conn.Config.Congestion || w.conn.roundTrip.Timeout() == 0 { return } if lossRate >= 15 { w.controlWindow = 3 * w.controlWindow / 4 } else if lossRate <= 5 { w.controlWindow += w.controlWindow / 4 } if w.controlWindow < 16 { w.controlWindow = 16 } if w.controlWindow > 2*w.conn.Config.GetSendingInFlightSize() { w.controlWindow = 2 * w.conn.Config.GetSendingInFlightSize() } } func (w *SendingWorker) Flush(current uint32) { w.Lock() if w.closed { w.Unlock() return } cwnd := w.firstUnacknowledged + w.conn.Config.GetSendingInFlightSize() if cwnd > w.remoteNextNumber { cwnd = w.remoteNextNumber } if w.conn.Config.Congestion && cwnd > w.firstUnacknowledged+w.controlWindow { cwnd = w.firstUnacknowledged + w.controlWindow } if !w.window.IsEmpty() { w.window.Flush(current, w.conn.roundTrip.Timeout(), cwnd) w.firstUnacknowledgedUpdated = false } updated := w.firstUnacknowledgedUpdated w.firstUnacknowledgedUpdated = false w.Unlock() if updated { w.conn.Ping(current, CommandPing) } } func (w *SendingWorker) CloseWrite() { w.Lock() defer w.Unlock() w.window.Clear(0xFFFFFFFF) } func (w *SendingWorker) IsEmpty() bool { w.RLock() defer w.RUnlock() return w.window.IsEmpty() } func (w *SendingWorker) UpdateNecessary() bool { return !w.IsEmpty() } func (w *SendingWorker) FirstUnacknowledged() uint32 { w.RLock() defer w.RUnlock() return w.firstUnacknowledged }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/io_test.go
transport/internet/kcp/io_test.go
package kcp_test import ( "testing" . "v2ray.com/core/transport/internet/kcp" ) func TestKCPPacketReader(t *testing.T) { reader := KCPPacketReader{ Security: &SimpleAuthenticator{}, } testCases := []struct { Input []byte Output []Segment }{ { Input: []byte{}, Output: nil, }, { Input: []byte{1}, Output: nil, }, } for _, testCase := range testCases { seg := reader.Read(testCase.Input) if testCase.Output == nil && seg != nil { t.Errorf("Expect nothing returned, but actually %v", seg) } else if testCase.Output != nil && seg == nil { t.Errorf("Expect some output, but got nil") } } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/config.go
transport/internet/kcp/config.go
// +build !confonly package kcp import ( "crypto/cipher" "v2ray.com/core/common" "v2ray.com/core/transport/internet" ) const protocolName = "mkcp" // GetMTUValue returns the value of MTU settings. func (c *Config) GetMTUValue() uint32 { if c == nil || c.Mtu == nil { return 1350 } return c.Mtu.Value } // GetTTIValue returns the value of TTI settings. func (c *Config) GetTTIValue() uint32 { if c == nil || c.Tti == nil { return 50 } return c.Tti.Value } // GetUplinkCapacityValue returns the value of UplinkCapacity settings. func (c *Config) GetUplinkCapacityValue() uint32 { if c == nil || c.UplinkCapacity == nil { return 5 } return c.UplinkCapacity.Value } // GetDownlinkCapacityValue returns the value of DownlinkCapacity settings. func (c *Config) GetDownlinkCapacityValue() uint32 { if c == nil || c.DownlinkCapacity == nil { return 20 } return c.DownlinkCapacity.Value } // GetWriteBufferSize returns the size of WriterBuffer in bytes. func (c *Config) GetWriteBufferSize() uint32 { if c == nil || c.WriteBuffer == nil { return 2 * 1024 * 1024 } return c.WriteBuffer.Size } // GetReadBufferSize returns the size of ReadBuffer in bytes. func (c *Config) GetReadBufferSize() uint32 { if c == nil || c.ReadBuffer == nil { return 2 * 1024 * 1024 } return c.ReadBuffer.Size } // GetSecurity returns the security settings. func (c *Config) GetSecurity() (cipher.AEAD, error) { if c.Seed != nil { return NewAEADAESGCMBasedOnSeed(c.Seed.Seed), nil } return NewSimpleAuthenticator(), nil } func (c *Config) GetPackerHeader() (internet.PacketHeader, error) { if c.HeaderConfig != nil { rawConfig, err := c.HeaderConfig.GetInstance() if err != nil { return nil, err } return internet.CreatePacketHeader(rawConfig) } return nil, nil } func (c *Config) GetSendingInFlightSize() uint32 { size := c.GetUplinkCapacityValue() * 1024 * 1024 / c.GetMTUValue() / (1000 / c.GetTTIValue()) if size < 8 { size = 8 } return size } func (c *Config) GetSendingBufferSize() uint32 { return c.GetWriteBufferSize() / c.GetMTUValue() } func (c *Config) GetReceivingInFlightSize() uint32 { size := c.GetDownlinkCapacityValue() * 1024 * 1024 / c.GetMTUValue() / (1000 / c.GetTTIValue()) if size < 8 { size = 8 } return size } func (c *Config) GetReceivingBufferSize() uint32 { return c.GetReadBufferSize() / c.GetMTUValue() } func init() { common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { return new(Config) })) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/crypt_test.go
transport/internet/kcp/crypt_test.go
package kcp_test import ( "testing" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" . "v2ray.com/core/transport/internet/kcp" ) func TestSimpleAuthenticator(t *testing.T) { cache := make([]byte, 512) payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'} auth := NewSimpleAuthenticator() b := auth.Seal(cache[:0], nil, payload, nil) c, err := auth.Open(cache[:0], nil, b, nil) common.Must(err) if r := cmp.Diff(c, payload); r != "" { t.Error(r) } } func TestSimpleAuthenticator2(t *testing.T) { cache := make([]byte, 512) payload := []byte{'a', 'b'} auth := NewSimpleAuthenticator() b := auth.Seal(cache[:0], nil, payload, nil) c, err := auth.Open(cache[:0], nil, b, nil) common.Must(err) if r := cmp.Diff(c, payload); r != "" { t.Error(r) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/connection.go
transport/internet/kcp/connection.go
// +build !confonly package kcp import ( "bytes" "io" "net" "runtime" "sync" "sync/atomic" "time" "v2ray.com/core/common/buf" "v2ray.com/core/common/signal" "v2ray.com/core/common/signal/semaphore" ) var ( ErrIOTimeout = newError("Read/Write timeout") ErrClosedListener = newError("Listener closed.") ErrClosedConnection = newError("Connection closed.") ) // State of the connection type State int32 // Is returns true if current State is one of the candidates. func (s State) Is(states ...State) bool { for _, state := range states { if s == state { return true } } return false } const ( StateActive State = 0 // Connection is active StateReadyToClose State = 1 // Connection is closed locally StatePeerClosed State = 2 // Connection is closed on remote StateTerminating State = 3 // Connection is ready to be destroyed locally StatePeerTerminating State = 4 // Connection is ready to be destroyed on remote StateTerminated State = 5 // Connection is destroyed. ) func nowMillisec() int64 { now := time.Now() return now.Unix()*1000 + int64(now.Nanosecond()/1000000) } type RoundTripInfo struct { sync.RWMutex variation uint32 srtt uint32 rto uint32 minRtt uint32 updatedTimestamp uint32 } func (info *RoundTripInfo) UpdatePeerRTO(rto uint32, current uint32) { info.Lock() defer info.Unlock() if current-info.updatedTimestamp < 3000 { return } info.updatedTimestamp = current info.rto = rto } func (info *RoundTripInfo) Update(rtt uint32, current uint32) { if rtt > 0x7FFFFFFF { return } info.Lock() defer info.Unlock() // https://tools.ietf.org/html/rfc6298 if info.srtt == 0 { info.srtt = rtt info.variation = rtt / 2 } else { delta := rtt - info.srtt if info.srtt > rtt { delta = info.srtt - rtt } info.variation = (3*info.variation + delta) / 4 info.srtt = (7*info.srtt + rtt) / 8 if info.srtt < info.minRtt { info.srtt = info.minRtt } } var rto uint32 if info.minRtt < 4*info.variation { rto = info.srtt + 4*info.variation } else { rto = info.srtt + info.variation } if rto > 10000 { rto = 10000 } info.rto = rto * 5 / 4 info.updatedTimestamp = current } func (info *RoundTripInfo) Timeout() uint32 { info.RLock() defer info.RUnlock() return info.rto } func (info *RoundTripInfo) SmoothedTime() uint32 { info.RLock() defer info.RUnlock() return info.srtt } type Updater struct { interval int64 shouldContinue func() bool shouldTerminate func() bool updateFunc func() notifier *semaphore.Instance } func NewUpdater(interval uint32, shouldContinue func() bool, shouldTerminate func() bool, updateFunc func()) *Updater { u := &Updater{ interval: int64(time.Duration(interval) * time.Millisecond), shouldContinue: shouldContinue, shouldTerminate: shouldTerminate, updateFunc: updateFunc, notifier: semaphore.New(1), } return u } func (u *Updater) WakeUp() { select { case <-u.notifier.Wait(): go u.run() default: } } func (u *Updater) run() { defer u.notifier.Signal() if u.shouldTerminate() { return } ticker := time.NewTicker(u.Interval()) for u.shouldContinue() { u.updateFunc() <-ticker.C } ticker.Stop() } func (u *Updater) Interval() time.Duration { return time.Duration(atomic.LoadInt64(&u.interval)) } func (u *Updater) SetInterval(d time.Duration) { atomic.StoreInt64(&u.interval, int64(d)) } type ConnMetadata struct { LocalAddr net.Addr RemoteAddr net.Addr Conversation uint16 } // Connection is a KCP connection over UDP. type Connection struct { meta ConnMetadata closer io.Closer rd time.Time wd time.Time // write deadline since int64 dataInput *signal.Notifier dataOutput *signal.Notifier Config *Config state State stateBeginTime uint32 lastIncomingTime uint32 lastPingTime uint32 mss uint32 roundTrip *RoundTripInfo receivingWorker *ReceivingWorker sendingWorker *SendingWorker output SegmentWriter dataUpdater *Updater pingUpdater *Updater } // NewConnection create a new KCP connection between local and remote. func NewConnection(meta ConnMetadata, writer PacketWriter, closer io.Closer, config *Config) *Connection { newError("#", meta.Conversation, " creating connection to ", meta.RemoteAddr).WriteToLog() conn := &Connection{ meta: meta, closer: closer, since: nowMillisec(), dataInput: signal.NewNotifier(), dataOutput: signal.NewNotifier(), Config: config, output: NewRetryableWriter(NewSegmentWriter(writer)), mss: config.GetMTUValue() - uint32(writer.Overhead()) - DataSegmentOverhead, roundTrip: &RoundTripInfo{ rto: 100, minRtt: config.GetTTIValue(), }, } conn.receivingWorker = NewReceivingWorker(conn) conn.sendingWorker = NewSendingWorker(conn) isTerminating := func() bool { return conn.State().Is(StateTerminating, StateTerminated) } isTerminated := func() bool { return conn.State() == StateTerminated } conn.dataUpdater = NewUpdater( config.GetTTIValue(), func() bool { return !isTerminating() && (conn.sendingWorker.UpdateNecessary() || conn.receivingWorker.UpdateNecessary()) }, isTerminating, conn.updateTask) conn.pingUpdater = NewUpdater( 5000, // 5 seconds func() bool { return !isTerminated() }, isTerminated, conn.updateTask) conn.pingUpdater.WakeUp() return conn } func (c *Connection) Elapsed() uint32 { return uint32(nowMillisec() - c.since) } // ReadMultiBuffer implements buf.Reader. func (c *Connection) ReadMultiBuffer() (buf.MultiBuffer, error) { if c == nil { return nil, io.EOF } for { if c.State().Is(StateReadyToClose, StateTerminating, StateTerminated) { return nil, io.EOF } mb := c.receivingWorker.ReadMultiBuffer() if !mb.IsEmpty() { c.dataUpdater.WakeUp() return mb, nil } if c.State() == StatePeerTerminating { return nil, io.EOF } if err := c.waitForDataInput(); err != nil { return nil, err } } } func (c *Connection) waitForDataInput() error { for i := 0; i < 16; i++ { select { case <-c.dataInput.Wait(): return nil default: runtime.Gosched() } } duration := time.Second * 16 if !c.rd.IsZero() { duration = time.Until(c.rd) if duration < 0 { return ErrIOTimeout } } timeout := time.NewTimer(duration) defer timeout.Stop() select { case <-c.dataInput.Wait(): case <-timeout.C: if !c.rd.IsZero() && c.rd.Before(time.Now()) { return ErrIOTimeout } } return nil } // Read implements the Conn Read method. func (c *Connection) Read(b []byte) (int, error) { if c == nil { return 0, io.EOF } for { if c.State().Is(StateReadyToClose, StateTerminating, StateTerminated) { return 0, io.EOF } nBytes := c.receivingWorker.Read(b) if nBytes > 0 { c.dataUpdater.WakeUp() return nBytes, nil } if err := c.waitForDataInput(); err != nil { return 0, err } } } func (c *Connection) waitForDataOutput() error { for i := 0; i < 16; i++ { select { case <-c.dataOutput.Wait(): return nil default: runtime.Gosched() } } duration := time.Second * 16 if !c.wd.IsZero() { duration = time.Until(c.wd) if duration < 0 { return ErrIOTimeout } } timeout := time.NewTimer(duration) defer timeout.Stop() select { case <-c.dataOutput.Wait(): case <-timeout.C: if !c.wd.IsZero() && c.wd.Before(time.Now()) { return ErrIOTimeout } } return nil } // Write implements io.Writer. func (c *Connection) Write(b []byte) (int, error) { reader := bytes.NewReader(b) if err := c.writeMultiBufferInternal(reader); err != nil { return 0, err } return len(b), nil } // WriteMultiBuffer implements buf.Writer. func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error { reader := &buf.MultiBufferContainer{ MultiBuffer: mb, } defer reader.Close() return c.writeMultiBufferInternal(reader) } func (c *Connection) writeMultiBufferInternal(reader io.Reader) error { updatePending := false defer func() { if updatePending { c.dataUpdater.WakeUp() } }() var b *buf.Buffer defer b.Release() for { for { if c == nil || c.State() != StateActive { return io.ErrClosedPipe } if b == nil { b = buf.New() _, err := b.ReadFrom(io.LimitReader(reader, int64(c.mss))) if err != nil { return nil } } if !c.sendingWorker.Push(b) { break } updatePending = true b = nil } if updatePending { c.dataUpdater.WakeUp() updatePending = false } if err := c.waitForDataOutput(); err != nil { return err } } } func (c *Connection) SetState(state State) { current := c.Elapsed() atomic.StoreInt32((*int32)(&c.state), int32(state)) atomic.StoreUint32(&c.stateBeginTime, current) newError("#", c.meta.Conversation, " entering state ", state, " at ", current).AtDebug().WriteToLog() switch state { case StateReadyToClose: c.receivingWorker.CloseRead() case StatePeerClosed: c.sendingWorker.CloseWrite() case StateTerminating: c.receivingWorker.CloseRead() c.sendingWorker.CloseWrite() c.pingUpdater.SetInterval(time.Second) case StatePeerTerminating: c.sendingWorker.CloseWrite() c.pingUpdater.SetInterval(time.Second) case StateTerminated: c.receivingWorker.CloseRead() c.sendingWorker.CloseWrite() c.pingUpdater.SetInterval(time.Second) c.dataUpdater.WakeUp() c.pingUpdater.WakeUp() go c.Terminate() } } // Close closes the connection. func (c *Connection) Close() error { if c == nil { return ErrClosedConnection } c.dataInput.Signal() c.dataOutput.Signal() switch c.State() { case StateReadyToClose, StateTerminating, StateTerminated: return ErrClosedConnection case StateActive: c.SetState(StateReadyToClose) case StatePeerClosed: c.SetState(StateTerminating) case StatePeerTerminating: c.SetState(StateTerminated) } newError("#", c.meta.Conversation, " closing connection to ", c.meta.RemoteAddr).WriteToLog() return nil } // LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it. func (c *Connection) LocalAddr() net.Addr { if c == nil { return nil } return c.meta.LocalAddr } // RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it. func (c *Connection) RemoteAddr() net.Addr { if c == nil { return nil } return c.meta.RemoteAddr } // SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline. func (c *Connection) SetDeadline(t time.Time) error { if err := c.SetReadDeadline(t); err != nil { return err } return c.SetWriteDeadline(t) } // SetReadDeadline implements the Conn SetReadDeadline method. func (c *Connection) SetReadDeadline(t time.Time) error { if c == nil || c.State() != StateActive { return ErrClosedConnection } c.rd = t return nil } // SetWriteDeadline implements the Conn SetWriteDeadline method. func (c *Connection) SetWriteDeadline(t time.Time) error { if c == nil || c.State() != StateActive { return ErrClosedConnection } c.wd = t return nil } // kcp update, input loop func (c *Connection) updateTask() { c.flush() } func (c *Connection) Terminate() { if c == nil { return } newError("#", c.meta.Conversation, " terminating connection to ", c.RemoteAddr()).WriteToLog() //v.SetState(StateTerminated) c.dataInput.Signal() c.dataOutput.Signal() c.closer.Close() c.sendingWorker.Release() c.receivingWorker.Release() } func (c *Connection) HandleOption(opt SegmentOption) { if (opt & SegmentOptionClose) == SegmentOptionClose { c.OnPeerClosed() } } func (c *Connection) OnPeerClosed() { switch c.State() { case StateReadyToClose: c.SetState(StateTerminating) case StateActive: c.SetState(StatePeerClosed) } } // Input when you received a low level packet (eg. UDP packet), call it func (c *Connection) Input(segments []Segment) { current := c.Elapsed() atomic.StoreUint32(&c.lastIncomingTime, current) for _, seg := range segments { if seg.Conversation() != c.meta.Conversation { break } switch seg := seg.(type) { case *DataSegment: c.HandleOption(seg.Option) c.receivingWorker.ProcessSegment(seg) if c.receivingWorker.IsDataAvailable() { c.dataInput.Signal() } c.dataUpdater.WakeUp() case *AckSegment: c.HandleOption(seg.Option) c.sendingWorker.ProcessSegment(current, seg, c.roundTrip.Timeout()) c.dataOutput.Signal() c.dataUpdater.WakeUp() case *CmdOnlySegment: c.HandleOption(seg.Option) if seg.Command() == CommandTerminate { switch c.State() { case StateActive, StatePeerClosed: c.SetState(StatePeerTerminating) case StateReadyToClose: c.SetState(StateTerminating) case StateTerminating: c.SetState(StateTerminated) } } if seg.Option == SegmentOptionClose || seg.Command() == CommandTerminate { c.dataInput.Signal() c.dataOutput.Signal() } c.sendingWorker.ProcessReceivingNext(seg.ReceivingNext) c.receivingWorker.ProcessSendingNext(seg.SendingNext) c.roundTrip.UpdatePeerRTO(seg.PeerRTO, current) seg.Release() default: } } } func (c *Connection) flush() { current := c.Elapsed() if c.State() == StateTerminated { return } if c.State() == StateActive && current-atomic.LoadUint32(&c.lastIncomingTime) >= 30000 { c.Close() } if c.State() == StateReadyToClose && c.sendingWorker.IsEmpty() { c.SetState(StateTerminating) } if c.State() == StateTerminating { newError("#", c.meta.Conversation, " sending terminating cmd.").AtDebug().WriteToLog() c.Ping(current, CommandTerminate) if current-atomic.LoadUint32(&c.stateBeginTime) > 8000 { c.SetState(StateTerminated) } return } if c.State() == StatePeerTerminating && current-atomic.LoadUint32(&c.stateBeginTime) > 4000 { c.SetState(StateTerminating) } if c.State() == StateReadyToClose && current-atomic.LoadUint32(&c.stateBeginTime) > 15000 { c.SetState(StateTerminating) } // flush acknowledges c.receivingWorker.Flush(current) c.sendingWorker.Flush(current) if current-atomic.LoadUint32(&c.lastPingTime) >= 3000 { c.Ping(current, CommandPing) } } func (c *Connection) State() State { return State(atomic.LoadInt32((*int32)(&c.state))) } func (c *Connection) Ping(current uint32, cmd Command) { seg := NewCmdOnlySegment() seg.Conv = c.meta.Conversation seg.Cmd = cmd seg.ReceivingNext = c.receivingWorker.NextNumber() seg.SendingNext = c.sendingWorker.FirstUnacknowledged() seg.PeerRTO = c.roundTrip.Timeout() if c.State() == StateReadyToClose { seg.Option = SegmentOptionClose } c.output.Write(seg) atomic.StoreUint32(&c.lastPingTime, current) seg.Release() }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/segment.go
transport/internet/kcp/segment.go
// +build !confonly package kcp import ( "encoding/binary" "v2ray.com/core/common/buf" ) // Command is a KCP command that indicate the purpose of a Segment. type Command byte const ( // CommandACK indicates an AckSegment. CommandACK Command = 0 // CommandData indicates a DataSegment. CommandData Command = 1 // CommandTerminate indicates that peer terminates the connection. CommandTerminate Command = 2 // CommandPing indicates a ping. CommandPing Command = 3 ) type SegmentOption byte const ( SegmentOptionClose SegmentOption = 1 ) type Segment interface { Release() Conversation() uint16 Command() Command ByteSize() int32 Serialize([]byte) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) } const ( DataSegmentOverhead = 18 ) type DataSegment struct { Conv uint16 Option SegmentOption Timestamp uint32 Number uint32 SendingNext uint32 payload *buf.Buffer timeout uint32 transmit uint32 } func NewDataSegment() *DataSegment { return new(DataSegment) } func (s *DataSegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) { s.Conv = conv s.Option = opt if len(buf) < 15 { return false, nil } s.Timestamp = binary.BigEndian.Uint32(buf) buf = buf[4:] s.Number = binary.BigEndian.Uint32(buf) buf = buf[4:] s.SendingNext = binary.BigEndian.Uint32(buf) buf = buf[4:] dataLen := int(binary.BigEndian.Uint16(buf)) buf = buf[2:] if len(buf) < dataLen { return false, nil } s.Data().Clear() s.Data().Write(buf[:dataLen]) buf = buf[dataLen:] return true, buf } func (s *DataSegment) Conversation() uint16 { return s.Conv } func (*DataSegment) Command() Command { return CommandData } func (s *DataSegment) Detach() *buf.Buffer { r := s.payload s.payload = nil return r } func (s *DataSegment) Data() *buf.Buffer { if s.payload == nil { s.payload = buf.New() } return s.payload } func (s *DataSegment) Serialize(b []byte) { binary.BigEndian.PutUint16(b, s.Conv) b[2] = byte(CommandData) b[3] = byte(s.Option) binary.BigEndian.PutUint32(b[4:], s.Timestamp) binary.BigEndian.PutUint32(b[8:], s.Number) binary.BigEndian.PutUint32(b[12:], s.SendingNext) binary.BigEndian.PutUint16(b[16:], uint16(s.payload.Len())) copy(b[18:], s.payload.Bytes()) } func (s *DataSegment) ByteSize() int32 { return 2 + 1 + 1 + 4 + 4 + 4 + 2 + s.payload.Len() } func (s *DataSegment) Release() { s.payload.Release() s.payload = nil } type AckSegment struct { Conv uint16 Option SegmentOption ReceivingWindow uint32 ReceivingNext uint32 Timestamp uint32 NumberList []uint32 } const ackNumberLimit = 128 func NewAckSegment() *AckSegment { return new(AckSegment) } func (s *AckSegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) { s.Conv = conv s.Option = opt if len(buf) < 13 { return false, nil } s.ReceivingWindow = binary.BigEndian.Uint32(buf) buf = buf[4:] s.ReceivingNext = binary.BigEndian.Uint32(buf) buf = buf[4:] s.Timestamp = binary.BigEndian.Uint32(buf) buf = buf[4:] count := int(buf[0]) buf = buf[1:] if len(buf) < count*4 { return false, nil } for i := 0; i < count; i++ { s.PutNumber(binary.BigEndian.Uint32(buf)) buf = buf[4:] } return true, buf } func (s *AckSegment) Conversation() uint16 { return s.Conv } func (*AckSegment) Command() Command { return CommandACK } func (s *AckSegment) PutTimestamp(timestamp uint32) { if timestamp-s.Timestamp < 0x7FFFFFFF { s.Timestamp = timestamp } } func (s *AckSegment) PutNumber(number uint32) { s.NumberList = append(s.NumberList, number) } func (s *AckSegment) IsFull() bool { return len(s.NumberList) == ackNumberLimit } func (s *AckSegment) IsEmpty() bool { return len(s.NumberList) == 0 } func (s *AckSegment) ByteSize() int32 { return 2 + 1 + 1 + 4 + 4 + 4 + 1 + int32(len(s.NumberList)*4) } func (s *AckSegment) Serialize(b []byte) { binary.BigEndian.PutUint16(b, s.Conv) b[2] = byte(CommandACK) b[3] = byte(s.Option) binary.BigEndian.PutUint32(b[4:], s.ReceivingWindow) binary.BigEndian.PutUint32(b[8:], s.ReceivingNext) binary.BigEndian.PutUint32(b[12:], s.Timestamp) b[16] = byte(len(s.NumberList)) n := 17 for _, number := range s.NumberList { binary.BigEndian.PutUint32(b[n:], number) n += 4 } } func (s *AckSegment) Release() {} type CmdOnlySegment struct { Conv uint16 Cmd Command Option SegmentOption SendingNext uint32 ReceivingNext uint32 PeerRTO uint32 } func NewCmdOnlySegment() *CmdOnlySegment { return new(CmdOnlySegment) } func (s *CmdOnlySegment) parse(conv uint16, cmd Command, opt SegmentOption, buf []byte) (bool, []byte) { s.Conv = conv s.Cmd = cmd s.Option = opt if len(buf) < 12 { return false, nil } s.SendingNext = binary.BigEndian.Uint32(buf) buf = buf[4:] s.ReceivingNext = binary.BigEndian.Uint32(buf) buf = buf[4:] s.PeerRTO = binary.BigEndian.Uint32(buf) buf = buf[4:] return true, buf } func (s *CmdOnlySegment) Conversation() uint16 { return s.Conv } func (s *CmdOnlySegment) Command() Command { return s.Cmd } func (*CmdOnlySegment) ByteSize() int32 { return 2 + 1 + 1 + 4 + 4 + 4 } func (s *CmdOnlySegment) Serialize(b []byte) { binary.BigEndian.PutUint16(b, s.Conv) b[2] = byte(s.Cmd) b[3] = byte(s.Option) binary.BigEndian.PutUint32(b[4:], s.SendingNext) binary.BigEndian.PutUint32(b[8:], s.ReceivingNext) binary.BigEndian.PutUint32(b[12:], s.PeerRTO) } func (*CmdOnlySegment) Release() {} func ReadSegment(buf []byte) (Segment, []byte) { if len(buf) < 4 { return nil, nil } conv := binary.BigEndian.Uint16(buf) buf = buf[2:] cmd := Command(buf[0]) opt := SegmentOption(buf[1]) buf = buf[2:] var seg Segment switch cmd { case CommandData: seg = NewDataSegment() case CommandACK: seg = NewAckSegment() default: seg = NewCmdOnlySegment() } valid, extra := seg.parse(conv, cmd, opt, buf) if !valid { return nil, nil } return seg, extra }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/connection_test.go
transport/internet/kcp/connection_test.go
package kcp_test import ( "io" "testing" "time" "v2ray.com/core/common/buf" . "v2ray.com/core/transport/internet/kcp" ) type NoOpCloser int func (NoOpCloser) Close() error { return nil } func TestConnectionReadTimeout(t *testing.T) { conn := NewConnection(ConnMetadata{Conversation: 1}, &KCPPacketWriter{ Writer: buf.DiscardBytes, }, NoOpCloser(0), &Config{}) conn.SetReadDeadline(time.Now().Add(time.Second)) b := make([]byte, 1024) nBytes, err := conn.Read(b) if nBytes != 0 || err == nil { t.Error("unexpected read: ", nBytes, err) } conn.Terminate() } func TestConnectionInterface(t *testing.T) { _ = (io.Writer)(new(Connection)) _ = (io.Reader)(new(Connection)) _ = (buf.Reader)(new(Connection)) _ = (buf.Writer)(new(Connection)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/io.go
transport/internet/kcp/io.go
// +build !confonly package kcp import ( "crypto/cipher" "crypto/rand" "io" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/transport/internet" ) type PacketReader interface { Read([]byte) []Segment } type PacketWriter interface { Overhead() int io.Writer } type KCPPacketReader struct { Security cipher.AEAD Header internet.PacketHeader } func (r *KCPPacketReader) Read(b []byte) []Segment { if r.Header != nil { if int32(len(b)) <= r.Header.Size() { return nil } b = b[r.Header.Size():] } if r.Security != nil { nonceSize := r.Security.NonceSize() overhead := r.Security.Overhead() if len(b) <= nonceSize+overhead { return nil } out, err := r.Security.Open(b[nonceSize:nonceSize], b[:nonceSize], b[nonceSize:], nil) if err != nil { return nil } b = out } var result []Segment for len(b) > 0 { seg, x := ReadSegment(b) if seg == nil { break } result = append(result, seg) b = x } return result } type KCPPacketWriter struct { Header internet.PacketHeader Security cipher.AEAD Writer io.Writer } func (w *KCPPacketWriter) Overhead() int { overhead := 0 if w.Header != nil { overhead += int(w.Header.Size()) } if w.Security != nil { overhead += w.Security.Overhead() } return overhead } func (w *KCPPacketWriter) Write(b []byte) (int, error) { bb := buf.StackNew() defer bb.Release() if w.Header != nil { w.Header.Serialize(bb.Extend(w.Header.Size())) } if w.Security != nil { nonceSize := w.Security.NonceSize() common.Must2(bb.ReadFullFrom(rand.Reader, int32(nonceSize))) nonce := bb.BytesFrom(int32(-nonceSize)) encrypted := bb.Extend(int32(w.Security.Overhead() + len(b))) w.Security.Seal(encrypted[:0], nonce, b, nil) } else { bb.Write(b) } _, err := w.Writer.Write(bb.Bytes()) return len(b), err }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/xor_amd64.go
transport/internet/kcp/xor_amd64.go
package kcp //go:noescape func xorfwd(x []byte) //go:noescape func xorbkd(x []byte)
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/cryptreal.go
transport/internet/kcp/cryptreal.go
package kcp import ( "crypto/aes" "crypto/cipher" "crypto/sha256" "v2ray.com/core/common" ) func NewAEADAESGCMBasedOnSeed(seed string) cipher.AEAD { HashedSeed := sha256.Sum256([]byte(seed)) aesBlock := common.Must2(aes.NewCipher(HashedSeed[:16])).(cipher.Block) return common.Must2(cipher.NewGCM(aesBlock)).(cipher.AEAD) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/kcp_test.go
transport/internet/kcp/kcp_test.go
package kcp_test import ( "context" "crypto/rand" "io" "testing" "time" "github.com/google/go-cmp/cmp" "golang.org/x/sync/errgroup" "v2ray.com/core/common" "v2ray.com/core/common/errors" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" . "v2ray.com/core/transport/internet/kcp" ) func TestDialAndListen(t *testing.T) { listerner, err := NewListener(context.Background(), net.LocalHostIP, net.Port(0), &internet.MemoryStreamConfig{ ProtocolName: "mkcp", ProtocolSettings: &Config{}, }, func(conn internet.Connection) { go func(c internet.Connection) { payload := make([]byte, 4096) for { nBytes, err := c.Read(payload) if err != nil { break } for idx, b := range payload[:nBytes] { payload[idx] = b ^ 'c' } c.Write(payload[:nBytes]) } c.Close() }(conn) }) common.Must(err) defer listerner.Close() port := net.Port(listerner.Addr().(*net.UDPAddr).Port) var errg errgroup.Group for i := 0; i < 10; i++ { errg.Go(func() error { clientConn, err := DialKCP(context.Background(), net.UDPDestination(net.LocalHostIP, port), &internet.MemoryStreamConfig{ ProtocolName: "mkcp", ProtocolSettings: &Config{}, }) if err != nil { return err } defer clientConn.Close() clientSend := make([]byte, 1024*1024) rand.Read(clientSend) go clientConn.Write(clientSend) clientReceived := make([]byte, 1024*1024) common.Must2(io.ReadFull(clientConn, clientReceived)) clientExpected := make([]byte, 1024*1024) for idx, b := range clientSend { clientExpected[idx] = b ^ 'c' } if r := cmp.Diff(clientReceived, clientExpected); r != "" { return errors.New(r) } return nil }) } if err := errg.Wait(); err != nil { t.Fatal(err) } for i := 0; i < 60 && listerner.ActiveConnections() > 0; i++ { time.Sleep(500 * time.Millisecond) } if v := listerner.ActiveConnections(); v != 0 { t.Error("active connections: ", v) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/config.pb.go
transport/internet/kcp/config.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: transport/internet/kcp/config.proto package kcp import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" serial "v2ray.com/core/common/serial" ) const ( // Verify that this generated code is sufficiently up-to-date. _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) // Verify that runtime/protoimpl is sufficiently up-to-date. _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) // This is a compile-time assertion that a sufficiently up-to-date version // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 // Maximum Transmission Unit, in bytes. type MTU struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` } func (x *MTU) Reset() { *x = MTU{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *MTU) String() string { return protoimpl.X.MessageStringOf(x) } func (*MTU) ProtoMessage() {} func (x *MTU) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use MTU.ProtoReflect.Descriptor instead. func (*MTU) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{0} } func (x *MTU) GetValue() uint32 { if x != nil { return x.Value } return 0 } // Transmission Time Interview, in milli-sec. type TTI struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` } func (x *TTI) Reset() { *x = TTI{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *TTI) String() string { return protoimpl.X.MessageStringOf(x) } func (*TTI) ProtoMessage() {} func (x *TTI) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use TTI.ProtoReflect.Descriptor instead. func (*TTI) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{1} } func (x *TTI) GetValue() uint32 { if x != nil { return x.Value } return 0 } // Uplink capacity, in MB. type UplinkCapacity struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` } func (x *UplinkCapacity) Reset() { *x = UplinkCapacity{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *UplinkCapacity) String() string { return protoimpl.X.MessageStringOf(x) } func (*UplinkCapacity) ProtoMessage() {} func (x *UplinkCapacity) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use UplinkCapacity.ProtoReflect.Descriptor instead. func (*UplinkCapacity) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{2} } func (x *UplinkCapacity) GetValue() uint32 { if x != nil { return x.Value } return 0 } // Downlink capacity, in MB. type DownlinkCapacity struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Value uint32 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"` } func (x *DownlinkCapacity) Reset() { *x = DownlinkCapacity{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *DownlinkCapacity) String() string { return protoimpl.X.MessageStringOf(x) } func (*DownlinkCapacity) ProtoMessage() {} func (x *DownlinkCapacity) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use DownlinkCapacity.ProtoReflect.Descriptor instead. func (*DownlinkCapacity) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{3} } func (x *DownlinkCapacity) GetValue() uint32 { if x != nil { return x.Value } return 0 } type WriteBuffer struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Buffer size in bytes. Size uint32 `protobuf:"varint,1,opt,name=size,proto3" json:"size,omitempty"` } func (x *WriteBuffer) Reset() { *x = WriteBuffer{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *WriteBuffer) String() string { return protoimpl.X.MessageStringOf(x) } func (*WriteBuffer) ProtoMessage() {} func (x *WriteBuffer) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use WriteBuffer.ProtoReflect.Descriptor instead. func (*WriteBuffer) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{4} } func (x *WriteBuffer) GetSize() uint32 { if x != nil { return x.Size } return 0 } type ReadBuffer struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields // Buffer size in bytes. Size uint32 `protobuf:"varint,1,opt,name=size,proto3" json:"size,omitempty"` } func (x *ReadBuffer) Reset() { *x = ReadBuffer{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *ReadBuffer) String() string { return protoimpl.X.MessageStringOf(x) } func (*ReadBuffer) ProtoMessage() {} func (x *ReadBuffer) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use ReadBuffer.ProtoReflect.Descriptor instead. func (*ReadBuffer) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{5} } func (x *ReadBuffer) GetSize() uint32 { if x != nil { return x.Size } return 0 } type ConnectionReuse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"` } func (x *ConnectionReuse) Reset() { *x = ConnectionReuse{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *ConnectionReuse) String() string { return protoimpl.X.MessageStringOf(x) } func (*ConnectionReuse) ProtoMessage() {} func (x *ConnectionReuse) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use ConnectionReuse.ProtoReflect.Descriptor instead. func (*ConnectionReuse) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{6} } func (x *ConnectionReuse) GetEnable() bool { if x != nil { return x.Enable } return false } // Maximum Transmission Unit, in bytes. type EncryptionSeed struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Seed string `protobuf:"bytes,1,opt,name=seed,proto3" json:"seed,omitempty"` } func (x *EncryptionSeed) Reset() { *x = EncryptionSeed{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *EncryptionSeed) String() string { return protoimpl.X.MessageStringOf(x) } func (*EncryptionSeed) ProtoMessage() {} func (x *EncryptionSeed) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use EncryptionSeed.ProtoReflect.Descriptor instead. func (*EncryptionSeed) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{7} } func (x *EncryptionSeed) GetSeed() string { if x != nil { return x.Seed } return "" } type Config struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Mtu *MTU `protobuf:"bytes,1,opt,name=mtu,proto3" json:"mtu,omitempty"` Tti *TTI `protobuf:"bytes,2,opt,name=tti,proto3" json:"tti,omitempty"` UplinkCapacity *UplinkCapacity `protobuf:"bytes,3,opt,name=uplink_capacity,json=uplinkCapacity,proto3" json:"uplink_capacity,omitempty"` DownlinkCapacity *DownlinkCapacity `protobuf:"bytes,4,opt,name=downlink_capacity,json=downlinkCapacity,proto3" json:"downlink_capacity,omitempty"` Congestion bool `protobuf:"varint,5,opt,name=congestion,proto3" json:"congestion,omitempty"` WriteBuffer *WriteBuffer `protobuf:"bytes,6,opt,name=write_buffer,json=writeBuffer,proto3" json:"write_buffer,omitempty"` ReadBuffer *ReadBuffer `protobuf:"bytes,7,opt,name=read_buffer,json=readBuffer,proto3" json:"read_buffer,omitempty"` HeaderConfig *serial.TypedMessage `protobuf:"bytes,8,opt,name=header_config,json=headerConfig,proto3" json:"header_config,omitempty"` Seed *EncryptionSeed `protobuf:"bytes,10,opt,name=seed,proto3" json:"seed,omitempty"` } func (x *Config) Reset() { *x = Config{} if protoimpl.UnsafeEnabled { mi := &file_transport_internet_kcp_config_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } func (x *Config) String() string { return protoimpl.X.MessageStringOf(x) } func (*Config) ProtoMessage() {} func (x *Config) ProtoReflect() protoreflect.Message { mi := &file_transport_internet_kcp_config_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(x) } // Deprecated: Use Config.ProtoReflect.Descriptor instead. func (*Config) Descriptor() ([]byte, []int) { return file_transport_internet_kcp_config_proto_rawDescGZIP(), []int{8} } func (x *Config) GetMtu() *MTU { if x != nil { return x.Mtu } return nil } func (x *Config) GetTti() *TTI { if x != nil { return x.Tti } return nil } func (x *Config) GetUplinkCapacity() *UplinkCapacity { if x != nil { return x.UplinkCapacity } return nil } func (x *Config) GetDownlinkCapacity() *DownlinkCapacity { if x != nil { return x.DownlinkCapacity } return nil } func (x *Config) GetCongestion() bool { if x != nil { return x.Congestion } return false } func (x *Config) GetWriteBuffer() *WriteBuffer { if x != nil { return x.WriteBuffer } return nil } func (x *Config) GetReadBuffer() *ReadBuffer { if x != nil { return x.ReadBuffer } return nil } func (x *Config) GetHeaderConfig() *serial.TypedMessage { if x != nil { return x.HeaderConfig } return nil } func (x *Config) GetSeed() *EncryptionSeed { if x != nil { return x.Seed } return nil } var File_transport_internet_kcp_config_proto protoreflect.FileDescriptor var file_transport_internet_kcp_config_proto_rawDesc = []byte{ 0x0a, 0x23, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x6b, 0x63, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x1a, 0x21, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x64, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1b, 0x0a, 0x03, 0x4d, 0x54, 0x55, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x1b, 0x0a, 0x03, 0x54, 0x54, 0x49, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x26, 0x0a, 0x0e, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x28, 0x0a, 0x10, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x21, 0x0a, 0x0b, 0x57, 0x72, 0x69, 0x74, 0x65, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x22, 0x20, 0x0a, 0x0a, 0x52, 0x65, 0x61, 0x64, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x22, 0x29, 0x0a, 0x0f, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x75, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x24, 0x0a, 0x0e, 0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x65, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x73, 0x65, 0x65, 0x64, 0x22, 0x97, 0x05, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x38, 0x0a, 0x03, 0x6d, 0x74, 0x75, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x2e, 0x4d, 0x54, 0x55, 0x52, 0x03, 0x6d, 0x74, 0x75, 0x12, 0x38, 0x0a, 0x03, 0x74, 0x74, 0x69, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x2e, 0x54, 0x54, 0x49, 0x52, 0x03, 0x74, 0x74, 0x69, 0x12, 0x5a, 0x0a, 0x0f, 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x63, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x31, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x2e, 0x55, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x52, 0x0e, 0x75, 0x70, 0x6c, 0x69, 0x6e, 0x6b, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x12, 0x60, 0x0a, 0x11, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x63, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x33, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x2e, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x52, 0x10, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x43, 0x61, 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x51, 0x0a, 0x0c, 0x77, 0x72, 0x69, 0x74, 0x65, 0x5f, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x2e, 0x57, 0x72, 0x69, 0x74, 0x65, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x52, 0x0b, 0x77, 0x72, 0x69, 0x74, 0x65, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x12, 0x4e, 0x0a, 0x0b, 0x72, 0x65, 0x61, 0x64, 0x5f, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x52, 0x0a, 0x72, 0x65, 0x61, 0x64, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x12, 0x4b, 0x0a, 0x0d, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x0c, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x45, 0x0a, 0x04, 0x73, 0x65, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x31, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x2e, 0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x65, 0x64, 0x52, 0x04, 0x73, 0x65, 0x65, 0x64, 0x4a, 0x04, 0x08, 0x09, 0x10, 0x0a, 0x42, 0x74, 0x0a, 0x25, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x6b, 0x63, 0x70, 0x50, 0x01, 0x5a, 0x25, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x6b, 0x63, 0x70, 0xaa, 0x02, 0x21, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x4b, 0x63, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( file_transport_internet_kcp_config_proto_rawDescOnce sync.Once file_transport_internet_kcp_config_proto_rawDescData = file_transport_internet_kcp_config_proto_rawDesc ) func file_transport_internet_kcp_config_proto_rawDescGZIP() []byte { file_transport_internet_kcp_config_proto_rawDescOnce.Do(func() { file_transport_internet_kcp_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_transport_internet_kcp_config_proto_rawDescData) }) return file_transport_internet_kcp_config_proto_rawDescData } var file_transport_internet_kcp_config_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_transport_internet_kcp_config_proto_goTypes = []interface{}{ (*MTU)(nil), // 0: v2ray.core.transport.internet.kcp.MTU (*TTI)(nil), // 1: v2ray.core.transport.internet.kcp.TTI (*UplinkCapacity)(nil), // 2: v2ray.core.transport.internet.kcp.UplinkCapacity (*DownlinkCapacity)(nil), // 3: v2ray.core.transport.internet.kcp.DownlinkCapacity (*WriteBuffer)(nil), // 4: v2ray.core.transport.internet.kcp.WriteBuffer (*ReadBuffer)(nil), // 5: v2ray.core.transport.internet.kcp.ReadBuffer (*ConnectionReuse)(nil), // 6: v2ray.core.transport.internet.kcp.ConnectionReuse (*EncryptionSeed)(nil), // 7: v2ray.core.transport.internet.kcp.EncryptionSeed (*Config)(nil), // 8: v2ray.core.transport.internet.kcp.Config (*serial.TypedMessage)(nil), // 9: v2ray.core.common.serial.TypedMessage } var file_transport_internet_kcp_config_proto_depIdxs = []int32{ 0, // 0: v2ray.core.transport.internet.kcp.Config.mtu:type_name -> v2ray.core.transport.internet.kcp.MTU 1, // 1: v2ray.core.transport.internet.kcp.Config.tti:type_name -> v2ray.core.transport.internet.kcp.TTI 2, // 2: v2ray.core.transport.internet.kcp.Config.uplink_capacity:type_name -> v2ray.core.transport.internet.kcp.UplinkCapacity 3, // 3: v2ray.core.transport.internet.kcp.Config.downlink_capacity:type_name -> v2ray.core.transport.internet.kcp.DownlinkCapacity 4, // 4: v2ray.core.transport.internet.kcp.Config.write_buffer:type_name -> v2ray.core.transport.internet.kcp.WriteBuffer 5, // 5: v2ray.core.transport.internet.kcp.Config.read_buffer:type_name -> v2ray.core.transport.internet.kcp.ReadBuffer 9, // 6: v2ray.core.transport.internet.kcp.Config.header_config:type_name -> v2ray.core.common.serial.TypedMessage 7, // 7: v2ray.core.transport.internet.kcp.Config.seed:type_name -> v2ray.core.transport.internet.kcp.EncryptionSeed 8, // [8:8] is the sub-list for method output_type 8, // [8:8] is the sub-list for method input_type 8, // [8:8] is the sub-list for extension type_name 8, // [8:8] is the sub-list for extension extendee 0, // [0:8] is the sub-list for field type_name } func init() { file_transport_internet_kcp_config_proto_init() } func file_transport_internet_kcp_config_proto_init() { if File_transport_internet_kcp_config_proto != nil { return } if !protoimpl.UnsafeEnabled { file_transport_internet_kcp_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*MTU); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*TTI); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*UplinkCapacity); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*DownlinkCapacity); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*WriteBuffer); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ReadBuffer); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ConnectionReuse); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*EncryptionSeed); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } file_transport_internet_kcp_config_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Config); i { case 0: return &v.state case 1: return &v.sizeCache case 2: return &v.unknownFields default: return nil } } } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transport_internet_kcp_config_proto_rawDesc, NumEnums: 0, NumMessages: 9, NumExtensions: 0, NumServices: 0, }, GoTypes: file_transport_internet_kcp_config_proto_goTypes, DependencyIndexes: file_transport_internet_kcp_config_proto_depIdxs, MessageInfos: file_transport_internet_kcp_config_proto_msgTypes, }.Build() File_transport_internet_kcp_config_proto = out.File file_transport_internet_kcp_config_proto_rawDesc = nil file_transport_internet_kcp_config_proto_goTypes = nil file_transport_internet_kcp_config_proto_depIdxs = nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/kcp.go
transport/internet/kcp/kcp.go
// Package kcp - A Fast and Reliable ARQ Protocol // // Acknowledgement: // skywind3000@github for inventing the KCP protocol // xtaci@github for translating to Golang package kcp //go:generate go run v2ray.com/core/common/errors/errorgen
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/output.go
transport/internet/kcp/output.go
// +build !confonly package kcp import ( "io" "sync" "v2ray.com/core/common/retry" "v2ray.com/core/common/buf" ) type SegmentWriter interface { Write(seg Segment) error } type SimpleSegmentWriter struct { sync.Mutex buffer *buf.Buffer writer io.Writer } func NewSegmentWriter(writer io.Writer) SegmentWriter { return &SimpleSegmentWriter{ writer: writer, buffer: buf.New(), } } func (w *SimpleSegmentWriter) Write(seg Segment) error { w.Lock() defer w.Unlock() w.buffer.Clear() rawBytes := w.buffer.Extend(seg.ByteSize()) seg.Serialize(rawBytes) _, err := w.writer.Write(w.buffer.Bytes()) return err } type RetryableWriter struct { writer SegmentWriter } func NewRetryableWriter(writer SegmentWriter) SegmentWriter { return &RetryableWriter{ writer: writer, } } func (w *RetryableWriter) Write(seg Segment) error { return retry.Timed(5, 100).On(func() error { return w.writer.Write(seg) }) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/segment_test.go
transport/internet/kcp/segment_test.go
package kcp_test import ( "testing" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" . "v2ray.com/core/transport/internet/kcp" ) func TestBadSegment(t *testing.T) { seg, buf := ReadSegment(nil) if seg != nil { t.Error("non-nil seg") } if len(buf) != 0 { t.Error("buf len: ", len(buf)) } } func TestDataSegment(t *testing.T) { seg := &DataSegment{ Conv: 1, Timestamp: 3, Number: 4, SendingNext: 5, } seg.Data().Write([]byte{'a', 'b', 'c', 'd'}) nBytes := seg.ByteSize() bytes := make([]byte, nBytes) seg.Serialize(bytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*DataSegment) if r := cmp.Diff(seg2, seg, cmpopts.IgnoreUnexported(DataSegment{})); r != "" { t.Error(r) } if r := cmp.Diff(seg2.Data().Bytes(), seg.Data().Bytes()); r != "" { t.Error(r) } } func Test1ByteDataSegment(t *testing.T) { seg := &DataSegment{ Conv: 1, Timestamp: 3, Number: 4, SendingNext: 5, } seg.Data().WriteByte('a') nBytes := seg.ByteSize() bytes := make([]byte, nBytes) seg.Serialize(bytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*DataSegment) if r := cmp.Diff(seg2, seg, cmpopts.IgnoreUnexported(DataSegment{})); r != "" { t.Error(r) } if r := cmp.Diff(seg2.Data().Bytes(), seg.Data().Bytes()); r != "" { t.Error(r) } } func TestACKSegment(t *testing.T) { seg := &AckSegment{ Conv: 1, ReceivingWindow: 2, ReceivingNext: 3, Timestamp: 10, NumberList: []uint32{1, 3, 5, 7, 9}, } nBytes := seg.ByteSize() bytes := make([]byte, nBytes) seg.Serialize(bytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*AckSegment) if r := cmp.Diff(seg2, seg); r != "" { t.Error(r) } } func TestCmdSegment(t *testing.T) { seg := &CmdOnlySegment{ Conv: 1, Cmd: CommandPing, Option: SegmentOptionClose, SendingNext: 11, ReceivingNext: 13, PeerRTO: 15, } nBytes := seg.ByteSize() bytes := make([]byte, nBytes) seg.Serialize(bytes) iseg, _ := ReadSegment(bytes) seg2 := iseg.(*CmdOnlySegment) if r := cmp.Diff(seg2, seg); r != "" { t.Error(r) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/kcp/xor.go
transport/internet/kcp/xor.go
// +build !amd64 package kcp // xorfwd performs XOR forwards in words, x[i] ^= x[i-4], i from 0 to len func xorfwd(x []byte) { for i := 4; i < len(x); i++ { x[i] ^= x[i-4] } } // xorbkd performs XOR backwords in words, x[i] ^= x[i-4], i from len to 0 func xorbkd(x []byte) { for i := len(x) - 1; i >= 4; i-- { x[i] ^= x[i-4] } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/http/hub.go
transport/internet/http/hub.go
// +build !confonly package http import ( "context" "io" "net/http" "strings" "time" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" "v2ray.com/core/common" "v2ray.com/core/common/net" http_proto "v2ray.com/core/common/protocol/http" "v2ray.com/core/common/serial" "v2ray.com/core/common/session" "v2ray.com/core/common/signal/done" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" ) type Listener struct { server *http.Server handler internet.ConnHandler local net.Addr config *Config } func (l *Listener) Addr() net.Addr { return l.local } func (l *Listener) Close() error { return l.server.Close() } type flushWriter struct { w io.Writer d *done.Instance } func (fw flushWriter) Write(p []byte) (n int, err error) { if fw.d.Done() { return 0, io.ErrClosedPipe } n, err = fw.w.Write(p) if f, ok := fw.w.(http.Flusher); ok { f.Flush() } return } func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request) { host := request.Host if !l.config.isValidHost(host) { writer.WriteHeader(404) return } path := l.config.getNormalizedPath() if !strings.HasPrefix(request.URL.Path, path) { writer.WriteHeader(404) return } writer.Header().Set("Cache-Control", "no-store") writer.WriteHeader(200) if f, ok := writer.(http.Flusher); ok { f.Flush() } remoteAddr := l.Addr() dest, err := net.ParseDestination(request.RemoteAddr) if err != nil { newError("failed to parse request remote addr: ", request.RemoteAddr).Base(err).WriteToLog() } else { remoteAddr = &net.TCPAddr{ IP: dest.Address.IP(), Port: int(dest.Port), } } forwardedAddrs := http_proto.ParseXForwardedFor(request.Header) if len(forwardedAddrs) > 0 && forwardedAddrs[0].Family().IsIP() { remoteAddr.(*net.TCPAddr).IP = forwardedAddrs[0].IP() } done := done.New() conn := net.NewConnection( net.ConnectionOutput(request.Body), net.ConnectionInput(flushWriter{w: writer, d: done}), net.ConnectionOnClose(common.ChainedClosable{done, request.Body}), net.ConnectionLocalAddr(l.Addr()), net.ConnectionRemoteAddr(remoteAddr), ) l.handler(conn) <-done.Wait() } func Listen(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, handler internet.ConnHandler) (internet.Listener, error) { httpSettings := streamSettings.ProtocolSettings.(*Config) listener := &Listener{ handler: handler, local: &net.TCPAddr{ IP: address.IP(), Port: int(port), }, config: httpSettings, } var server *http.Server config := tls.ConfigFromStreamSettings(streamSettings) if config == nil { h2s := &http2.Server{} server = &http.Server{ Addr: serial.Concat(address, ":", port), Handler: h2c.NewHandler(listener, h2s), ReadHeaderTimeout: time.Second * 4, } } else { server = &http.Server{ Addr: serial.Concat(address, ":", port), TLSConfig: config.GetTLSConfig(tls.WithNextProto("h2")), Handler: listener, ReadHeaderTimeout: time.Second * 4, } } listener.server = server go func() { tcpListener, err := internet.ListenSystem(ctx, &net.TCPAddr{ IP: address.IP(), Port: int(port), }, streamSettings.SocketSettings) if err != nil { newError("failed to listen on", address, ":", port).Base(err).WriteToLog(session.ExportIDToError(ctx)) return } if config == nil { err = server.Serve(tcpListener) if err != nil { newError("stoping serving H2C").Base(err).WriteToLog(session.ExportIDToError(ctx)) } } else { err = server.ServeTLS(tcpListener, "", "") if err != nil { newError("stoping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx)) } } }() return listener, nil } func init() { common.Must(internet.RegisterTransportListener(protocolName, Listen)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/http/dialer.go
transport/internet/http/dialer.go
// +build !confonly package http import ( "context" gotls "crypto/tls" "net/http" "net/url" "sync" "golang.org/x/net/http2" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" "v2ray.com/core/transport/internet/tls" "v2ray.com/core/transport/pipe" ) var ( globalDialerMap map[net.Destination]*http.Client globalDialerAccess sync.Mutex ) func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config) (*http.Client, error) { globalDialerAccess.Lock() defer globalDialerAccess.Unlock() if globalDialerMap == nil { globalDialerMap = make(map[net.Destination]*http.Client) } if client, found := globalDialerMap[dest]; found { return client, nil } transport := &http2.Transport{ DialTLS: func(network string, addr string, tlsConfig *gotls.Config) (net.Conn, error) { rawHost, rawPort, err := net.SplitHostPort(addr) if err != nil { return nil, err } if len(rawPort) == 0 { rawPort = "443" } port, err := net.PortFromString(rawPort) if err != nil { return nil, err } address := net.ParseAddress(rawHost) pconn, err := internet.DialSystem(context.Background(), net.TCPDestination(address, port), nil) if err != nil { return nil, err } cn := gotls.Client(pconn, tlsConfig) if err := cn.Handshake(); err != nil { return nil, err } if !tlsConfig.InsecureSkipVerify { if err := cn.VerifyHostname(tlsConfig.ServerName); err != nil { return nil, err } } state := cn.ConnectionState() if p := state.NegotiatedProtocol; p != http2.NextProtoTLS { return nil, newError("http2: unexpected ALPN protocol " + p + "; want q" + http2.NextProtoTLS).AtError() } if !state.NegotiatedProtocolIsMutual { return nil, newError("http2: could not negotiate protocol mutually").AtError() } return cn, nil }, TLSClientConfig: tlsSettings.GetTLSConfig(tls.WithDestination(dest)), } client := &http.Client{ Transport: transport, } globalDialerMap[dest] = client return client, nil } // Dial dials a new TCP connection to the given destination. func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { httpSettings := streamSettings.ProtocolSettings.(*Config) tlsConfig := tls.ConfigFromStreamSettings(streamSettings) if tlsConfig == nil { return nil, newError("TLS must be enabled for http transport.").AtWarning() } client, err := getHTTPClient(ctx, dest, tlsConfig) if err != nil { return nil, err } opts := pipe.OptionsFromContext(ctx) preader, pwriter := pipe.New(opts...) breader := &buf.BufferedReader{Reader: preader} request := &http.Request{ Method: "PUT", Host: httpSettings.getRandomHost(), Body: breader, URL: &url.URL{ Scheme: "https", Host: dest.NetAddr(), Path: httpSettings.getNormalizedPath(), }, Proto: "HTTP/2", ProtoMajor: 2, ProtoMinor: 0, Header: make(http.Header), } // Disable any compression method from server. request.Header.Set("Accept-Encoding", "identity") response, err := client.Do(request) if err != nil { return nil, newError("failed to dial to ", dest).Base(err).AtWarning() } if response.StatusCode != 200 { return nil, newError("unexpected status", response.StatusCode).AtWarning() } bwriter := buf.NewBufferedWriter(pwriter) common.Must(bwriter.SetBuffered(false)) return net.NewConnection( net.ConnectionOutput(response.Body), net.ConnectionInput(bwriter), net.ConnectionOnClose(common.ChainedClosable{breader, bwriter, response.Body}), ), nil } func init() { common.Must(internet.RegisterTransportDialer(protocolName, Dial)) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/transport/internet/http/errors.generated.go
transport/internet/http/errors.generated.go
package http import "v2ray.com/core/common/errors" type errPathObjHolder struct{} func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false