本文整理汇总了Python中transitions.Machine.on_exit_await_report方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.on_exit_await_report方法的具体用法?Python Machine.on_exit_await_report怎么用?Python Machine.on_exit_await_report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transitions.Machine
的用法示例。
在下文中一共展示了Machine.on_exit_await_report方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Sender
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import on_exit_await_report [as 别名]
class Sender(object):
"""
Class representing the endpoint of the steganographic communication initiating
the steganographic connection setup.
"""
config = None
messenger = None
transmitter = None
steganogram = None
sending_thread = None
states = [
State.IDLE,
State.NOTIFY_SENT,
State.LISTEN,
State.AWAIT_REPORT,
State.FIN
]
def __init__(self, config, messenger, transmitter):
"""
:param config: configuration parameters for the sender
:param messenger: object responsible for communicating the desire of setting up a covert channel
should have:
notify() - notifies the other endpoint that is about to start sending stegano packets
receive() - listens for and receives confirmations of notify()
:param transmitter: object responsible for handling the steganographic communication
"""
self.config = config
self.messenger = messenger
self.transmitter = transmitter
self._load_config()
self.triggers = {
State.IDLE: "send_notify",
State.NOTIFY_SENT: "recv_notify_ack",
State.LISTEN: "recv_pkt",
State.AWAIT_REPORT: "recv_report",
}
self.machine = Machine(model=self, states=Sender.states, initial=State.IDLE)
self.machine.add_transition(trigger=self.triggers[State.IDLE], source=State.IDLE, dest=State.NOTIFY_SENT)
self.machine.on_exit_idle("notify")
self.machine.add_transition(trigger=self.triggers[State.NOTIFY_SENT], source=State.NOTIFY_SENT, dest=State.LISTEN,
conditions=["recvd_notify_ack"])
# TODO: self.machine.on_exit_notify_sent("configure_iptables")
self.machine.add_transition(trigger=self.triggers[State.LISTEN], source=State.LISTEN, dest=State.AWAIT_REPORT,
conditions=["sent_steg"])
self.machine.add_transition(trigger=self.triggers[State.AWAIT_REPORT], source=State.AWAIT_REPORT, dest=State.FIN,
conditions=["recvd_report"])
self.machine.on_exit_await_report("send_report_ack")
def run(self):
self.sending_thread = threading.Thread(name="SendThread", target=self._nfqueue_send)
self.sending_thread.start()
while self.state != State.FIN:
print str(self.state)
trigger = self.triggers[self.state]
getattr(self, trigger)()
time.sleep(2) # for presentation purposes on seminar
def notify(self):
print "Sending {}".format(Messages.NOTIFY)
self.messenger.notify(Messages.NOTIFY)
def recvd_notify_ack(self):
if self.messenger.receive() == Messages.NOTIFY_ACK:
print "Received {}. Will embed steganogram in next packet".format(Messages.NOTIFY_ACK)
return True
return False
def sent_steg(self):
if self.steganogram is None:
print "Steganogram embedded. Waiting for {}".format(Messages.REPORT)
return True
return False
def recvd_report(self):
if self.messenger.receive() == Messages.REPORT:
print "Received {}".format(Messages.REPORT)
return True
return False
def send_report_ack(self):
print "Sending {}. Ending conversation".format(Messages.REPORT_ACK)
self.messenger.notify(Messages.REPORT_ACK)
def _nfqueue_send(self):
self.nfqueue = NetfilterQueue()
self.nfqueue.bind(self.send_queue_num, self._handle_outgoing_packets)
self.nfqueue.run()
def _handle_outgoing_packets(self, pkt):
#.........这里部分代码省略.........