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/common/buf/readv_test.go
common/buf/readv_test.go
// +build !wasm package buf_test import ( "crypto/rand" "net" "testing" "github.com/google/go-cmp/cmp" "golang.org/x/sync/errgroup" "v2ray.com/core/common" . "v2ray.com/core/common/buf" "v2ray.com/core/testing/servers/tcp" ) func TestReadvReader(t *testing.T) { tcpServer := &tcp.Server{ MsgProcessor: fu...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/buf/readv_unix.go
common/buf/readv_unix.go
// +build illumos package buf import "golang.org/x/sys/unix" type unixReader struct { iovs [][]byte } func (r *unixReader) Init(bs []*Buffer) { iovs := r.iovs if iovs == nil { iovs = make([][]byte, 0, len(bs)) } for _, b := range bs { iovs = append(iovs, b.v) } r.iovs = iovs } func (r *unixReader) Read(...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/buf/readv_reader.go
common/buf/readv_reader.go
// +build !wasm package buf import ( "io" "runtime" "syscall" "v2ray.com/core/common/platform" ) type allocStrategy struct { current uint32 } func (s *allocStrategy) Current() uint32 { return s.current } func (s *allocStrategy) Adjust(n uint32) { if n >= s.current { s.current *= 4 } else { s.current =...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/buf/multi_buffer_test.go
common/buf/multi_buffer_test.go
package buf_test import ( "bytes" "crypto/rand" "io" "testing" "github.com/google/go-cmp/cmp" "io/ioutil" "os" "v2ray.com/core/common" . "v2ray.com/core/common/buf" ) func TestMultiBufferRead(t *testing.T) { b1 := New() common.Must2(b1.WriteString("ab")) b2 := New() common.Must2(b2.WriteString("cd")) ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/buf/copy_test.go
common/buf/copy_test.go
package buf_test import ( "crypto/rand" "io" "testing" "github.com/golang/mock/gomock" "v2ray.com/core/common/buf" "v2ray.com/core/common/errors" "v2ray.com/core/testing/mocks" ) func TestReadError(t *testing.T) { mockCtl := gomock.NewController(t) defer mockCtl.Finish() mockReader := mocks.NewReader(moc...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/session_test.go
common/mux/session_test.go
package mux_test import ( "testing" . "v2ray.com/core/common/mux" ) func TestSessionManagerAdd(t *testing.T) { m := NewSessionManager() s := m.Allocate() if s.ID != 1 { t.Error("id: ", s.ID) } if m.Size() != 1 { t.Error("size: ", m.Size()) } s = m.Allocate() if s.ID != 2 { t.Error("id: ", s.ID) } ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/errors.generated.go
common/mux/errors.generated.go
package mux 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/common/mux/client.go
common/mux/client.go
package mux import ( "context" "io" "sync" "time" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/errors" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/common/session" "v2ray.com/core/common/signal/done" "v2ray.com/core/common/task" "v2ray.com/cor...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/frame_test.go
common/mux/frame_test.go
package mux_test import ( "testing" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/mux" "v2ray.com/core/common/net" ) func BenchmarkFrameWrite(b *testing.B) { frame := mux.FrameMetadata{ Target: net.TCPDestination(net.DomainAddress("www.v2ray.com"), net.Port(80)), Session...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/writer.go
common/mux/writer.go
package mux import ( "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/common/serial" ) type Writer struct { dest net.Destination writer buf.Writer id uint16 followup bool hasError bool transferTy...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/reader.go
common/mux/reader.go
package mux import ( "io" "v2ray.com/core/common/buf" "v2ray.com/core/common/crypto" "v2ray.com/core/common/serial" ) // PacketReader is an io.Reader that reads whole chunk of Mux frames every time. type PacketReader struct { reader io.Reader eof bool } // NewPacketReader creates a new PacketReader. func N...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/client_test.go
common/mux/client_test.go
package mux_test import ( "context" "testing" "time" "github.com/golang/mock/gomock" "v2ray.com/core/common" "v2ray.com/core/common/errors" "v2ray.com/core/common/mux" "v2ray.com/core/common/net" "v2ray.com/core/common/session" "v2ray.com/core/testing/mocks" "v2ray.com/core/transport" "v2ray.com/core/tran...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/mux_test.go
common/mux/mux_test.go
package mux_test import ( "io" "testing" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/common/mux" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/transport/pipe" ) func readAll(reader buf.Reader) (buf.MultiBuffer, error) {...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/session.go
common/mux/session.go
package mux import ( "sync" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/protocol" ) type SessionManager struct { sync.RWMutex sessions map[uint16]*Session count uint16 closed bool } func NewSessionManager() *SessionManager { return &SessionManager{ count: 0, sessi...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/server.go
common/mux/server.go
package mux import ( "context" "io" "v2ray.com/core" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/errors" "v2ray.com/core/common/log" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/common/session" "v2ray.com/core/features/routing" "v2ray.com/core...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/frame.go
common/mux/frame.go
package mux import ( "encoding/binary" "io" "v2ray.com/core/common" "v2ray.com/core/common/bitmask" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" "v2ray.com/core/common/serial" ) type SessionStatus byte const ( SessionStatusNew SessionStatus = 0x01 SessionS...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/mux/mux.go
common/mux/mux.go
package mux //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/common/retry/errors.generated.go
common/retry/errors.generated.go
package retry 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/common/retry/retry_test.go
common/retry/retry_test.go
package retry_test import ( "testing" "time" "v2ray.com/core/common" "v2ray.com/core/common/errors" . "v2ray.com/core/common/retry" ) var ( errorTestOnly = errors.New("This is a fake error.") ) func TestNoRetry(t *testing.T) { startTime := time.Now().Unix() err := Timed(10, 100000).On(func() error { retur...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/retry/retry.go
common/retry/retry.go
package retry // import "v2ray.com/core/common/retry" //go:generate go run v2ray.com/core/common/errors/errorgen import ( "time" ) var ( ErrRetryFailed = newError("all retry attempts failed") ) // Strategy is a way to retry on a specific function. type Strategy interface { // On performs a retry on a specific fu...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/network.go
common/net/network.go
package net func (n Network) SystemString() string { switch n { case Network_TCP: return "tcp" case Network_UDP: return "udp" default: return "unknown" } } // HasNetwork returns true if the network list has a certain network. func HasNetwork(list []Network, network Network) bool { for _, value := range li...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/destination.pb.go
common/net/destination.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: common/net/destination.proto package net import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobu...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/port.pb.go
common/net/port.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: common/net/port.proto package net import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runti...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/errors.generated.go
common/net/errors.generated.go
package net 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/common/net/port_test.go
common/net/port_test.go
package net_test import ( "testing" . "v2ray.com/core/common/net" ) func TestPortRangeContains(t *testing.T) { portRange := &PortRange{ From: 53, To: 53, } if !portRange.Contains(Port(53)) { t.Error("expected port range containing 53, but actually not") } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/connection.go
common/net/connection.go
// +build !confonly package net import ( "io" "net" "time" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/signal/done" ) type ConnectionOption func(*connection) func ConnectionLocalAddr(a net.Addr) ConnectionOption { return func(c *connection) { c.local = a } } func Connectio...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/net.go
common/net/net.go
// Package net is a drop-in replacement to Golang's net package, with some more functionalities. package net // import "v2ray.com/core/common/net" //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/common/net/port.go
common/net/port.go
package net import ( "encoding/binary" "strconv" ) // Port represents a network port in TCP and UDP protocol. type Port uint16 // PortFromBytes converts a byte array to a Port, assuming bytes are in big endian order. // @unsafe Caller must ensure that the byte array has at least 2 elements. func PortFromBytes(port...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/system.go
common/net/system.go
package net import "net" // DialTCP is an alias of net.DialTCP. var DialTCP = net.DialTCP var DialUDP = net.DialUDP var DialUnix = net.DialUnix var Dial = net.Dial type ListenConfig = net.ListenConfig var Listen = net.Listen var ListenTCP = net.ListenTCP var ListenUDP = net.ListenUDP var ListenUnix = net.ListenUnix...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/destination.go
common/net/destination.go
package net import ( "net" "strings" ) // Destination represents a network destination including address and protocol (tcp / udp). type Destination struct { Address Address Port Port Network Network } // DestinationFromAddr generates a Destination from a net address. func DestinationFromAddr(addr net.Addr) D...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/network.pb.go
common/net/network.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: common/net/network.proto package net import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/ru...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/address_test.go
common/net/address_test.go
package net_test import ( "net" "testing" "github.com/google/go-cmp/cmp" . "v2ray.com/core/common/net" ) func TestAddressProperty(t *testing.T) { type addrProprty struct { IP []byte Domain string Family AddressFamily String string } testCases := []struct { Input Address Output addrProprty ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/destination_test.go
common/net/destination_test.go
package net_test import ( "testing" "github.com/google/go-cmp/cmp" . "v2ray.com/core/common/net" ) func TestDestinationProperty(t *testing.T) { testCases := []struct { Input Destination Network Network String string NetString string }{ { Input: TCPDestination(IPAddress([]byte{1, 2, 3,...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/address.pb.go
common/net/address.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: common/net/address.proto package net import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/ru...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/net/address.go
common/net/address.go
package net import ( "bytes" "net" "strings" ) var ( // LocalHostIP is a constant value for localhost IP in IPv4. LocalHostIP = IPAddress([]byte{127, 0, 0, 1}) // AnyIP is a constant value for any IP in IPv4. AnyIP = IPAddress([]byte{0, 0, 0, 0}) // LocalHostDomain is a constant value for localhost domain. ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/uuid/uuid.go
common/uuid/uuid.go
package uuid // import "v2ray.com/core/common/uuid" import ( "bytes" "crypto/rand" "encoding/hex" "v2ray.com/core/common" "v2ray.com/core/common/errors" ) var ( byteGroups = []int{8, 4, 4, 4, 12} ) type UUID [16]byte // String returns the string representation of this UUID. func (u *UUID) String() string { ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/uuid/uuid_test.go
common/uuid/uuid_test.go
package uuid_test import ( "testing" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" . "v2ray.com/core/common/uuid" ) func TestParseBytes(t *testing.T) { str := "2418d087-648d-4990-86e8-19dca1d006d3" bytes := []byte{0x24, 0x18, 0xd0, 0x87, 0x64, 0x8d, 0x49, 0x90, 0x86, 0xe8, 0x19, 0xdc, 0xa1, 0xd0, 0x0...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/stack/bytes.go
common/stack/bytes.go
package stack // TwoBytes is a [2]byte which is always allocated on stack. // //go:notinheap type TwoBytes [2]byte // EightBytes is a [8]byte which is always allocated on stack. // //go:notinheap type EightBytes [8]byte
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/session/session.go
common/session/session.go
// Package session provides functions for sessions of incoming requests. package session // import "v2ray.com/core/common/session" import ( "context" "math/rand" "v2ray.com/core/common/errors" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol" ) // ID of a session. type ID uint32 // NewID generates a...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/session/context.go
common/session/context.go
package session import "context" type sessionKey int const ( idSessionKey sessionKey = iota inboundSessionKey outboundSessionKey contentSessionKey muxPreferedSessionKey sockoptSessionKey ) // ContextWithID returns a new context with the given ID. func ContextWithID(ctx context.Context, id ID) context.Context ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/serial/typed_message.pb.go
common/serial/typed_message.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: common/serial/typed_message.proto package serial import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/serial/typed_message.go
common/serial/typed_message.go
package serial import ( "errors" "reflect" "github.com/golang/protobuf/proto" ) // ToTypedMessage converts a proto Message into TypedMessage. func ToTypedMessage(message proto.Message) *TypedMessage { if message == nil { return nil } settings, _ := proto.Marshal(message) return &TypedMessage{ Type: GetMe...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/serial/serial.go
common/serial/serial.go
package serial import ( "encoding/binary" "io" ) // ReadUint16 reads first two bytes from the reader, and then coverts them to an uint16 value. func ReadUint16(reader io.Reader) (uint16, error) { var b [2]byte if _, err := io.ReadFull(reader, b[:]); err != nil { return 0, err } return binary.BigEndian.Uint16(...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/serial/string.go
common/serial/string.go
package serial import ( "fmt" "strings" ) // ToString serialize an arbitrary value into string. func ToString(v interface{}) string { if v == nil { return " " } switch value := v.(type) { case string: return value case *string: return *value case fmt.Stringer: return value.String() case error: ret...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/serial/typed_message_test.go
common/serial/typed_message_test.go
package serial_test import ( "testing" . "v2ray.com/core/common/serial" ) func TestGetInstance(t *testing.T) { p, err := GetInstance("") if p != nil { t.Error("expected nil instance, but got ", p) } if err == nil { t.Error("expect non-nil error, but got nil") } } func TestConvertingNilMessage(t *testing....
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/serial/serial_test.go
common/serial/serial_test.go
package serial_test import ( "bytes" "testing" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/serial" ) func TestUint16Serial(t *testing.T) { b := buf.New() defer b.Release() n, err := serial.WriteUint16(b, 10) common.Must(err) if n != 2 { t.E...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/serial/string_test.go
common/serial/string_test.go
package serial_test import ( "errors" "testing" "github.com/google/go-cmp/cmp" . "v2ray.com/core/common/serial" ) func TestToString(t *testing.T) { s := "a" data := []struct { Value interface{} String string }{ {Value: s, String: s}, {Value: &s, String: s}, {Value: errors.New("t"), String: "t"}, ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/log/log_test.go
common/log/log_test.go
package log_test import ( "testing" "github.com/google/go-cmp/cmp" "v2ray.com/core/common/log" "v2ray.com/core/common/net" ) type testLogger struct { value string } func (l *testLogger) Handle(msg log.Message) { l.value = msg.String() } func TestLogRecord(t *testing.T) { var logger testLogger log.Register...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/log/logger_test.go
common/log/logger_test.go
package log_test import ( "io/ioutil" "os" "strings" "testing" "time" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/common/log" ) func TestFileLogger(t *testing.T) { f, err := ioutil.TempFile("", "vtest") common.Must(err) path := f.Name() common.Must(f.Close()) creator, err := C...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/log/log.go
common/log/log.go
package log // import "v2ray.com/core/common/log" import ( "sync" "v2ray.com/core/common/serial" ) // Message is the interface for all log messages. type Message interface { String() string } // Handler is the interface for log handler. type Handler interface { Handle(msg Message) } // GeneralMessage is a gene...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/log/access.go
common/log/access.go
package log import ( "context" "strings" "v2ray.com/core/common/serial" ) type logKey int const ( accessMessageKey logKey = iota ) type AccessStatus string const ( AccessAccepted = AccessStatus("accepted") AccessRejected = AccessStatus("rejected") ) type AccessMessage struct { From interface{} To i...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/log/log.pb.go
common/log/log.pb.go
// Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 // protoc v3.13.0 // source: common/log/log.proto package log import ( proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtim...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/log/logger.go
common/log/logger.go
package log import ( "io" "log" "os" "time" "v2ray.com/core/common/platform" "v2ray.com/core/common/signal/done" "v2ray.com/core/common/signal/semaphore" ) // Writer is the interface for writing logs. type Writer interface { Write(string) error io.Closer } // WriterCreator is a function to create LogWriter...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/timer.go
common/signal/timer.go
package signal import ( "context" "sync" "time" "v2ray.com/core/common" "v2ray.com/core/common/task" ) type ActivityUpdater interface { Update() } type ActivityTimer struct { sync.RWMutex updated chan struct{} checkTask *task.Periodic onTimeout func() } func (t *ActivityTimer) Update() { select { cas...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/notifier.go
common/signal/notifier.go
package signal // Notifier is a utility for notifying changes. The change producer may notify changes multiple time, and the consumer may get notified asynchronously. type Notifier struct { c chan struct{} } // NewNotifier creates a new Notifier. func NewNotifier() *Notifier { return &Notifier{ c: make(chan struc...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/timer_test.go
common/signal/timer_test.go
package signal_test import ( "context" "runtime" "testing" "time" . "v2ray.com/core/common/signal" ) func TestActivityTimer(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) timer := CancelAfterInactivity(ctx, cancel, time.Second*4) time.Sleep(time.Second * 6) if ctx.Err() == nil { t...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/notifier_test.go
common/signal/notifier_test.go
package signal_test import ( "testing" . "v2ray.com/core/common/signal" ) func TestNotifierSignal(t *testing.T) { n := NewNotifier() w := n.Wait() n.Signal() select { case <-w: default: t.Fail() } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/pubsub/pubsub.go
common/signal/pubsub/pubsub.go
package pubsub import ( "errors" "sync" "time" "v2ray.com/core/common" "v2ray.com/core/common/signal/done" "v2ray.com/core/common/task" ) type Subscriber struct { buffer chan interface{} done *done.Instance } func (s *Subscriber) push(msg interface{}) { select { case s.buffer <- msg: default: } } fun...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/pubsub/pubsub_test.go
common/signal/pubsub/pubsub_test.go
package pubsub_test import ( "testing" . "v2ray.com/core/common/signal/pubsub" ) func TestPubsub(t *testing.T) { service := NewService() sub := service.Subscribe("a") service.Publish("a", 1) select { case v := <-sub.Wait(): if v != 1 { t.Error("expected subscribed value 1, but got ", v) } default: ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/semaphore/semaphore.go
common/signal/semaphore/semaphore.go
package semaphore // Instance is an implementation of semaphore. type Instance struct { token chan struct{} } // New create a new Semaphore with n permits. func New(n int) *Instance { s := &Instance{ token: make(chan struct{}, n), } for i := 0; i < n; i++ { s.token <- struct{}{} } return s } // Wait return...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/signal/done/done.go
common/signal/done/done.go
package done import ( "sync" ) // Instance is a utility for notifications of something being done. type Instance struct { access sync.Mutex c chan struct{} closed bool } // New returns a new Done. func New() *Instance { return &Instance{ c: make(chan struct{}), } } // Done returns true if Close() is ca...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/task/periodic.go
common/task/periodic.go
package task import ( "sync" "time" ) // Periodic is a task that runs periodically. type Periodic struct { // Interval of the task being run Interval time.Duration // Execute is the task function Execute func() error access sync.Mutex timer *time.Timer running bool } func (t *Periodic) hasClosed() bool ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/task/periodic_test.go
common/task/periodic_test.go
package task_test import ( "testing" "time" "v2ray.com/core/common" . "v2ray.com/core/common/task" ) func TestPeriodicTaskStop(t *testing.T) { value := 0 task := &Periodic{ Interval: time.Second * 2, Execute: func() error { value++ return nil }, } common.Must(task.Start()) time.Sleep(time.Second...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/task/task_test.go
common/task/task_test.go
package task_test import ( "context" "errors" "strings" "testing" "time" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" . "v2ray.com/core/common/task" ) func TestExecuteParallel(t *testing.T) { err := Run(context.Background(), func() error { time.Sleep(time.Millisecond * 200) return errors....
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/task/task.go
common/task/task.go
package task import ( "context" "v2ray.com/core/common/signal/semaphore" ) // OnSuccess executes g() after f() returns nil. func OnSuccess(f func() error, g func() error) func() error { return func() error { if err := f(); err != nil { return err } return g() } } // Run executes a list of tasks in para...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/task/common.go
common/task/common.go
package task import "v2ray.com/core/common" // Close returns a func() that closes v. func Close(v interface{}) func() error { return func() error { return common.Close(v) } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/dice/dice.go
common/dice/dice.go
// Package dice contains common functions to generate random number. // It also initialize math/rand with the time in seconds at launch time. package dice // import "v2ray.com/core/common/dice" import ( "math/rand" "time" ) // Roll returns a non-negative number between 0 (inclusive) and n (exclusive). func Roll(n i...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/dice/dice_test.go
common/dice/dice_test.go
package dice_test import ( "math/rand" "testing" . "v2ray.com/core/common/dice" ) func BenchmarkRoll1(b *testing.B) { for i := 0; i < b.N; i++ { Roll(1) } } func BenchmarkRoll20(b *testing.B) { for i := 0; i < b.N; i++ { Roll(20) } } func BenchmarkIntn1(b *testing.B) { for i := 0; i < b.N; i++ { rand...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/windows.go
common/platform/windows.go
// +build windows package platform import "path/filepath" func ExpandEnv(s string) string { // TODO return s } func LineSeparator() string { return "\r\n" } func GetToolLocation(file string) string { const name = "v2ray.location.tool" toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(g...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/platform_test.go
common/platform/platform_test.go
package platform_test import ( "os" "path/filepath" "runtime" "testing" "v2ray.com/core/common" . "v2ray.com/core/common/platform" ) func TestNormalizeEnvName(t *testing.T) { cases := []struct { input string output string }{ { input: "a", output: "A", }, { input: "a.a", output: "A_A"...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/others.go
common/platform/others.go
// +build !windows package platform import ( "os" "path/filepath" ) func ExpandEnv(s string) string { return os.ExpandEnv(s) } func LineSeparator() string { return "\n" } func GetToolLocation(file string) string { const name = "v2ray.location.tool" toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(na...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/platform.go
common/platform/platform.go
package platform // import "v2ray.com/core/common/platform" import ( "os" "path/filepath" "strconv" "strings" ) type EnvFlag struct { Name string AltName string } func NewEnvFlag(name string) EnvFlag { return EnvFlag{ Name: name, AltName: NormalizeEnvName(name), } } func (f EnvFlag) GetValue(defau...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/filesystem/file.go
common/platform/filesystem/file.go
package filesystem import ( "io" "os" "v2ray.com/core/common/buf" "v2ray.com/core/common/platform" ) type FileReaderFunc func(path string) (io.ReadCloser, error) var NewFileReader FileReaderFunc = func(path string) (io.ReadCloser, error) { return os.Open(path) } func ReadFile(path string) ([]byte, error) { r...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/ctlcmd/errors.generated.go
common/platform/ctlcmd/errors.generated.go
package ctlcmd 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/common/platform/ctlcmd/attr_windows.go
common/platform/ctlcmd/attr_windows.go
// +build windows package ctlcmd import "syscall" func getSysProcAttr() *syscall.SysProcAttr { return &syscall.SysProcAttr{ HideWindow: true, } }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/ctlcmd/ctlcmd.go
common/platform/ctlcmd/ctlcmd.go
package ctlcmd import ( "io" "os" "os/exec" "strings" "v2ray.com/core/common/buf" "v2ray.com/core/common/platform" ) //go:generate go run v2ray.com/core/common/errors/errorgen func Run(args []string, input io.Reader) (buf.MultiBuffer, error) { v2ctl := platform.GetToolLocation("v2ctl") if _, err := os.Stat(...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/platform/ctlcmd/attr_other.go
common/platform/ctlcmd/attr_other.go
// +build !windows package ctlcmd import "syscall" func getSysProcAttr() *syscall.SysProcAttr { return nil }
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/chunk_test.go
common/crypto/chunk_test.go
package crypto_test import ( "bytes" "io" "testing" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/common/crypto" ) func TestChunkStreamIO(t *testing.T) { cache := bytes.NewBuffer(make([]byte, 0, 8192)) writer := NewChunkStreamWriter(PlainChunkSizeParser{}, cache) reader := NewChunkS...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/aes.go
common/crypto/aes.go
package crypto import ( "crypto/aes" "crypto/cipher" "v2ray.com/core/common" ) // NewAesDecryptionStream creates a new AES encryption stream based on given key and IV. // Caller must ensure the length of key and IV is either 16, 24 or 32 bytes. func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream { r...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/errors.generated.go
common/crypto/errors.generated.go
package crypto 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/common/crypto/chacha20.go
common/crypto/chacha20.go
package crypto import ( "crypto/cipher" "v2ray.com/core/common/crypto/internal" ) // NewChaCha20Stream creates a new Chacha20 encryption/descryption stream based on give key and IV. // Caller must ensure the length of key is 32 bytes, and length of IV is either 8 or 12 bytes. func NewChaCha20Stream(key []byte, iv ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/io.go
common/crypto/io.go
package crypto import ( "crypto/cipher" "io" "v2ray.com/core/common/buf" ) type CryptionReader struct { stream cipher.Stream reader io.Reader } func NewCryptionReader(stream cipher.Stream, reader io.Reader) *CryptionReader { return &CryptionReader{ stream: stream, reader: reader, } } func (r *CryptionRe...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/chacha20_test.go
common/crypto/chacha20_test.go
package crypto_test import ( "crypto/rand" "encoding/hex" "testing" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" . "v2ray.com/core/common/crypto" ) func mustDecodeHex(s string) []byte { b, err := hex.DecodeString(s) common.Must(err) return b } func TestChaCha20Stream(t *testing.T) { var cases =...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/crypto.go
common/crypto/crypto.go
// Package crypto provides common crypto libraries for V2Ray. package crypto // import "v2ray.com/core/common/crypto" //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/common/crypto/benchmark_test.go
common/crypto/benchmark_test.go
package crypto_test import ( "crypto/cipher" "testing" . "v2ray.com/core/common/crypto" ) const benchSize = 1024 * 1024 func benchmarkStream(b *testing.B, c cipher.Stream) { b.SetBytes(benchSize) input := make([]byte, benchSize) output := make([]byte, benchSize) b.ResetTimer() for i := 0; i < b.N; i++ { c...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/auth.go
common/crypto/auth.go
package crypto import ( "crypto/cipher" "io" "math/rand" "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/bytespool" "v2ray.com/core/common/protocol" ) type BytesGenerator func() []byte func GenerateEmptyBytes() BytesGenerator { var b [1]byte return func() []byte { return b[:0] ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/chunk.go
common/crypto/chunk.go
package crypto import ( "encoding/binary" "io" "v2ray.com/core/common" "v2ray.com/core/common/buf" ) // ChunkSizeDecoder is a utility class to decode size value from bytes. type ChunkSizeDecoder interface { SizeBytes() int32 Decode([]byte) (uint16, error) } // ChunkSizeEncoder is a utility class to encode siz...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/auth_test.go
common/crypto/auth_test.go
package crypto_test import ( "bytes" "crypto/aes" "crypto/cipher" "crypto/rand" "io" "testing" "github.com/google/go-cmp/cmp" "v2ray.com/core/common" "v2ray.com/core/common/buf" . "v2ray.com/core/common/crypto" "v2ray.com/core/common/protocol" ) func TestAuthenticationReaderWriter(t *testing.T) { key :=...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/internal/chacha_core_gen.go
common/crypto/internal/chacha_core_gen.go
// +build generate package main import ( "fmt" "log" "os" ) func writeQuarterRound(file *os.File, a, b, c, d int) { add := "x%d+=x%d\n" xor := "x=x%d^x%d\n" rotate := "x%d=(x << %d) | (x >> (32 - %d))\n" fmt.Fprintf(file, add, a, b) fmt.Fprintf(file, xor, d, a) fmt.Fprintf(file, rotate, d, 16, 16) fmt.Fp...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/internal/chacha.go
common/crypto/internal/chacha.go
package internal //go:generate go run chacha_core_gen.go import ( "encoding/binary" ) const ( wordSize = 4 // the size of ChaCha20's words stateSize = 16 // the size of ChaCha20's state, in words blockSize = stateSize * wordSize // the size of ChaCha20's block, in bytes ) t...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/crypto/internal/chacha_core.generated.go
common/crypto/internal/chacha_core.generated.go
package internal import "encoding/binary" func ChaCha20Block(s *[16]uint32, out []byte, rounds int) { var x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 = s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15] for i := 0; i < rounds; i += 2 { var...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/matchers_test.go
common/strmatcher/matchers_test.go
package strmatcher_test import ( "testing" "v2ray.com/core/common" . "v2ray.com/core/common/strmatcher" ) func TestMatcher(t *testing.T) { cases := []struct { pattern string mType Type input string output bool }{ { pattern: "v2ray.com", mType: Domain, input: "www.v2ray.com", outpu...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/domain_matcher_test.go
common/strmatcher/domain_matcher_test.go
package strmatcher_test import ( "reflect" "testing" . "v2ray.com/core/common/strmatcher" ) func TestDomainMatcherGroup(t *testing.T) { g := new(DomainMatcherGroup) g.Add("v2ray.com", 1) g.Add("google.com", 2) g.Add("x.a.com", 3) g.Add("a.b.com", 4) g.Add("c.a.b.com", 5) g.Add("x.y.com", 4) g.Add("x.y.com...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/matchers.go
common/strmatcher/matchers.go
package strmatcher import ( "regexp" "strings" ) type fullMatcher string func (m fullMatcher) Match(s string) bool { return string(m) == s } func (m fullMatcher) String() string { return "full:" + string(m) } type substrMatcher string func (m substrMatcher) Match(s string) bool { return strings.Contains(s, s...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/full_matcher.go
common/strmatcher/full_matcher.go
package strmatcher type FullMatcherGroup struct { matchers map[string][]uint32 } func (g *FullMatcherGroup) Add(domain string, value uint32) { if g.matchers == nil { g.matchers = make(map[string][]uint32) } g.matchers[domain] = append(g.matchers[domain], value) } func (g *FullMatcherGroup) addMatcher(m fullMa...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/domain_matcher.go
common/strmatcher/domain_matcher.go
package strmatcher import "strings" func breakDomain(domain string) []string { return strings.Split(domain, ".") } type node struct { values []uint32 sub map[string]*node } // DomainMatcherGroup is a IndexMatcher for a large set of Domain matchers. // Visible for testing only. type DomainMatcherGroup struct {...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/strmatcher_test.go
common/strmatcher/strmatcher_test.go
package strmatcher_test import ( "reflect" "testing" "v2ray.com/core/common" . "v2ray.com/core/common/strmatcher" ) // See https://github.com/v2fly/v2ray-core/issues/92#issuecomment-673238489 func TestMatcherGroup(t *testing.T) { rules := []struct { Type Type Domain string }{ { Type: Regex, Dom...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/strmatcher.go
common/strmatcher/strmatcher.go
package strmatcher import ( "regexp" ) // Matcher is the interface to determine a string matches a pattern. type Matcher interface { // Match returns true if the given string matches a predefined pattern. Match(string) bool String() string } // Type is the type of the matcher. type Type byte const ( // Full is...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/benchmark_test.go
common/strmatcher/benchmark_test.go
package strmatcher_test import ( "strconv" "testing" "v2ray.com/core/common" . "v2ray.com/core/common/strmatcher" ) func BenchmarkDomainMatcherGroup(b *testing.B) { g := new(DomainMatcherGroup) for i := 1; i <= 1024; i++ { g.Add(strconv.Itoa(i)+".v2ray.com", uint32(i)) } b.ResetTimer() for i := 0; i < b...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false
v2ray/v2ray-core
https://github.com/v2ray/v2ray-core/blob/d80440f3d57b45c829dbf513306f7adf9a0f3f76/common/strmatcher/full_matcher_test.go
common/strmatcher/full_matcher_test.go
package strmatcher_test import ( "reflect" "testing" . "v2ray.com/core/common/strmatcher" ) func TestFullMatcherGroup(t *testing.T) { g := new(FullMatcherGroup) g.Add("v2ray.com", 1) g.Add("google.com", 2) g.Add("x.a.com", 3) g.Add("x.y.com", 4) g.Add("x.y.com", 6) testCases := []struct { Domain string ...
go
MIT
d80440f3d57b45c829dbf513306f7adf9a0f3f76
2026-01-07T08:35:44.381088Z
false