42 lines
1.1 KiB
Go
Raw Normal View History

2020-12-30 14:54:20 +05:30
package networkclientpool
import (
"github.com/projectdiscovery/fastdialer/fastdialer"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
2020-12-30 14:54:20 +05:30
)
var (
normalClient *fastdialer.Dialer
)
// Init initializes the clientpool implementation
2024-04-03 17:50:57 +02:00
func Init(options *types.Options) error {
2021-09-07 17:31:46 +03:00
// Don't create clients if already created in the past.
2020-12-30 14:54:20 +05:30
if normalClient != nil {
return nil
}
normalClient = protocolstate.Dialer
2020-12-30 14:54:20 +05:30
return nil
}
// Configuration contains the custom configuration options for a client
type Configuration struct {
CustomDialer *fastdialer.Dialer
}
2020-12-30 14:54:20 +05:30
// Hash returns the hash of the configuration to allow client pooling
func (c *Configuration) Hash() string {
return ""
}
// Get creates or gets a client for the protocol based on custom configuration
2021-08-23 16:21:18 +03:00
func Get(options *types.Options, configuration *Configuration /*TODO review unused parameters*/) (*fastdialer.Dialer, error) {
if configuration != nil && configuration.CustomDialer != nil {
return configuration.CustomDialer, nil
}
2020-12-30 14:54:20 +05:30
return normalClient, nil
}