Skip to content

Commit

Permalink
chg: [MAS] Added subscription handlers in the CollectingBehaviour of …
Browse files Browse the repository at this point in the history
…the aggregation agent.
  • Loading branch information
cedricbonhomme committed Dec 26, 2023
1 parent 4ab48bf commit 99267c4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
54 changes: 25 additions & 29 deletions scandale/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from api.schemas import ScanDataCreate

# import getpass

try:
from instance import config
except Exception:
Expand Down Expand Up @@ -74,38 +72,31 @@ async def run(self):
else:
print("Did not received any message after 10 seconds")

class SharingBehav(OneShotBehaviour):
async def run(self):
print("SharingBehav running")
msg = Message(to="probe1@localhost") # Instantiate the message
msg.set_metadata(
"performative", "inform"
) # Set the "inform" FIPA performative
msg.set_metadata(
"ontology", "myOntology"
) # Set the ontology of the message content
msg.set_metadata(
"language", "OWL-S"
) # Set the language of the message content
msg.body = "data" # Set the message content

await self.send(msg)
print("Message sent!")

# set exit_code for the behaviour
self.exit_code = "Job Finished!"

# stop agent from behaviour
# await self.agent.stop()
def on_subscribed(self, jid):
print(
"[{}] Agent {} has accepted the subscription.".format(
self.agent.name, jid.split("@")[0]
)
)
print(
"[{}] Contacts List: {}".format(
self.agent.name, self.agent.presence.get_contacts()
)
)

def on_subscribe(self, jid):
print(
"[{}] Agent {} asked for subscription. Let's aprove it.".format(
self.agent.name, jid.split("@")[0]
)
)
self.presence.approve(jid)

async def setup(self):
print("Agent starting . . .")
collecting_behav = self.CollectingBehav()
self.add_behaviour(collecting_behav)

# self.sharing_behav = self.SharingBehav()
# self.add_behaviour(self.sharing_behav)

self.presence.set_available()
self.presence.subscribe("probe1@localhost")

Expand All @@ -117,9 +108,14 @@ async def main():
agent = AggregationEngine(jid, passwd)
await agent.start()

print("Contacts:")
contacts = agent.presence.get_contacts()
for contact in contacts:
print(f" {contact}")

await agent.web.start(hostname="127.0.0.1", port="10000")
print("Web Graphical Interface available at:")
print("http://127.0.0.1:10000/spade")
print(" http://127.0.0.1:10000/spade")
print("Wait until user interrupts with ctrl+C")

# wait until user interrupts with ctrl+C
Expand Down
2 changes: 1 addition & 1 deletion scandale/probe-agent.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "scan",
"period": 3600,
"target": "",
"command": "nmap -p 443 --script /home/cedric/git/nmap-scripts/ms-exchange-version-nse/ms-exchange-version.nse 158.64.126.2",
"command": "nmap -p 443 --script /home/cedric/git/nmap-scripts/ms-exchange-version-nse/ms-exchange-version.nse 127.0.0.1",
"format": "nmap",
"args": [],

Expand Down

0 comments on commit 99267c4

Please sign in to comment.