summaryrefslogtreecommitdiffstats
path: root/src/git_tftpd/protocol.py
diff options
context:
space:
mode:
authorAlexander <alex@spline.inf.fu-berlin.de>2015-08-28 02:43:22 +0200
committerAlexander <alex@spline.inf.fu-berlin.de>2015-08-28 02:43:22 +0200
commitb5e718d6f4d37ca31c12eef603c6199c4b89a046 (patch)
tree3f8a96985aae9a998a9a65e9cc8bda3f12ae0fc0 /src/git_tftpd/protocol.py
downloadgit-tftpd-b5e718d6f4d37ca31c12eef603c6199c4b89a046.tar.gz
git-tftpd-b5e718d6f4d37ca31c12eef603c6199c4b89a046.tar.bz2
git-tftpd-b5e718d6f4d37ca31c12eef603c6199c4b89a046.zip
Initial commit
Diffstat (limited to 'src/git_tftpd/protocol.py')
-rw-r--r--src/git_tftpd/protocol.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/git_tftpd/protocol.py b/src/git_tftpd/protocol.py
new file mode 100644
index 0000000..ce270c7
--- /dev/null
+++ b/src/git_tftpd/protocol.py
@@ -0,0 +1,31 @@
+from tftp.protocol import TFTP
+from twisted.internet.defer import inlineCallbacks, returnValue
+
+
+class TFTPProtocol(TFTP):
+ """Simple hack to stop sending packets, if the connection was closed."""
+
+ def __init__(self, backend, _clock=None):
+ TFTP.__init__(self, backend, _clock)
+ self._real_session_sendData = None
+
+ def _session_sendData(self, session, bytes):
+ if session.transport.connected:
+ # Send data, if "connection" is established
+ self._real_session_sendData(bytes)
+ elif session.timeout_watchdog is not None and \
+ session.timeout_watchdog.active():
+ # Kill the timeout watchdog, so that we do not get:
+ # "Timed out after a successful transfer"
+ session.timeout_watchdog.cancel()
+
+ @inlineCallbacks
+ def _startSession(self, datagram, addr, mode):
+ session = yield TFTP._startSession(self, datagram, addr, mode)
+
+ # monkey patch the sendData method
+ self._real_session_sendData = session.session.sendData
+ session.session.sendData = \
+ lambda bytes: self._session_sendData(session.session, bytes)
+
+ returnValue(session)