Summary of the invention
In view of this, the purpose of the present invention is to provide a kind of message processing method and device, to solve in the prior art
Existing Message processing is easy to appear omission, and code is complicated and does not allow problem easy to maintain.
In a first aspect, being applied to safe distribution of electric power interactive gateway, institute the embodiment of the invention provides a kind of message processing method
State safe distribution of electric power interactive gateway and be built-in with TCP state machine, the safe distribution of electric power interactive gateway respectively with the distribution in distribution network
Main website is connected with distribution terminal, the method includes:
Receive TCP message to be processed;
Message processing mode and institute are determined according to the initial state of the heading of the TCP message and the state machine
State the NextState of state machine;
Handle the TCP message according to the Message processing mode, and by the initial state of state machine be updated to it is described under
One state.
With reference to first aspect, the embodiment of the invention provides the first possible embodiments of first aspect, wherein institute
It states and Message processing mode and the state is determined according to the heading of the TCP message and the initial state of the state machine
The NextState of machine, including:
The message characteristic of the TCP message is determined according to the heading of the TCP message;
The message characteristic is input to the state machine, so that the state machine is according to preset state-transition table and works as
The preceding initial state determines the processing mode to the TCP message and the NextState.
With reference to first aspect, the embodiment of the invention provides second of possible embodiments of first aspect, wherein
Further include before receiving TCP message to be processed:
According to the message characteristic of user configuration and Message processing mode, it is arranged pre- in TCP state machine and TCP state machine
If state-transition table, in the state-transition table comprising multiple groups initial state, message characteristic, NextState and processing mode it
Between corresponding relationship.
With reference to first aspect, the embodiment of the invention provides the third possible embodiments of first aspect, wherein institute
It states and handles the TCP message according to the Message processing mode, including:
Transparent transmission processing or discard processing are carried out to the TCP message.
Second aspect, the embodiment of the present invention also provide a kind of message process device, including:
Receiving module, for receiving TCP message to be processed;
Determining module, for determining message according to the heading of the TCP message and the initial state of the state machine
The NextState of processing mode and the state machine;
Processing module, for handling the TCP message according to the Message processing mode, and by the initial state of state machine
It is updated to the NextState.
In conjunction with second aspect, the embodiment of the invention provides the first possible embodiments of second aspect, wherein institute
Determining module is stated, including:
First determination unit, for determining the message characteristic of the TCP message according to the heading of the TCP message;
Second determination unit, for the message characteristic to be input to the state machine, so that the state machine is according to pre-
If state-transition table and the current initial state, determine the processing mode to the TCP message and the NextState.
In conjunction with second aspect, the embodiment of the invention provides second of possible embodiments of second aspect, wherein institute
Further include before stating receiving module:
TCP state machine is arranged for the message characteristic and Message processing mode according to user configuration in setup module, and
Preset state-transition table in TCP state machine includes multiple groups initial state, message characteristic, Xia Yizhuan in the state-transition table
Corresponding relationship between state and processing mode.
In conjunction with second aspect, the embodiment of the invention provides the third possible embodiments of second aspect, wherein institute
Processing module is stated, including:
Processing unit, for carrying out transparent transmission processing or discard processing to the TCP message.
The third aspect, present example also provide a kind of electronic equipment, including memory, processor, in the memory
It is stored with the computer program that can be run on the processor, wherein the processor executes real when the computer program
Method described in existing first aspect.
Fourth aspect, the embodiment of the present invention also provide a kind of meter of non-volatile program code that can be performed with processor
Calculation machine readable medium, wherein said program code makes the processor execute first aspect the method.
The embodiment of the present invention brings following beneficial effect:The embodiment of the present invention passes through receives TCP report to be processed first
Text;Then Message processing mode and institute are determined according to the initial state of the heading of the TCP message and the state machine
State the NextState of state machine;The TCP message finally is handled according to the Message processing mode, and by the starting shape of state machine
State is updated to the NextState.
The embodiment of the present invention can the initial state when receiving TCP message based on state machine determine Message processing side
Formula, and can between distribution main website and distribution terminal message the different transmission stages, according to determining Message processing mode in net
It shuts realization and carries out different processing to TCP message.Moreover, updating the initial state of state machine, just after handling TCP message
Use when receiving TCP message next time, to Message processing caused by avoiding since the message current transmission stage cannot be distinguished
The problem of omitting reduces code complexity, enhances code robustness and maintainability.
Other features and advantages of the present invention will illustrate in the following description, also, partly become from specification
It obtains it is clear that understand through the implementation of the invention.The objectives and other advantages of the invention are in specification, claims
And specifically noted structure is achieved and obtained in attached drawing.
To enable the above objects, features and advantages of the present invention to be clearer and more comprehensible, preferred embodiment is cited below particularly, and cooperate
Appended attached drawing, is described in detail below.
Specific embodiment
In order to make the object, technical scheme and advantages of the embodiment of the invention clearer, below in conjunction with attached drawing to the present invention
Technical solution be clearly and completely described, it is clear that described embodiments are some of the embodiments of the present invention, rather than
Whole embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art are not making creative work premise
Under every other embodiment obtained, shall fall within the protection scope of the present invention.
Currently, existing safe distribution of electric power interactive gateway in the case where not receiving message, receives the SYN report that main website is sent
Movement A is executed when literary, in the case where the upper message received is the SYN of terminal hair, receive what main website was sent
When SYNACK message execution act B, however, in practical application safe distribution of electric power interactive gateway be difficult distinguish " do not received
Message " and " the SYN both of these case that the upper message received is terminal hair ", cause to be easy to appear something lost to the processing of message
Leakage causes the processing of message to be easy to appear omission, and code is complicated and does not allow easy to maintain.A kind of message provided in an embodiment of the present invention
Processing method and processing device, can the initial state when receiving TCP message based on state machine determine Message processing mode, and energy
In the different transmission stages of message, realize on gateway according to determining Message processing mode between distribution main website and distribution terminal
Different processing is carried out to TCP message.Moreover, the initial state of state machine is updated after handling TCP message, convenient for next time
Use when receiving TCP message avoids omitting Message processing caused by since the message current transmission stage cannot be distinguished
The problem of, reduce code complexity, enhances code robustness and maintainability.
For convenient for understanding the present embodiment, first to a kind of message processing method disclosed in the embodiment of the present invention into
Row is discussed in detail, as shown in Figure 1, the message processing method can be applied to safe distribution of electric power interactive gateway, the safe distribution of electric power
Interactive gateway is built-in with TCP state machine, the safe distribution of electric power interactive gateway respectively with the distribution main website and distribution in distribution network
Terminal connection, includes the following steps:
Step S101 receives TCP message to be processed;
In embodiments of the present invention, illustratively, described in following Tables 1 and 2 state-transition table shown in first row
TCP message can be F_SYN message, or R_SYN message, can also be F_SYN/ACK message, R_SYN/ACK message,
F_ACK message, R_ACK message, F_FIN message, R_FIN message, F_FIN/ACK message, R_FIN/ACK message, RST message,
F_PUSH message, R_PUSH message, F_PUSH/ACK message, R_PUSH/ACK message.
Table 1
Table 2
In embodiments of the present invention, TCP message to be processed can be the transmission of distribution main website, be also possible to distribution terminal
It sends.
Step S102 determines Message processing according to the initial state of the heading of the TCP message and the state machine
The NextState of mode and the state machine;
It in embodiments of the present invention, include message characteristic inside the heading of the TCP message;
The state machine shares 13 kinds of states, as shown in the first row of Tables 1 and 2, illustratively there is CLOSED, SYN_S_
SENT, SYN_T_SENT, SYN_S_RCVD, SYN_T_RCVD, ESTABLISHED, S_FIN_WAIT1, T_FIN_WAIT1, S_
FIN_WAIT2, T_FIN_WAIT2, ST_FIN_WAIT, S_CLOSING and T_CLOSING etc..The initial state of the state machine
Refer to the current state of the state machine.The NextState of the state machine is next shape that state machine terminates that current state is switched to
State.
In practical applications, there are two types of Message processing modes, respectively transparent transmission processing and discard processing, specifically, transparent transmission
Processing may include:Normal transparent transmission retransmits transparent transmission and uncommon transparent transmission etc., and normal transparent transmission refers to state machine by requesting for comments
(Request For Comments, abbreviation RFC) transparent transmission message;After re-transmission transparent transmission refers to that state machine transparent transmission message returns to current state
Transparent transmission message again;Uncommon transparent transmission refers to uncommon normal transparent transmission in practical applications.Discard processing refers in Tables 1 and 2
It is illegal to abandon.
Step S103 handles the TCP message according to the Message processing mode, and the initial state of state machine is updated
For the NextState.
The embodiment of the present invention can the initial state when receiving TCP message based on state machine determine Message processing side
Formula, and can between distribution main website and distribution terminal message the different transmission stages, according to determining Message processing mode in net
It shuts realization and carries out different processing to message.Moreover, the initial state of state machine is updated, under being convenient for after handling TCP message
Use when once receiving TCP message avoids Message processing occur caused by since the message current transmission stage cannot be distinguished
The problem of omission, reduces code complexity, enhances code robustness and maintainability.
In another embodiment of the present invention, as shown in Fig. 2, the step S102 may comprise steps of:
Step S201 determines the message characteristic of the TCP message according to the heading of the TCP message.
In embodiments of the present invention, the message characteristic of the TCP message includes sending direction and type of message.In reality
In, there are two types of sending directions, the message that terminal direction is sent to from main website direction is indicated respectively with the message that F_ starts, with R_
The message of beginning indicates the message that main website direction is sent to from terminal direction.Type of message includes SYN, ACK, FIN, RST, PUSH etc.
Content, these message contents can be designed specifically as the case may be.Connection is established in SYN expression, and ACK indicates response, and FIN is indicated
Connection is closed, RST indicates connection resetting, and PUSH indicates that DATA data are transmitted.Illustratively, F_ACK expression is sent to from main website
Terminal, the message that content is in response to, R_SYN indicates to be sent to main website from terminal, and content is to establish the message of connection.
The message characteristic is input to the state machine by step S202, so that the state machine is according to preset state
Transfer table and the current initial state, determine the processing mode to the TCP message and the NextState.
Illustratively, the current state of the state machine is in CLOSED state, message characteristic F_SYN is input to described
State machine can determine that the processing mode of TCP message is transparent transmission, and the NextState is according to preset state-transition table
SYN_S_SENT。
In embodiments of the present invention, the starting according to the heading and the state machine of the TCP message can be passed through
State determines the NextState of Message processing mode and the state machine, provides foundation for the Message processing of next step.
In another embodiment of the present invention, further include before the step S101:
According to the message characteristic of user configuration and Message processing mode, it is arranged pre- in TCP state machine and TCP state machine
If state-transition table, in the state-transition table comprising multiple groups initial state, message characteristic, NextState and processing mode it
Between corresponding relationship.
The TCP state machine that the present invention is arranged, as shown in figure 3, the state of ellipse representation state machine, arrow indicates state conversion
Direction, the character representation message having on arrow, arrow are to be directed toward NextState by the current state of state machine.
Preset state-transition table in the TCP state machine of setting, as shown in figure 3, the first row indicates the current shape of state machine
State, first row indicate the message received, and the information of other positions indicates the NextState and Message processing mode of state machine.
So including the corresponding relationship between multiple groups initial state, message characteristic, NextState and processing mode in state-transition table.
Through the embodiment of the present invention, can be convenient for utilizing preset shape in the TCP state machine and TCP state machine set
State transfer table determines the NextState and Message processing mode of state machine.
In another embodiment of the present invention, the step S103, including:
Transparent transmission processing or discard processing are carried out to the TCP message.
Transparent transmission processing is a kind of mode of Message processing, i.e., under current state, to the message transmission received, state machine
It is updated according to preset state machine state transfer table to NextState.Illustratively, current state is SYN_S_SENT, if receiving
The message arrived is R_SYN/ACK, and state machine is then updated according to preset state machine state transfer table to NextState SYN_S_
RCVD。
Discard processing is another mode of Message processing, i.e., under current state, packet loss to receiving, and shape
State machine will return to CLOSED init state.Illustratively, current state is SYN_S_SENT, if the message received is F_
SYN/ACK, state machine then return to CLOSED init state according to preset state machine state transfer table.
Through the embodiment of the present invention, message can be handled, processing mode is transparent transmission or discarding.
In another embodiment of the present invention, as shown in figure 4, the apparatus may include with lower module:
Receiving module 11, for receiving TCP message to be processed;
Determining module 12, for determining report according to the heading of the TCP message and the initial state of the state machine
The NextState of literary processing mode and the state machine;
Processing module 13, for handling the TCP message according to the Message processing mode, and by the starting shape of state machine
State is updated to the NextState.
The technical effect and preceding method embodiment phase of device provided by the embodiment of the present invention, realization principle and generation
Together, to briefly describe, Installation practice part does not refer to place, can refer to corresponding contents in preceding method embodiment.
In another embodiment of the present invention, the determining module, including:
First determination unit, for determining the message characteristic of the TCP message according to the heading of the TCP message;
Second determination unit, for the message characteristic to be input to the state machine, so that the state machine is according to pre-
If state-transition table and the current initial state, determine the processing mode to the TCP message and the NextState.
In another embodiment of the present invention, further include before the receiving module:
TCP state machine is arranged for the message characteristic and Message processing mode according to user configuration in setup module, and
Preset state-transition table in TCP state machine includes multiple groups initial state, message characteristic, Xia Yizhuan in the state-transition table
Corresponding relationship between state and processing mode.
In another embodiment of the present invention, the processing module, including:
Processing unit, for carrying out transparent transmission processing or discard processing to the TCP message.
In another embodiment of the present invention, a kind of non-volatile program code that can be performed with processor is also provided
Computer-readable medium, said program code make the processor execute embodiment of the method the method.
The flow chart and block diagram in the drawings show system, method and computer journeys based on multiple embodiments of the invention
The architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generation
A part of one module, section or code of table, a part of the module, section or code include one or more use
The executable instruction of the logic function as defined in realizing.It should also be noted that in some implementations as replacements, being marked in box
The function of note can also occur in a different order than that indicated in the drawings.For example, two continuous boxes can actually base
Originally it is performed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.It is also noted that
It is the combination of each box in block diagram and or flow chart and the box in block diagram and or flow chart, can uses and execute rule
The dedicated hardware based system of fixed function or movement is realized, or can use the group of specialized hardware and computer instruction
It closes to realize.
The computer program product of message processing method provided by the embodiment of the present invention, including storing program code
Computer readable storage medium, the instruction that said program code includes can be used for executing previous methods side as described in the examples
Method, specific implementation can be found in embodiment of the method, and details are not described herein.
It is apparent to those skilled in the art that for convenience and simplicity of description, the system of foregoing description
It with the specific work process of device, can refer to corresponding processes in the foregoing method embodiment, details are not described herein.
In addition, in the description of the embodiment of the present invention unless specifically defined or limited otherwise, term " installation ", " phase
Even ", " connection " shall be understood in a broad sense, for example, it may be being fixedly connected, may be a detachable connection, or be integrally connected;It can
To be mechanical connection, it is also possible to be electrically connected;It can be directly connected, can also can be indirectly connected through an intermediary
Connection inside two elements.For the ordinary skill in the art, above-mentioned term can be understood at this with concrete condition
Concrete meaning in invention.
It, can be with if the function is realized in the form of SFU software functional unit and when sold or used as an independent product
It is stored in a computer readable storage medium.Based on this understanding, technical solution of the present invention is substantially in other words
The part of the part that contributes to existing technology or the technical solution can be embodied in the form of software products, the meter
Calculation machine software product is stored in a storage medium, including some instructions are used so that a computer equipment (can be a
People's computer, server or network equipment etc.) it performs all or part of the steps of the method described in the various embodiments of the present invention.
And storage medium above-mentioned includes:USB flash disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), arbitrary access are deposited
The various media that can store program code such as reservoir (RAM, Random Access Memory), magnetic or disk.
In the description of the present invention, it should be noted that term " center ", "upper", "lower", "left", "right", "vertical",
The orientation or positional relationship of the instructions such as "horizontal", "inner", "outside" be based on the orientation or positional relationship shown in the drawings, merely to
Convenient for description the present invention and simplify description, rather than the device or element of indication or suggestion meaning must have a particular orientation,
It is constructed and operated in a specific orientation, therefore is not considered as limiting the invention.In addition, term " first ", " second ",
" third " is used for descriptive purposes only and cannot be understood as indicating or suggesting relative importance.
Finally it should be noted that:Embodiment described above, only a specific embodiment of the invention, to illustrate the present invention
Technical solution, rather than its limitations, scope of protection of the present invention is not limited thereto, although with reference to the foregoing embodiments to this hair
It is bright to be described in detail, those skilled in the art should understand that:Anyone skilled in the art
In the technical scope disclosed by the present invention, it can still modify to technical solution documented by previous embodiment or can be light
It is readily conceivable that variation or equivalent replacement of some of the technical features;And these modifications, variation or replacement, do not make
The essence of corresponding technical solution is detached from the spirit and scope of technical solution of the embodiment of the present invention, should all cover in protection of the invention
Within the scope of.Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.