p2p网络配置

源码样式:

    // For listening from blockchain network.
	P2pListenAddrs []string `toml:"p2p_listen_addrs"`
	// To connect other hosts as a p2p network.
	Bootnodes []string `toml:"bootnodes"`

	ProtocolID string `toml:"protocol_id"`
	// 0: RSA
	// 1: Ed25519
	// 2: Secp256k1
	// 3: ECDSA
	NodeKeyType int `toml:"node_key_type"`

	NodeKeyRandSeed int64 `toml:"node_key_rand_seed"`

	NodeKey string `toml:"node_key"`

	// Only RSA has this param.
	NodeKeyBits int `toml:"node_key_bits"`
	// When use param 'NodeKey', 'NodeKeyFile' will not work.
	NodeKeyFile string `toml:"node_key_file"`
  • P2pListenAddrs: 表示区块链节点监听的P2P协议的地址
  • Bootnodes: 链接P2P网络中的其他区块链节点,用来同步历史区块
  • ProtocolID: P2P网络里自定义的协议名称
  • NodeKeyType: P2P节点的key的加密类型,用来生成p2p地址的 key。目前支持四种加密算法:
    • 0表示RSA
    • 1表示Ed25519
    • 2表示Secp256k1
    • 3表示ECDSA
  • NodeKeyRandSeed: 生成p2p节点的key的种子,用来生成P2P地址的key。当该项不为空时,则无需配置NodeKey了。
  • NodeKey:P2P地址的key,用来生成p2p地址。当NodeKeyRandSeed不为空时,该项可不填。
  • NodeKeyBits: key的比特位,此配置只有RSA这个加密算法才需要。 其他类型的加密算法并不需要配置该参数。
  • NodeKeyFile: 读取p2p地址的key的文件, 只有 NodeKey为空的时候,系统才会读取该配置项。

配置示例:


p2p_listen_addrs = ["/ip4/127.0.0.1/tcp/8887"]

protocol_id = "yu"

node_key_type = 1
node_key_rand_seed = 1