Editing NatT protocol

From EMule Wiki
Jump to: navigation, search

Warning: The database has been locked for maintenance, so you will not be able to save your edits right now. You may wish to cut-n-paste the text into a text file and save it for later.

The administrator who locked it offered this explanation: site maintenance

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 5: Line 5:
 
NAT (Network Address Translation) Traversal allows Low ID to Low ID connections.
 
NAT (Network Address Translation) Traversal allows Low ID to Low ID connections.
 
There are different techniques to achieve this, like STUN (Simple Traversal of UDP through NATs), or TURN (Traversal Using Relay NAT). For obvious reasons TURN is not suitable for any kind of file sharing applications.  
 
There are different techniques to achieve this, like STUN (Simple Traversal of UDP through NATs), or TURN (Traversal Using Relay NAT). For obvious reasons TURN is not suitable for any kind of file sharing applications.  
The NatT for eMule uses there for STUN, as well as a attempt to become a High ID by reusing the Listening port for outgoing connections, if the NAT device is a Full Cone this technique will make the client fully connectible, but it works only in a few cases.
+
The NatT for eMule uses there for STUN, as well as a attempt to become a High ID by reusing the Listening port for outgoing connections, if the NAT device is a Full Cone this technique will make the client fully connectable, but it works only in a few cases.
 
The main implementation using STUN can connect even through hardware firewalls, it only fails on Symmetric NAT’s, there are as well methods to penetrate these but they require to much overhead and are there fore like TURN not suitable for file sharing.
 
The main implementation using STUN can connect even through hardware firewalls, it only fails on Symmetric NAT’s, there are as well methods to penetrate these but they require to much overhead and are there fore like TURN not suitable for file sharing.
  
Line 13: Line 13:
 
== NAT Tunneling ==
 
== NAT Tunneling ==
 
To establish a communication tunnel from Alice to Bob through a NAT or a firewall Alice (A) sends first an call-back request to Carlo (C) witch records Alice’s UDP port and IP and relays them together with the request to Bob (B).
 
To establish a communication tunnel from Alice to Bob through a NAT or a firewall Alice (A) sends first an call-back request to Carlo (C) witch records Alice’s UDP port and IP and relays them together with the request to Bob (B).
At this point Bob knows all he needs but Alice does not know enough (she does not know his UDP port). Now Bob tries to contact Alice directly over UDP (now his NAT/FW is open for messages form Alice) if she is behind a Full Cone Nat, she will get the message and will be able to reply. If she don’t answers after a short time Bob sends an own call-back request to Carlo or Dave (this depends on the later described different call-back relay schemes), he does the same as before and tells Alice the UDP port and IP of Bob. Now she can send him messages and he will receive them (this fails only if one of the two have a symmetric NAT, see the appendix for explanation). If this is not the first communication between Alice and Bob, Alice knows Bobs old UDP port and before she issue a call-back request she always tries to ping Bob directly. When the port is still valid, this will not only success on a full Cone NAT, but can also helps to save one call-back request on other NAT Types / Firewalls.<br>
+
At this point Bob knows all he needs but Alice does not know enough (she does not know his UDP port). Now Bob tries to contact Alice directly over UDP (now his NAT/FW is open for messages form Alice) if she is behind a Full Cone Nat, she will get the message and will be able to reply. If she don’t answers after a short time Bob sends an own call-back request to Carlo or Dave (this depends on the later described different call-back relay schemes), he does the same as before and tells Alice the UDP port and IP of Bob. Now she can send him messages and he will receive them (this fails only if one of the two have a symmetric NAT, see the appendix for explanation). If everything works they now have a working tunnel, to not loose it they exchange ping messages every few seconds as long as they need the tunnel.
If everything works they now have a working tunnel, to not loose it they exchange ping messages every few seconds as long as they need the tunnel.
+
 
+
  
 
<pre>
 
<pre>
Line 30: Line 28:
 
<pre>
 
<pre>
 
[uint8] pOPS  // bit Field
 
[uint8] pOPS  // bit Field
               // 5 reserved
+
               // 4 reserved
               // 2 IdKind
+
               // 3 IdKind
 
               // 1 req answer
 
               // 1 req answer
[ID]          // variable length determined by the Ping Options above may not be set at all
+
[ID]          // variable length determined by the Ping Options above
 
[Obfiscation]  // uint8    obfuSetings
 
[Obfiscation]  // uint8    obfuSetings
 
               // hash128  userHash
 
               // hash128  userHash
 
</pre>
 
</pre>
There are yet 3 ID Kinds:
 
* IdKind == 0 :: means no ID field sent
 
* IdKind == 1 :: [uint32 4] ed2k ID
 
* IdKind == 2 :: [hash128 16] Kad ID
 
* IdKind == 3 :: [hash128 16] User Hash
 
  
 
== Callback Methods ==
 
== Callback Methods ==
  
 
=== eServer (Lugdunum) ===
 
=== eServer (Lugdunum) ===
The eserver call-back is supported since eserver 17.15, it requires both clients to be on the same server. The call-back is sent to the server from the client’s UDP socket for client to client communication (not from the regular one for client to servers communication), the packet must be obfuscated the server way otherwise it won’t be accepted, the reason why this is done over the client socket is that the server have to see the UDP port of the socket used for NatT. The eserver usually forwards the request from Alice to Bob over his TCP connection with the server this may be delayed up to 12 seconds (to send more requests in one TCP frame), but if the eserver knows a very recent client UDP port of Bob (he may have issued a request to some one seconds ago) than he forwards the call-back request imminently using UDP to Bob. The packet arrives on the client socket but is obfuscated as well the server way (not for simplicity but in order to allow Bob to verify that the packet really was sent by his server) so Bob have to look on the packet’s source IP and direct it to the server UDP socket processing function. The eserver may not forward the ID of Alice to Bob instead he sends a call-back request as if it would come from Bob to Alice telling her Bob’s UDP port that way and saving one UDP frame from Bob (Bob have to check if requester ID is 0 and if it is don’t issue an own call-back request to Alice after the ping fails).
+
The eserver call-back is supported since eserver 17.15, it requires booth clients to be on the same server. The call-back is sent to the server from the client’s UDP socket for client to client communication (not from the regular one for client to servers communication), the packet must be obfuscated the server way otherwise it won’t be accepted, the reason why this is done over the client socket is that the server have to see the UDP port of the socket used for NatT. The eserver usually forwards the request from Alice to Bob over his TCP connection with the server this may be delayed up to 12 seconds (to send more requests in one TCP frame), but if the eserver knows a very recent client UDP port of Bob (he may have issued a request to some one seconds ago) than he forwards the call-back request imminently using UDP to Bob. The packet arrives on the client socket but is obfuscated as well the server way (not for simplicity but in order to allow Bob to verify that the packet really was sent by his server) so Bob have to look on the packet’s source IP and direct it to the server UDP socket processing function. The eserver may not forward the ID of Alice to Bob instead he sends a call-back request as if it would come from Bob to Alice telling her Bob’s UDP port that way and saving one UDP frame from Bob (Bob have to check if requester ID is 0 and if it is don’t issue an own call-back request to Alice after the ping fails).
  
 
The client advertises his support of NatT by setting the flag SRVCAP_NATTRAVERSAL in the server login tag CT_SERVER_FLAGS. The server notifies his support by the SRV_TCPFLG_NATTRAVERSAL and SRV_UDPFLG_NATTRAVERSAL flags.  
 
The client advertises his support of NatT by setting the flag SRVCAP_NATTRAVERSAL in the server login tag CT_SERVER_FLAGS. The server notifies his support by the SRV_TCPFLG_NATTRAVERSAL and SRV_UDPFLG_NATTRAVERSAL flags.  
Line 62: Line 55:
 
/* if eserver gave you a LOWID : the tcp port of the client as seen by eserver (if NAT : the port allocated by NAT device) */
 
/* if eserver gave you a LOWID : the tcp port of the client as seen by eserver (if NAT : the port allocated by NAT device) */
 
</pre>
 
</pre>
The seen port is sent in order to support the attempt described in the top to become a HighID by reusing the listening port, the server tries the connection attempt here form a different IP than his own, this behaviour is optional.
+
The seen port is sent in order to support the attempt described in the top to become a HighID by reusing the listening port, the server tries the connection attempt here form a different IP than his own, this behavior is optional.
  
  
Line 76: Line 69:
 
[uint16 4] Seen Client UDP Port
 
[uint16 4] Seen Client UDP Port
 
[uint32 4] Requester ID (Alice's ID) (may be 0)
 
[uint32 4] Requester ID (Alice's ID) (may be 0)
[obfuscation 17]  // optional
+
[obfuscation 17]  // obtional
 
                 // [uint8 1] obfuscation settings
 
                 // [uint8 1] obfuscation settings
                 // [hash128 16] userhash
+
                 // [hash128 16] userhast
 
</pre>
 
</pre>
  
Line 112: Line 105:
 
[hash128 16]    // File Hash of the pinged file
 
[hash128 16]    // File Hash of the pinged file
 
// the part below is the unofficial mod part (unchanged)
 
// the part below is the unofficial mod part (unchanged)
[uint8 1]        // Mod Opcode (OP_NAT_CALLBACKREQUEST_KAD)
 
 
...
 
...
 
</pre>
 
</pre>
Line 143: Line 135:
 
</pre>
 
</pre>
  
Please refer to the [[NatT_protocol#Additional Features for NatT|Additional Features for NatT]] section for further informations on the XS Buddy feature.
+
Please refer to the Additional Features for NatT section for further informations on the XS Buddy feature.
  
 
== User Mode TCP ==
 
== User Mode TCP ==
Line 167: Line 159:
  
 
=== Communication ===
 
=== Communication ===
All send data segments are equipped with a unique sequence number indicating their position in the data stream. When Bob (B) receives a NAT_DATA segment form Alice (A) he acknowledges it with an NAT_DATA_ACK, if Alice don’t get the acknowledgement she will resend the segment, she will also resend it if she gets acknowledgements for 3 segments with an higher sequence Number when the, while the a acknowledgment for the older segment is still missing (Fast retransmission).
+
All send data segments are equipped with a unique sequence number indicating their position in the data stream. When Bob (B) receives a NAT_DATA segment form Alice (A) he acknowledges it with an NAT_DATA_ACK, if Alice don’t get the acknowledgment she will resend the segment, she will also resend it if she gets acknowledgements for 3 segments with an higher sequence Number when the, while the a acknowledgment for the older segment is still missing (Fast retransmission).
 
+
Note: The sequence number of sent segments always starts with 1 and is incremented by one.
+
 
+
  
 
<pre>
 
<pre>
 
A                    B
 
A                    B
 
             ...
 
             ...
DATA        --->  OnReceived(0)
+
DATA        --->  OnRecived(0)
 
OnSend(0)  <---    DATA_ACK
 
OnSend(0)  <---    DATA_ACK
 
             ...
 
             ...
Line 254: Line 243:
 
The Source Packet is built the following way:
 
The Source Packet is built the following way:
 
<pre>
 
<pre>
[hash128 16]    // file hash
+
[hast128 16]    // file hash
 
[uint16 2]      // source count
 
[uint16 2]      // source count
 
// Source entries 1:
 
// Source entries 1:
Line 380: Line 369:
 
|-
 
|-
 
|}
 
|}
 
== Additional Modifications ==
 
 
=== Fix for eServer Connect ===
 
Due to the need of having the server's UDP Key it is needed to alternate the connection procedure to first obtain the server infos over UDP by OP_GLOBSERVSTATREQ, by the way this is sense full also for obfuscation to get the obfuscated server port.
 
 
=== Fix for Bandwidth Control ===
 
The sending/receiving functions of the Client UDP Socket must not count the size of NatT Data/Ack packets, this bandwidth is already counted by the EMSocket like regular TCP traffic. Counting it on the UDP Socket will result in false values and waisted bandwidth!
 
 
  
 
== NAT Types ==
 
== NAT Types ==
Line 409: Line 389:
 
|-
 
|-
 
|OP_NAT_PING
 
|OP_NAT_PING
| '0xD7'
+
| '_'
 
|-
 
|-
 
|
 
|
 
|-
 
|-
 
|OP_NAT_SYN
 
|OP_NAT_SYN
| '0xD0'
+
| '_'
 
|-
 
|-
 
|OP_NAT_SYN_ACK
 
|OP_NAT_SYN_ACK
| '0xD1'
+
| '_'
 
|-
 
|-
 
|OP_NAT_DATA
 
|OP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'0xB5'
+
| '_'
 
|-
 
|-
 
|OP_CALLBACKREQUEST_XS
 
|OP_CALLBACKREQUEST_XS
| '0xBA'
+
| '_'
 
|-
 
|-
 
|OP_NAT_CALLBACKREQUEST_XS
 
|OP_NAT_CALLBACKREQUEST_XS
| '0xBB'
+
| '_'
 
|-
 
|-
 
|
 
|
 
|-
 
|-
 
|OP_PUBLICPORT_REQ
 
|OP_PUBLICPORT_REQ
| '0xA7'
+
| '_'
 
|-
 
|-
 
|OP_PUBLICPORT_ANSWER
 
|OP_PUBLICPORT_ANSWER
| '0xA8'
+
| '_'
|-
+
|
+
|
+
|-
+
|SRVCAP_NATTRAVERSAL
+
| '0x1000'
+
|-
+
|SRV_TCPFLG_NATTRAVERSAL
+
| '0x00001000'
+
|-
+
|SRV_UDPFLG_NATTRAVERSAL
+
| '0x00010000'
+
 
|-
 
|-
 
|}
 
|}
 
Note: The UDP range 0xD0 to 0xDF is completely reserver for NatT
 
 
== See also ==
 
 
* [[Nattraversal]]
 
 
[[category:Mod_protocol_extensions]]
 

Please note that all contributions to EMule Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see EMule Wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)
Personal tools