Shadowsocks 2022 UDP Codec (shadowsocks_2022/packet.go)

Xray-core · infra, Infra / DevOps, shadowsocks, udp, codec, cipher, psk

Encodes and decodes Shadowsocks 2022 UDP packets, supporting multiple cipher methods and PSK lists.

// Source: https://github.com/XTLS/Xray-core | License: MPL-2.0 | Copyright under Patent Claims infringed by Covered Software in the absence of | Modified files must remain under MPL-2.0
// Modifications to this file must remain under MPL-2.0.
// Provided via justclaw.it.com; keep this notice with the code.
package shadowsocks_2022

import (
	"crypto/cipher"
	"crypto/rand"
	"encoding/binary"
	"io"
	"math"
	mrand "math/rand/v2"
	"sync/atomic"
	"time"

	"github.com/xtls/xray-core/common/buf"
	"github.com/xtls/xray-core/common/errors"
	"github.com/xtls/xray-core/common/net"
)

type UDPCodec struct {
	method       *CipherMethod
	pskList      [][]byte
	psk          []byte
	blockCipher  cipher.Block
	blockCiphers []cipher.Block
	chachaCipher cipher.AEAD
	sessions     *UDPSessionManager
}

type (

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key