コード例 #1
0
	def handle_relay_connected_cell(self, cell_bytes, direction):
		"""
		Function for handling the connected cell when it is received by a router
		:param cell_bytes: The struct received by the router for the connected cell
		"""
		parsed_connected_cell = Parser.parse_encoded_connected_cell(cell_bytes)
		processed_connected_cell = Processor.process_connected_cell_router(parsed_connected_cell, self.session_key)
		self.conn.sendall(ComplexStructEncoder.encode(processed_connected_cell))
		return
コード例 #2
0
    def begin_end_destination_stream(self, ip_addr: str, port: int = 80):

        addrport = pack('!IH', int(ip_address(ip_addr)), port)
        flag_dict = {
            'IPV6_PREF': 0,
            'IPV4_NOT_OK': 0,
            'IPV6_OK': 1
        }  # Need to set the flag according to the spec. But for now its fine

        # Build a begin cell to send to the exit node
        begin_cell = Builder.build_begin_cell(addrport, flag_dict,
                                              self.circ_id, 0, 1,
                                              self.session_key01,
                                              self.session_key02,
                                              self.session_key03)

        # Send the begin cell down the first hop
        # Sending a JSON String down the socket
        self.skt.client_send_data(ComplexStructEncoder.encode(begin_cell))

        # Wait for the relay_connected cell to arrive
        # Get the relay_connected cell in response and convert it to python Cell Object
        cell_bytes = self.skt.client_recv_data()
        relay_connected_cell_parsed = Parser.parse_encoded_connected_cell(
            cell_bytes)
        relay_connected_cell = Processor.process_connected_cell_proxy(
            relay_connected_cell_parsed, self.session_key01,
            self.session_key02, self.session_key03)

        print(vars(relay_connected_cell))
        print(vars(relay_connected_cell.PAYLOAD))
        print(vars(relay_connected_cell.PAYLOAD.Data))
        if relay_connected_cell is not None:
            return 0
        else:
            return -1