mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
common.Must
This commit is contained in:
parent
22fa151391
commit
7c751fcca0
@ -14,3 +14,6 @@ const (
|
||||
type PacketDispatcher interface {
|
||||
DispatchToOutbound(session *proxy.SessionInfo) ray.InboundRay
|
||||
}
|
||||
|
||||
type Inspector interface {
|
||||
}
|
||||
|
@ -25,3 +25,10 @@ func Release(v interface{}) {
|
||||
releasable.Release()
|
||||
}
|
||||
}
|
||||
|
||||
// Must panics if err is not nil.
|
||||
func Must(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/serial"
|
||||
)
|
||||
@ -135,9 +136,9 @@ func (v *AuthenticationReader) EnsureChunk() error {
|
||||
v.buffer.Clear()
|
||||
} else {
|
||||
leftover := v.buffer.Bytes()
|
||||
v.buffer.Reset(func(b []byte) (int, error) {
|
||||
common.Must(v.buffer.Reset(func(b []byte) (int, error) {
|
||||
return copy(b, leftover), nil
|
||||
})
|
||||
}))
|
||||
}
|
||||
err = v.buffer.AppendSupplier(buf.ReadFrom(v.reader))
|
||||
if err == nil {
|
||||
|
@ -1,3 +1,2 @@
|
||||
// Provides common crypto libraries for V2Ray.
|
||||
|
||||
// Package crypto provides common crypto libraries for V2Ray.
|
||||
package crypto
|
||||
|
@ -20,9 +20,6 @@ func NewCryptionReader(stream cipher.Stream, reader io.Reader) *CryptionReader {
|
||||
}
|
||||
|
||||
func (v *CryptionReader) Read(data []byte) (int, error) {
|
||||
if v.reader == nil {
|
||||
return 0, common.ErrObjectReleased
|
||||
}
|
||||
nBytes, err := v.reader.Read(data)
|
||||
if nBytes > 0 {
|
||||
v.stream.XORKeyStream(data[:nBytes], data[:nBytes])
|
||||
@ -40,6 +37,7 @@ type CryptionWriter struct {
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
// NewCryptionWriter creates a new CryptionWriter.
|
||||
func NewCryptionWriter(stream cipher.Stream, writer io.Writer) *CryptionWriter {
|
||||
return &CryptionWriter{
|
||||
stream: stream,
|
||||
@ -47,14 +45,13 @@ func NewCryptionWriter(stream cipher.Stream, writer io.Writer) *CryptionWriter {
|
||||
}
|
||||
}
|
||||
|
||||
// Write implements io.Writer.Write().
|
||||
func (v *CryptionWriter) Write(data []byte) (int, error) {
|
||||
if v.writer == nil {
|
||||
return 0, common.ErrObjectReleased
|
||||
}
|
||||
v.stream.XORKeyStream(data, data)
|
||||
return v.writer.Write(data)
|
||||
}
|
||||
|
||||
// Release implements common.Releasable.Release().
|
||||
func (v *CryptionWriter) Release() {
|
||||
common.Release(v.writer)
|
||||
common.Release(v.stream)
|
||||
|
@ -1,11 +1,12 @@
|
||||
package blackhole
|
||||
|
||||
import (
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Must listed after config.pb.go
|
||||
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory))
|
||||
common.Must(proxy.RegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory)))
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/app/dispatcher"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/log"
|
||||
@ -211,5 +212,5 @@ func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.Inb
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy.MustRegisterInboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory))
|
||||
common.Must(proxy.RegisterInboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory)))
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/app/dns"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/errors"
|
||||
@ -141,5 +142,5 @@ func (v *Factory) Create(space app.Space, config interface{}, meta *proxy.Outbou
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory))
|
||||
common.Must(proxy.RegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory)))
|
||||
}
|
||||
|
@ -20,12 +20,6 @@ func RegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func MustRegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) {
|
||||
if err := RegisterInboundHandlerCreator(name, creator); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory) error {
|
||||
if _, found := outboundFactories[name]; found {
|
||||
return common.ErrDuplicatedName
|
||||
@ -34,12 +28,6 @@ func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory)
|
||||
return nil
|
||||
}
|
||||
|
||||
func MustRegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory) {
|
||||
if err := RegisterOutboundHandlerCreator(name, creator); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func CreateInboundHandler(name string, space app.Space, config interface{}, meta *InboundHandlerMeta) (InboundHandler, error) {
|
||||
creator, found := inboundFactories[name]
|
||||
if !found {
|
||||
|
@ -297,5 +297,5 @@ func (v *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *pro
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy.MustRegisterInboundHandlerCreator(serial.GetMessageType(new(ServerConfig)), new(ServerFactory))
|
||||
common.Must(proxy.RegisterInboundHandlerCreator(serial.GetMessageType(new(ServerConfig)), new(ServerFactory)))
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package shadowsocks
|
||||
|
||||
import (
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Must happen after config is initialized
|
||||
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(ClientConfig)), new(ClientFactory))
|
||||
proxy.MustRegisterInboundHandlerCreator(serial.GetMessageType(new(ServerConfig)), new(ServerFactory))
|
||||
common.Must(proxy.RegisterOutboundHandlerCreator(serial.GetMessageType(new(ClientConfig)), new(ClientFactory)))
|
||||
common.Must(proxy.RegisterInboundHandlerCreator(serial.GetMessageType(new(ServerConfig)), new(ServerFactory)))
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/app/dispatcher"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/bufio"
|
||||
"v2ray.com/core/common/crypto"
|
||||
@ -333,5 +334,5 @@ func (v *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *pro
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy.MustRegisterInboundHandlerCreator(serial.GetMessageType(new(ServerConfig)), new(ServerFactory))
|
||||
common.Must(proxy.RegisterInboundHandlerCreator(serial.GetMessageType(new(ServerConfig)), new(ServerFactory)))
|
||||
}
|
||||
|
@ -271,5 +271,5 @@ func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.Inb
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy.MustRegisterInboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory))
|
||||
common.Must(proxy.RegisterInboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory)))
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/bufio"
|
||||
"v2ray.com/core/common/log"
|
||||
@ -178,5 +179,5 @@ func (v *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.Out
|
||||
}
|
||||
|
||||
func init() {
|
||||
proxy.MustRegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory))
|
||||
common.Must(proxy.RegisterOutboundHandlerCreator(serial.GetMessageType(new(Config)), new(Factory)))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user