Ejemplo n.º 1
0
    def read_response(self, stream: IngressStream):
        if (stream.read(2) != b"OK"):
            raise IOError("Peer returned bad response")

        size = struct.unpack("!I", stream.read(4))[0]
        data = stream.read(size)
        stream.close()
        return data
Ejemplo n.º 2
0
        def read_response(stream: IngressStream):
            response = PathResponse.deserialise(stream)
            stream.close()

            # Prepend hop to respondant repeater
            # TODO these flags may need to be looked at some more or the 
            # PathNode object redesigned
            # HACK we should probably just get some sort of full representation
            # from the RPP repeater we ask the path from, but can't at the moment as we require peer info
            response.nodes.insert(0, PathNode.PathNode(stream.origin, PathNode.FLAGS_NONE, self.__muxer.get_peer_info(stream.origin)))

            # TODO generate many possible strategies
            return [PathStrategy(PathInfo([x.instance for x in response.nodes]), response.nodes[0].peer_info),]
Ejemplo n.º 3
0
    def __rx_stream(self, stream: IngressStream):
        # Figure out what data follows
        following = stream.read(1)

        if (following == DATA_FOLLOWING_ANSWER
                and CAPABILITY_QUERY_ANSWER in self.__capabilities):
            self.__handle_answer(stream)

        elif (following == DATA_FOLLOWING_QUERY
              and CAPABILITY_QUERY_ANSWER in self.__capabilities):
            self.__handle_query(stream)

        elif (following == DATA_FOLLOWING_REQUEST):
            self.__handle_request(stream)

        else:
            stream.close()