Developers.Gnutella.Packet.TimeToLiveAndHops
Time to Live and Hops
This page describes how Gnutella packets work: [1]
There are two numbers stored in the header of every Gnutella packet: TTL and Hops. This part of the document describes how they work:
<source lang="c"> TTL Time To Live. The number of times the message
will be forwarded by Gnutella servents before it is removed from the network. Each servent will decrement the TTL before passing it on to another servent. When the TTL reaches 0, the message will no longer be forwarded (and MUST not).
Hops The number of times the message has been forwarded.
As a message is passed from servent to servent, the TTL and Hops fields of the header must satisfy the following condition: TTL(0) = TTL(i) + Hops(i) Where TTL(i) and Hops(i) are the value of the TTL and Hops fields of the message, and TTL(0) is maximum number of hops a message will travel (usually 7).
</source>
The "usually 7" in the document is wrong. Really old Gnutella applications had packets travel 7 hops. The number commonly in use now is just 3.
Imagine computer 1 makes a new packet and wants to send it. It wants the packet to travel 3 hops. The specification says "Each servent will decrement the TTL before passing it on to another servent." So, computer 1 prepares a packet with the numbers below, and sends it across the Internet. The rule is: fill out the numbers not for you, but for the destination computer. The source computer sends the remote computer a packet with numbers that will make sense when it arrives:
TTL: 2 Hops: 1
This is how it looks flying through the Internet, and how the receiving computer (computer 2) gets it. That computer then adjusts the numbers, and sends it for a second trip:
TTL: 1 Hops: 2
Computer 3 gets it like this. It adjusts the numbers, and sends it one last time:
TTL: 0 Hops: 3
Computer 4 gets it like this. The packet has arrived with a TTL of 0, meaning it's valid, but dead. It can't be forwarded again. It travelled across the Internet 3 times. TTL + Hops = 3 in each case.