Blockchain communication methods, devices, computer equipment and storage media
By creating communication channels between blockchain nodes, the time delay caused by smart contract verification and gas fees in existing blockchain communication is solved, achieving a more efficient communication process.
Patent Information
- Application Number
- CN202310167002.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-13
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2043-02-13
AI Technical Summary
In existing blockchain communication methods, each communication message needs to be verified through a smart contract and gas fees need to be paid, resulting in excessively long communication time delays and reduced user experience.
By leveraging the channel creation capabilities of blockchain nodes, a second blockchain node can be selected to create a communication channel. This allows terminal devices to communicate directly through the communication channel of the second blockchain node without having to undergo smart contract verification and pay gas fees every time a communication message is sent.
It effectively reduces communication latency and improves user experience.
Smart Images

Figure CN116155973B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of blockchain technology, and more specifically, to a blockchain communication method, apparatus, computer equipment, and storage medium. Background Technology
[0002] Blockchain is a distributed ledger technology maintained by multiple parties, where the data cannot be altered. It features decentralization, joint maintenance, immutability, and cryptographic security.
[0003] Existing decentralized communication uses smart contracts for direct communication. The process of sending communication messages through smart contracts is as follows: users initiate transactions on the blockchain through decentralized applications, carrying communication addresses and communication messages in the transactions. After the smart contract verifies the transaction and publishes it, a communication event is generated. When the terminal device monitors the communication event, if the communication address in the communication event matches the user address of the terminal device, a notification is sent to the user of the terminal device so that the user can view the communication message and initiate a transaction to reply.
[0004] However, because users need to initiate a transaction every time they send a communication message, and each transaction requires paying gas fees to the blockchain, and each communication message needs to be propagated through a smart contract and verified by a consensus mechanism, the communication time delay is very long, which reduces the user experience. Summary of the Invention
[0005] The purpose of this invention is to address the shortcomings of the prior art by providing a blockchain communication method, apparatus, computer equipment, and storage medium, so that terminal devices can communicate through the communication channel of blockchain nodes, thereby reducing communication time delay and improving user experience.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows:
[0007] In a first aspect, embodiments of this application provide a blockchain communication method applied to a first blockchain node among multiple blockchain nodes on a blockchain, the method comprising:
[0008] Receive a channel creation request sent by a first terminal device, wherein the channel creation request includes: the device identifier of the second terminal device;
[0009] Based on the channel creation capabilities of the plurality of blockchain nodes, a second blockchain node is determined from the plurality of blockchain nodes;
[0010] A broadcast channel creation event is provided, the channel creation event including: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier, so that the second terminal device generates a response message corresponding to the channel creation event;
[0011] If the response message indicates that the second terminal device agrees to create a communication channel, a channel creation response event is broadcast so that the second blockchain node creates a communication channel based on the channel creation event and the channel creation response event;
[0012] The system determines that the second blockchain node has successfully created the communication channel and broadcasts a channel creation success event. The channel creation success event includes the channel identifier, so that the first terminal device can send a communication message to the second terminal device through the communication channel.
[0013] Secondly, embodiments of this application also provide a blockchain communication method, applied to a second blockchain node among multiple blockchain nodes on a blockchain, the method comprising:
[0014] The system receives a channel creation event and a channel creation response event broadcast by a first blockchain node. The channel creation event is generated by the first blockchain node based on a channel creation request sent by a first terminal device and the channel creation capabilities of the plurality of blockchain nodes. The channel creation response event is generated by the first blockchain node based on a response message sent by a second terminal device in response to the channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier.
[0015] Determine whether the node identifier in the channel creation event is its own node identifier; if so, create a communication channel based on the channel identifier.
[0016] The first blockchain node is notified that the communication channel has been successfully created, and the first blockchain node sends the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
[0017] Thirdly, embodiments of this application also provide a blockchain communication device, applied to a first blockchain node among multiple blockchain nodes on a blockchain, the device comprising:
[0018] The request receiving module is used to receive a channel creation request sent by the first terminal device, wherein the channel creation request includes: the device identifier of the second terminal device;
[0019] A node determination module is used to determine a second blockchain node from the plurality of blockchain nodes based on the channel creation capabilities of the plurality of blockchain nodes;
[0020] An event broadcasting module is created to broadcast a channel creation event, which includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier, so that the second terminal device generates a response message corresponding to the channel creation event;
[0021] The response event broadcasting module is used to broadcast a channel creation response event if the response message indicates that the second terminal device agrees to create a communication channel, so that the second blockchain node creates a communication channel based on the channel creation event and the channel creation response event;
[0022] The channel identifier sending module is used to determine that the second blockchain node has successfully created the communication channel and broadcast a channel creation success event. The channel creation success event includes the channel identifier, so that the first terminal device can send a communication message to the second terminal device through the communication channel.
[0023] Fourthly, embodiments of this application also provide a blockchain communication device applied to a second blockchain node among multiple blockchain nodes on a blockchain, the device comprising:
[0024] The event receiving module is used to receive channel creation events and channel creation response events broadcast by the first blockchain node. The channel creation event is generated by the first blockchain node based on the channel creation request sent by the first terminal device and the channel creation capabilities of the plurality of blockchain nodes. The channel creation response event is generated based on the response message sent by the second terminal device in response to the channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier.
[0025] The node identifier determination module is used to determine whether the node identifier in the channel creation event is its own node identifier. If so, a communication channel is created based on the channel identifier.
[0026] The response message sending module is used to send a response message indicating successful channel creation to the first blockchain node, so that the first blockchain node sends the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
[0027] Fifthly, embodiments of this application also provide a computer device, including: a processor, a storage medium, and a bus, wherein the storage medium stores program instructions executable by the processor, and when the computer device is running, the processor communicates with the storage medium via the bus, and the processor executes the program instructions to perform the steps of the blockchain communication method as described in any of the first aspects, or to perform the steps of the blockchain communication method as described in any of the second aspects.
[0028] In a sixth aspect, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the blockchain communication method as described in any of the first aspects, or performs the steps of the blockchain communication method as described in any of the second aspects.
[0029] The beneficial effects of this application are:
[0030] This application provides a blockchain communication method, apparatus, computer device, and storage medium. A first blockchain node in the blockchain selects a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node through a smart contract. This allows a first terminal device and a second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience. Attached Figure Description
[0031] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 A schematic diagram of a blockchain communication system provided in an embodiment of this application;
[0033] Figure 2 A flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 1 ;
[0034] Figure 3 A flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 2 ;
[0035] Figure 4 A flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 3 ;
[0036] Figure 5 A flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 4 ;
[0037] Figure 6 A flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 5 ;
[0038] Figure 7 A flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 6 ;
[0039] Figure 8 Schematic diagram of the structure of the blockchain communication device provided in the embodiments of this application Figure 1 ;
[0040] Figure 9 Schematic diagram of the structure of the blockchain communication device provided in the embodiments of this application Figure 2 ;
[0041] Figure 10 A schematic diagram of a computer device provided in an embodiment of this application. Detailed Implementation
[0042] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.
[0043] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0044] Furthermore, the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Additionally, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0045] It should be noted that, where there is no conflict, the features in the embodiments of this application can be combined with each other.
[0046] A blockchain is a distributed database with the participation of multiple distributed nodes. It consists of a series of blocks, each of which can store transaction data between two or more participants. The transaction data is immutable and cannot be forged. Transactions between blockchains include, but are not limited to, the exchange of valuable goods such as services, currencies, and assets.
[0047] To facilitate understanding of the solutions presented in this application, an application system based on this application is provided for reference only. Please refer to it. Figure 1 This is a schematic diagram of the blockchain communication system provided in the embodiments of this application, such as... Figure 1 As shown, the blockchain communication system includes: a blockchain consisting of multiple blockchain nodes 10 and multiple terminal devices 20. The blockchain in this application is a public blockchain, and smart contracts are deployed on the public blockchain. Generally, all blockchain nodes on the public blockchain share the smart contract, and each blockchain node can call the functions of the smart contract.
[0048] Smart contracts provide node management and communication channel management functions. The node management function is used to provide registration, deregistration and update functions for blockchain nodes, while the communication channel management function is used to provide communication channel allocation and release functions for terminal devices.
[0049] In some embodiments, blockchain node 10 needs to register in a smart contract in order to provide communication capabilities for the entire blockchain network. When registering, blockchain node 10 needs to write its node identifier and channel creation capability into the smart contract. The smart contract manages the communication resources of all registered blockchain nodes in a unified manner. When the channel creation capability of a blockchain node changes, such as when the channel creation capability of a blockchain node is expanded, it needs to be updated in the smart contract.
[0050] Blockchain node 10 is a computer device in the blockchain, such as a mobile device, mining machine, and server. The terminal device 20 has a blockchain transaction client installed and running. The blockchain transaction client is a decentralized application (DAPP) that assembles transactions by calling the software development kit (SDK) and sends the transaction request to the first blockchain node in the blockchain. The first blockchain node calls the communication channel management function of the smart contract and allocates a communication channel to the terminal device based on the transaction request and the channel creation capability of blockchain node 10, so as to realize communication between DAPPs on the terminal device through the communication channel.
[0051] The existing decentralized communication based on the aforementioned blockchain communication system uses smart contracts for direct communication. The process of sending communication messages through smart contracts is as follows: the user initiates a transaction on the chain through the DAPP on the first terminal device. The transaction carries the communication address and communication message. After the smart contract verifies the transaction and publishes it, a communication event is generated. After the second terminal device monitors the communication event, if the communication address in the communication event matches the user address of the second terminal device, a notification is sent to the user of the second terminal device so that the user can view the communication message and initiate a transaction to reply.
[0052] However, because users need to initiate a transaction every time they send a communication message, and each transaction requires paying gas fees to the blockchain, and each communication message needs to be propagated through a smart contract and verified by a consensus mechanism, the communication time delay is very long, which reduces the user experience.
[0053] To address the problems existing in the prior art, this application proposes to provide a blockchain communication method. The method involves a first blockchain node in the aforementioned blockchain communication system selecting a second blockchain node to create a communication channel based on the channel creation capability of the blockchain node via a smart contract on the blockchain. This allows the first terminal device to communicate directly with the second terminal device through the communication channel of the second blockchain node, eliminating the need for the smart contract to verify each communication message, thus reducing communication latency and improving user experience.
[0054] Please refer to Figure 2 The following is a flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 1 ,like Figure 2 As shown, the method may include:
[0055] S11: Receive a channel creation request sent by the first terminal device. The channel creation request includes the device identifier of the second terminal device.
[0056] In this embodiment, both the first and second terminal devices are equipped with DApps that execute blockchain transactions. After the user assembles the transaction by calling the SDK through the DApp on the first terminal device, the user initiates a transaction request through the DApp. The transaction request includes the device identifier of the second terminal device and communication messages. In response to the transaction request, the DApp initiates a channel creation request to the blockchain. The channel creation request includes the device identifier of the second terminal device. The blockchain, being a public blockchain, elects a first blockchain node from multiple blockchain nodes. This first blockchain node receives the channel creation request initiated by the DApp.
[0057] S12: Determine the second blockchain node from among multiple blockchain nodes based on the channel creation capabilities of multiple blockchain nodes.
[0058] In this embodiment, the first blockchain node invokes the smart convention, which has node management function and communication channel management function. The node management function is used to manage the blockchain nodes in the blockchain to determine the channel creation capability of each blockchain node in the blockchain. The communication channel management function is used to allocate blockchain nodes that can provide communication channels to the first terminal device in response to the channel creation request of the first terminal device.
[0059] In some embodiments, after receiving a channel creation request, the first blockchain node obtains the channel creation capabilities of multiple blockchain nodes in the blockchain according to the communication channel management function of the smart contract, determines whether there is a blockchain node among the multiple blockchain nodes that can create a communication channel for the first terminal device, and if there is at least one blockchain node that can create a communication channel for the first terminal device, then a blockchain node can be selected from at least one blockchain node as the second blockchain node according to a preset selection rule.
[0060] In one possible implementation, if the smart contract determines that multiple blockchain nodes cannot create a communication channel, the smart contract sends a channel creation failure event to the DAPP on the first terminal device through the first blockchain node. After the DAPP on the first terminal device hears the channel creation failure event, it prompts the user that the communication resources of the blockchain node are insufficient. The user can wait for a period of time and then resend the transaction request through the DAPP on the first terminal device.
[0061] S13: Broadcast channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier, so that the second terminal device generates a response message corresponding to the channel creation event.
[0062] In this embodiment, after the smart contract determines the second blockchain node, it broadcasts a channel creation event, which carries the device identifier of the second terminal device, the node identifier of the second blockchain node, and the pre-assigned channel identifier.
[0063] Multiple terminal device DApps monitor channel creation events in real time. When a channel creation event broadcast by the smart contract is detected, the DApp determines whether the device identifier carried in the channel creation event is the device identifier of its own terminal device. If the DApp of the second terminal device determines that the device identifier carried in the channel creation event is the device identifier of the second terminal device, it generates a notification message to instruct the user's other terminal devices to request to establish a communication connection with the second terminal device. After receiving the notification message, the user can decide whether to agree to establish a communication connection with the first terminal device. If the user agrees, the DApp of the second terminal device generates a response message for the channel creation event and sends the response message to the smart contract.
[0064] In some embodiments, the DAPP on the second terminal device can send response messages to the smart contract through the smart contract's contract interface.
[0065] S14: If the response message indicates that the second terminal device agrees to create a communication channel, a channel creation response event is broadcast so that the second blockchain node can create a communication channel based on the channel creation event and the channel creation response event.
[0066] In this embodiment, after the smart contract receives the response message sent by the second terminal device and determines that the second terminal device agrees to establish a communication connection with the first terminal device based on the response message, the smart contract then broadcasts and publishes a channel creation response event.
[0067] Multiple blockchain nodes in the blockchain listen for channel creation events in real time. When they hear a channel creation event broadcast by a smart contract, they determine whether the node identifier carried in the channel creation event is the node identifier of their own blockchain node. Specifically, after the second blockchain node determines that the node identifier carried in the channel creation event is the node identifier of the second blockchain node, it combines the channel creation response event to determine that the second terminal device agrees to establish a communication connection with the first terminal device. A communication channel is then created based on the channel identifier. This communication channel is a communication channel between the first terminal device, the second blockchain node, and the second terminal device.
[0068] In some embodiments, if a response message indicates that the second terminal device does not agree to establish a communication connection with the first terminal device, the smart contract sends a channel creation failure event to the first terminal device.
[0069] S15: Determine that the second blockchain node has successfully created a communication channel, and broadcast a channel creation success event. The channel creation success event includes a channel identifier, so that the first terminal device can send communication messages to the second terminal device through the communication channel.
[0070] In this embodiment, after the second blockchain node successfully creates a channel, it sends a response message indicating successful channel creation to the smart contract. Based on the response message, the smart contract determines that the second blockchain node has successfully created a communication channel and broadcasts the successful channel creation event. After the DAPP of the first terminal device hears the successful channel creation event, it sends the communication message in the transaction request to the second blockchain node through the communication channel. The second blockchain node then sends the communication message to the DAPP of the second terminal device through the communication channel.
[0071] The blockchain communication method provided in the above embodiments involves a first blockchain node in the blockchain selecting a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node via a smart contract. This allows the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0072] In one possible implementation, prior to determining the second blockchain node from multiple blockchain nodes based on the channel creation capability of multiple blockchain nodes, the method may further include:
[0073] It receives registration requests from multiple blockchain nodes, and the registration requests include: the node identifier of each blockchain node and the channel creation capability of each blockchain node.
[0074] In this embodiment, before providing channel creation services to terminal devices through the blockchain, the blockchain needs to determine the channel creation capabilities of each blockchain node. Through the node management function provided by the smart contract in the blockchain, each blockchain node is registered to the smart contract, so that the smart contract can determine the channel creation capabilities of each blockchain node.
[0075] The blockchain communication method provided in the above embodiments determines the channel creation capability of each blockchain node by receiving registration requests from multiple blockchain nodes. This ensures that a second blockchain node capable of creating a communication channel can be provided to the terminal device based on the channel creation capability of each blockchain node. Communication between the first terminal device and the second terminal device is realized through the communication channel created by the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0076] In one possible implementation, determining the second blockchain node from multiple blockchain nodes based on their channel creation capabilities may include:
[0077] The second blockchain node is determined from multiple blockchain nodes based on the number of channels that can be created and the number of channels that have been created.
[0078] In this embodiment, the channel creation capability of a blockchain node is: the number of communication channels that a blockchain node can support establishing, the number of channels already created being the number of communication channels that the blockchain node has already created for DAPPs on other terminal devices, and the smart contract selects one blockchain node from at least one blockchain node as the second blockchain node according to a preset selection rule based on the number of channels that multiple blockchain nodes can create and the number of channels already created.
[0079] In some embodiments, determining the second blockchain node from multiple blockchain nodes based on the number of channels that can be created and the number of channels that have been created by multiple blockchain nodes may include:
[0080] Based on the number of channels that can be created and the number of channels that have already been created, the blockchain node with the fewest number of channels created and the number of channels that have already been created is identified as the second blockchain node.
[0081] In this embodiment, each blockchain node has limited communication resources and a limited number of channels that can be created. Therefore, when providing communication channels for the DAPP of the terminal device, it is necessary to determine whether the blockchain node still has communication channels available, that is, to determine whether the number of channels created by each blockchain node exceeds the number of channels that can be created. At least one blockchain node whose number of created channels does not exceed the number of channels that can be created is determined from multiple blockchain nodes. Then, in order to ensure a balanced allocation of communication resources among the blockchain nodes, the blockchain node with the fewest created channels is selected from at least one blockchain node as the second blockchain node.
[0082] The blockchain communication method provided in the above embodiments selects the second blockchain node with the fewest created channels from multiple blockchain nodes based on the number of channels that can be created and the data of channels already created. The second blockchain node provides channel creation services to the first terminal device, so that the first terminal device can communicate with the second terminal device through the communication channel created by the second blockchain node. This eliminates the need for the first and second terminal devices to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication time latency and improving user experience.
[0083] Please refer to Figure 3 The following is a flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 2 ,like Figure 3 As shown, the method may further include:
[0084] S21: Receive the encryption key of the first terminal device sent by the first terminal device. The encryption key is obtained by the first terminal device encrypting the message key based on the public key of the second terminal device.
[0085] In this embodiment, the first terminal device and the second terminal device communicate directly through a communication channel created by the second blockchain node. Since there is no need for verification by a smart contract, the communication messages need to be encrypted by the DAPP of the first terminal device to ensure the security of the communication. In order to read the communication messages, the second terminal device needs to decrypt the encrypted communication messages.
[0086] In some embodiments, a symmetric encryption algorithm means that the message sender and the message receiver use the same key to encrypt and decrypt the message respectively, while an asymmetric encryption algorithm means that the message sender and the message receiver use different keys to encrypt and decrypt the message respectively. Since asymmetric encryption algorithms can only encrypt simple strings and cannot encrypt text content, this embodiment uses a symmetric encryption algorithm to encrypt the communication message using the message key to obtain a ciphertext message, and then uses an asymmetric encryption algorithm to encrypt the message key to obtain an encryption key.
[0087] In one possible implementation, since the first terminal device needs to communicate with the second terminal device, the public key of the second terminal device can be used to encrypt the message key to obtain an encryption key. Only the second terminal device can use the private key corresponding to the public key to decrypt the encryption key to obtain the message key, and then use the decrypted message key to decrypt the ciphertext message to obtain the communication message. Even if other terminal devices receive the ciphertext message, they cannot decrypt the encryption key because they do not have the private key corresponding to the public key, and therefore cannot obtain the message key used to decrypt the ciphertext message.
[0088] After the DAPP of the first terminal device encrypts the message key to obtain the encryption key, it sends the encryption key to the blockchain. The first terminal device can send the encryption key along with the channel creation request when sending the channel creation request to the first blockchain node, or it can send the encryption key separately to the first blockchain node.
[0089] S22: Broadcast the encryption key so that the second terminal device can obtain the encryption key.
[0090] In this embodiment, after receiving the encryption key, the first blockchain node broadcasts the encryption key so that multiple terminal devices can receive it. Since the encryption key is obtained by encrypting the message key using the public key of the second terminal device, only the private key of the second terminal device can decrypt the encryption key to obtain the message key. Even if other terminal devices hear the encryption key, they cannot decrypt it to obtain the message key.
[0091] The blockchain communication method provided in the above embodiments broadcasts the encryption key used by the first terminal device to encrypt the communication message to the second terminal device, so that the second terminal device can use its private key to decrypt the encryption key to obtain the message key, and use the message key to decrypt the ciphertext message, thereby ensuring the security of communication between the first terminal device and the second terminal device using the communication channel.
[0092] Please refer to Figure 4 The following is a flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 3 ,like Figure 4 As shown, the method may further include:
[0093] S31: Receive the channel release notification sent by the second blockchain node.
[0094] The channel release notification is generated when the second blockchain node does not receive a response message from the first terminal device or the second terminal device for the connection detection message within a preset time.
[0095] In this embodiment, in order to ensure the normal use of the communication channel and not waste the communication resources of the second blockchain node, the second blockchain node needs to continuously perform heartbeat detection with the first terminal device and the second terminal device. The heartbeat detection is used to detect whether the communication parties maintain a connection. The second blockchain node sends connection detection messages to the first terminal device and the second terminal device and determines whether it receives response messages from the first terminal device and the second terminal device in response to the connection detection messages within a preset time, so as to determine whether the second blockchain node maintains a heartbeat with the first terminal device and the second terminal device.
[0096] If the second blockchain node does not receive a response message from the first terminal device or the second terminal device for the connection detection message within a preset time, it determines that the communication channel is not in normal use. The second blockchain node releases the communication channel and sends a channel release notification to the blockchain in the form of a transaction to notify the smart contract that the communication channel corresponding to the channel identifier has been released.
[0097] S32: Verify the channel release notification.
[0098] In this embodiment, after receiving the channel release notification, the smart contract verifies the channel release notification. The verification includes: determining whether the communication channel has been successfully released, and determining whether the communication channel released by the channel release notification is the communication channel of the second blockchain node. When it is determined that the communication channel has been successfully released and the communication channel released by the channel release notification is the communication channel of the second blockchain node, the channel release notification verification is determined to be successful.
[0099] S33: If the verification passes, broadcast the channel release event so that the first terminal device and the second terminal device determine that the communication channel corresponding to the channel identifier is released.
[0100] In this embodiment, if the smart contract determines that the channel release notification has been verified, it broadcasts a channel release event. The channel release event includes a channel identifier. After receiving the channel release event, the first terminal device and the second terminal device determine that the communication channel corresponding to the channel identifier has been released and communication messages can no longer be sent through the communication channel. In this case, if the first terminal device and the second terminal device need to communicate with each other, they need to recreate the communication channel through the smart contract.
[0101] The blockchain communication method provided in the above embodiments, after verifying the channel release notification sent by the second blockchain node, notifies the first terminal device and the second terminal device that the communication channel has been released, thus avoiding the waste of the blockchain node's communication resources.
[0102] Based on the above embodiments, this application also provides a blockchain communication method applied to a second blockchain node.
[0103] Please refer to Figure 5 The following is a flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 4 ,like Figure 5 As shown, the method may include:
[0104] S41: Receive the channel creation event and channel creation response event broadcast by the first blockchain node.
[0105] Among them, the channel creation event is generated by the first blockchain node based on the channel creation request sent by the first terminal device and the channel creation capabilities of multiple blockchain nodes, and the channel creation response event is generated by the first blockchain node based on the response message sent by the second terminal device in response to the channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier.
[0106] In this embodiment, the first blockchain node receives a channel creation request sent by the first terminal device. The first blockchain node calls Smart Saving to obtain the channel creation capabilities of multiple blockchain nodes in the blockchain, selects a second blockchain node from the multiple blockchain nodes according to the channel creation capabilities of the multiple blockchain nodes, and broadcasts the channel creation event.
[0107] After multiple terminal devices detect a channel creation event, they determine whether the device identifier carried in the channel creation event is their own device identifier. Among them, the second terminal device, after confirming that the device identifier in the channel creation event is its own device identifier, sends a notification message to the user. This notification message is used to instruct the user that the first terminal device requests to establish a communication connection with the second terminal device. After receiving the notification message, the user can decide whether to agree to establish a communication connection with the first terminal device. If the user agrees, the second terminal device's DAPP generates a response message for the channel creation event and sends the response message to the smart contract.
[0108] After the smart contract receives the response message from the second terminal device and determines that the second terminal device agrees to establish a communication connection with the first terminal device based on the response message, the smart contract then broadcasts and publishes a channel creation response event.
[0109] S42: Determine whether the node identifier in the channel creation event is the same as its own node identifier. If so, create a communication channel based on the channel identifier.
[0110] In this embodiment, multiple blockchain nodes in the blockchain monitor channel creation events in real time. When a channel creation event broadcast by a smart contract is detected, the node identifier carried in the channel creation event is determined to be the node identifier of its own blockchain node. Specifically, after the second blockchain node determines that the node identifier carried in the channel creation event is the node identifier of the second blockchain node, it combines the channel creation response event to determine that the second terminal device agrees to establish a communication connection with the first terminal device. A communication channel is then created based on the channel identifier. This communication channel is a communication channel between the first terminal device, the second blockchain node, and the second terminal device.
[0111] S43: Notify the first blockchain node that the communication channel has been successfully created, and cause the first blockchain node to send the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
[0112] In this embodiment, after the second blockchain node successfully creates a communication channel, it sends a response message indicating successful channel creation to the smart contract. Based on the response message, the smart contract determines that the second blockchain node has successfully created the communication channel and broadcasts the successful channel creation event. After the DAPP of the first terminal device hears the successful channel creation event, it sends the communication message in the transaction request to the second blockchain node through the communication channel. The second blockchain node then sends the communication message to the DAPP of the second terminal device through the communication channel.
[0113] The blockchain communication method provided in the above embodiments involves a first blockchain node in the blockchain selecting a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node via a smart contract. This allows the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0114] Please refer to Figure 6 The following is a flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 5 ,like Figure 6 As shown, the method may further include:
[0115] S51: Receive a ciphertext message sent by the first terminal device. The ciphertext message is a message obtained by the first terminal device encrypting the communication message according to the message key.
[0116] In this embodiment, after the second blockchain node successfully provides a communication channel to the first terminal device and the second terminal device, the first terminal device and the second terminal device can communicate through the communication channel. During the communication process, the DAPP of the first terminal device encrypts the communication message to obtain a ciphertext message, and sends the ciphertext message to the second blockchain node through the communication channel.
[0117] In this process, the DAPP of the first terminal device encrypts the communication message using a preset message key to obtain a ciphertext message, and uses the public key of the second terminal device to encrypt the message key to obtain an encryption key. The encryption key can be sent when the DAPP of the first terminal device sends a channel creation request to the first blockchain node, and the first blockchain node broadcasts the encryption key to the second terminal device through the channel creation event.
[0118] S52: Send a ciphertext message to the second terminal device through the communication channel, so that the second terminal device can decrypt the encryption key of the first terminal device obtained in advance according to the public key to obtain the message key, and then decrypt the ciphertext message according to the message key.
[0119] In this embodiment, the second blockchain node sends the encrypted message to the second terminal device through the communication channel. The second terminal device decrypts the encryption key pre-sent by the first terminal device according to the private key corresponding to the public key to obtain the message key. After receiving the encrypted message, the second terminal device uses the message key to decrypt the encrypted message to obtain the communication message.
[0120] Since the first terminal device uses the public key of the second terminal device to encrypt the message key to obtain the encryption key, among the multiple terminal devices, only the second terminal device can use its private key to decrypt the encryption key to obtain the message key for decrypting the ciphertext message; other terminal devices cannot decrypt the encryption key.
[0121] The blockchain communication method provided in the above embodiments involves a second blockchain node sending a ciphertext message encrypted by the first terminal device to the second terminal device through a communication channel. The second terminal device then uses its private key to decrypt the ciphertext message, obtaining a message key, and uses the message key to decrypt the ciphertext message, thus ensuring the security of communication between the first and second terminal devices using the communication channel.
[0122] Please refer to Figure 7 The following is a flowchart illustrating the blockchain communication method provided in the embodiments of this application. Figure 6 ,like Figure 7 As shown, the method may further include:
[0123] S61: Send a connection detection message to the first terminal device and the second terminal device.
[0124] In this embodiment, in order to ensure the normal use of the communication channel and not waste the communication resources of the second blockchain node, the second blockchain node needs to continuously perform heartbeat detection with the first terminal device and the second terminal device. The heartbeat detection is used to detect whether the communication parties maintain a connection.
[0125] The second blockchain node determines whether it maintains a heartbeat with the first and second terminal devices by sending connection detection messages to the first and second terminal devices and determining whether it receives response messages from the first and second terminal devices within a preset time.
[0126] S62: If no response message is received from the first terminal device and / or the second terminal device within a preset time, the communication channel is released.
[0127] In this embodiment, the rule for the second blockchain node to detect whether it is maintaining a heartbeat with the first and second terminal devices is as follows: it periodically sends connection detection messages to the first and second terminal devices, and detects whether it receives response messages from the first and second terminal devices within a preset time. If no response messages are received, it is determined that the communication channel is not being used normally, and the second blockchain node releases the communication channel.
[0128] In some embodiments, the second blockchain node may continuously send multiple connection detection messages to the first terminal device and the second terminal device. If none of the multiple connection detection messages receive the corresponding response message, it is determined that the communication channel needs to be released.
[0129] S63: Send a channel release notification to the first blockchain node, so that the first blockchain node broadcasts a channel release event if the channel release notification is verified, so that the first terminal device and the second terminal device determine that the communication channel corresponding to the channel identifier has been released.
[0130] In this embodiment, after the second blockchain node releases the communication channel, it sends a channel release notification to the first blockchain node. The smart contract on the first blockchain node verifies the channel release notification. If the channel release notification passes the verification, the first blockchain node broadcasts the channel release event. After receiving the channel release event, the first terminal device and the second terminal device determine that the communication channel has been released and can no longer send communication messages through the communication channel.
[0131] In the blockchain communication method provided in the above embodiments, the second blockchain node determines whether it needs to release the communication channel by judging whether a connection is still maintained between the second and first terminal devices. When it is determined that the communication channel needs to be released, the communication channel is released, and a channel release notification is sent to the first blockchain node to notify the first and second terminal devices that the communication channel has been released, thereby avoiding the waste of the blockchain node's communication resources.
[0132] Based on the embodiments of the above-described blockchain communication method, this application also provides a blockchain communication device applied to a first blockchain node among multiple blockchain nodes on a blockchain. Please refer to... Figure 8 A schematic diagram of the structure of the blockchain communication device provided in the embodiments of this application. Figure 1 ,like Figure 8 As shown, the device includes:
[0133] The request receiving module 11 is used to receive a channel creation request sent by the first terminal device. The channel creation request includes: the device identifier of the second terminal device.
[0134] The node determination module 12 is used to determine the second blockchain node from multiple blockchain nodes based on the channel creation capabilities of multiple blockchain nodes.
[0135] The event broadcasting module 13 is used to broadcast channel creation events. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier, so that the second terminal device can generate a response message corresponding to the channel creation event.
[0136] The response event broadcast module 14 is used to broadcast a channel creation response event if a response message indicates that the second terminal device agrees to create a communication channel, so that the second blockchain node can create a communication channel based on the channel creation event and the channel creation response event;
[0137] The channel identifier sending module 15 is used to determine that the second blockchain node has successfully created a communication channel and broadcast a channel creation success event. The channel creation success event includes a channel identifier, so that the first terminal device can send communication messages to the second terminal device through the communication channel.
[0138] The blockchain communication device provided in the above embodiments allows a first blockchain node in the blockchain to select a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node through a smart contract. This enables the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication time latency and improving user experience.
[0139] Optionally, the device may also include:
[0140] The node registration module is used to receive registration requests from multiple blockchain nodes. The registration requests include: the node identifier of each blockchain node and the channel creation capability of each blockchain node.
[0141] The blockchain communication device provided in the above embodiments receives registration requests from multiple blockchain nodes to determine the channel creation capabilities of each blockchain node. This ensures that a second blockchain node capable of creating a communication channel can be provided to the terminal device based on the channel creation capabilities of each blockchain node. Communication between the first terminal device and the second terminal device is realized through the communication channel created by the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0142] In one possible implementation, the node determination module is specifically used to determine a second blockchain node from multiple blockchain nodes based on the number of channels that can be created and the number of channels that have been created.
[0143] In some embodiments, the node determination module is specifically used to determine, based on the number of channels that can be created and the number of channels that have been created, from multiple blockchain nodes, the blockchain node with the fewest number of channels that have been created and does not exceed the number of channels that can be created is the second blockchain node.
[0144] The blockchain communication device provided in the above embodiments selects the second blockchain node with the fewest created channels from multiple blockchain nodes based on the number of channels that can be created and the data of channels already created. The second blockchain node provides channel creation services to the first terminal device, so that the first terminal device can communicate with the second terminal device through the communication channel created by the second blockchain node. This eliminates the need for the first and second terminal devices to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication time latency and improving user experience.
[0145] Optionally, the device may also include:
[0146] The key receiving module is used to receive the encryption key of the first terminal device sent by the first terminal device. The encryption key is obtained by the first terminal device encrypting the message key based on the public key of the second terminal device.
[0147] The key broadcasting module is used to broadcast the encryption key so that the second terminal device can obtain the encryption key.
[0148] The blockchain communication device provided in the above embodiments broadcasts the encryption key used by the first terminal device to encrypt communication messages to the second terminal device, so that the second terminal device can use its private key to decrypt the encryption key to obtain the message key, and use the message key to decrypt the ciphertext message, thereby ensuring the security of communication between the first terminal device and the second terminal device using the communication channel.
[0149] Optionally, the device may also include:
[0150] The release notification receiving module is used to receive the channel release notification sent by the second blockchain node. The channel release notification is generated when the second blockchain node does not receive the response message generated by the first terminal device and the second terminal device for the connection detection message within a preset time.
[0151] The release notification verification module is used to verify the channel release notification;
[0152] The release event broadcast module is used to broadcast a channel release event if the verification passes, so that the first terminal device and the second terminal device can determine that the communication channel corresponding to the channel identifier has been released.
[0153] The blockchain communication device provided in the above embodiments, after verifying the channel release notification sent to the second blockchain node, notifies the first terminal device and the second terminal device that the communication channel has been released, thus avoiding the waste of the blockchain node's communication resources.
[0154] Based on the embodiments of the above-described blockchain communication method, this application also provides a blockchain communication device applied to a second blockchain node among multiple blockchain nodes on a blockchain. Please refer to... Figure 9 A schematic diagram of the structure of the blockchain communication device provided in the embodiments of this application. Figure 2 ,like Figure 9 As shown, the device includes:
[0155] The event receiving module 21 is used to receive the channel creation event and the channel creation response event broadcast by the first blockchain node. The channel creation event is generated by the first blockchain node based on the channel creation request sent by the first terminal device and the channel creation capabilities of multiple blockchain nodes. The channel creation response event is generated based on the response message sent by the second terminal device in response to the channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier.
[0156] The node identifier judgment module 22 is used to determine whether the node identifier in the channel creation event is its own node identifier. If so, a communication channel is created based on the channel identifier.
[0157] The response message sending module 23 is used to send a response message indicating successful channel creation to the first blockchain node, so that the first blockchain node sends the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
[0158] The blockchain communication device provided in the above embodiments allows a first blockchain node in the blockchain to select a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node through a smart contract. This enables the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication time latency and improving user experience.
[0159] Optionally, the device may also include:
[0160] The encrypted message receiving module is used to receive encrypted messages sent by the first terminal device. The encrypted message is a message obtained by the first terminal device encrypting the communication message according to the message key.
[0161] The encrypted message sending module is used to send encrypted messages to a second terminal device through a communication channel, so that the second terminal device can decrypt the encrypted key of the first terminal device in advance according to the public key to obtain the message key, and then decrypt the encrypted message according to the message key.
[0162] In the blockchain communication device provided in the above embodiments, the second blockchain node sends the encrypted ciphertext message from the first terminal device to the second terminal device through the communication channel, so that the second terminal device can use the private key encryption key to decrypt it, obtain the message key, and use the message key to decrypt the ciphertext message, thereby ensuring the security of communication between the first terminal device and the second terminal device using the communication channel.
[0163] Optionally, the device may also include:
[0164] The detection message sending module is used to send connection detection messages to the first terminal device and the second terminal device.
[0165] The channel release module is used to release the communication channel if no response message is received from the first terminal device and / or the second terminal device within a preset time.
[0166] The release notification sending module is used to send a channel release notification to the first blockchain node, so that the first blockchain node broadcasts a channel release event if the channel release notification is verified, so that the first terminal device and the second terminal device can determine that the communication channel corresponding to the channel identifier has been released.
[0167] In the blockchain communication device provided in the above embodiments, the second blockchain node determines whether it needs to release the communication channel by judging whether a connection is still maintained between the first terminal device and the second terminal device. When it is determined that the communication channel needs to be released, the communication channel is released, and a channel release notification is sent to the first blockchain node to notify the first terminal device and the second terminal device that the communication channel has been released, thereby avoiding the waste of the communication resources of the blockchain node.
[0168] The above-described device is used to execute the method provided in the foregoing embodiments, and its implementation principle and technical effect are similar, so they will not be described again here.
[0169] These modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more microprocessors, or one or more Field Programmable Gate Arrays (FPGAs). Alternatively, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a system-on-a-chip (SOC).
[0170] Please refer to Figure 10 This is a schematic diagram of a computer device provided in an embodiment of this application, such as... Figure 10 As shown, the computer device 100 includes a processor 101, a storage medium 102, and a bus. The storage medium 102 stores program instructions executable by the processor 101. When the computer device 100 is running, the processor 101 communicates with the storage medium 102 via the bus. The processor 101 executes the program instructions to perform steps of a blockchain communication method applied to a first blockchain node in the blockchain, or to perform steps of a blockchain communication method applied to a second blockchain node in the blockchain.
[0171] Specifically, the steps by which the processor executes the blockchain communication method applied to the first blockchain node include:
[0172] The system receives a channel creation request from a first terminal device, the request including the device identifier of the second terminal device; determines the second blockchain node from among multiple blockchain nodes based on their channel creation capabilities; broadcasts a channel creation event, including the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier, so that the second terminal device generates a response message corresponding to the channel creation event; if the response message indicates that the second terminal device agrees to create a communication channel, it broadcasts a channel creation response event, so that the second blockchain node creates a communication channel based on the channel creation event and the response event; confirms that the second blockchain node has successfully created the communication channel, and broadcasts a channel creation success event, including the channel identifier, so that the first terminal device can send a communication message to the second terminal device through the communication channel.
[0173] In the above embodiments, the blockchain communication method executed by the processor involves a first blockchain node in the blockchain selecting a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node via a smart contract. This allows the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0174] In one possible implementation, before the processor determines the second blockchain node from among the multiple blockchain nodes based on the channel creation capability of multiple blockchain nodes, it also performs the following steps:
[0175] It receives registration requests from multiple blockchain nodes, and the registration requests include: the node identifier of each blockchain node and the channel creation capability of each blockchain node.
[0176] In the above embodiments, the blockchain communication method executed by the processor receives registration requests from multiple blockchain nodes to determine the channel creation capability of each blockchain node. This ensures that a second blockchain node capable of creating a communication channel can be provided to the terminal device based on the channel creation capability of each blockchain node. Communication between the first terminal device and the second terminal device is realized through the communication channel created by the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0177] In one possible implementation, the processor performing the steps described above, which involve determining a second blockchain node from multiple blockchain nodes based on the channel creation capability of multiple blockchain nodes, may include:
[0178] The second blockchain node is determined from multiple blockchain nodes based on the number of channels that can be created and the number of channels that have been created.
[0179] In some embodiments, the processor performing the step of determining a second blockchain node from a plurality of blockchain nodes based on the number of channels that can be created and the number of channels that have been created by the plurality of blockchain nodes may include:
[0180] Based on the number of channels that can be created and the number of channels that have already been created, the blockchain node with the fewest number of channels created and the number of channels that have already been created is identified as the second blockchain node.
[0181] In the blockchain communication method executed by the processor in the above embodiments, based on the number of channels that can be created and the data of channels already created, a second blockchain node with the fewest created channels is selected from multiple blockchain nodes. The second blockchain node provides channel creation services to the first terminal device, so that the first terminal device can communicate with the second terminal device through the communication channel created by the second blockchain node. This eliminates the need for the first and second terminal devices to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0182] In one possible implementation, the steps of the processor executing the above-described blockchain communication method may further include:
[0183] The device receives the encryption key sent by the first terminal device, which is obtained by encrypting the message key using the public key of the second terminal device; and broadcasts the encryption key so that the second terminal device can obtain the encryption key.
[0184] In the above embodiments, the blockchain communication method executed by the processor broadcasts the encryption key used by the first terminal device to encrypt the communication message to the second terminal device, so that the second terminal device can use its private key to decrypt the encryption key to obtain the message key, and use the message key to decrypt the ciphertext message, thereby ensuring the security of communication between the first terminal device and the second terminal device using the communication channel.
[0185] In one possible implementation, the steps of the processor executing the above-described blockchain communication method may further include:
[0186] Receive the channel release notification sent by the second blockchain node; verify the channel release notification; if the verification passes, broadcast the channel release event so that the first terminal device and the second terminal device can determine that the communication channel corresponding to the channel identifier has been released.
[0187] In the above embodiments, the blockchain communication method executed by the processor notifies the first terminal device and the second terminal device that the communication channel has been released after the channel release notification sent to the second blockchain node passes verification, thus avoiding the waste of the communication resources of the blockchain node.
[0188] The steps by which the processor executes the blockchain communication method applied to the second blockchain node include:
[0189] Receive the channel creation event and channel creation response event broadcast by the first blockchain node; determine whether the node identifier in the channel creation event is its own node identifier; if so, create a communication channel based on the channel identifier; notify the first blockchain node that the communication channel has been successfully created, so that the first blockchain node sends the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
[0190] In the above embodiments, the blockchain communication method executed by the processor involves a first blockchain node in the blockchain selecting a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node via a smart contract. This allows the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0191] In one possible implementation, the steps of the processor executing the above-described blockchain communication method may further include:
[0192] The system receives a ciphertext message sent by a first terminal device, which is a message obtained by the first terminal device encrypting a communication message according to a message key. The system then sends the ciphertext message to a second terminal device through a communication channel, so that the second terminal device can decrypt the ciphertext message according to the message key obtained in advance by decrypting the encryption key of the first terminal device according to the public key.
[0193] In the blockchain communication method executed by the processor in the above embodiments, the second blockchain node sends the encrypted ciphertext message from the first terminal device to the second terminal device through the communication channel, so that the second terminal device can use the private key encryption key to decrypt it, obtain the message key, and use the message key to decrypt the ciphertext message, thereby ensuring the security of communication between the first terminal device and the second terminal device using the communication channel.
[0194] In one possible implementation, the steps of the processor executing the above-described blockchain communication method may further include:
[0195] Send a connection detection message to the first terminal device and the second terminal device; if no response message is received from the first terminal device and / or the second terminal device within a preset time, release the communication channel; send a channel release notification to the first blockchain node, so that the first blockchain node broadcasts the channel release event if the channel release notification is verified, so that the first terminal device and the second terminal device determine that the communication channel corresponding to the channel identifier has been released.
[0196] In the blockchain communication method executed by the processor in the above embodiments, the second blockchain node determines whether it needs to release the communication channel by judging whether a connection is still maintained between the first terminal device and the second terminal device. When it is determined that the communication channel needs to be released, the communication channel is released, and a channel release notification is sent to the first blockchain node to notify the first terminal device and the second terminal device that the communication channel has been released, so as to avoid wasting the communication resources of the blockchain node.
[0197] Optionally, the present invention also provides a computer-readable storage medium storing a computer program, which is executed by a processor to perform steps of a blockchain communication method applied to a first blockchain node in the blockchain, or to perform steps of a blockchain communication method applied to a second blockchain node in the blockchain.
[0198] Specifically, the steps of the computer program executing the blockchain communication method applied to the first blockchain node include:
[0199] The system receives a channel creation request from a first terminal device, the request including the device identifier of the second terminal device; determines the second blockchain node from among multiple blockchain nodes based on their channel creation capabilities; broadcasts a channel creation event, including the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier, so that the second terminal device generates a response message corresponding to the channel creation event; if the response message indicates that the second terminal device agrees to create a communication channel, it broadcasts a channel creation response event, so that the second blockchain node creates a communication channel based on the channel creation event and the response event; confirms that the second blockchain node has successfully created the communication channel, and broadcasts a channel creation success event, including the channel identifier, so that the first terminal device can send a communication message to the second terminal device through the communication channel.
[0200] In the above embodiments, the blockchain communication method executed by the computer program involves a first blockchain node in the blockchain selecting a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node via a smart contract. This allows the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0201] In one possible implementation, before the computer program determines the second blockchain node from among the multiple blockchain nodes based on the channel creation capability of the multiple blockchain nodes, it also performs the following steps:
[0202] It receives registration requests from multiple blockchain nodes, and the registration requests include: the node identifier of each blockchain node and the channel creation capability of each blockchain node.
[0203] The blockchain communication method executed by the computer program in the above embodiments determines the channel creation capability of each blockchain node by receiving registration requests from multiple blockchain nodes. This ensures that a second blockchain node capable of creating a communication channel can be provided to the terminal device based on the channel creation capability of each blockchain node. Communication between the first terminal device and the second terminal device is realized through the communication channel created by the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0204] In one possible implementation, the computer program performing the steps described above, which involve determining a second blockchain node from multiple blockchain nodes based on the channel creation capability of multiple blockchain nodes, may include:
[0205] The second blockchain node is determined from multiple blockchain nodes based on the number of channels that can be created and the number of channels that have been created.
[0206] In some embodiments, the computer program performing the step of determining a second blockchain node from a plurality of blockchain nodes based on the number of channels that can be created and the number of channels that have been created may include:
[0207] Based on the number of channels that can be created and the number of channels that have already been created, the blockchain node with the fewest number of channels created and the number of channels that have already been created is identified as the second blockchain node.
[0208] The blockchain communication method executed by the computer program in the above embodiments selects the second blockchain node with the fewest created channels from multiple blockchain nodes based on the number of channels that can be created and the data of channels already created. The second blockchain node provides channel creation services to the first terminal device, so that the first terminal device can communicate with the second terminal device through the communication channel created by the second blockchain node. This eliminates the need for the first and second terminal devices to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0209] In one possible implementation, the steps of the computer program executing the above-described blockchain communication method may further include:
[0210] The device receives the encryption key sent by the first terminal device, which is obtained by encrypting the message key using the public key of the second terminal device; and broadcasts the encryption key so that the second terminal device can obtain the encryption key.
[0211] The blockchain communication method executed by the computer program in the above embodiments broadcasts the encryption key used by the first terminal device to encrypt the communication message to the second terminal device, so that the second terminal device can use its private key to decrypt the encryption key to obtain the message key, and use the message key to decrypt the ciphertext message, thereby ensuring the security of communication between the first terminal device and the second terminal device using the communication channel.
[0212] In one possible implementation, the steps of the computer program executing the above-described blockchain communication method may further include:
[0213] Receive the channel release notification sent by the second blockchain node; verify the channel release notification; if the verification passes, broadcast the channel release event so that the first terminal device and the second terminal device can determine that the communication channel corresponding to the channel identifier has been released.
[0214] In the above embodiments, the blockchain communication method executed by the computer program notifies the first terminal device and the second terminal device that the communication channel has been released after the channel release notification sent to the second blockchain node passes verification, thus avoiding the waste of the communication resources of the blockchain node.
[0215] The steps of the computer program executing the above-described blockchain communication method applied to the second blockchain node include:
[0216] Receive the channel creation event and channel creation response event broadcast by the first blockchain node; determine whether the node identifier in the channel creation event is its own node identifier; if so, create a communication channel based on the channel identifier; notify the first blockchain node that the communication channel has been successfully created, so that the first blockchain node sends the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
[0217] In the above embodiments, the blockchain communication method executed by the computer program involves a first blockchain node in the blockchain selecting a second blockchain node to create a communication channel based on the channel creation capabilities of each blockchain node via a smart contract. This allows the first terminal device and the second terminal device to communicate through the communication channel of the second blockchain node. This eliminates the need for the first terminal device and the second terminal device to undergo smart contract verification and pay gas fees every time a communication message is sent, effectively reducing communication latency and improving user experience.
[0218] In one possible implementation, the steps of the computer program executing the above-described blockchain communication method may further include:
[0219] The system receives a ciphertext message sent by a first terminal device, which is a message obtained by the first terminal device encrypting a communication message according to a message key. The system then sends the ciphertext message to a second terminal device through a communication channel, so that the second terminal device can decrypt the ciphertext message according to the message key obtained in advance by decrypting the encryption key of the first terminal device according to the public key.
[0220] In the above embodiment, the blockchain communication method executed by the computer program involves the second blockchain node sending the encrypted ciphertext message from the first terminal device to the second terminal device through a communication channel. The second terminal device then uses its private key to decrypt the ciphertext message, obtaining the message key, and uses the message key to decrypt the ciphertext message, thus ensuring the security of communication between the first and second terminal devices using the communication channel.
[0221] In one possible implementation, the steps of the computer program executing the above-described blockchain communication method may further include:
[0222] Send a connection detection message to the first terminal device and the second terminal device; if no response message is received from the first terminal device and / or the second terminal device within a preset time, release the communication channel; send a channel release notification to the first blockchain node, so that the first blockchain node broadcasts the channel release event if the channel release notification is verified, so that the first terminal device and the second terminal device determine that the communication channel corresponding to the channel identifier has been released.
[0223] In the above embodiment, the blockchain communication method executed by the computer program involves the second blockchain node determining whether a connection is still maintained between itself and the first and second terminal devices to determine whether the communication channel needs to be released. When it is determined that the communication channel needs to be released, the communication channel is released, and a channel release notification is sent to the first blockchain node to notify the first and second terminal devices that the communication channel has been released, thus avoiding the waste of the blockchain node's communication resources.
[0224] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0225] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0226] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0227] The integrated units implemented as software functional units described above can be stored in a computer-readable storage medium. These software functional units, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0228] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A blockchain communication method, characterized in that, The method, applied to the first blockchain node among multiple blockchain nodes on a blockchain, includes: Receive a channel creation request sent by a first terminal device, wherein the channel creation request includes: the device identifier of the second terminal device; Based on the channel creation capabilities of the plurality of blockchain nodes, a second blockchain node is determined from the plurality of blockchain nodes; A broadcast channel creation event is provided, which includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier. This allows the second terminal device to generate a notification message after determining that the device identifier carried in the channel creation event is the device identifier of the second terminal device. The user of the second terminal device then determines, based on the notification message, that they agree to establish a communication connection with the first terminal device and generate a response message corresponding to the channel creation event. If the response message indicates that the second terminal device agrees to create a communication channel, a channel creation response event is broadcast so that the second blockchain node creates a communication channel based on the channel creation event and the channel creation response event. The communication channel is a communication channel between the first terminal device, the second blockchain node, and the second terminal device. The system determines that the second blockchain node has successfully created the communication channel and broadcasts a channel creation success event. The channel creation success event includes the channel identifier, so that the first terminal device can send a communication message to the second terminal device through the communication channel.
2. The method as described in claim 1, characterized in that, Before determining the second blockchain node from the plurality of blockchain nodes based on their channel creation capabilities, the method further includes: The system receives registration requests from the plurality of blockchain nodes, the registration requests including: the node identifier of each blockchain node and the channel creation capability of each blockchain node.
3. The method as described in claim 1, characterized in that, The step of determining the second blockchain node from the plurality of blockchain nodes based on their channel creation capabilities includes: The second blockchain node is determined from the plurality of blockchain nodes based on the number of channels that can be created and the number of channels that have been created.
4. The method as described in claim 3, characterized in that, The step of determining the second blockchain node from the plurality of blockchain nodes based on the number of channels that can be created and the number of channels that have been created includes: Based on the number of channels that can be created and the number of channels that have already been created, the blockchain node with the fewest number of channels that have already been created is determined from among the plurality of blockchain nodes.
5. The method as described in claim 1, characterized in that, The method further includes: The device receives the encryption key of the first terminal device sent by the first terminal device, wherein the encryption key is obtained by the first terminal device encrypting the message key based on the public key of the second terminal device; The encryption key is broadcast so that the second terminal device can obtain the encryption key.
6. The method as described in claim 1, characterized in that, The method further includes: Receive a channel release notification sent by the second blockchain node, wherein the channel release notification is generated by the second blockchain node when it does not receive a response message generated by the first terminal device and the second terminal device for the connection detection message within a preset time; Verify the channel release notification; If the verification passes, a channel release event is broadcast so that the first terminal device and the second terminal device determine that the communication channel corresponding to the channel identifier has been released.
7. A blockchain communication method, characterized in that, The method, applied to a second blockchain node among multiple blockchain nodes on a blockchain, includes: The system receives a channel creation event and a channel creation response event broadcast by a first blockchain node. The channel creation event is generated by the first blockchain node based on a channel creation request sent by a first terminal device and the channel creation capabilities of the multiple blockchain nodes. The channel creation response event is generated by the first blockchain node based on a response message sent by a second terminal device in response to the channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier. After the second terminal device determines that the device identifier carried in the channel creation event is the device identifier of the second terminal device, it generates a notification message. The user of the second terminal device determines that they agree to establish a communication connection with the first terminal device based on the notification message and generates the response message. Determine whether the node identifier in the channel creation event is its own node identifier. If so, create a communication channel based on the channel identifier. The communication channel is a communication channel between the first terminal device, the second blockchain node, and the second terminal device. The first blockchain node is notified that the communication channel has been successfully created, and the first blockchain node sends the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
8. The method as described in claim 7, characterized in that, The method further includes: Receive a ciphertext message sent by the first terminal device, wherein the ciphertext message is a message obtained by the first terminal device encrypting the communication message according to a message key; The encrypted message is sent to the second terminal device through the communication channel, so that the second terminal device can decrypt the encrypted key of the first terminal device obtained in advance according to the public key to obtain the message key, and then decrypt the encrypted message according to the message key.
9. The method as described in claim 7, characterized in that, The method further includes: Send connection detection messages to the first terminal device and the second terminal device; If no response message is received from the first terminal device and / or the second terminal device within a preset time, the communication channel is released; A channel release notification is sent to the first blockchain node, so that the first blockchain node broadcasts a channel release event if the channel release notification is verified, so that the first terminal device and the second terminal device determine that the communication channel corresponding to the channel identifier has been released.
10. A blockchain communication device, characterized in that, The device is used as the first blockchain node among multiple blockchain nodes on a blockchain, and the device includes: The request receiving module is used to receive a channel creation request sent by the first terminal device, wherein the channel creation request includes: the device identifier of the second terminal device; A node determination module is used to determine a second blockchain node from the plurality of blockchain nodes based on the channel creation capabilities of the plurality of blockchain nodes; An event broadcasting module is created to broadcast a channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier. This enables the second terminal device to generate a notification message after determining that the device identifier carried in the channel creation event is the device identifier of the second terminal device. The user of the second terminal device then determines that they agree to establish a communication connection with the first terminal device based on the notification message, and generates a response message corresponding to the channel creation event. The response event broadcast module is used to broadcast a channel creation response event if the response message indicates that the second terminal device agrees to create a communication channel, so that the second blockchain node creates a communication channel based on the channel creation event and the channel creation response event, and the communication channel is a communication channel between the first terminal device, the second blockchain node and the second terminal device; The channel identifier sending module is used to determine that the second blockchain node has successfully created the communication channel and broadcast a channel creation success event. The channel creation success event includes the channel identifier, so that the first terminal device can send a communication message to the second terminal device through the communication channel.
11. A blockchain communication device, characterized in that, The device is used as a second blockchain node among multiple blockchain nodes on a blockchain, the device comprising: An event receiving module is used to receive channel creation events and channel creation response events broadcast by a first blockchain node. The channel creation event is generated by the first blockchain node based on a channel creation request sent by a first terminal device and the channel creation capabilities of the multiple blockchain nodes. The channel creation response event is generated based on a response message sent by a second terminal device in response to the channel creation event. The channel creation event includes: the device identifier of the second terminal device, the node identifier of the second blockchain node, and the channel identifier. After the second terminal device determines that the device identifier carried in the channel creation event is the device identifier of the second terminal device, it generates a notification message. The user of the second terminal device determines that they agree to establish a communication connection with the first terminal device based on the notification message and generates the response message. The node identifier determination module is used to determine whether the node identifier in the channel creation event is its own node identifier. If so, a communication channel is created according to the channel identifier. The communication channel is a communication channel between the first terminal device, the second blockchain node, and the second terminal device. The response message sending module is used to send a response message indicating successful channel creation to the first blockchain node, so that the first blockchain node sends the channel identifier of the communication channel to the first terminal device, so that the first terminal device can send communication messages to the second terminal device through the communication channel corresponding to the channel identifier.
12. A computer device, characterized in that, include: The system includes a processor, a storage medium, and a bus. The storage medium stores program instructions executable by the processor. When the computer device is running, the processor communicates with the storage medium via the bus. The processor executes the program instructions to perform the steps of the blockchain communication method as described in any one of claims 1 to 6, or to perform the steps of the blockchain communication method as described in any one of claims 7 to 9.
13. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, performs the steps of the blockchain communication method as described in any one of claims 1 to 6, or performs the steps of the blockchain communication method as described in any one of claims 7 to 9.
Citation Information
Patent Citations
Communication connection control method and related equipment
CN110839034A