Specific embodiment
In order to make those skilled in the art better understand the technical solutions in the application, below in conjunction with the application reality
The attached drawing in example is applied, the technical scheme in the embodiment of the application is clearly and completely described, it is clear that described implementation
Example is merely a part but not all of the embodiments of the present application.Based on the embodiment in the application, this field is common
The application protection all should belong in technical staff's every other embodiment obtained without creative efforts
Range.
As previously mentioned, in block platform chain development process, the client-side program that there is an urgent need to can communicate with block chain,
For initiating operation relevant to currency is encrypted.For this purpose, the application is intended to provide a kind of block chain client of low consumption of resources
With the communication plan between block chain.
Fig. 1 is the flow chart of the embodiment of the present application block chain communication means.Method shown in FIG. 1 can be by hereafter corresponding
Device execute, comprising:
Step S102, block chain client is when preparing to send message to block chain, in multiple candidate accesses of block chain
Selection target node in node.
In this step, block chain client can be based on pre-set selection mode, connect from available multiple candidates
Destination node is chosen in ingress.
For example, block chain client can be based on priority weighting, the candidate access node conduct of highest priority is selected
Destination node.For another example, electronic equipment can pick out a candidate access node as destination node using polling mode.By
Not unique in the selection mode of destination node, the embodiment of the present application is not especially limited.
Step S104, block chain client initiate the connection for being directed to destination node.
In this step, the number for allowing block chain client to initiate the connection to destination node is preset.Block chain visitor
The connection for being directed to destination node is persistently initiated at family end within a preset period of time, until successful connection or connection failure number reach
To preset times.Wherein, in order to avoid block chain client consumes excess resource during initiating the connection, preset times with
It is advisable for no less than 2 times and not more than 4 times.
Step S106, if successful connection, block chain client transmits the message to destination node.
It should be understood that access node of the destination node as block chain, received message can be further sent to block
Chain server-side.
Based on block chain communication means shown in FIG. 1, block chain client is when preparing to send information to block chain, directly
The access node in connection block chain is attempted, and sends information to access node after successful connection.Due to entire communication process
The available mode that block chain client monitors access node is not needed, so that the execution complexity and resource of block chain client disappear
Consumption is greatly optimized.
On above-mentioned basis, the method for the embodiment of the present application can also connect mistake with destination node in block chain client
When losing, above-mentioned steps S102 is re-executed to above-mentioned steps S106.As long as that is, having attachable candidate access node, block chain
Client is surely successfully transmitted outbound message with regard to one.
It describes in detail below to block chain communication means.
In the embodiment of the present application, block chain client can be arranged in multiple candidate access nodes in block chain client
Host node and slave node.Wherein, host node, which is elected to be, is higher than slave node for the priority of destination node.
As a kind of implementation, block chain client starts communication thread when preparing to send message to block chain, with
Obtain multiple candidate access nodes of access block chain.Later, block chain client configuring area in multiple candidate access nodes
The host node and slave node of block chain client
Specifically, block chain client can be connect based on the priority weighting of candidate access node from above-mentioned multiple candidates
The candidate access node of highest priority is chosen in ingress as host node, remaining candidate access node is as slave node.
It is connect for example, block chain client gets candidate access node 1, candidate access node 2 and choosing based on communication thread
Ingress 3.Wherein, the corresponding priority weighting of candidate access node 1 is III, the corresponding priority weighting of candidate access node 2
It is III, the corresponding priority weighting of candidate access node 3 is I.If priority weighting is directly proportional to value, block chain client
Candidate access node 1 can be used as to host node, and regard candidate access node 2 and candidate access node 3 as slave node.
As another implementation, block chain client starts communication thread when preparing to send message to block chain,
To obtain multiple candidate access nodes of access block chain.Later, block chain client is matched based on the history node of local cache
Confidence breath determines the host node and slave node of block chain client from multiple candidate access nodes.
Specifically, block chain client can continue to use the host node and slave node previously configured when being ready for sending message.
For example, block chain client, which is based on communication thread, gets candidate access node 1 to candidate access node 8.Wherein,
If history node indicates that candidate access node 5 was once used as the host node of block chain client, block chain client with confidence
Candidate access node 5 is directly continued to use as host node, remaining candidate access node 1-4,6-8 is made when this sends message in end
For slave node.
After determining host node, block chain client can be using host node as destination node, and attempts to initiate for mesh
Mark the connection of node.
Wherein, if host node (for example the number of connection master node failure is greater than predetermined threshold), block chain can not be connected
Client can select slave node as updated host node in multiple candidate access nodes of block chain, and will be after update
Host node as the destination node.
As exemplary introduction, block chain client can be when that can not connect host node, according to priority weighting from big
To small sequence, a slave node is chosen as host node.Alternatively, block chain client can also be chosen by the way of poll
One slave node is as host node.Since mode is not unique, the embodiment of the present application is not especially limited.
In addition, in extreme circumstances, if block chain client is whole in the connection initiated for multiple candidate access nodes
When failure, then multiple candidate access nodes of access block chain can be updated again through communication thread, and re-execute above-mentioned
Step S102 to step S106, to guarantee that message can be successfully transmitted.
In addition, block chain client can also be mentioned in the connection all failures initiated for multiple candidate access nodes
Show the inspection network equipment, or starting network state check process, so that whether check in time is that network problem causes connection to be lost
It loses.
Example introduction is carried out below with reference to main flow of the different implementations to the method for the present embodiment.
Implementation one
As shown in Fig. 2, the main flow of this implementation one includes:
Step S201, block chain client configure the host node of block chain client and standby in multiple candidate access nodes
Node.
Step S202, block chain client initiate the connection for being directed to host node.
Step S203, block chain client judge whether to be successfully connected host node;It is to then follow the steps S204;It is no, then it holds
Row step S206.
Step S204, block chain client send message to host node.
Step S205, block chain client judge whether message sends success;It is then to terminate;It is no, then return to step
S202。
Whether step S206, the judgement of block chain client are directed to the reconnection number of host node less than 3;It is then to return to step
S202;It is no, then follow the steps S207.
Step S207, block chain client chooses a slave node and is updated to host node, and returns to step S202.
Based on above-mentioned implementation one, block chain client, can be in candidate access node when needing to send communication data
Middle configuration host node and slave node, and preferentially attempt to initiate the connection to host node.If successful connection, disappear to host node transmission
Breath.If connection failure, then slave node is updated to host node, and reattempt to and initiate the connection to updated host node, thus
As long as guarantee has attachable candidate access node, information one is surely sent successfully, realizes block chain client and block
Reliability communications between chain.Maintain communication to monitor candidate access node in addition, whole process does not need block chain client
Available mode, therefore the execution logic and resource consumption of block chain client has been greatly optimized.
This implementation two
As shown in figure 3, the main flow of this implementation two includes:
Step S301, block chain client judge locally whether be cached with history node configuration information, the configuration of history node
Information indicates the host node of block chain client history setting and from node;It is to then follow the steps S302;It is no, it thens follow the steps
S303。
Step S302, block chain client are based on history node configuration information, determine the master in multiple candidate access nodes
Node and slave node.
In this step, the candidate access section for being once set as host node can be determined based on history node configuration information
Point, and host node is set by candidate's access node, remaining candidate access node is set as slave node.
Step S303, block chain client configure the host node of block chain client and standby in multiple candidate access nodes
Node.
Step S304, block chain client initiate the connection for being directed to host node.
Step S305, block chain client judge whether to be successfully connected host node;It is to then follow the steps S306;It is no, then it holds
Row step S309.
Step S306, block chain client send message to host node.
Step S307, block chain client judge whether message sends success;It is then to terminate;It is no, then return to step
S304。
Step S308, block chain client generate new history node configuration information and are cached.
In this step, if previously caching the history node configuration information haveing been friends in the past, new history node can be configured
Information replaces old history node configuration information.
Whether step S309, the judgement of block chain client are directed to the reconnection number of host node less than 3;It is then to return to step
S304;It is no, then follow the steps S310.
Step S310, block chain client chooses a slave node and is updated to host node, and returns to step S304.
Based on above-mentioned implementation two, block chain client, can be according to local cache when needing to send communication data
History node configuration information continues to continue to use in multiple candidate choosing accesses once configured host node, and preferentially attempts to main section
Point initiates the connection.If successful connection, message is sent to host node.If connection failure, then slave node is updated to host node, and
It reattempts to and is initiated the connection to updated host node, as long as to guarantee there is attachable candidate access node, information one
Surely send the reliability communications successfully realized between block chain client and block chain.In addition, whole process does not need area
Block chain client maintains communication to monitor the available mode of candidate access node, therefore holding for block chain client has been greatly optimized
Row logic and resource consumption.
It is the introduction to the method for the embodiment of the present application above.It should be understood that not departing from hereinbefore basis,
Variation appropriate can also be carried out, these variations also should be regarded as the protection scope of the embodiment of the present application.
With above-mentioned block chain communication means correspondingly, as shown in figure 4, the embodiment of the present application also provide it is a kind of based on block
Chain communication device 400, comprising:
Node selection module 410, when block chain client prepares to send message to block chain, in the more of the block chain
Selection target node in a candidate's access node.
Initiation module 420 is connected, the connection for the destination node is played.
Information sending module 430 sends communication data to destination node if being used for successful connection.
Block chain communication device based on shown in Fig. 4, block chain client is when preparing to send information to block chain, directly
The access node in connection block chain is attempted, and sends information to access node after successful connection.Due to entire communication process
The available mode that block chain client monitors access node is not needed, so that the execution complexity and resource of block chain client disappear
Consumption is greatly optimized.
Optionally, the device of the embodiment of the present application can also determine block chain client in multiple candidate access nodes
Host node and slave node, and preferentially choose host node as destination node.
As one of implementation, the node selection module 410 of the embodiment of the present application includes:
Node acquiring unit starts communication thread, to obtain multiple candidate access nodes of access block chain.
Node configuration unit configures the host node of the block chain client and standby in the multiple candidate access node
Node, wherein the priority that the host node is selected as the destination node is higher than the slave node.
Illustratively, it is assumed that node acquiring unit is based on communication thread and gets candidate access node 1, candidate access node
2 and select access node 3.Wherein, the corresponding priority weighting of candidate access node 1 is III, and candidate access node 2 is corresponding preferential
Grade weight is III, and the corresponding priority weighting of candidate access node 3 is I.If priority weighting is directly proportional to value, Qu Jiedian
Configuration unit as standby to save candidate access node 1 as host node, and by candidate access node 2 and candidate access node 3
Point.
As another implementation, the node selection module 410 of the embodiment of the present application can also include:
Node acquiring unit starts communication thread, to obtain multiple candidate access nodes of access block chain.
Node configures determining module, the history node configuration information based on local cache, from multiple candidate access nodes
Determine the host node and slave node of the block chain client.
Illustratively, it is assumed that node acquiring unit is based on communication thread and gets candidate access node 1 to candidate's access section
Point 8.Wherein, find that candidate access node 5 was once used as the host node of block chain client with confidence based on history node, then
Node, which configures determining module, directly to regard candidate access node 5 as host node, remaining candidate access node 1-4,6-8 conduct
Slave node.
Optionally, node selection module 410 specifically selected in multiple candidate access nodes of block chain host node as
Destination node.
Optionally, when the number for connecting master node failure is greater than predetermined threshold, node selection module 410 is in block chain
Select slave node as updated host node in multiple candidate's access nodes, and using updated host node as the target
Node.As long as the device one of the embodiment of the present application is surely successfully transmitted information that is, there is attachable candidate access node.
Optionally, the device node acquiring unit of the embodiment of the present application can also be for the multiple candidate access node
When the connection of initiation all fails, multiple candidate access nodes of access block chain are updated again through communication thread.
Optionally, the device of the embodiment of the present application includes:
Network prompts module prompts to check in the connection all failures initiated for the multiple candidate access node
The network equipment.
Obviously, the block chain communication device of the embodiment of the present application can be used as above-mentioned block chain communication means shown in FIG. 1
Executing subject, therefore the block chain communication device can be realized the function that block chain communication means is realized in Fig. 1-Fig. 3.By
Identical in principle, repeats no more herein.
Fig. 5 is the structural schematic diagram of one embodiment electronic equipment of the application.Referring to FIG. 5, in hardware view, the electricity
Sub- equipment includes processor, optionally further comprising internal bus, network interface, memory.Wherein, memory may be comprising interior
It deposits, such as high-speed random access memory (Random-Access Memory, RAM), it is also possible to further include non-volatile memories
Device (non-volatile memory), for example, at least 1 magnetic disk storage etc..Certainly, which is also possible that other
Hardware required for business.
Processor, network interface and memory can be connected with each other by internal bus, which can be ISA
(Industry Standard Architecture, industry standard architecture) bus, PCI (Peripheral
Component Interconnect, Peripheral Component Interconnect standard) bus or EISA (Extended Industry Standard
Architecture, expanding the industrial standard structure) bus etc..The bus can be divided into address bus, data/address bus, control always
Line etc..Only to be indicated with a four-headed arrow in Fig. 5, it is not intended that an only bus or a type of convenient for indicating
Bus.
Memory, for storing program.Specifically, program may include program code, and said program code includes calculating
Machine operational order.Memory may include memory and nonvolatile memory, and provide instruction and data to processor.
Processor is from the then operation into memory of corresponding computer program is read in nonvolatile memory, in logical layer
Question and answer are formed on face to data mining device.Processor executes the program that memory is stored, and is specifically used for executing following behaviour
Make:
When block chain client prepares to send message to block chain, in multiple candidate access nodes of the block chain
Selection target node;
Initiate the connection for being directed to the destination node;
If successful connection, the destination node is sent the message to.
Electronic equipment based on the embodiment of the present application, block chain client is when preparing to send information to block chain, directly
The access node in connection block chain is attempted, and sends information to access node after successful connection.Due to entire communication process
The available mode that block chain client monitors access node is not needed, so that the execution complexity and resource of block chain client disappear
Consumption is greatly optimized.
Block chain communication means disclosed in the above-mentioned embodiment illustrated in fig. 1 such as the application can be applied in processor, or
It is realized by processor.Processor may be a kind of IC chip, the processing capacity with signal.During realization, on
Each step for stating method can be completed by the integrated logic circuit of the hardware in processor or the instruction of software form.It is above-mentioned
Processor can be general processor, including central processing unit (Central Processing Unit, CPU), network processes
Device (Network Processor, NP) etc.;Can also be digital signal processor (Digital Signal Processor,
DSP), specific integrated circuit (Application Specific Integrated Circuit, ASIC), field programmable gate
Array (Field-Programmable Gate Array, FPGA) either other programmable logic device, discrete gate or crystalline substance
Body pipe logical device, discrete hardware components.May be implemented or execute disclosed each method in the embodiment of the present application, step and
Logic diagram.General processor can be microprocessor or the processor is also possible to any conventional processor etc..In conjunction with
The step of method disclosed in the embodiment of the present application, can be embodied directly in hardware decoding processor and execute completion, or with decoding
Hardware and software module combination in processor execute completion.Software module can be located at random access memory, flash memory, read-only storage
In the storage medium of this fields such as device, programmable read only memory or electrically erasable programmable memory, register maturation.It should
The step of storage medium is located at memory, and processor reads the information in memory, completes the above method in conjunction with its hardware.
It should be understood that above-mentioned block chain communication device may be implemented shown in Fig. 1-Fig. 3 in the electronic equipment of the embodiment of the present application
Embodiment function, repeats no more herein.
Certainly, other than software realization mode, other implementations are not precluded in the electronic equipment of the application, for example patrol
Collect device or the mode of software and hardware combining etc., that is to say, that the executing subject of following process flow is not limited to each patrol
Unit is collected, hardware or logical device are also possible to.
In addition, the embodiment of the present application also proposed a kind of computer readable storage medium, the computer readable storage medium
One or more programs are stored, which includes instruction, and it is included the portable of multiple application programs which, which works as,
When formula electronic equipment executes, the method that the portable electronic device can be made to execute embodiment illustrated in fig. 1, and be specifically used for executing
Following methods:
When block chain client prepares to send message to block chain, in multiple candidate access nodes of the block chain
Selection target node;
Initiate the connection for being directed to the destination node;
If successful connection, the destination node is sent the message to.
It should be understood that above-metioned instruction can make above when the portable electronic device for being included multiple application programs executes
The block chain communication device realizes Fig. 1-embodiment illustrated in fig. 3 function, and repeats no more herein.
It will be understood by those skilled in the art that the embodiment of this specification can provide as the production of method, system or computer program
Product.Therefore, complete hardware embodiment, complete software embodiment or implementation combining software and hardware aspects can be used in this specification
The form of example.Moreover, it wherein includes the computer of computer usable program code that this specification, which can be used in one or more,
The computer program implemented in usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) produces
The form of product.
It is above-mentioned that this specification specific embodiment is described.Other embodiments are in the scope of the appended claims
It is interior.In some cases, the movement recorded in detail in the claims or step can be come according to the sequence being different from embodiment
It executes and desired result still may be implemented.In addition, process depicted in the drawing not necessarily require show it is specific suitable
Sequence or consecutive order are just able to achieve desired result.In some embodiments, multitasking and parallel processing be also can
With or may be advantageous.
The above is only the embodiments of this specification, are not limited to this specification.For those skilled in the art
For, this specification can have various modifications and variations.All any modifications made within the spirit and principle of this specification,
Equivalent replacement, improvement etc., should be included within the scope of the claims of this specification.