@@ -446,12 +446,9 @@ func (cfg *Config) newBasicHost(swrm *swarm.Swarm, eventBus event.Bus) (*bhost.B
446
446
return h , nil
447
447
}
448
448
449
- // NewNode constructs a new libp2p Host from the Config.
450
- //
451
- // This function consumes the config. Do not reuse it (really!).
452
- func (cfg * Config ) NewNode () (host.Host , error ) {
449
+ func (cfg * Config ) validate () error {
453
450
if cfg .EnableAutoRelay && ! cfg .Relay {
454
- return nil , fmt .Errorf ("cannot enable autorelay; relay is not enabled" )
451
+ return fmt .Errorf ("cannot enable autorelay; relay is not enabled" )
455
452
}
456
453
// If possible check that the resource manager conn limit is higher than the
457
454
// limit set in the conn manager.
@@ -462,6 +459,33 @@ func (cfg *Config) NewNode() (host.Host, error) {
462
459
}
463
460
}
464
461
462
+ if len (cfg .PSK ) > 0 && cfg .ShareTCPListener {
463
+ return errors .New ("cannot use shared TCP listener with PSK" )
464
+ }
465
+
466
+ return nil
467
+ }
468
+
469
+ // NewNode constructs a new libp2p Host from the Config.
470
+ //
471
+ // This function consumes the config. Do not reuse it (really!).
472
+ func (cfg * Config ) NewNode () (host.Host , error ) {
473
+
474
+ validateErr := cfg .validate ()
475
+ if validateErr != nil {
476
+ if cfg .ResourceManager != nil {
477
+ cfg .ResourceManager .Close ()
478
+ }
479
+ if cfg .ConnManager != nil {
480
+ cfg .ConnManager .Close ()
481
+ }
482
+ if cfg .Peerstore != nil {
483
+ cfg .Peerstore .Close ()
484
+ }
485
+
486
+ return nil , validateErr
487
+ }
488
+
465
489
if ! cfg .DisableMetrics {
466
490
rcmgr .MustRegisterWith (cfg .PrometheusRegisterer )
467
491
}
0 commit comments