github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/p2p/opts.go (about)

     1  package p2p
     2  
     3  import (
     4  	"encoding/hex"
     5  
     6  	"github.com/ipfs/go-blockservice"
     7  	"github.com/libp2p/go-libp2p/core/crypto"
     8  	hst "github.com/libp2p/go-libp2p/core/host"
     9  	"go.uber.org/fx"
    10  
    11  	"github.com/celestiaorg/celestia-node/libs/fxutil"
    12  )
    13  
    14  // WithP2PKey sets custom Ed25519 private key for p2p networking.
    15  func WithP2PKey(key crypto.PrivKey) fx.Option {
    16  	return fxutil.ReplaceAs(key, new(crypto.PrivKey))
    17  }
    18  
    19  // WithP2PKeyStr sets custom hex encoded Ed25519 private key for p2p networking.
    20  func WithP2PKeyStr(key string) fx.Option {
    21  	decKey, err := hex.DecodeString(key)
    22  	if err != nil {
    23  		return fx.Error(err)
    24  	}
    25  
    26  	privKey, err := crypto.UnmarshalEd25519PrivateKey(decKey)
    27  	if err != nil {
    28  		return fx.Error(err)
    29  	}
    30  
    31  	return fxutil.ReplaceAs(privKey, new(crypto.PrivKey))
    32  }
    33  
    34  // WithHost sets custom Host's data for p2p networking.
    35  func WithHost(hst hst.Host) fx.Option {
    36  	return fxutil.ReplaceAs(hst, new(HostBase))
    37  }
    38  
    39  // WithBlockService allows to replace the default BlockService.
    40  func WithBlockService(bServ blockservice.BlockService) fx.Option {
    41  	return fxutil.ReplaceAs(bServ, new(blockservice.BlockService))
    42  }