P2P network

Design objective

FISCO BCOS P2P model, with basic functions for efficient, commonly-used and safe internet communication, supports unicast, multicast and broadcast of blockchain messages, synchronizes nodes status and adapts multiple protocols.

P2P main functions

  • Blockchain node identification

The nodes on blockchain are uniquely identified by node ID, which is used for addressing nodes.

  • Network connection management

It maintains TCP persistent connection between nodes, automatically disconnect and reconnect when connection exceptions occur.

  • Messaging

Messages can be unicasted, multi-casted and broadcasted among nodes on blockchain.

  • Status syncing

Node status can be synchronized on blockchain.

Blockchain node ID

Node ID is generated by the public key of ECC algorithm. Each node owns one and unique ECC key pair, as each node is identified by one and only node ID.

Usually, there files are needed when adding a node to blockchain network:

  • node.key key of node in ECC format

  • node.crt node certificate issued by CA

  • ca.crt CA certificate provided by CA

Besides a unique node ID, nodes can follow Topic for addressing.

Node addressing:

  • Addressing by node ID

To locate a node by its node ID.

  • Addressing by Topic

To locate a group of nodes that follows some Topic.

Network Connection Management

Blockchain nodes will automatically start and maintain TCP permanent connection, or reconnect when there is exception in system and network.

CA certificate will be used to verify nodes during connection.

Connection process

sequenceDiagram participant Node A participant Node B Node A->>Node A: load key and certificate Node B->>Node B: load key and certificate Node A->>Node B: start connection Node B->>Node A: connected Node B->Node A: start SSL shaking Node A->>Node A: acquire public key from certificate as node ID Node B->>Node B: acquire public key from certificate as node ID Node B->Node A: shaking succeeded, start SSL connection

Messaging

Messaging among nodes supports unicast, multicast and broadcast.

  • Unicast, one node sends messages to another node, addressing through node ID.

  • Multicast, one node sends messages to a group of nodes, addressing through Topic.

  • Broadcast, one node sends messages to all nodes.

Unicast process

sequenceDiagram participant Node A participant Node B Node A->>Node A: filter nodes by node ID Node A->>Node B: send message Node B->>Node A: return message

Multicast process

sequenceDiagram participant Node A participant Node B participant Node C participant Node D Node A->>Node A: select Node B and C from Topic 1 Node A->>Node B: send message Node A->>Node C: send message Node B->>Node B: select Node C and D from Topic 2 Node B->>Node C: send message Node B->>Node D: send message Node C->>Node C: select Node D from Topic 3 Node C->>Node D: send message

Broadcast process

sequenceDiagram participant Node A participant Node B participant Node C participant Node D Node A->>Node A: iterate over each node ID Node A->>Node B: send message Node A->>Node C: send message Node A->>Node D: send message Node B->>Node B: iterate over each node ID Node B->>Node C: send message Node B->>Node D: send message Node C->>Node C: iterate over each node ID Node C->>Node D: send message

Status syncing

Every node maintains its own status and broadcasts the Seq regularly to synchronize all nodes.

sequenceDiagram participant Node A participant Node B Node A->Node B: broadcast seq Node A->>Node A: tell whether the seq of Node B has changed Node A->>Node B: seq changed, request status checking Node B->>Node A: return node status Node A->>Node A: update status and seq of Node B