| Andrew Cooke | Contents | Latest | RSS | Twitter | Previous | Next

C[omp]ute

Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

Last 100 entries

Real-life Financial Co Without ACID Database...; Flexible Muscle-Based Locomotion for Bipedal Creatures; SQL Performance Explained; The Little Manual of API Design; Multiple Word Sizes; CRC - Next Steps; FizzBuzz; Update on CRCs; Decent Links / Discussion Community; Automated Reasoning About LLVM Optimizations and Undefined Behavior; A Painless Guide To CRC Error Detection Algorithms; Tests in Julia; Dave Eggers: what's so funny about peace, love and Starship?; Cello - High Level C Programming; autoreconf needs tar; Will Self Goes To Heathrow; Top 5 BioInformatics Papers; Vasovagal Response; Good Food in Vina; Chilean Drug Criminals Use Subsitution Cipher; Adrenaline; Stiglitz on the Impact of Technology; Why Not; How I Am 5; Lenovo X240 OpenSuse 13.1; NSA and GCHQ - Psychological Trolls; Finite Fields in Julia (Defining Your Own Number Type); Julian Assange; Starting Qemu on OpenSuse; Noisy GAs/TMs; Venezuela; Reinstalling GRUB with EFI; Instructions For Disabling KDE Indexing; Evolving Speakers; Changing Salt Size in Simple Crypt 3.0.0; Logarithmic Map (Moved); More Info; Words Found in Voynich Manuscript; An Inventory Of 3D Space-Filling Curves; Foxes Using Magnetic Fields To Hunt; 5 Rounds RC5 No Rotation; JP Morgan and Madoff; Ori - Secure, Distributed File System; Physical Unclonable Functions (PUFs); Prejudice on Reddit; Recursion OK; Optimizing Julia Code; Cash Handouts in Brazil; Couple Nice Music Videos; It Also Works!; Adaptive Plaintext; It Works!; RC5 Without Rotation (2); 8 Years...; Attack Against Encrypted Linux Disks; Pushing Back On NSA At IETF; Summary of Experimental Ethics; Very Good Talk On Security, Snowden; Locusts are Grasshoppers!; Vagrant (OpenSuse and IDEs); Interesting Take On Mandela's Context; Haskell Cabal O(n^2) / O(n) Fix; How I Am 4; Chilean Charity Supporting Women; Doing SSH right; Festival of Urban Intervention; Neat Idea - Wormholes Provide Entanglement; And a Link....; Simple Encryption for Python 2.7; OpenSuse 13.1 Is Better!; Little Gain...; More Details on Technofull Damage; Palmrest Cracked Too....; Tecnofull (Lenovo Support) Is Fucking Useless; The Neuroscientist Who Discovered He Was a Psychopath; Interpolating Polynomials; Bottlehead Crack as Pre-amp; Ooops K702!; Bottlehead Crack, AKG K701; Breaking RC5 Without Rotation; Great post thank you; Big Balls of Mud; Phabricator - Tools for working together; Amazing Julia RC5 Code Parameterized By Word Size; Chi-Square Can Be Two-Sided; Why Do Brits Accept Surveillance?; Statistics Done Wrong; Mesas Trape from Bravo; European Report on Crypto Primitives and Protocols; Interesting Omissions; Oryx And Crake (Margaret Atwood); Music and Theory; My Arduino Programs; Elliptic Curve Crypto; Re: Licensing Interpreted Code; Licensing Interpreted Code; ASUS 1015E-DS03 OpenSuse 12.3 SSD; translating lettuce feature files into stub steps files; Re: translating lettuce feature files into stub steps files; A Tale of Two Psychiatrists; The Real Reason the Poor Go Without Bank Accounts

© 2006-2013 Andrew Cooke (site) / post authors (content).

What is TCP hole punching?

From: andrew cooke <andrew@...>

Date: Tue, 8 Feb 2011 07:19:15 -0300

It is common (largely because of the restricted number of IPV4 addresses) for
several computers to share the same "external" address.  This is done by NAT
(Network Address Translation) at the point where the internal network meets
the external network.

By default, NAT does not support "incoming" connections.  This is because
there is no simple way for a computer connecting from "outside" to identify a
particular internal computer (since all share the same external address).

The lack of incoming connections means that an application on a computer on an
internal network must initiate all network exchanges and, furthermore, can
only connect to a computer that does have an external address.  This is a
problem for peer-to-peer (P2P) systems, since it requires a separate, public
server to act as the target for connections.

The problem is made worse by the fact that the TCP specification does not
allow for a conversation to be "redirected" to a different machine.  When two
P2P peers have both connected to a central server there is no simple mechanism
for them to address each other directly; all traffic must continue to be
routed through the public server to which the initial connections were made.

This last point is the problem solved by TCP hole punching.  It is a mechanism
that allows two peers to converse directly, even when NAT is in use.

Because a variety of implementations are used, the details that follow are
only a rough sketch.  See the references posted by others for more details [I
am writing this answer not because I am an expert on this, but because I found
neither of the other answers to be very clear].

In general, hole punching requires the following:

- An external, public server that is the target for initial connections, 
  and which helps coordinate the connection process.  

- Two peers behind NAT, who will eventually be connected directly.

- NAT implementations that are lenient in the traffic that they accept, 
  and which are predictable in how they operate.  

- A protocol (like TCP) which is lenient in the traffic it accepts and 
  which, in particular, uses a state machine and messages that are more 
  symmetric than the server / client roles that are assumed at a higher 
  level.

The "leniency" I mention above is driven by the need for these components to
function reliably on unreliable networks and to support a wide variety of
traffic (it is not, typically, a result of poor implementation).

The general process (bearing in mind that this is only a rough sketch) for
hole punching is:

- Peers connect to a central, public server and agree on which pairs will
  connect.

- The central server identifies, for each NAT, how future outgoing connections
  are created (when a peer makes a connection that passes through the NAT then
  a port must be opened on on the NAT to receive the response; typically the
  port numbers used are sequential).

- Peers then open new connections, each aware of the external (NAT) address
  and likely port of the other peer.

By manipulating the TCP traffic (eg. by setting TTL values so that some
outgoing packets cannot reach the other peer) and/or by exploiting uncertainty
in timings and leniency in the NAT and TCP implementations, and by exploiting
symmetry in the underlying state machines and messages, it is then possible
for the two new connections, each of which was opened as client, to reach a
state as though they were opened in a normal client / server conversation.
Once the two peer connections are in the desired state no further use is made
of the public server; the peers can communicate directly with each other.

[From an old Quora answer]

Andrew

Comment on this post