Programming ideas and network protocol processing

Source: Internet
Author: User

Four things happened recently.1. JAVA programming ideas
I have been reading JAVA programming thoughts recently. I want to program, use words, and think everywhere!
2. A protocol is being implemented recently.
How to judge a piece of data is an IP datagram is very simple, but it is a big problem. More ideas are triggered.
3. heartbleed of OpenSSL
The length of the header field of a data packet is not the actual length of the data packet. The key is why you trust the so-called peer data.
4. Memory Protection
Do not expect code behavior to be normal. The key is to protect your memory and use mprotect to cancel all access permissions. when you really want to access it, open the permissions again, generally, you can grant permissions to SIGSEGV. The underlying protection is the most reliable! For all computer processing, the fundamental thing is the memory.

First, let's take a look at the formation of Internet protocols. They are not achieved overnight, but on the shoulders of many giants and gnomiters.
1. Internet communication protocols are not designed from the beginning, but are completely designed on the basis of telecommunication networks (telephone communication networks;
2. Internet communication protocols initially run on general computers (as well as a small number of proprietary embedded devices). The principle at the beginning of the design is that the protocol header should be as small as possible to save bandwidth.
3. The 2nd principle is called the mean principle. At the beginning of the design, CPU resources are also a scarce resource. Therefore, the protocol header is not only small, but also simple and easy to parse.
4. In earlier terminal years, the regulations were responsible for defining the format and interpreting it, which subsequently affected the formation of the network protocol stack.


Then, let's take a look at the classification and description of objects in the object-oriented ideology. It is a symbol of entering a civilized society. The animal world and primitive people are not described. They only have sensory concepts, in addition to human beings in a civilized society, there are also descriptions, such as ID cards, archives, and feature descriptions ,.... some people say this is Plato's legacy, but we actually live in Plato's abstract world.
The emergence of types, as the beginning of a programming civilized society, is of extraordinary significance. It once changed the concept of not caring about types, once, you can force type conversion, however, no one guarantees the correctness of such conversions, but in the object world, type is the most basic concept. Any data must have a description to indicate itself, these descriptions even include the names of fields, so that you can perform reflection, introspection, serialization. You need to know that animals and barbarians do not understand introspection... in the object world programming, I can finally answer "who am I?" In the past, you got a pointer and you don't know what type it is. Now you can understand it. In C, run the following code:

struct A *a = ...b = (struct B*)a;
Correct? In fact, this transformation is safe in only one case, depending on the definition of struct:
struct A {       struct B b;       ...};
Do you see anything? This is the type! Programming in the object world, if there is a variable, you can use the reflection mechanism to get its type and get all the features of this type. In a non-object world, a large number of system crashes are caused by "inappropriate transformation". All the Code has no type check mechanism, and everything is in the memory, the program can explain the data content in the memory at will. In fact, the correct method is that the metadata, type information, and description information of the content should also be stored together with the content, just as our ID card should be carried with us, We strictly follow the practice. If I cannot prove your identity information, I cannot even prove that I am a person. The reason why people think that I am at least a person, it may be because the other party thinks that I am similar to him, but this method is not strict.

Finally, let's take a look at the protocol processing. For network packets, you cannot prove that this packet is a strict IP packet or an HTTP packet, of course, I cannot treat the IP address as a perfect protocol. Fortunately, we do not have to be too harsh on the IP address because it inherits the simplicity of the Telecommunications signaling protocol. In other words, after a few tests, we can prove that a piece of data is an IP packet, because we only need to judge that a few fields comply with the format of the IP protocol header. However, this approach is not suitable for application protocols.
The data communication field can be divided into two subsystems: the content subsystem located on the transmission layer, and the content subsystem under it belongs to the transmission subsystem. The equivalent classification is the classification between the familiar resource subnet and the Communication Subnet. For the Communication Subnet, the Protocol is standard, so we can use the telecommunications network's set of procedures, but now people have transplanted that practice to the application layer, which is a breeding ground for bugs. Although many application-layer protocols are also standardized, such standardization cannot be expected. You cannot say that it is suitable if there is no error. I have mentioned in a long time ago that the application layer protocol must have a self-explanatory mechanism. The purpose of the application layer protocol is information exchange, this involves encoding and interpretation of encoding. Is it similar to object serialization and deserialization? In this case, only data exchange can be obtained, rather than waiting for others, counting on others means that the Communication Subnet may be spoofed. The purpose of the Communication Subnet is not information exchange. It is only an identification mechanism and does not involve complicated interpretation issues, so no self-interpretation is required.
Object serialization is a method, and the XML and ASN.1 methods are more common. For XML, in addition to data content, there are also node attributes and names. For ASN.1, everything can be encoded in a unified TLV format, including content and description. Aside from the network protocol, we only consider one scenario. If you have a piece of binary data, please let me know what type it is. When you implement this, do you mimic the IP address or use ASN.1?
RMI is a data exchange that integrates logical processing, which may be better?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.