def __init__(self, agent, p2p=False): # , msgrecv): self._client = agent.getAID().getName() #self.msgrecv = msgrecv self.myAgent = agent self._server = agent.server # Add Disco Behaviour agent.addBehaviour(DiscoBehaviour(), Behaviour.MessageTemplate(Iq(queryNS=NS_DISCO_INFO))) # Add Stream Initiation Behaviour iqsi = Iq() si = iqsi.addChild("si") si.setNamespace(NS_SI) #"http://jabber.org/protocol/si") agent.addBehaviour(StreamInitiationBehaviour(), Behaviour.MessageTemplate(iqsi)) # Add P2P Behaviour self.p2p_ready = False # Actually ready for P2P communication self.p2p = p2p self.p2p_routes = {} self.p2p_lock = thread.allocate_lock() self.p2p_send_lock = thread.allocate_lock() self._p2p_failures = 0 # Counter for failed attempts to send p2p messages if p2p: agent.registerLogComponent("p2p") self.P2PPORT = random.randint(70000, 80000) # Random P2P port number p2pb = P2PBehaviour() agent.addBehaviour(p2pb)
def __init__(self, agent, p2p=False): # , msgrecv): self._client = agent.getAID().getName() #self.msgrecv = msgrecv self.myAgent = agent self._server = agent.server # Add Disco Behaviour agent.addBehaviour( DiscoBehaviour(), Behaviour.MessageTemplate(Iq(queryNS=NS_DISCO_INFO))) # Add Stream Initiation Behaviour iqsi = Iq() si = iqsi.addChild("si") si.setNamespace(NS_SI) #"http://jabber.org/protocol/si") agent.addBehaviour(StreamInitiationBehaviour(), Behaviour.MessageTemplate(iqsi)) # Add P2P Behaviour self.p2p_ready = False # Actually ready for P2P communication self.p2p = p2p self.p2p_routes = {} self.p2p_lock = thread.allocate_lock() self.p2p_send_lock = thread.allocate_lock() self._p2p_failures = 0 # Counter for failed attempts to send p2p messages if p2p: agent.registerLogComponent("p2p") self.P2PPORT = random.randint(70000, 80000) # Random P2P port number p2pb = P2PBehaviour() agent.addBehaviour(p2pb)
def handle_iq(self, session, iq): children = iq.getChildren() # Respond to pings so server doesn't kick us if iq.getType() == 'get' and children and children[0].getName() == 'ping': response = Iq(to=iq.getFrom(), frm=iq.getTo(), typ='result') response.setID(iq.getID()) session.send(response) raise NodeProcessed
def send_vcard(self,conn, base64_img=None, mime_type=None, nick=None): iq_vcard = Iq(typ='set') vcard = iq_vcard.addChild(name='vCard', namespace=NS_VCARD) if nick is not None: vcard.addChild(name='NICKNAME', payload=[nick]) if base64_img is not None and mime_type is not None: photo = vcard.addChild(name='PHOTO') photo.setTagData(tag='TYPE', val=mime_type) photo.setTagData(tag='BINVAL', val=base64_img) conn.send(iq_vcard)
def __init__(self, agent): # , msgrecv): self._client = agent.getAID().getName() #self.msgrecv = msgrecv self.myAgent = agent self._server = agent.server agent.addBehaviour( RPCServerBehaviour(), Behaviour.MessageTemplate(Iq(typ='set', queryNS=NS_RPC)))
def onEnd(self): self.myAgent._P2P.p2p_ready = False if self.server is not None: self.server.server_close() # shutdown() if not self.finished: try: for sock in self.server.requests: try: sock.close() del sock except: pass self.server.socket.close() #del self.server except: pass iq = Iq("result", queryNS=NS_DISCO_INFO) for to in self.myAgent._P2P.p2p_routes.keys(): iq.setTo(to) self.myAgent.send(iq) self.finished = True