Structure of the Gnutella node:
There are four types of concurrent processes on a Gnutella node: connection, coordination instance, download instance, and upload instance ).
The connection processor is responsible for managing the establishment of all connections, including self-initiated connections and connections initiated by other nodes. Each coordination process is responsible for processing the activity and status of a closed connection used for handshake and query. When this node needs to upload or download files, a corresponding upload connection or download connection will be established, all activities and statuses of the connection will also be monitored by an upload or download process.
It is worth noting that at the same time, there is only one connection processor in the node, but there may be 0 or more coordinating processes, downloading processes or uploading processes.
Gnutella node connection processor:
The connection processor has six statuses: offline, waiting for ACK, ping, online, search, and coonection request. When a Gnutella node establishes a connection with one or more other nodes, its status is online. At the same time, the connection processor also has a global variable ccount, which is used to save the current number of connections.
Gnutella node coordination process:
The coordinating process has two statuses: Waiting for message and terminate.
When a connection is established for Handshake Communication between nodes, a process in a municipality is also created to manage all the activities and statuses of the new connection.
The coordination process is in the wait for message status at the initial stage of creation. In this status, the coordination process receives five messages, namely Ping, query (search), Pong, and queryhit (search result) and push.
When the coordination process receives a ping message, it first returns a pong message to the node that sent the ping message, and then determines whether the value of the TTL field in the ping message is greater than 0. If the value is greater than zero, after the TTL value is decreased, it is forwarded to other adjacent nodes. In this process, the global flag of the node that sends the ping message and the corresponding route that returns the pong information will be recorded.
When the coordination process receives a query message, the node determines its TTL value. If the value is greater than 0, the node degrades the TTL value and forwards it to other adjacent nodes. Then, determine whether the local file contains a match file with the query message. If yes, return the corresponding queryhit message. In this process, the global flag of the node that sends the ping message and the corresponding route that returns Pong information will be recorded.
When the coordination process receives a queryhit message, it first uses the Global flag in the message to determine whether the message has responded to the query message sent by the node. If not, then, the queryhit message is forwarded based on the recorded route that returns the queryhit message.
When the coordination process receives a push message, a new connection pointing to the push message node will be established, and an HTTP giv message will be sent. After the new connection is created, the new connection will be handed over to a new upload process.
If either of the two ends of the connection managed by the coordination process breaks the connection, the coordination process enters the "Terminate" status.
Gnutella node download process
The download process has five statuses: connect to peer, wait for file, download file, download finished, and terminate.
When a local node requests to download a file from a remote node or the remote node sends a file from a local push request, the download process is created.
The download process is in the connect to peer status at the initial stage of creation. To start file download, the local node sends an http get message containing the file information to be downloaded, and converts the download process status to wait for file.
When a connection error occurs, the download process status changes from wait for file to download finished. If the connection persists and starts to receive data from the remote end, the status of the download process changes from wait for file to download file.
When the file content is continuously sent from the remote end, the download process will always be in the download file State until all the file information is transmitted and no data packet exists in the connection, the download process status changes to download finished.
When the connection is interrupted on the local or remote node, the download process is transferred to the terminate status.
Upload process of Gnutella Node
The upload process has four statuses: Send HTTP header, upload file, upload finished, and terminate.
When the local node receives push information from the remote node and needs to pass the local file to the remote node, the upload process is created.
The upload process is in the send HTTP header status at the initial stage of creation. When receiving an http get message sent from the remote end and converting the upload Process status to upload file.
When the file content is continuously sent to the remote end, the download process will always be in the Upload File status until all the file information is transmitted, the status of the download process is changed to upload finished.
When the connection is interrupted on the local or remote node, the download process is transferred to the terminate status.