Go to the latest version of this document.

# ``twisted`.`pair`.`tuntap`.`TuntapPort``

class documentation

`class TuntapPort(abstract.FileDescriptor): (source)`

Constructor: `TuntapPort(interface, proto, maxPacketSize, reactor, system)`

Implements interfaces: `twisted.internet.interfaces.IListeningPort`

View In Hierarchy

A Port that reads and writes packets from/to a TUN/TAP-device.

Method | `__init__` | No summary
Method | `__repr__` | Undocumented
Method | `connectionLost` | Cleans up my socket.
Method | `doRead` | Called when my socket is ready for reading.
Method | `fileno` | File Descriptor number for select().
Method | `getHost` | Get the local address of this `TuntapPort`.
Method | `logPrefix` | Returns the name of my class, to prefix log entries with.
Method | `loseConnection` | Close this tunnel. Use `TuntapPort.stopListening` instead.
Method | `startListening` | Create and bind my socket, and begin listening on it.
Method | `stopListening` | Stop accepting connections on this port.
Method | `write` | Write the given data as a single datagram.
Method | `writeSequence` | Write a datagram constructed from a `list` of `bytes`.
Class Variable | `maxThroughput` | Undocumented
Instance Variable | `connected` | Undocumented
Instance Variable | `disconnecting` | Undocumented
Instance Variable | `ethernet` | Undocumented
Instance Variable | `interface` | Undocumented
Instance Variable | `logstr` | Undocumented
Instance Variable | `maxPacketSize` | Undocumented
Instance Variable | `protocol` | Undocumented
Method | `_bindSocket` | Open the tunnel.
Method | `_openTunnel` | Open the named tunnel using the given mode.
Instance Variable | `_fileno` | Undocumented
Instance Variable | `_mode` | Undocumented
Instance Variable | `_stoppedDeferred` | Undocumented
Instance Variable | `_system` | Undocumented

Inherited from `FileDescriptor`:

Method | `doWrite` | Called when data can be written.
Method | `getPeer` | Get the remote address of this connection.
Method | `loseWriteConnection` | Undocumented
Method | `pauseProducing` | Pause producing data.
Method | `readConnectionLost` | Indicates read connection was lost.
Method | `resumeProducing` | Resume producing data.
Method | `startReading` | Start waiting for read availability.
Method | `startWriting` | Start waiting for write availability.
Method | `stopConsuming` | Stop consuming data.
Method | `stopProducing` | Stop producing data.
Method | `stopReading` | Stop waiting for read availability.
Method | `stopWriting` | Stop waiting for write availability.
Method | `writeConnectionLost` | Indicates write connection was lost.
Method | `writeSomeData` | Write as much as possible of the given data, immediately.
Constant | `SEND_LIMIT` | Undocumented
Class Variable | `bufferSize` | Undocumented
Instance Variable | `dataBuffer` | Undocumented
Instance Variable | `disconnected` | Undocumented
Instance Variable | `offset` | Undocumented
Instance Variable | `producer` | Undocumented
Instance Variable | `producerPaused` | Undocumented
Instance Variable | `reactor` | Undocumented
Method | `_closeWriteConnection` | Undocumented
Method | `_isSendBufferFull` | Determine whether the user-space send buffer for this transport is full or not.
Method | `_maybePauseProducer` | Possibly pause a producer, if there is one and the send buffer is full.
Method | `_postLoseConnection` | Called after a loseConnection(), when all data has been written.
Class Variable | `_writeDisconnected` | Undocumented
Instance Variable | `_tempDataBuffer` | Undocumented
Instance Variable | `_tempDataLen` | Undocumented
Instance Variable | `_writeDisconnecting` | Undocumented

Inherited from `_ConsumerMixin` (via `FileDescriptor`):

Method | `registerProducer` | Register to receive data from a producer.
Method | `unregisterProducer` | Stop consuming data from a producer, without disconnecting.
Instance Variable | `streamingProducer` | `bool` or `int`

Inherited from `_LogOwner` (via `FileDescriptor`, `_ConsumerMixin`):

Method | `_getLogPrefix` | Determine the log prefix to use for messages related to `applicationObject`, which may or may not be an `interfaces.ILoggingContext` provider.

def __init__(self, interface, proto, maxPacketSize=8192, reactor=None, system=None): (source)
overrides `twisted.internet.abstract.FileDescriptor.__init__`

Parameters
interface | Undocumented
proto | Undocumented
maxPacketSize | Undocumented
reactor | An `IReactorFDSet` provider which this descriptor will use to get readable and writeable event notifications. If no value is given, the global reactor will be used.
system | Undocumented

def __repr__(self) -> `str`: (source)

Undocumented

def connectionLost(self, reason=None): (source)
from `twisted.internet.interfaces.IFileDescriptor`
overrides `twisted.internet.abstract.FileDescriptor.connectionLost`

Cleans up my socket.

Parameters
reason | Ignored. Do not use this.

def doRead(self): (source)
from `twisted.internet.interfaces.IReadDescriptor`
overrides `twisted.internet.abstract.FileDescriptor.doRead`

Called when my socket is ready for reading.

def fileno(self): (source)
from `twisted.internet.interfaces.IFileDescriptor`
overrides `twisted.internet.abstract.FileDescriptor.fileno`

File Descriptor number for select().

This method must be overridden or assigned in subclasses to indicate a valid file descriptor for the operating system.

def getHost(self): (source)
from `twisted.internet.interfaces.IListeningPort`
overrides `twisted.internet.abstract.FileDescriptor.getHost`

Get the local address of this `TuntapPort`.

Returns
`TunnelAddress` | A `TunnelAddress` which describes the tunnel device to which this object is bound.

def logPrefix(self): (source)
from `twisted.internet.interfaces.ILoggingContext`
overrides `twisted.internet.abstract._LogOwner.logPrefix`

Returns the name of my class, to prefix log entries with.

def loseConnection(self): (source)
from `twisted.internet.interfaces.ITransport`
overrides `twisted.internet.abstract.FileDescriptor.loseConnection`

Deprecated since version 14.0.0: `loseConnection` was deprecated in Twisted 14.0.0; please use `twisted.pair.tuntap.TuntapPort.stopListening` instead.

Close this tunnel. Use `TuntapPort.stopListening` instead.

def startListening(self): (source)
from `twisted.internet.interfaces.IListeningPort`

Create and bind my socket, and begin listening on it.

This must be called after creating a server to begin listening on the specified tunnel.

def stopListening(self): (source)
from `twisted.internet.interfaces.IListeningPort`

Stop accepting connections on this port.

This will shut down my socket and call self.connectionLost().

Returns
A `Deferred` that fires when this port has stopped.

def write(self, datagram): (source)
from `twisted.internet.interfaces.IConsumer`
overrides `twisted.internet.abstract.FileDescriptor.write`

Write the given data as a single datagram.

Parameters
datagram:`bytes` | The data that will make up the complete datagram to be written.

def writeSequence(self, seq): (source)
from `twisted.internet.interfaces.ITransport`
overrides `twisted.internet.abstract.FileDescriptor.writeSequence`

Write a datagram constructed from a `list` of `bytes`.

Parameters
seq:`list` of `bytes` | The data that will make up the complete datagram to be written.

maxThroughput = (source)

Undocumented

connected: `int` = (source)
overrides `twisted.internet.abstract.FileDescriptor.connected`

Undocumented

disconnecting: `bool` = (source)
overrides `twisted.internet.abstract.FileDescriptor.disconnecting`

Undocumented

ethernet: `int` = (source)

Undocumented

interface = (source)

Undocumented

logstr = (source)

Undocumented

maxPacketSize = (source)

Undocumented

protocol = (source)

Undocumented

def _bindSocket(self): (source)

Open the tunnel.

def _openTunnel(self, name, mode): (source)

Open the named tunnel using the given mode.

Parameters
name:`bytes` | The name of the tunnel to open.
mode | Flags from `TunnelFlags` with exactly one of `TunnelFlags.IFF_TUN` or `TunnelFlags.IFF_TAP` set.

Returns
A `_TunnelDescription` representing the newly opened tunnel.

_fileno: `int` = (source)

Undocumented

_mode = (source)

Undocumented

_stoppedDeferred = (source)

Undocumented

_system = (source)

Undocumented