Package nattraverso :: Module portmapper :: Class NATMapper
[show private | hide private]
[frames | no frames]

Class NATMapper

Known Subclasses:
UPnPMapper

Define methods to map port objects (as returned by twisted's listenXX). This allows NAT to be traversed from incoming packets.

Currently the only implementation of this class is the UPnP Mapper, which can map UDP and TCP ports, if an UPnP Device exists.
Method Summary
  __init__(self)
twisted.internet.defer.Deferred get_port_mappings(self)
Returns a deferred that will be called with a dictionnary of the existing mappings.
  info(self, port)
Returns the existing mapping for the given port object.
twisted.internet.defer.Deferred map(self, port)
Create a mapping for the given twisted's port object.
twisted.internet.defer.Deferred unmap(self, port)
Remove an existing mapping for the given twisted's port object.
  _check_valid_port(self, port)
Various Port object validity checks.

Method Details

get_port_mappings(self)

Returns a deferred that will be called with a dictionnary of the existing mappings.

The dictionnary structure is the following:
  • Keys: tuple (protocol, external_port)
    • protocol is "TCP" or "UDP".
    • external_port is the external port number, as see on the WAN side.
  • Values:tuple (internal_ip, internal_port)
    • internal_ip is the LAN ip address of the host.
    • internal_port is the internal port number mapped to external_port.
Returns:
A deferred called with the above defined dictionnary
           (type=twisted.internet.defer.Deferred)

info(self, port)

Returns the existing mapping for the given port object. That means map() has to be called before.
Parameters:
port - The port object to retreive info from
           (type=a twisted.internet.interfaces.IListeningPort object)
Returns:
a tuple (extaddress, extport).
Raises:
ValueError - When there is no such existing mapping

See Also: map() function

map(self, port)

Create a mapping for the given twisted's port object.

The deferred will call back with a tuple (extaddr, extport):
  • extaddr: The ip string of the external ip address of this host
  • extport: the external port number used to map the given Port object
When called multiple times with the same Port, callback with the existing mapping.
Parameters:
port - The port object to map
           (type=a twisted.internet.interfaces.IListeningPort object)
Returns:
A deferred called with the above defined tuple
           (type=twisted.internet.defer.Deferred)

unmap(self, port)

Remove an existing mapping for the given twisted's port object.
Parameters:
port - The port object to unmap
           (type=a twisted.internet.interfaces.IListeningPort object)
Returns:
A deferred called with None
           (type=twisted.internet.defer.Deferred)
Raises:
ValueError - When there is no such existing mapping

_check_valid_port(self, port)

Various Port object validity checks. Raise a ValueError.

Generated by Epydoc 2.1 on Tue Aug 30 14:56:47 2005 http://epydoc.sf.net