github.com/decred/dcrlnd@v0.7.6/lncfg/rpcmiddleware.go (about)

     1  package lncfg
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  const (
     9  	// defaultRPCMiddlewareTimeout is the time after which a request sent to
    10  	// a gRPC interception middleware times out. This value is chosen very
    11  	// low since in a worst case scenario that time is added to a request's
    12  	// full duration twice (request and response interception) if a
    13  	// middleware is very slow.
    14  	defaultRPCMiddlewareTimeout = 2 * time.Second
    15  )
    16  
    17  // RPCMiddleware holds the configuration for RPC interception middleware.
    18  type RPCMiddleware struct {
    19  	Enable           bool          `long:"enable" description:"Enable the RPC middleware interceptor functionality."`
    20  	InterceptTimeout time.Duration `long:"intercepttimeout" description:"Time after which a RPC middleware intercept request will time out and return an error if it hasn't yet received a response."`
    21  	Mandatory        []string      `long:"addmandatory" description:"Add the named middleware to the list of mandatory middlewares. All RPC requests are blocked/denied if any of the mandatory middlewares is not registered. Can be specified multiple times."`
    22  }
    23  
    24  // Validate checks the values configured for the RPC middleware.
    25  func (r *RPCMiddleware) Validate() error {
    26  	if r.InterceptTimeout < 0 {
    27  		return fmt.Errorf("RPC middleware intercept timeout cannot " +
    28  			"be negative")
    29  	}
    30  
    31  	return nil
    32  }
    33  
    34  // DefaultRPCMiddleware returns the default values for the RPC interception
    35  // middleware configuration.
    36  func DefaultRPCMiddleware() *RPCMiddleware {
    37  	return &RPCMiddleware{
    38  		InterceptTimeout: defaultRPCMiddlewareTimeout,
    39  	}
    40  }