Is there any possibility to decorate the Port class from twisted.internet.udp ? I would like to modify the behavior of some methods of the Port class so that it looses or duplicates ... or delays packets from time to time. My goal is to "simulate" some perturbation and to test if my own protocol (designed above UDP) behaves correctly.
Any idea ?
thanks in advance
You don't want to decorate or subclass or modify the behavior of the
udp.Port
class in any way except by submitting patches upstream to Twisted. For one thing, this class really should have been made private; it was never intended for public use, it's an implementation detail of theIReactorUDP
interface.Second, it's not the only such implementation detail within Twisted. See also
twisted.internet.iocpreactor.udp.Port
, which doesn't share much of its implementation.What you want to do is to simply write a wrapper that implements the same interface - something that implements
IUDPTransport
- and then doself.transport = MyPacketDelayingWrapper(self.transport)
in yourDatagramProtocol
.