diff --git a/app/commander/commander.go b/app/commander/commander.go index 1846648f8..9461e73a3 100644 --- a/app/commander/commander.go +++ b/app/commander/commander.go @@ -100,3 +100,9 @@ func (c *Commander) Close() error { return nil } + +func init() { + common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) { + return NewCommander(ctx, cfg.(*Config)) + })) +} diff --git a/app/commander/init.go b/app/commander/init.go deleted file mode 100644 index 701716ce0..000000000 --- a/app/commander/init.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !confonly - -package commander - -import ( - "context" - - "v2ray.com/core/common" -) - -func init() { - common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) { - return NewCommander(ctx, cfg.(*Config)) - })) -} diff --git a/app/dns/init.go b/app/dns/init.go deleted file mode 100644 index 894ca3e52..000000000 --- a/app/dns/init.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !confonly - -package dns - -import ( - "context" - - "v2ray.com/core/common" -) - -func init() { - common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { - return New(ctx, config.(*Config)) - })) -} diff --git a/app/dns/server.go b/app/dns/server.go index 05e48d69f..68858ad52 100644 --- a/app/dns/server.go +++ b/app/dns/server.go @@ -220,3 +220,9 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err return nil, newError("returning nil for domain ", domain).Base(lastErr) } + +func init() { + common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { + return New(ctx, config.(*Config)) + })) +} diff --git a/transport/internet/kcp/config.go b/transport/internet/kcp/config.go index 2a484d3a7..00a253fcb 100644 --- a/transport/internet/kcp/config.go +++ b/transport/internet/kcp/config.go @@ -3,6 +3,7 @@ package kcp import ( "crypto/cipher" + "v2ray.com/core/common" "v2ray.com/core/transport/internet" ) @@ -96,3 +97,9 @@ func (c *Config) GetReceivingInFlightSize() uint32 { func (c *Config) GetReceivingBufferSize() uint32 { return c.GetReadBufferSize() / c.GetMTUValue() } + +func init() { + common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { + return new(Config) + })) +} diff --git a/transport/internet/kcp/dialer.go b/transport/internet/kcp/dialer.go index 7cde8f074..03df1fbe9 100644 --- a/transport/internet/kcp/dialer.go +++ b/transport/internet/kcp/dialer.go @@ -6,6 +6,7 @@ import ( "io" "sync/atomic" + "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/dice" "v2ray.com/core/common/net" @@ -91,3 +92,7 @@ func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet return iConn, nil } + +func init() { + common.Must(internet.RegisterTransportDialer(protocolName, DialKCP)) +} diff --git a/transport/internet/kcp/init.go b/transport/internet/kcp/init.go deleted file mode 100644 index 70cb51db1..000000000 --- a/transport/internet/kcp/init.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build !confonly - -package kcp - -import ( - "v2ray.com/core/common" - "v2ray.com/core/transport/internet" -) - -func init() { - common.Must(internet.RegisterTransportDialer(protocolName, DialKCP)) -} - -func init() { - common.Must(internet.RegisterTransportListener(protocolName, ListenKCP)) -} - -func init() { - common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { - return new(Config) - })) -} diff --git a/transport/internet/kcp/listener.go b/transport/internet/kcp/listener.go index e52776953..c2dba56cc 100644 --- a/transport/internet/kcp/listener.go +++ b/transport/internet/kcp/listener.go @@ -6,6 +6,7 @@ import ( "crypto/tls" "sync" + "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" @@ -189,3 +190,7 @@ func (w *Writer) Close() error { 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)) +} diff --git a/transport/internet/quic/dialer.go b/transport/internet/quic/dialer.go index 11cc43ed4..5f03a78ca 100644 --- a/transport/internet/quic/dialer.go +++ b/transport/internet/quic/dialer.go @@ -210,3 +210,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me return client.openConnection(destAddr, config, tlsConfig, streamSettings.SocketSettings) } + +func init() { + common.Must(internet.RegisterTransportDialer(protocolName, Dial)) +} diff --git a/transport/internet/quic/hub.go b/transport/internet/quic/hub.go index d380a91dd..3c17ac0ea 100644 --- a/transport/internet/quic/hub.go +++ b/transport/internet/quic/hub.go @@ -4,6 +4,7 @@ import ( "context" "time" + "v2ray.com/core/common" "v2ray.com/core/common/net" "v2ray.com/core/common/protocol/tls/cert" "v2ray.com/core/common/signal/done" @@ -130,3 +131,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti return listener, nil } + +func init() { + common.Must(internet.RegisterTransportListener(protocolName, Listen)) +} diff --git a/transport/internet/quic/init.go b/transport/internet/quic/init.go deleted file mode 100644 index 6665b184e..000000000 --- a/transport/internet/quic/init.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build !confonly - -package quic - -import ( - "v2ray.com/core/common" - "v2ray.com/core/transport/internet" -) - -func init() { - common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { - return new(Config) - })) -} - -func init() { - common.Must(internet.RegisterTransportDialer(protocolName, Dial)) -} - -func init() { - common.Must(internet.RegisterTransportListener(protocolName, Listen)) -} diff --git a/transport/internet/quic/quic.go b/transport/internet/quic/quic.go index 79fc1288c..6de1d6021 100644 --- a/transport/internet/quic/quic.go +++ b/transport/internet/quic/quic.go @@ -1,5 +1,10 @@ package quic +import ( + "v2ray.com/core/common" + "v2ray.com/core/transport/internet" +) + //go:generate errorgen // Here is some modification needs to be done before update quic vendor. @@ -10,3 +15,9 @@ package quic const protocolName = "quic" const internalDomain = "quic.internal.v2ray.com" + +func init() { + common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} { + return new(Config) + })) +}