Exemple #1
0
    def handle_packets(self, packet_id, packet):
        '''Handle actions depending on the ID of the packet.'''
        if packet_id in packets_by_id: # Known packet type?
            packet_id = packets_by_id[packet_id]
        else: # The packet has an unknown ID
            reason = 'Invalid packetId: %i' % packet_id
            libs.events.broadcast('logthis', 'Invalid packet: %s' %packet_id)
            disc = make_packet('Disconnect',reasonType='Custom',
                               reason=reason,reasonlength=len(reason))
            self.send(disc)
            return

        # Take acctions depending on the type of packet
        if packet_id == 'ConnectionRequest':
            print('sending acceptConnection')
            #self.connected = True
            accept_connection = make_packet('AcceptConnection', int=1)
            self.send(accept_connection, 1)
            print('acceptConnection sent')

        elif packet_id == 'AcceptConnection':
            print('got acceptConnection')
            self.connected = True

        elif packet_id == 'Message':
            libs.events.broadcast('got_message', packet)

        else:
            print packet_id, packet
Exemple #2
0
 def beginHandshake(self):
     connectionRequest = libs.packets.packets[0]
     ip = "192.168.1.104"
     key="5416435343454"
     # encryptionmethod = "aes"
     packet = make_packet("ConnectionRequest", encryptionmethod="rsa",ip=ip,
                        iplength = len(ip), key = key, keylength = len(key))
     self.send(packet)
Exemple #3
0
 def _begin_handshake(self):
     print 'shaking hands'
     ip = self.ip     # not sure what ip and key we need here?
     key=self.keyid   # ours or the friends?
     # encryptionmethod = "aes"
     packet = make_packet("ConnectionRequest", encryptionmethod="rsa",ip=ip,
                        iplength = len(ip), key = key, keylength = len(key))
     self.send(packet)
Exemple #4
0
    def send_message(self,message):
        '''Sends a Text message to a friend'''
        keyid = self.keyid
        keyidlength = len(keyid)
        tstamp = time.time()
        messagelength = len(message)

        pack = make_packet("Message",to_node_length = keyidlength, to_node = keyid,
                            timestamp = tstamp, message_length = messagelength,
                            message = message)

        self.send(pack)