MCPcopy
hub / github.com/apache/caldera / operation_loop

Method operation_loop

app/contacts/contact_tcp.py:27–46  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

25 loop.create_task(self.operation_loop())
26
27 async def operation_loop(self):
28 while True:
29 await self.tcp_handler.refresh()
30 for session in self.tcp_handler.sessions:
31 _, instructions = await self.contact_svc.handle_heartbeat(paw=session.paw)
32 for instruction in instructions:
33 try:
34 self.log.debug('TCP instruction: %s' % instruction.id)
35 status, _, response, agent_reported_time = await self.tcp_handler.send(
36 session.id,
37 self.decode_bytes(instruction.command),
38 timeout=instruction.timeout
39 )
40 beacon = dict(paw=session.paw,
41 results=[dict(id=instruction.id, output=self.encode_string(response), status=status, agent_reported_time=agent_reported_time)])
42 await self.contact_svc.handle_heartbeat(**beacon)
43 await asyncio.sleep(instruction.sleep)
44 except Exception as e:
45 self.log.debug('[-] operation exception: %s' % e)
46 await asyncio.sleep(20)
47
48
49class TcpSessionHandler(BaseWorld):

Callers 1

startMethod · 0.95

Calls 5

refreshMethod · 0.80
sendMethod · 0.80
decode_bytesMethod · 0.80
encode_stringMethod · 0.80
handle_heartbeatMethod · 0.45

Tested by

no test coverage detected