Network security communication method and device
Technical Field
The invention relates to the technical field of communication protocols, and particularly provides a network security communication method and device.
Background
TCP and UDP are two main transport protocols of a transport layer, TCP is a transport protocol oriented to a connection byte stream, and provides reliable service to an application layer, and UDP is a transport protocol oriented to Packet (as in IP Packet, when a peer-to-peer protocol stack communicates, a connection does not need to be established in advance), unreliable, and deliver best-effort (best-effort). In order to achieve the goal, the TCP designs modules of message numbering, confirmation, overtime retransmission, sliding windows, congestion control and the like, so that the TCP needs to pay a large cost in work.
Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a network security communication method with strong practicability.
The invention further aims to provide a network security communication device which is reasonable in design, safe and applicable.
The technical scheme adopted by the invention for solving the technical problems is as follows:
a network security communication method comprises the following steps:
s1, starting the nodes, opening the ports as the KCP protocol communication ports among the nodes, and opening the ports of the node discovery mechanism;
s2, through node discovery mechanism, the node in block chain obtains IP, KCP protocol monitoring port of peer node in network;
s3, establishing a KCP protocol connection based on UDP between nodes;
s4, negotiating and establishing an encryption channel between nodes;
s5, sending messages between nodes;
s6, the node sends a message to the block chain service layer for processing;
s7, the KCP connection is disconnected between the nodes at one time.
Further, in step S2, the node discovery mechanism is completed by using kademlia algorithm, and when the node a is started for the first time, a unique node ID is generated and recorded as a node ID;
and the node A carries out ping-pong interaction with the public-related node through the hard-coded public-related node address, and if the public node survives, the public node is added into the K bucket.
Further, the NODE A initiates a FIND _ NODE request to the public gateway NODE, acquires the NODE closest to the NODE A, and adds the acquired NODE with the closest distance into the K bucket, the NODE A sends the FIND _ NODE request again to the NODE which is acquired just before, acquires the information of the NODE adjacent to the NODE A, and adds the information into the K bucket, and the steps are repeated to construct a routing table.
Preferably, the node a starts a timer and refreshes the K buckets at intervals.
Further, in step S3, data communication is established with the IP of the node in the blockchain network and the open port obtained in step S2.
Further, in step S4, the nodes use Diffie-Hellman algorithm to perform key exchange, the node a selects a large prime number p, a base number g, and a random number a, calculates a ═ g ^ amod p, and sends the values of p, g, and a to the node b;
b, after receiving, generating a random number B, calculating B ═ g ^ B mod p, and then calculating s ^ A bmod p; b sends B to A, and A calculates s1 ═ B ^ a mod p. Here s1 will equal s as the key for the two-party communication;
both parties start communication using a preset symmetric encryption algorithm and s as a key.
Further, in step S5, the node a encrypts the message using the key obtained in step S4 and sends the message to the node b via the network communication data link in step S3.
Further, in step S6, after receiving the message through the network communication data link in step S3, the node b decrypts the message by using the key generated in step S4, and then forwards the message to the blockchain service layer for processing.
A network security communication device, comprising: at least one memory and at least one processor;
the at least one memory to store a machine readable program;
the at least one processor is configured to invoke the machine readable program to perform a network security communication method.
Compared with the prior art, the network security communication method and the network security communication device have the following outstanding beneficial effects:
under the condition of network fluctuation, the block chain network using the KCP protocol can reduce the network delay by about 30% -40% compared with the block chain network using the TCP/IP protocol, namely, the number of the transmitted data packets in unit time is increased by 43% -67%, namely, the theoretical TPS on the network level is increased by 43% -67%. The penetrability of the network is enhanced, and the probability of intercepting network data by network equipment such as a firewall is reduced. And an encrypted channel is adopted, so that the safety of data communication is ensured.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a flow diagram of a network security communication method;
fig. 2 is a schematic architecture diagram of a network security communication method.
Detailed Description
The present invention will be described in further detail with reference to specific embodiments in order to better understand the technical solutions of the present invention. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
A preferred embodiment is given below:
as shown in fig. 1-2, a network security communication method in this embodiment includes the following steps:
s1, starting the node, wherein the open 12345 port is a communication port of the KCP protocol between the nodes, and the open 12346 port is a port of a node discovery mechanism.
S2, through node discovery mechanism, the node in block chain obtains the IP and KCP protocol monitoring port of the peer node in the network.
Node discovery is completed by adopting a kademlia algorithm. When the node A is started for the first time, a unique node ID is generated and recorded as the node ID. And the node A carries out ping-pong interaction with the public node A through the hard-coded public node address, and if the public node survives, the public node is added into the K bucket. The NODE A initiates a FIND _ NODE request to the public NODE, acquires the NODEs closest to the NODE A, and adds the NODEs into the K bucket. NODE a sends the FIND _ NODE request again to the NODE that was just obtained, acquires information of NODEs adjacent to it and joins the K bucket. This is repeated until a sufficiently large routing table is constructed.
Wherein node a starts a timer, refreshing K buckets every several hours.
S3, establishing UDP-based KCP protocol connection between the nodes.
The node acquires the IP and open port of other nodes in the blockchain network, and establishes data communication therewith, through step S2. It should be noted that the communication protocol between the nodes is the KCP protocol carried over UDP.
And S4, negotiating and establishing the encrypted channel between the nodes.
First, key exchange is performed between nodes. The key exchange uses the Diffie-Hellman algorithm. The node A selects a large prime number p, a base number g and a random number a, calculates A ^ g ^ a mod p, and sends the values of p, g and A to the node B; b, generating a random number B after receiving B, calculating B ═ g ^ B mod p, and then calculating s ^ A ^ B mod p; b sends B to A, and A calculates s1 ═ B ^ a mod p. Here s1 will equal s as the key for the two-party communication.
Both parties start communication using a preset symmetric encryption algorithm and s as a key.
And S5, sending the message, wherein the node A encrypts the message by using the key obtained in the step S4 and then sends the message to the node B through the network communication data link in the step S3.
And S6, receiving the message, after the node B receives the message through the network communication data link in the step S3, decrypting the message by using the key generated in the step S4, and then transferring the message to a block chain service layer for processing.
And S7, disconnecting, and sequentially disconnecting KCP among the nodes.
A network security communication device, comprising: at least one memory and at least one processor;
the at least one memory to store a machine readable program;
the at least one processor is configured to invoke the machine readable program to perform a network security communication method.
The above embodiments are only specific cases of the present invention, and the protection scope of the present invention includes but is not limited to the above embodiments, and any suitable changes or substitutions that are consistent with the claims of a network security communication method and apparatus of the present invention and are made by those skilled in the art should fall within the protection scope of the present invention.
Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that changes, modifications, substitutions and alterations can be made in these embodiments without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.