mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-23 06:58:39 +00:00
New config file style
This commit is contained in:
parent
4b636d90bd
commit
377d9dc095
22
common.go
22
common.go
@ -556,12 +556,8 @@ type Config struct {
|
|||||||
MaxTimeDiff time.Duration
|
MaxTimeDiff time.Duration
|
||||||
ShortIds map[[8]byte]bool
|
ShortIds map[[8]byte]bool
|
||||||
|
|
||||||
LimitFbUploadRate float64
|
LimitFallbackUpload LimitFallback
|
||||||
LimitFbUploadBurst int64
|
LimitFallbackDownload LimitFallback
|
||||||
LimitFbUploadAfter int64
|
|
||||||
LimitFbDownloadRate float64
|
|
||||||
LimitFbDownloadBurst int64
|
|
||||||
LimitFbDownloadAfter int64
|
|
||||||
|
|
||||||
// Rand provides the source of entropy for nonces and RSA blinding.
|
// Rand provides the source of entropy for nonces and RSA blinding.
|
||||||
// If Rand is nil, TLS uses the cryptographic random reader in package
|
// If Rand is nil, TLS uses the cryptographic random reader in package
|
||||||
@ -953,6 +949,12 @@ func (c *Config) ticketKeyFromBytes(b [32]byte) (key ticketKey) {
|
|||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LimitFallback struct {
|
||||||
|
BytesPerSec float64
|
||||||
|
BurstBytesPerSec int64
|
||||||
|
AfterBytes int64
|
||||||
|
}
|
||||||
|
|
||||||
// maxSessionTicketLifetime is the maximum allowed lifetime of a TLS 1.3 session
|
// maxSessionTicketLifetime is the maximum allowed lifetime of a TLS 1.3 session
|
||||||
// ticket, and the lifetime we set for all tickets we send.
|
// ticket, and the lifetime we set for all tickets we send.
|
||||||
const maxSessionTicketLifetime = 7 * 24 * time.Hour
|
const maxSessionTicketLifetime = 7 * 24 * time.Hour
|
||||||
@ -977,12 +979,8 @@ func (c *Config) Clone() *Config {
|
|||||||
MaxClientVer: c.MaxClientVer,
|
MaxClientVer: c.MaxClientVer,
|
||||||
MaxTimeDiff: c.MaxTimeDiff,
|
MaxTimeDiff: c.MaxTimeDiff,
|
||||||
ShortIds: c.ShortIds,
|
ShortIds: c.ShortIds,
|
||||||
LimitFbUploadRate: c.LimitFbUploadRate,
|
LimitFallbackUpload: c.LimitFallbackUpload,
|
||||||
LimitFbUploadBurst: c.LimitFbUploadBurst,
|
LimitFallbackDownload: c.LimitFallbackDownload,
|
||||||
LimitFbUploadAfter: c.LimitFbUploadAfter,
|
|
||||||
LimitFbDownloadRate: c.LimitFbDownloadRate,
|
|
||||||
LimitFbDownloadBurst: c.LimitFbDownloadBurst,
|
|
||||||
LimitFbDownloadAfter: c.LimitFbDownloadAfter,
|
|
||||||
Rand: c.Rand,
|
Rand: c.Rand,
|
||||||
Time: c.Time,
|
Time: c.Time,
|
||||||
Certificates: c.Certificates,
|
Certificates: c.Certificates,
|
||||||
|
18
tls.go
18
tls.go
@ -247,14 +247,14 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
if config.Show && hs.clientHello != nil {
|
if config.Show && hs.clientHello != nil {
|
||||||
fmt.Printf("REALITY remoteAddr: %v\tforwarded SNI: %v\n", remoteAddr, hs.clientHello.serverName)
|
fmt.Printf("REALITY remoteAddr: %v\tforwarded SNI: %v\n", remoteAddr, hs.clientHello.serverName)
|
||||||
}
|
}
|
||||||
if config.LimitFbUploadRate == 0 || config.LimitFbUploadBurst == 0 {
|
if config.LimitFallbackUpload.BytesPerSec == 0 || config.LimitFallbackUpload.BurstBytesPerSec == 0 {
|
||||||
io.Copy(target, underlying)
|
io.Copy(target, underlying)
|
||||||
} else {
|
} else {
|
||||||
// Limit upload speed for fallback connection
|
// Limit upload speed for fallback connection
|
||||||
io.Copy(target, &RatelimitedConn{
|
io.Copy(target, &RatelimitedConn{
|
||||||
Conn: underlying,
|
Conn: underlying,
|
||||||
Bucket: ratelimit.NewBucketWithRate(config.LimitFbUploadRate, config.LimitFbUploadBurst),
|
Bucket: ratelimit.NewBucketWithRate(config.LimitFallbackUpload.BytesPerSec, config.LimitFallbackUpload.BurstBytesPerSec),
|
||||||
LimitAfter: config.LimitFbUploadAfter - config.LimitFbUploadBurst,
|
LimitAfter: config.LimitFallbackUpload.AfterBytes - config.LimitFallbackUpload.BurstBytesPerSec,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,28 +387,28 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
if hs.c.conn == conn { // if we processed the Client Hello successfully but the target did not
|
if hs.c.conn == conn { // if we processed the Client Hello successfully but the target did not
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
if config.LimitFbUploadRate == 0 || config.LimitFbUploadBurst == 0 {
|
if config.LimitFallbackUpload.BytesPerSec == 0 || config.LimitFallbackUpload.BurstBytesPerSec == 0 {
|
||||||
io.Copy(target, underlying)
|
io.Copy(target, underlying)
|
||||||
} else {
|
} else {
|
||||||
// Limit upload speed for fallback connection (handshake ok but hello failed)
|
// Limit upload speed for fallback connection (handshake ok but hello failed)
|
||||||
io.Copy(target, &RatelimitedConn{
|
io.Copy(target, &RatelimitedConn{
|
||||||
Conn: underlying,
|
Conn: underlying,
|
||||||
Bucket: ratelimit.NewBucketWithRate(config.LimitFbUploadRate, config.LimitFbUploadBurst),
|
Bucket: ratelimit.NewBucketWithRate(config.LimitFallbackUpload.BytesPerSec, config.LimitFallbackUpload.BurstBytesPerSec),
|
||||||
LimitAfter: config.LimitFbUploadAfter - config.LimitFbUploadBurst,
|
LimitAfter: config.LimitFallbackUpload.AfterBytes - config.LimitFallbackUpload.BurstBytesPerSec,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
waitGroup.Done()
|
waitGroup.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
conn.Write(s2cSaved)
|
conn.Write(s2cSaved)
|
||||||
if config.LimitFbDownloadRate == 0 || config.LimitFbDownloadBurst == 0 {
|
if config.LimitFallbackDownload.BytesPerSec == 0 || config.LimitFallbackDownload.BurstBytesPerSec == 0 {
|
||||||
io.Copy(underlying, target)
|
io.Copy(underlying, target)
|
||||||
} else {
|
} else {
|
||||||
// Limit download speed for fallback connection
|
// Limit download speed for fallback connection
|
||||||
io.Copy(underlying, &RatelimitedConn{
|
io.Copy(underlying, &RatelimitedConn{
|
||||||
Conn: target,
|
Conn: target,
|
||||||
Bucket: ratelimit.NewBucketWithRate(config.LimitFbDownloadRate, config.LimitFbDownloadBurst),
|
Bucket: ratelimit.NewBucketWithRate(config.LimitFallbackDownload.BytesPerSec, config.LimitFallbackDownload.BurstBytesPerSec),
|
||||||
LimitAfter: config.LimitFbDownloadAfter - config.LimitFbDownloadBurst,
|
LimitAfter: config.LimitFallbackDownload.AfterBytes - config.LimitFallbackDownload.BurstBytesPerSec,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Here is bidirectional direct forwarding:
|
// Here is bidirectional direct forwarding:
|
||||||
|
Loading…
Reference in New Issue
Block a user