Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod: update the comments in filter directory #586

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/extension/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func SetAuthenticator(name string, fcn func() filter.Authenticator) {
}

// GetAuthenticator finds the Authenticator with @name
// if not found, it will panic
// panic if not found
zouyx marked this conversation as resolved.
Show resolved Hide resolved
func GetAuthenticator(name string) filter.Authenticator {
if authenticators[name] == nil {
panic("authenticator for " + name + " is not existing, make sure you have import the package.")
Expand All @@ -46,7 +46,7 @@ func SetAccesskeyStorages(name string, fcn func() filter.AccessKeyStorage) {
}

// GetAccesskeyStorages finds the storage with the @name.
// If not found, it will panic.
// Panic if not found
func GetAccesskeyStorages(name string) filter.AccessKeyStorage {
if accesskeyStorages[name] == nil {
panic("accesskeyStorages for " + name + " is not existing, make sure you have import the package.")
Expand Down
4 changes: 2 additions & 2 deletions filter/access_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/apache/dubbo-go/protocol"
)

// AccessKeyPair stores the basic attributes for authentication.
type AccessKeyPair struct {
AccessKey string `yaml:"accessKey" json:"accessKey,omitempty" property:"accessKey"`
SecretKey string `yaml:"secretKey" json:"secretKey,omitempty" property:"secretKey"`
Expand All @@ -31,8 +32,7 @@ type AccessKeyPair struct {
Options string `yaml:"options" json:"options,omitempty" property:"options"`
}

// AccessKeyStorage
// This SPI Extension support us to store our AccessKeyPair or load AccessKeyPair from other
// AccessKeyStorage supports us to store our AccessKeyPair or load AccessKeyPair from other
// storage, such as filesystem.
type AccessKeyStorage interface {
GetAccessKeyPair(protocol.Invocation, *common.URL) *AccessKeyPair
Expand Down
9 changes: 4 additions & 5 deletions filter/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import (
"github.com/apache/dubbo-go/protocol"
)

// Authenticator
// Authenticator defines how an Authenticator works.
// Custom Authenticator must be set by calling auth.SetAuthenticator before use.
type Authenticator interface {

// Sign
// give a sign to request
// Sign adds signature to the invocation
Sign(protocol.Invocation, *common.URL) error

// Authenticate
// verify the signature of the request is valid or not
// Authenticate verifies the signature of the request
Authenticate(protocol.Invocation, *common.URL) error
}
4 changes: 3 additions & 1 deletion filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"github.com/apache/dubbo-go/protocol"
)

// Filter
// Filter interface defines the functions of a filter
// Extension - Filter
type Filter interface {
// Invoke is the core function of a filter, it determins the process of the filter
Invoke(context.Context, protocol.Invoker, protocol.Invocation) protocol.Result
// OnResponse updates the results from Invoke and then returns the modified results.
OnResponse(context.Context, protocol.Result, protocol.Invoker, protocol.Invocation) protocol.Result
}
8 changes: 4 additions & 4 deletions filter/filter_impl/active_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ func init() {
extension.SetFilter(active, GetActiveFilter)
}

// ActiveFilter ...
// ActiveFilter tracks the requests status
type ActiveFilter struct {
}

// Invoke ...
// Invoke starts to record the requests status
func (ef *ActiveFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking active filter. %v,%v", invocation.MethodName(), len(invocation.Arguments()))
invocation.(*invocation2.RPCInvocation).SetAttachments(dubboInvokeStartTime, strconv.FormatInt(protocol.CurrentTimeMillis(), 10))
protocol.BeginCount(invoker.GetUrl(), invocation.MethodName())
return invoker.Invoke(ctx, invocation)
}

// OnResponse ...
// OnResponse update the active count base on the request result.
func (ef *ActiveFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
startTime, err := strconv.ParseInt(invocation.(*invocation2.RPCInvocation).AttachmentsByKey(dubboInvokeStartTime, "0"), 10, 64)
if err != nil {
Expand All @@ -64,7 +64,7 @@ func (ef *ActiveFilter) OnResponse(ctx context.Context, result protocol.Result,
return result
}

// GetActiveFilter ...
// GetActiveFilter creates ActiveFilter instance
func GetActiveFilter() filter.Filter {
return &ActiveFilter{}
}
7 changes: 3 additions & 4 deletions filter/filter_impl/auth/accesskey_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ import (
"github.com/apache/dubbo-go/protocol"
)

// DefaultAccesskeyStorage
// The default implementation of AccesskeyStorage
// DefaultAccesskeyStorage is the default implementation of AccesskeyStorage
type DefaultAccesskeyStorage struct {
}

// GetAccessKeyPair
// get AccessKeyPair from url by the key "accessKeyId" and "secretAccessKey"
// GetAccessKeyPair retrieves AccessKeyPair from url by the key "accessKeyId" and "secretAccessKey"
func (storage *DefaultAccesskeyStorage) GetAccessKeyPair(invocation protocol.Invocation, url *common.URL) *filter.AccessKeyPair {
return &filter.AccessKeyPair{
AccessKey: url.GetParam(constant.ACCESS_KEY_ID_KEY, ""),
Expand All @@ -43,6 +41,7 @@ func init() {
extension.SetAccesskeyStorages(constant.DEFAULT_ACCESS_KEY_STORAGE, GetDefaultAccesskeyStorage)
}

// GetDefaultAccesskeyStorage initiates an empty DefaultAccesskeyStorage
func GetDefaultAccesskeyStorage() filter.AccessKeyStorage {
return &DefaultAccesskeyStorage{}
}
5 changes: 3 additions & 2 deletions filter/filter_impl/auth/consumer_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import (
"github.com/apache/dubbo-go/protocol"
)

// ConsumerSignFilter
// This filter is working for signing the request on consumer side
// ConsumerSignFilter signs the request on consumer side
type ConsumerSignFilter struct {
}

func init() {
extension.SetFilter(constant.CONSUMER_SIGN_FILTER, getConsumerSignFilter)
}

// Invoke retrieves the configured Authenticator to add signature to invocation
func (csf *ConsumerSignFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking ConsumerSign filter.")
url := invoker.GetUrl()
Expand All @@ -52,6 +52,7 @@ func (csf *ConsumerSignFilter) Invoke(ctx context.Context, invoker protocol.Invo
return invoker.Invoke(ctx, invocation)
}

// OnResponse dummy process, returns the result directly
func (csf *ConsumerSignFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
Expand Down
10 changes: 4 additions & 6 deletions filter/filter_impl/auth/default_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ func init() {
extension.SetAuthenticator(constant.DEFAULT_AUTHENTICATOR, GetDefaultAuthenticator)
}

// DefaultAuthenticator
// The default implemetation of Authenticator
// DefaultAuthenticator is the default implementation of Authenticator
type DefaultAuthenticator struct {
}

// Sign
// add the signature for the invocation
// Sign adds the signature to the invocation
func (authenticator *DefaultAuthenticator) Sign(invocation protocol.Invocation, url *common.URL) error {
currentTimeMillis := strconv.Itoa(int(time.Now().Unix() * 1000))

Expand Down Expand Up @@ -84,8 +82,7 @@ func getSignature(url *common.URL, invocation protocol.Invocation, secrectKey st
return signature, nil
}

// Authenticate
// This method verifies whether the signature sent by the requester is correct
// Authenticate verifies whether the signature sent by the requester is correct
func (authenticator *DefaultAuthenticator) Authenticate(invocation protocol.Invocation, url *common.URL) error {
accessKeyId := invocation.AttachmentsByKey(constant.AK_KEY, "")

Expand Down Expand Up @@ -122,6 +119,7 @@ func getAccessKeyPair(invocation protocol.Invocation, url *common.URL) (*filter.
}
}

// GetDefaultAuthenticator creates an empty DefaultAuthenticator instance
func GetDefaultAuthenticator() filter.Authenticator {
return &DefaultAuthenticator{}
}
Expand Down
5 changes: 3 additions & 2 deletions filter/filter_impl/auth/provider_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import (
"github.com/apache/dubbo-go/protocol"
)

// ProviderAuthFilter
// This filter is used to verify the correctness of the signature on provider side
// ProviderAuthFilter verifies the correctness of the signature on provider side
type ProviderAuthFilter struct {
}

func init() {
extension.SetFilter(constant.PROVIDER_AUTH_FILTER, getProviderAuthFilter)
}

// Invoke retrieves the configured Authenticator to verify the signature in an invocation
func (paf *ProviderAuthFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking providerAuth filter.")
url := invoker.GetUrl()
Expand All @@ -55,6 +55,7 @@ func (paf *ProviderAuthFilter) Invoke(ctx context.Context, invoker protocol.Invo
return invoker.Invoke(ctx, invocation)
}

// OnResponse dummy process, returns the result directly
func (paf *ProviderAuthFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
Expand Down
5 changes: 3 additions & 2 deletions filter/filter_impl/auth/sign_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"strings"
)

// Sign
// get a signature string with given information, such as metadata or parameters
// Sign gets a signature string with given bytes
func Sign(metadata, key string) string {
return doSign([]byte(metadata), key)
}

// SignWithParams returns a signature with giving params and metadata.
func SignWithParams(params []interface{}, metadata, key string) (string, error) {
if params == nil || len(params) == 0 {
return Sign(metadata, key), nil
Expand Down Expand Up @@ -61,6 +61,7 @@ func doSign(bytes []byte, key string) string {
return base64.URLEncoding.EncodeToString(signature)
}

// IsEmpty verify whether the inputted string is empty
func IsEmpty(s string, allowSpace bool) bool {
if len(s) == 0 {
return true
Expand Down
6 changes: 3 additions & 3 deletions filter/filter_impl/echo_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func init() {
extension.SetFilter(ECHO, GetFilter)
}

// EchoFilter
// EchoFilter health check
// RPCService need a Echo method in consumer, if you want to use EchoFilter
// eg:
// Echo func(ctx context.Context, arg interface{}, rsp *Xxx) error
type EchoFilter struct{}

// Invoke ...
// Invoke response to the callers with its first argument.
func (ef *EchoFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
logger.Infof("invoking echo filter.")
logger.Debugf("%v,%v", invocation.MethodName(), len(invocation.Arguments()))
Expand All @@ -58,7 +58,7 @@ func (ef *EchoFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invo
return invoker.Invoke(ctx, invocation)
}

// OnResponse ...
// OnResponse dummy process, returns the result directly
func (ef *EchoFilter) OnResponse(_ context.Context, result protocol.Result, _ protocol.Invoker,
_ protocol.Invocation) protocol.Result {

Expand Down
9 changes: 4 additions & 5 deletions filter/filter_impl/execute_limit_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ func init() {
extension.SetFilter(name, GetExecuteLimitFilter)
}

// ExecuteLimitFilter will limit the number of in-progress request and it's thread-safe.
/**
* ExecuteLimitFilter
* The filter will limit the number of in-progress request and it's thread-safe.
* example:
* "UserProvider":
* registry: "hangzhouzk"
Expand Down Expand Up @@ -80,7 +79,7 @@ type ExecuteState struct {
concurrentCount int64
}

// Invoke ...
// Invoke judges whether the current processing requests over the threshold
func (ef *ExecuteLimitFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
methodConfigPrefix := "methods." + invocation.MethodName() + "."
ivkURL := invoker.GetUrl()
Expand Down Expand Up @@ -122,7 +121,7 @@ func (ef *ExecuteLimitFilter) Invoke(ctx context.Context, invoker protocol.Invok
return invoker.Invoke(ctx, invocation)
}

// OnResponse ...
// OnResponse dummy process, returns the result directly
func (ef *ExecuteLimitFilter) OnResponse(_ context.Context, result protocol.Result, _ protocol.Invoker, _ protocol.Invocation) protocol.Result {
return result
}
Expand All @@ -138,7 +137,7 @@ func (state *ExecuteState) decrease() {
var executeLimitOnce sync.Once
var executeLimitFilter *ExecuteLimitFilter

// GetExecuteLimitFilter ...
// GetExecuteLimitFilter returns the singleton ExecuteLimitFilter instance
func GetExecuteLimitFilter() filter.Filter {
executeLimitOnce.Do(func() {
executeLimitFilter = &ExecuteLimitFilter{
Expand Down
6 changes: 3 additions & 3 deletions filter/filter_impl/generic_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
// GenericFilter ...
type GenericFilter struct{}

// Invoke ...
// Invoke turns the parameters to map for generic method
func (ef *GenericFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
if invocation.MethodName() == constant.GENERIC && len(invocation.Arguments()) == 3 {
oldArguments := invocation.Arguments()
Expand All @@ -73,13 +73,13 @@ func (ef *GenericFilter) Invoke(ctx context.Context, invoker protocol.Invoker, i
return invoker.Invoke(ctx, invocation)
}

// OnResponse ...
// OnResponse dummy process, returns the result directly
func (ef *GenericFilter) OnResponse(_ context.Context, result protocol.Result, _ protocol.Invoker,
_ protocol.Invocation) protocol.Result {
return result
}

// GetGenericFilter ...
// GetGenericFilter returns GenericFilter instance
func GetGenericFilter() filter.Filter {
return &GenericFilter{}
}
Expand Down
2 changes: 2 additions & 0 deletions filter/filter_impl/graceful_shutdown_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type gracefulShutdownFilter struct {
shutdownConfig *config.ShutdownConfig
}

// Invoke add the requests count and block the new requests if application is closing
zouyx marked this conversation as resolved.
Show resolved Hide resolved
func (gf *gracefulShutdownFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
if gf.rejectNewRequest() {
logger.Info("The application is closing, new request will be rejected.")
Expand All @@ -62,6 +63,7 @@ func (gf *gracefulShutdownFilter) Invoke(ctx context.Context, invoker protocol.I
return invoker.Invoke(ctx, invocation)
}

// OnResponse reduce the number of active processes then return the process result
zouyx marked this conversation as resolved.
Show resolved Hide resolved
func (gf *gracefulShutdownFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
atomic.AddInt32(&gf.activeCount, -1)
// although this isn't thread safe, it won't be a problem if the gf.rejectNewRequest() is true.
Expand Down
Loading