2
0
Эх сурвалжийг харах

Allow to customize default options

Ettore Di Giacinto 4 жил өмнө
parent
commit
c893b02244

+ 2 - 2
pkg/edgevpn/config.go

@@ -43,8 +43,8 @@ type Config struct {
 	NetLinkBootstrap bool
 	NetLinkBootstrap bool
 
 
 	// Handle is a handle consumed by HumanInterfaces to handle received messages
 	// Handle is a handle consumed by HumanInterfaces to handle received messages
-	Handle  func(bool, *hub.Message)
-	Options []libp2p.Option
+	Handle                     func(bool, *hub.Message)
+	AdditionalOptions, Options []libp2p.Option
 }
 }
 
 
 type Handler func(*hub.Message) error
 type Handler func(*hub.Message) error

+ 5 - 1
pkg/edgevpn/connection.go

@@ -58,11 +58,15 @@ func (e *EdgeVPN) genHost(ctx context.Context) (host.Host, error) {
 		libp2p.ConnectionGater(cg),
 		libp2p.ConnectionGater(cg),
 	}
 	}
 
 
+	if len(e.config.Options) != 0 {
+		opts = e.config.Options
+	}
+
 	for _, d := range e.config.ServiceDiscovery {
 	for _, d := range e.config.ServiceDiscovery {
 		opts = append(opts, d.Option(ctx))
 		opts = append(opts, d.Option(ctx))
 	}
 	}
 
 
-	opts = append(opts, e.config.Options...)
+	opts = append(opts, e.config.AdditionalOptions...)
 
 
 	if e.config.Insecure {
 	if e.config.Insecure {
 		opts = append(opts, libp2p.NoSecurity)
 		opts = append(opts, libp2p.NoSecurity)

+ 8 - 0
pkg/edgevpn/options.go

@@ -23,6 +23,7 @@ func IfaceWriter(i *water.Interface) Handler {
 	})
 	})
 }
 }
 
 
+// WithLibp2pOptions Overrides defaults options
 func WithLibp2pOptions(i ...libp2p.Option) func(cfg *Config) error {
 func WithLibp2pOptions(i ...libp2p.Option) func(cfg *Config) error {
 	return func(cfg *Config) error {
 	return func(cfg *Config) error {
 		cfg.Options = append(cfg.Options, i...)
 		cfg.Options = append(cfg.Options, i...)
@@ -30,6 +31,13 @@ func WithLibp2pOptions(i ...libp2p.Option) func(cfg *Config) error {
 	}
 	}
 }
 }
 
 
+func WithLibp2pAdditionalOptions(i ...libp2p.Option) func(cfg *Config) error {
+	return func(cfg *Config) error {
+		cfg.AdditionalOptions = append(cfg.Options, i...)
+		return nil
+	}
+}
+
 func WithInterface(i *water.Interface) func(cfg *Config) error {
 func WithInterface(i *water.Interface) func(cfg *Config) error {
 	return func(cfg *Config) error {
 	return func(cfg *Config) error {
 		cfg.Interface = i
 		cfg.Interface = i