From ae6bf0f96dec6b9568d5f587f76968a7c7dc7d41 Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Sun, 29 Nov 2020 08:48:56 -0600 Subject: [PATCH] messenger v0.9 --- __pycache__/agent.cpython-38.pyc | Bin 2536 -> 2048 bytes __pycache__/mail.cpython-38.pyc | Bin 1488 -> 1603 bytes __pycache__/mailroom.cpython-38.pyc | Bin 968 -> 968 bytes __pycache__/message.cpython-38.pyc | Bin 732 -> 708 bytes __pycache__/schemes.cpython-38.pyc | Bin 1146 -> 1001 bytes __pycache__/server.cpython-38.pyc | Bin 678 -> 1206 bytes __pycache__/session.cpython-38.pyc | Bin 1374 -> 1803 bytes agent.py | 72 ++++++++------------------- mail.py | 9 ++-- message.py | 6 +-- schemes.py | 20 ++++---- server.py | 39 +++++++++++++-- session.py | 74 +++++++++++----------------- 13 files changed, 105 insertions(+), 115 deletions(-) diff --git a/__pycache__/agent.cpython-38.pyc b/__pycache__/agent.cpython-38.pyc index 2fc5689b5cc0d30cf855f8f967b0b4c297a01ed6..e02fcf36c48affe73aacdc1f047fdfe6102c204e 100644 GIT binary patch literal 2048 zcmZuyPj4eN6t~Bo$#k0j+dr%T0a;GuKr4X|2ha*sw6K>hqT0(`M#I?cPMUav?X;wt zp6Hctu!mIQ(l5b{X41 zcP6T`U{(%mTTA0@s%A8rsJbd`t&V$VwSB#C;~jWk@SR?%dM{u8*gGqyyTNr8-HHLO zaqh!3+aLsKNkLi)62fsvuIWKPavdY}X^kimeokj^*kf>}CUlMOd8BL=uJzozI^yr_j#4m>T7xDW9HZ2ttq8It-kpUG9 zqQ~dai$e6UJ|I%AgE<6V5HfD%uQrfpz}6+IvGvhZZ-UD{(}+tWLj4F8abWl^D&9kZ z4D}NfcbL5ox{qNR3ahrvAUKB!BjR1Zguj`D<>IC@Si}W#=@4_^gJVLi=M$exF zjBh1-r4?7;_P`e4K^i9Ok^q zmQdd+)jsuJ?nS(h9x!zl!rMZt-3h7V1A|>7CL?GE=x$M0(B1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rZrHy_jRL#j@1nC;R3#Lz#9ER`3i!@VH% z!*|=~!wy<+*|XoL*t8P5by?B0pXdi=k?!cKbO(`@H<@q3H5bMW`VW?LP{{F$Q2qyX C%OJV{ diff --git a/__pycache__/mail.cpython-38.pyc b/__pycache__/mail.cpython-38.pyc index 6a79f0ad1e61fc959517db1db5396963092b1808..67d45850e4dc9d4560aa372e5c7b7a68af339f60 100644 GIT binary patch delta 736 zcmZvZ&ubGw6vyYyk7S!xDB;@-ABD_6gIYLZ>a4~o|q++&iJX^b9K3@Jn2C4^!D6tYQR970s21Hv*nzP71+Qk>LnIbfmT588bzKhS zNSTCowwLLmOih{;xs8&S2qj6bvN~6>r+v(`!o>weWmIJr#i>I;hanxlsgDw^viGZq zGz2qPhaQ})QMo5&_nAMM-AA-#XRL*Dm~sPWyk+mamY;KQBP=;CIjD*_Xo+bF|lRp-&qZL(JDt(g}I2o=gKn&)0xQP)BMf4aKoHOx9 zc-?FN`F2F9H^@+Vy+MWs*4NS4uraAAvQnA1b*|}2UeZ`}KmCmrA%zU2=zjb69{=m^ WJa-9lyR7qrv3f>t&plKL()$aH!=sk~ diff --git a/__pycache__/mailroom.cpython-38.pyc b/__pycache__/mailroom.cpython-38.pyc index cba747dd28fdfe6f6432b3f4f81071a1886a5894..cf55692f201a934d6bf5f349f54fdf9a75010839 100644 GIT binary patch delta 20 acmX@XeuAAll$V!_0SL;A_HE?e%M1WCM+HUz delta 20 acmX@XeuAAll$V!_0SH!Q?%c?|ml*&xT?K0Z diff --git a/__pycache__/message.cpython-38.pyc b/__pycache__/message.cpython-38.pyc index 77079d0b612704e5531ab0b8b26223cbb1873b52..20e50b36d79678f3901e207dcbbb37911e68d5d8 100644 GIT binary patch delta 311 zcmcb^dW4lXl$V!_0SFS7?uz%E$QxJB2IL$D;^J9AqJ$xfaRJjph9a2~<^?P%j0+h( z8B!QL7#JA}A#$t>8EP477_!(vs){SXERYyu3Bv;R8pbS+g^aaKC7eKUuGtJJOf^hk zni(j=J)2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Tb_%h_B%k;#F(oif^=i(?lF|pA>bptB;d(^l5S=(ToaaDxqnRdO(Vx z+=WOKJ%LzanDIKk$D&wU!d&!3uU(^drhbsp#ZrzZY6hC6t4sN1mW(Qkp#qpyQhyuf pMnEc&p*At}Gt#b%8hMe3?nQoiia)WO|M$#An^oM`^!7J|{Q>y4^WOjf diff --git a/__pycache__/server.cpython-38.pyc b/__pycache__/server.cpython-38.pyc index ff30f0d620cc8f4ccfa5e5949a0e36dc6e4633d5..41fac4eebd5c91ed9d2f744607a7db83a8acfc05 100644 GIT binary patch literal 1206 zcmZuw&2AGh5cc1ClWh`Os6hNj9FQUbxgZV|LL5K>2^B;^LcT=H+D*4fb|c#XS}mt? zgeRzwc8|OS7v92GPP_u*z}P9JNO`B^EfWi6B8zL4#z11sRD*62T=EagIbwG8uh9qAj_MK_;>#+aOmY-a>=q z2Y5%DqCG9Mbh=X-o8P^LQ08y{Gax$T=Qo(8~Km$;&b=rcLM7}x%fyI@z&DllJM(Dt8L@hMC}jn(Mr<;C*jy9DiI` zRamiRR3S&{81xbBf^cza_KGYo9UrH5M`^Jt%YRN7(UEGJzfpQLOY^DYi@8j#8bsPB zAMRXIf><3kx(znLm%hIseHxZO?+jlWrOhyv;{|Zj5XA6-G80?Qher|LoB=acjFle3 zQMl{Ye9!f!>7vMXMo0A5z?ZoIfM`NHIKiCs=xMx48R3NgO4_SLufy&?O+o!}n4u{) zK&eoT8ni4KGzPJ_CeRqMzHX^yb=05(Xc)^YXqtoL(uNY^%|Yy#R@ocP!IO>w95q%u zwpip+L>_O47zR|Y`dv1Mq=rO=R4n04*nwmgL(ohM0O1}`>QH?i^voMhj^nPr0agod z%;G~Ni6zjrEOafcnT;&Aq@jPhF@#Jv_b)%m4OBWW#{KP5_y3m5^vk0E6K@Q-_D|fg zM^Cq2IQH!6^A|38t6rNjn<#5sw5*7a>;ws4S-oU3&9|*jtziHNuVZ}`uW;j)Jn51x^}=;4xwkWOE_z(4%{->X`8XQf{$se?Dy|5^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C5Ouz z?04D>B@1Te6<6zU&<45|Vxl(SJL@h=G{>ANq^RoPnRP7J6$}-^cN^#~7j*^COO9%= zWc5Q32y#e!lzBIyPP~}T?q9)tk8C|W<-rWUe7z`Kb z;p!c0?Xx~}0l3in)Uo82)9O7?x(!|9V?%%f*M+#G+n^s?cqn8s7VuCcc|LCV6xf&B zZk``ai+ZsWga;3UYENC-h9A|4W?i6W$JtYz&ad+d2Hwl5*4qd-Yb z4+trgRMgb`i)|@T{sI*3b+kg$`x1P5lKT8sTjscC4hFJjyJS(MP?YI@H=`S zd?f~1QNFBRFN-F7wRF`jv5y$T5t#EBZLB~Lr@=t}^c?NxIaWLqoO95JpiY4Cq)(68 zgiPpXMuGVWk%8xm9a2~ks61GIG`>15Su0`mKJ3yE(GBYmN-@3;SDPV`vM`00vYyLr zG01!-3sr|hTNvMEHFvt)0@ojMz7UIT@#{`+(`oB^nc5y11v71WYudf?)v(tB-Nu@= z+19q#?!G)cupwk$26fm!gf6m(jXUi%Ezb^B#pF?8yu#Pj1&vD5YLjG}S!)OeucuK4-kJ<7KS-6&ncE0+yNzzq6r z413nxWCNWp?7)?ky7km?<_=6=RCVY|t%qNjO&~Un+C*fkq03%Gh>ohx0lVw))nNwV zi?kDT*!bFviN8bt&&V@KpO8Lr*E}?ZI#c;BG8LRM1uK4z8I1oIGbc#Dod?qmE#8w| zL~{vDI^XuLM4r+m?A~)l*$#&ORr$QqWdW~EV)6|La0pI#L_3r*sGW_k{;B*-=z2G< zp+k{+>`*BOl^Oy4vYwZ6ca)W_CzeuGxs*+J*(E%|6*Q;EXl8f|7TXCY4e<%(QIaGJ z%~$wga9<2`Q*FxetQH$Dja?3pT)Q;hm`*G{$C^LK2*mr>Ms;#;dfNMl;qU+nO&BOm Fg5Q^SQaJzs diff --git a/agent.py b/agent.py index 3d9c283..4d654b3 100644 --- a/agent.py +++ b/agent.py @@ -13,74 +13,44 @@ class Agent: """ def __init__(self, connection): - self.connection = connection + self.service = None + self.client_connection = connection - # Submit a request for info, return response. - # Must disclose what service it's for. - async def fetch(self, entities, service): - - # Assert list. - if type(entities) == str: - entities = [entities] - - print(f"Fetching {[e for e in entities]} for {service}") - - # Build intent. + def fetch(self, entity, invocation): + # Create the intent. params = { - "service": service, - "entities": entities - }; intent = typs.Intent("fetch", params) - - # Send intent to agent, wait for response. - await self.send_agent_intent(intent) - response = await self.recv_agent_intent() - - # Parse response and return entities. - entities = response.params.get("found") - print(f"Fetch response: {entities}") - return entities + "entity": entity, + "service": self.service, + "invocation": invocation + } + intent = typs.Intent(name="fetch", params=params) - # Text the client something. Also, let agent know - # when your service is complete via the complete - # attribute. - # Must disclose what service it's for. - async def notify(self, text, end=False): + self.send_agent_intent(intent) + intent = self.recv_agent_intent() - print(f"Notifying: {text} for {self.service}") + response = intent.params.get("response") + return response + def notify(self, text, end=False): + # Create the intent. params = { - "service": self.service, - "text": text, + "text": text, + "service": "message", "end": end } - - # Build the intent - intent = typs.Intent("notify", params) - - # Send intent to agent. - await self.send_agent_intent(intent) - - # Get user info. - async def sync(self): - - intent = typs.Intent("sync", params={}) + intent = typs.Intent(name="notify", params=params) # Send intent to agent. - await self.send_agent_intent(intent) - - # Recv and return profile. - intent = await self.recv_agent_intent() - profile = intent.params.get("profile") - return profile + self.send_agent_intent(intent) async def recv_agent_intent(self): - package = await self.connection.recv() + package = await self.client_connection.recv() intent = self.__decode(package) return intent async def send_agent_intent(self, intent): package = self.__encode(intent) - await self.connection.send(package) + await self.client_connection.send(package) def __encode(self, intent: typs.Intent): package = json.dumps(intent.__dict__) diff --git a/mail.py b/mail.py index 489b2a0..c2a61a5 100644 --- a/mail.py +++ b/mail.py @@ -8,9 +8,10 @@ class Mail: """Session interface for mailroom. Two main IO methods. Will translate intents to mail and vice versa. + Should be a parent class of Session. """ def __init__(self): - pass + self.crimata_id = False # Receive intent. async def mailbox_recv(self): @@ -21,6 +22,7 @@ class Mail: # Send intent. def mailbox_send(self, intent): mail = self.__encode(intent) + print(f"Putting message into outbox {self.crimata_id}") mailroom.put_mail(self.crimata_id, mail) def __encode(self, intent: typs.Intent) -> typs.Mail: @@ -33,10 +35,11 @@ class Mail: @staticmethod def __decode(mail: typs.Mail) -> typs.Intent: - name = "notify" + name = "message" params = { + "owner": mail.owner, "text": mail.text #dev only } intent = typs.Intent(name, params) return intent - \ No newline at end of file + \ No newline at end of file diff --git a/message.py b/message.py index 76a1c02..ef5959b 100644 --- a/message.py +++ b/message.py @@ -6,9 +6,7 @@ import mailroom # Independent loop that updates mailboxes. -async def messenger(): - - print("Running Messenger") +async def messenger(): while True: @@ -19,7 +17,6 @@ async def messenger(): # Grab a mailbox. mailbox = mailroom.que.get() - print(f"Handling mailbox: {mailbox.name}.") # Handle every message in outbox. while not mailbox.outbox.empty(): @@ -27,6 +24,7 @@ async def messenger(): # Get mailbox of target and put mail there. target_mailbox = mailroom.get_mailbox(message.target) + print(f"{mailbox.name} -> {target_mailbox.name}: {message.text}") await target_mailbox.inbox.put(message) # Put the mailbox back diff --git a/schemes.py b/schemes.py index 1703a86..9a85986 100644 --- a/schemes.py +++ b/schemes.py @@ -3,27 +3,29 @@ class Schemes: - def __init__(self): - self.service = None + def handle_intent(self, intent): + print(f"Handling {intent.name}.") - async def handle_intent(self, intent): - print(f"Handling intent {intent.name}.") - - # Set the service + # Set the service. self.service = intent.name + # Run intent endpoint. if intent.name == "init": - await self.init(intent) + self.init(intent) + if intent.name == "message": self.message(intent) - async def init(self, intent): + # Init session by setting Crimata ID. + def init(self, intent): self.crimata_id = intent.params.get("crimata_id") - await self.notify("Messaging is live.") + print(f"Initalized for {self.crimata_id}") + # Push message to anoter Crimata ID. def message(self, intent): text = intent.params.get("text") target = intent.params.get("target") #crimata_id + print(f"Messaging {target}: '{text}'") # Uses mail.Mail interface. diff --git a/server.py b/server.py index 58ce7b8..c7bbdc0 100644 --- a/server.py +++ b/server.py @@ -1,27 +1,60 @@ # server.py +import json +import uuid import asyncio import websockets +import typs import session HOST = "localhost" PORT = 8764 +token_refs = {} # Makes instance of a Messenger session for every client that connects. -async def launch_session(connection, path): +async def launch_session(token, connection): + + # Create the session. s = session.Session(connection) + # Login if token. + if token in token_refs.keys(): + crimata_id = token_refs.get(token) + s.crimata_id = crimata_id + + print(f"Reconnected: {crimata_id}") + + # Update client's login token. + intent = typs.Intent("token", params={"text": token}) + await s.send_agent_intent(intent) + + # Run core loops. await asyncio.gather( - s.do_agent_intents(), + s.do_agent_intents(), s.deliver_mail() ) + # Update state before end. + token_refs.update({token: s.crimata_id}) + + print("Ended session.") + +async def main(connection, path): + token = await connection.recv() + + # Create Session ID if None. + if token not in token_refs.keys(): + token = str(uuid.uuid4()) + + # Start session with token. + await launch_session(token, connection) #! Not stopping on disconnect + # Run run for every new connection. async def lift(): print(f"Listening for connections on {HOST}:{PORT}") - await websockets.serve(launch_session, HOST, PORT) \ No newline at end of file + await websockets.serve(main, HOST, PORT) \ No newline at end of file diff --git a/session.py b/session.py index 29a1d37..9aa152f 100644 --- a/session.py +++ b/session.py @@ -2,6 +2,7 @@ import time import asyncio +import websockets import mail import agent @@ -17,65 +18,48 @@ class Session(schemes.Schemes, agent.Agent, mail.Mail): """ def __init__(self, connection): agent.Agent.__init__(self, connection) + mail.Mail.__init__(self) - self.crimata_id = False + self.on = True - print("Launched new session") + print("Launched sesssion.") # Recv intents run desired endpoint. async def do_agent_intents(self): - while True: + while self.on: - # Recv intent from agent. - intent = await self.recv_agent_intent() - print(f"Intent: {intent.name}") + try: + intent = await asyncio.wait_for( + self.recv_agent_intent(), timeout=0.2) + except asyncio.TimeoutError: + continue + except websockets.exceptions.ConnectionClosed: + await self.shutdown() + continue # Call corresponding endpoint. - await self.handle_intent(intent) - - await asyncio.sleep(0.1) + self.handle_intent(intent) # Send mail back to agent. async def deliver_mail(self): - while True: + while self.on: - # Sleep until Crimata ID. if not self.crimata_id: - await asyncio.sleep(1) + await asyncio.sleep(0.1) continue - intent = await self.mailbox_recv() - await self.send_agent_intent(intent) - - await asyncio.sleep(0.1) - - - - - - - - - - - - - - - - - - # async def hello(self): - - # intent = await self.recv_agent_intent() - - # response = await self.fetch("crimata_id", service="message") - # self.profile = response.get("profile") - - # target = intent.params.get("target") - # await self.notify(f"Messenger APP: Received Message Intent", - # service="message", complete=True) + # Try recv. + try: + intent = await asyncio.wait_for( + self.mailbox_recv(), timeout=0.2) + except asyncio.TimeoutError: + continue - # print("Shutting down in 10s") + # Send message to Agent. + print("Sending message") + await self.send_agent_intent(intent) - # await asyncio.sleep(10) + # Shutdown protocol. + async def shutdown(self): + print("Shutting down session.") + self.on = False \ No newline at end of file -- 2.43.0